1+ #=
2+ ([source code](SOURCE_URL))
3+
4+ minimalistic script, that solves a stochastic Poisson problem on a uniform mesh
5+
6+ usage:
7+ - run main: main(; problem = problem, kwargs...)
8+ =#
9+
10+ module PoissonSimple
11+
12+ using ExtendableASGFEM
13+ using ExtendableFEM
14+ using ExtendableFEMBase
15+ using ExtendableGrids
16+ using GridVisualize
17+
18+ function main (;
19+ problem = PoissonProblemPrimal,
20+ nrefs = 4 , # number of uniform refinements of the initial grid
21+ order = 2 , # polynomial order of the FEspaces
22+ decay = 2.0 , # decay factor for the random coefficient
23+ mean = problem == PoissonProblemPrimal ? 1.0 : 0.0 , # mean value of coefficient
24+ domain = " square" , # domain, e.g., "square" or "lshape"
25+ initial_modes = [[0 ], [1 ,0 ], [0 ,1 ], [0 ,0 ,1 ]], # initial multi-indices for stochastic basis
26+ f! = (result, qpinfo) -> (result[1 ] = 1 ), # right-hand side function
27+ use_iterative_solver = true , # use iterative solver ? (otherwise direct)
28+ Plotter = nothing )
29+
30+ # # prepare stochastic coefficient
31+ τ = (problem <: PoissonProblemPrimal ) ? 0.9 : 1.0
32+ if problem <: PoissonProblemPrimal
33+ @assert mean >= 1 " coefficient needs to be at least 1 to ensure ellipticity"
34+ end
35+ C = StochasticCoefficientCosinus (; τ = τ, decay = decay, mean = mean)
36+
37+ # # prepare grid
38+ xgrid = if domain == " square"
39+ uniform_refine (grid_unitsquare (Triangle2D), nrefs)
40+ elseif domain == " lshape"
41+ uniform_refine (grid_lshape (Triangle2D), nrefs)
42+ else
43+ error (" unknown domain: $domain " )
44+ end
45+
46+ # # prepare stochastic basis
47+ multi_indices = Array {Array{Int,1},1} (initial_modes)
48+ prepare_multi_indices! (multi_indices)
49+ M = maximum (length .(multi_indices))
50+ OBType = problem <: PoissonProblemPrimal ? LegendrePolynomials : HermitePolynomials
51+ ansatz_deg = maximum ([maximum (multi_indices[k]) for k in 1 : length (multi_indices)]) + 4
52+ TensorBasis = TensorizedBasis (OBType, M, ansatz_deg, 2 * ansatz_deg, 2 * ansatz_deg, multi_indices = multi_indices)
53+
54+ # # prepare FE spaces
55+ if problem <: LogTransformedPoissonProblemDual
56+ FEType = [HDIVRTk{2 ,order}, order == 0 ? L2P0{1 } : H1Pk{1 ,2 ,order}]
57+ FES = [FESpace {FEType[1]} (xgrid), FESpace {FEType[2]} (xgrid; broken = true )]
58+ unames = [" p" , " u" ]
59+ else
60+ FEType = H1Pk{1 ,2 ,order}
61+ FES = FESpace {FEType} (xgrid)
62+ unames = [" u" ]
63+ end
64+
65+ # # create solution vector
66+ sol = SGFEVector (FES, TensorBasis; active_modes = 1 : length (multi_indices), unames = unames)
67+
68+ # # solve problem
69+ @info " Solving..."
70+ solve! (problem, sol, C; rhs = f!, use_iterative_solver = use_iterative_solver)
71+
72+ # # plot solution
73+ if ! isnothing (Plotter)
74+ p = plot_modes (sol; Plotter = Plotter, ncols = 4 )
75+ display (p)
76+ end
77+
78+ return sol, xgrid
79+ end
80+
81+ end # module
0 commit comments