Skip to content

Commit ae8bbca

Browse files
author
chmerdon
committed
improved documentation
1 parent 811a7c5 commit ae8bbca

6 files changed

Lines changed: 159 additions & 45 deletions

File tree

Project.toml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,66 @@
11
name = "ExtendableASGFEM"
22
uuid = "a4750d0b-645d-4217-869c-e25952806e24"
3+
version = "1.0.0"
34
authors = ["Christian Merdon <merdon@wias-berlin.de>", "Martin Eigel <martin.eigel@wias-berlin.de>"]
4-
version = "1.0"
55

66
[deps]
7+
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
8+
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
79
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
810
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
911
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
12+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
13+
DrWatson = "634d3b9d-ee7a-5ddf-bec9-22491ea816e1"
1014
ExtendableFEM = "a722555e-65e0-4074-a036-ca7ce79a4aed"
1115
ExtendableFEMBase = "12fb9182-3d4c-4424-8fd1-727a0899810c"
1216
ExtendableGrids = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
1317
ExtendableSparse = "95c220a8-a1cf-11e9-0c77-dbfce5f500b3"
1418
GridVisualize = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
1519
IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153"
1620
Krylov = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7"
21+
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
1722
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1823
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1924
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2025
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2126
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2227
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
28+
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
2329

2430
[compat]
25-
ExplicitImports = "1"
2631
Aqua = "0.8"
32+
CairoMakie = "0.13.10"
33+
DataFrames = "1.8.1"
2734
Distributed = "1.9"
2835
Distributions = "0.25.120"
2936
DocStringExtensions = "0.9.4"
37+
Documenter = "1.15.0"
3038
DoubleFloats = "1.4.3"
31-
Krylov = "0.10.1"
32-
LinearAlgebra = "1.9"
39+
DrWatson = "2.19.1"
40+
ExplicitImports = "1"
3341
ExtendableFEM = "1.3"
3442
ExtendableFEMBase = "1.3"
3543
ExtendableGrids = "1.13"
3644
ExtendableSparse = "1.7"
3745
GridVisualize = "1.12"
3846
IterativeSolvers = "0.9.2"
47+
Krylov = "0.10.1"
48+
LaTeXStrings = "1.4.0"
49+
LinearAlgebra = "1.9"
3950
Printf = "1.9"
4051
Random = "1.9"
4152
SparseArrays = "1.9"
4253
SpecialFunctions = "2.5.1"
4354
StaticArrays = "1.9.13"
4455
Test = "1.9"
56+
UnicodePlots = "3.8.1"
4557
julia = "^1.9"
4658

47-
4859
[extras]
4960
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
61+
DoubleFloats = "497a8b3b-efae-58df-a0af-a86822472b78"
5062
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
5163
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
52-
DoubleFloats = "497a8b3b-efae-58df-a0af-a86822472b78"
53-
5464

5565
[targets]
5666
test = ["Aqua", "ExplicitImports", "DoubleFloats", "Test"]

docs/make.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ makedocs(
2828
"Plotting" => [
2929
"plots.md",
3030
]
31+
"Scripts" => [
32+
"poisson_script.md",
33+
]
3134
],
3235
)
3336

docs/src/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ This package provides an implementation of the stochastic Galerkin finite elemen
44

55
Spatial discretization is performed using the finite element packages [ExtendableFEM.jl](https://github.com/WIAS-PDELib/ExtendableFEM.jl) and [ExtendableFEMBase.jl](https://github.com/WIAS-PDELib/ExtendableFEMBase.jl).
66

7+
8+
## Example Script
9+
10+
A script for running adaptive SGFEM experiments is provided in `scripts/poisson.jl`. It supports:
11+
- Poisson problem with linear coefficient
12+
- Log-transformed Poisson problem with exponential coefficient
13+
- Dual formulation of the log-transformed problem (WIP)
14+
15+
The script handles both spatial and stochastic adaptivity, and includes tools for result visualization and error analysis. For a detailed description of all available parameters and usage instructions, see [Script Documentation](poisson_script.md).
16+
17+
18+
719
## References
820

921
- [1] "Adaptive stochastic Galerkin FEM"

docs/src/poisson_script.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Script on Poisson Problems
2+
3+
The script `scripts/poisson.jl` provides an implementation of adaptive stochastic Galerkin FEM for various formulations of the parametric Poisson problem.
4+
5+
## Available Problem Types
6+
7+
- `PoissonProblemPrimal`: Standard Poisson problem with linear coefficient `a`
8+
- `LogTransformedPoissonProblemPrimal`: Log-transformed Poisson problem with exponential coefficient `exp(a)`
9+
- `LogTransformedPoissonProblemDual`: Dual formulation of the log-transformed problem (WIP)
10+
11+
## Usage
12+
13+
The main function to run experiments is:
14+
```julia
15+
run(; problem = problem_type, kwargs...)
16+
```
17+
18+
Results can be loaded and visualized using:
19+
```julia
20+
show_results(; kwargs...) # show results and statistics
21+
produce_plots(; kwargs...) # generate convergence and other plots
22+
```
23+
24+
## Parameters
25+
26+
The following parameters can be specified (with their defaults):
27+
28+
### Problem Configuration
29+
- `problem = LogTransformedPoissonProblemPrimal`: Problem type to solve
30+
- `domain = "square"`: Domain shape ("square" or "lshape")
31+
- `order = 1`: Polynomial order of finite elements
32+
- `initial_refs = 1`: Initial uniform mesh refinements
33+
34+
### Stochastic Parameters
35+
- `C = StochasticCoefficientCosinus`: Type of stochastic coefficient
36+
- `decay = 2`: Decay rate of the coefficient expansion
37+
- `mean = 0`: Mean value of the coefficient
38+
- `maxm = 150`: Maximum number of terms in coefficient expansion
39+
- `initial_modes = [[0]]`: Initial active stochastic modes
40+
41+
### Adaptive Parameters
42+
- `θ_stochastic = 0.5`: Marking parameter for stochastic refinement
43+
- `θ_spatial = 0.5`: Marking parameter for spatial refinement
44+
- `factor_tail = 1`: Factor for tail estimator comparison
45+
- `tail_extension = [10, 2]`: Extension parameters for [0] mode and others
46+
- `maxdofs = 1.0e4`: Maximum degrees of freedom
47+
- `nsamples = 150`: Number of samples for error computation
48+
- `use_equilibration_estimator = false`: Use equilibration error estimator instead of standard residual estimator
49+
50+
### Solver Options
51+
- `use_iterative_solver = true`: Use iterative solver (instead of a direct solver with full matrix)
52+
- `bonus_quadorder_a = 2`: Additional quadrature order for coefficient
53+
- `bonus_quadorder_f = 0`: Additional quadrature order for right-hand side
54+
55+
### Right-Hand Side
56+
- `f = (result, qpinfo) -> (result[1] = 1)`: Right-hand side function
57+
58+
### Visualization
59+
- `Plotter = nothing`: Plotting backend (e.g., CairoMakie)
60+
61+
## Results Storage
62+
63+
Results are automatically stored using [DrWatson.jl](https://github.com/JuliaDynamics/DrWatson.jl) in the `data` folder. The filename includes most problem parameters for reproducibility:
64+
65+
```
66+
data/[problem]/[domain]/order=[order]_maxdofs=[maxdofs]_decay=[decay]_mean=[mean]_θ=([θ_spatial],[θ_stochastic])_tail=[tail_extension]
67+
```
68+
69+
If the equilibration estimator is used, `_eq` is appended to the filename.

scripts/poisson.jl

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
runs AFEM loop for stochastic Poisson problem
66
7-
main usage:
7+
usage:
88
- run experiment: run(; problem = problem, kwargs...)
99
- load results : show_results(; kwargs...)
1010
- produce plots : produce_plots(; kwargs...)
@@ -78,6 +78,42 @@ default_args = Dict(
7878
)
7979

8080

81+
## that is the main function to run and save results
82+
function run(; force = false, kwargs...)
83+
data = deepcopy(default_args)
84+
85+
for (k, v) in kwargs
86+
data[String(k)] = v
87+
end
88+
Plotter = data["Plotter"]
89+
90+
## load/produce data
91+
data, ~ = produce_or_load(_main, data, filename = filename, force = force)
92+
93+
## plot final solution
94+
results = data["results"]
95+
sol = data["solution"]
96+
multi_indices = data["multi_indices"]
97+
repair_grid!(sol.FES_space[1].xgrid)
98+
if Plotter === nothing
99+
for j in 1:num_multiindices(sol)
100+
@show extrema(view(sol[j]))
101+
println(stdout, unicode_scalarplot(sol[j]; title = "MI $(multi_indices[j])"))
102+
end
103+
else
104+
plot_modes(sol; Plotter = Plotter, ncols = 4)
105+
end
106+
107+
@info "final multi_indices = "
108+
for m in multi_indices
109+
println("$m")
110+
end
111+
@show results
112+
return data
113+
end
114+
115+
116+
# loads (or produces) a result file and prints the data
81117
function show_results(; force = false, mode_history_up_to_level = 15, kwargs...)
82118
data = deepcopy(default_args)
83119

@@ -113,8 +149,9 @@ function show_results(; force = false, mode_history_up_to_level = 15, kwargs...)
113149
return data
114150
end
115151

116-
117-
function main(
152+
# the main AFEM loop for the given problem and data
153+
# (this function does not check for existing results, better use run !)
154+
function _main(
118155
data = nothing;
119156
debug = false,
120157
plot_solution = false,
@@ -396,40 +433,6 @@ function main(
396433
end
397434

398435

399-
function run(; force = false, kwargs...)
400-
data = deepcopy(default_args)
401-
402-
for (k, v) in kwargs
403-
data[String(k)] = v
404-
end
405-
Plotter = data["Plotter"]
406-
407-
## load/produce data
408-
data, ~ = produce_or_load(main, data, filename = filename, force = force)
409-
410-
## plot final solution
411-
results = data["results"]
412-
sol = data["solution"]
413-
multi_indices = data["multi_indices"]
414-
repair_grid!(sol.FES_space[1].xgrid)
415-
if Plotter === nothing
416-
for j in 1:num_multiindices(sol)
417-
@show extrema(view(sol[j]))
418-
println(stdout, unicode_scalarplot(sol[j]; title = "MI $(multi_indices[j])"))
419-
end
420-
else
421-
plot_modes(sol; Plotter = Plotter, ncols = 4)
422-
end
423-
424-
@info "final multi_indices = "
425-
for m in multi_indices
426-
println("$m")
427-
end
428-
@show results
429-
return data
430-
end
431-
432-
433436
function produce_plots(;
434437
order = default_args["order"],
435438
decay = default_args["decay"],

src/modelproblems/logpoisson_dual.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
"""
22
$(TYPEDEF)
33
4-
Dual log-transformed formulation of the Poisson problem with exponential stochastic coefficient (WIP).
4+
5+
Poisson problem with exponential stochastic coefficient ``e^a`` that seeks ``u`` such that
6+
7+
``-\\mathrm{div}(e^a(y,x) \\nabla u(y,x)) = f(x) \\quad \\text{for } (y,x) \\in \\Gamma \\times D``
8+
9+
The dual formulation of the log-transformed formulation of the Poisson problem
10+
introduces the auxiliary stress variable ``p := - e^a(y,x) \\nabla u(y,x) = -∇ũ - ∇aũ`` for the transformed
11+
``ũ := e^{-a} u``.
12+
13+
Its weak formulation seeks ``(p,ũ)`` such that
14+
15+
```math
16+
\\begin{aligned}
17+
(p, q) + (ũ \\nabla a, q) - (\\mathrm{div}(q), ũ) & = 0 \\quad \\text{for all } q \\\\
18+
-(\\mathrm{div}(p), v) & = (f, v) \\quad \\text{for all } v
19+
\\end{aligned}
20+
```
21+
522
"""
623
abstract type LogTransformedPoissonProblemDual <: AbstractModelProblem end
724

0 commit comments

Comments
 (0)