Skip to content

Commit 7a8a674

Browse files
author
chmerdon
committed
added error calculation to simple script
1 parent 33bf00d commit 7a8a674

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

scripts/poisson_simple.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ using GridVisualize
1717

1818
function main(;
1919
problem = PoissonProblemPrimal,
20-
nrefs = 4, # number of uniform refinements of the initial grid
20+
nrefs = 3, # number of uniform refinements of the initial grid
2121
order = 2, # polynomial order of the FEspaces
2222
decay = 2.0, # decay factor for the random coefficient
2323
mean = problem == PoissonProblemPrimal ? 1.0 : 0.0, # mean value of coefficient
2424
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
25+
initial_modes = [[0], [1,0], [0,1], [2,0], [0,0,1]], # initial multi-indices for stochastic basis
2626
f! = (result, qpinfo) -> (result[1] = 1), # right-hand side function
2727
use_iterative_solver = true, # use iterative solver ? (otherwise direct)
2828
Plotter = nothing)
@@ -69,13 +69,20 @@ function main(;
6969
@info "Solving..."
7070
solve!(problem, sol, C; rhs = f!, use_iterative_solver = use_iterative_solver)
7171

72+
## compute exact error (by MC sampling)
73+
weightederrorH1, weightederrorL2, uniformerrorH1, uniformerrorL2 = calculate_sampling_error(sol, C; problem = problem, rhs = f!, order = order + 1, nsamples = 50)
74+
7275
## plot solution
7376
if !isnothing(Plotter)
7477
p = plot_modes(sol; Plotter = Plotter, ncols = 4)
7578
display(p)
7679
end
7780

78-
return sol, xgrid
81+
@info "RESULTS
82+
|| ∇(u-u_h) || (w,u) = $(sqrt(weightederrorH1[end])), $(sqrt(uniformerrorH1[end]))
83+
|| u - u_h || (w,u) = $(sqrt(weightederrorL2[end])), $(sqrt(uniformerrorL2[end]))"
84+
85+
return sol
7986
end
8087

8188
end # module

src/sampling_error.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function calculate_sampling_error(
9292
dim = size(SolutionSGFEM.FES_space[1].xgrid[Coordinates], 1),
9393
Msamples = maxm(C),
9494
parallel_sampling = true,
95-
dimensionwise_error = false,
95+
dimensionwise_error = true,
9696
energy_norm = true,
9797
debug = false,
9898
nsamples = 100
@@ -122,7 +122,7 @@ function calculate_sampling_error(
122122

123123
## solve problem for the current sample
124124
FESSampling = FES4sampling(problem, dim, xgrid, order)
125-
sol_det[s] = ExtendableFEM.solve(PD, FESSampling; verbosity = debug ? 0 : -1)
125+
sol_det[s] = ExtendableFEM.solve(PD, FESSampling; verbosity = debug ? 0 : -1, timeroutputs = :none)
126126

127127
print(".")
128128
end

0 commit comments

Comments
 (0)