Skip to content

Commit cbc5f4c

Browse files
Merge pull request #541 from xtalax/mol
MOL move to analytic errors for burgers
2 parents 14b7c8d + 53b54f4 commit cbc5f4c

File tree

3 files changed

+155
-241
lines changed

3 files changed

+155
-241
lines changed

benchmarks/MethodOfLinesPDE/MOL_fdm.jl

Lines changed: 0 additions & 232 deletions
This file was deleted.
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
---
2+
title: Burgers FDM Work-Precision Diagrams with Various MethodOfLines Methods
3+
author: Alex Jones
4+
---
5+
6+
This benchmark is for the MethodOfLines package, which is an automatic PDE discretization package.
7+
It is concerned with comparing the performance of various discretization methods for the Burgers equation.
8+
9+
```julia
10+
using MethodOfLines, DomainSets, OrdinaryDiffEq, ModelingToolkit, DiffEqDevTools, LinearAlgebra,
11+
LinearSolve, Plots
12+
```
13+
14+
Here is the burgers equation with a Dirichlet and Neumann boundary conditions,
15+
16+
```julia
17+
# pdesys1 has Dirichlet BCs, pdesys2 has Neumann BCs
18+
const N = 30
19+
20+
@parameters x t
21+
@variables u(..)
22+
Dx = Differential(x)
23+
Dt = Differential(t)
24+
x_min = 0.0
25+
x_max = 1.0
26+
t_min = 0.0
27+
t_max = 20.0
28+
29+
solver = FBDF()
30+
31+
analytic_u(t, x) = x / (t + 1)
32+
33+
analytic = [u(t, x) => analytic_u]
34+
35+
eq = Dt(u(t, x)) ~ -u(t, x) * Dx(u(t, x))
36+
37+
bcs1 = [u(0, x) ~ x,
38+
u(t, x_min) ~ analytic_u(t, x_min),
39+
u(t, x_max) ~ analytic_u(t, x_max)]
40+
41+
bcs2 = [u(0, x) ~ x,
42+
Dx(u(t, x_min)) ~ 1 / (t + 1),
43+
Dx(u(t, x_max)) ~ 1 / (t + 1)]
44+
45+
domains = [t ∈ Interval(t_min, t_max),
46+
x ∈ Interval(x_min, x_max)]
47+
48+
@named pdesys1 = PDESystem(eq, bcs1, domains, [t, x], [u(t, x)])
49+
@named pdesys2 = PDESystem(eq, bcs2, domains, [t, x], [u(t, x)])
50+
```
51+
52+
Here is a uniform discretization with the Upwind scheme:
53+
54+
```julia
55+
discupwind1 = MOLFiniteDifference([x => N], t, advection_scheme=UpwindScheme())
56+
discupwind2 = MOLFiniteDifference([x => N-1], t, advection_scheme=UpwindScheme(), grid_align=edge_align)
57+
```
58+
59+
Here is a uniform discretization with the WENO scheme:
60+
61+
```julia
62+
discweno1 = MOLFiniteDifference([x => N], t, advection_scheme=WENOScheme())
63+
discweno2 = MOLFiniteDifference([x => N-1], t, advection_scheme=WENOScheme(), grid_align=edge_align)
64+
```
65+
66+
Here is a non-uniform discretization with the Upwind scheme, using tanh (nonuniform WENO is not implemented yet):
67+
68+
```julia
69+
gridf(x) = tanh.(x) ./ 2 .+ 0.5
70+
gridnu1 = gridf(vcat(-Inf, range(-3.0, 3.0, length=N-2), Inf))
71+
gridnu2 = gridf(vcat(-Inf, range(-3.0, 3.0, length=N - 3), Inf))
72+
73+
discnu1 = MOLFiniteDifference([x => gridnu1], t, advection_scheme=UpwindScheme())
74+
discnu2 = MOLFiniteDifference([x => gridnu2], t, advection_scheme=UpwindScheme(), grid_align=edge_align)
75+
```
76+
77+
Here are the problems for pdesys1:
78+
79+
```julia
80+
probupwind1 = discretize(pdesys1, discupwind1; analytic=analytic)
81+
probupwind2 = discretize(pdesys1, discupwind2; analytic=analytic)
82+
83+
probweno1 = discretize(pdesys1, discweno1; analytic=analytic)
84+
probweno2 = discretize(pdesys1, discweno2; analytic=analytic)
85+
86+
probnu1 = discretize(pdesys1, discnu1; analytic=analytic)
87+
probnu2 = discretize(pdesys1, discnu2; analytic=analytic)
88+
89+
probs1 = [probupwind1, probupwind2, probnu1, probnu2, probweno1, probweno2]
90+
```
91+
92+
## Work-Precision Plot for Burgers Equation, Dirichlet BCs
93+
94+
```julia
95+
dummy_appxsol = [nothing for i in 1:length(probs1)]
96+
abstols = 1.0 ./ 10.0 .^ (5:8)
97+
reltols = 1.0 ./ 10.0 .^ (1:4);
98+
setups = [Dict(:alg => solver, :prob_choice => 1),
99+
Dict(:alg => solver, :prob_choice => 2),
100+
Dict(:alg => solver, :prob_choice => 3),
101+
Dict(:alg => solver, :prob_choice => 4),
102+
Dict(:alg => solver, :prob_choice => 5),
103+
Dict(:alg => solver, :prob_choice => 6),]
104+
names = ["Uniform Upwind, center_align", "Uniform Upwind, edge_align", "Nonuniform Upwind, center_align",
105+
"Nonuniform Upwind, edge_align", "WENO, center_align", "WENO, edge_align"];
106+
107+
wp = WorkPrecisionSet(probs1, abstols, reltols, setups; names=names,
108+
save_everystep=false, appxsol = dummy_appxsol, maxiters=Int(1e5),
109+
numruns=10, wrap=Val(false))
110+
plot(wp)
111+
```
112+
113+
Here are the problems for pdesys2:
114+
115+
```julia
116+
probupwind1 = discretize(pdesys2, discupwind1; analytic=analytic)
117+
probupwind2 = discretize(pdesys2, discupwind2; analytic=analytic)
118+
119+
probweno1 = discretize(pdesys2, discweno1; analytic=analytic)
120+
probweno2 = discretize(pdesys2, discweno2; analytic=analytic)
121+
122+
probnu1 = discretize(pdesys2, discnu1; analytic=analytic)
123+
probnu2 = discretize(pdesys2, discnu2; analytic=analytic)
124+
125+
probs2 = [probupwind1, probupwind2, probnu1, probnu2, probweno1, probweno2]
126+
```
127+
128+
## Work-Precision Plot for Burgers Equation, Neumann BCs
129+
130+
```julia
131+
abstols = 1.0 ./ 10.0 .^ (5:8)
132+
reltols = 1.0 ./ 10.0 .^ (1:4);
133+
setups = [Dict(:alg => solver, :prob_choice => 1),
134+
Dict(:alg => solver, :prob_choice => 2),
135+
Dict(:alg => solver, :prob_choice => 3),
136+
Dict(:alg => solver, :prob_choice => 4),
137+
Dict(:alg => solver, :prob_choice => 5),
138+
Dict(:alg => solver, :prob_choice => 6),]
139+
names = ["Uniform Upwind, center_align", "Uniform Upwind, edge_align", "Nonuniform Upwind, center_align",
140+
"Nonuniform Upwind, edge_align", "WENO, center_align", "WENO, edge_align"];
141+
142+
wp = WorkPrecisionSet(probs2, abstols, reltols, setups; names=names,
143+
save_everystep=false, maxiters=Int(1e5),
144+
numruns=10, wrap=Val(false))
145+
plot(wp)
146+
```

0 commit comments

Comments
 (0)