Skip to content

Commit 1057bf2

Browse files
update for PDEBase
1 parent 6ac47a1 commit 1057bf2

File tree

3 files changed

+114
-24
lines changed

3 files changed

+114
-24
lines changed

src/DiffEqProblemLibrary.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ __precompile__(false)
22

33
module DiffEqProblemLibrary
44

5-
using DiffEqBase, ParameterizedFunctions,
5+
using DiffEqBase, ParameterizedFunctions, DiffEqPDEBase,
66
FiniteElementDiffEq, AlgebraicDiffEq, JLD
77

88
include("ode_premade_problems.jl")
@@ -31,7 +31,11 @@ export prob_ode_linear, prob_ode_bigfloatlinear, prob_ode_2Dlinear,
3131
prob_stokes_homogenous, prob_stokes_dirichletzero, prob_poisson_birthdeathsystem,
3232
prob_poisson_birthdeathinteractingsystem, prob_femheat_birthdeathinteractingsystem,
3333
prob_femheat_birthdeathsystem, prob_femheat_diffusionconstants,
34-
heatProblemExample_grayscott,heatProblemExample_gierermeinhardt
34+
heatProblemExample_grayscott,heatProblemExample_gierermeinhardt,
35+
prob_femheat_stochasticbirthdeath_fast,prob_femheat_pure11,prob_femheat_moving7
36+
37+
38+
export cs_fempoisson_wave,cs_femheat_moving_dt,cs_femheat_moving_dx, cs_femheat_moving_faster_dt
3539

3640
#Example Meshes
3741
export meshExample_bunny, meshExample_flowpastcylindermesh, meshExample_lakemesh,

src/fem_premade_problems.jl

Lines changed: 107 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ f = (t,x) -> (-5).*exp.((-25).*((3/2)+6.*t.^2+x[:,1]+x[:,1].^2+x[:,2]+x[:,2].^2+
66
x[:,2]))).*((-20)+(-100).*t.^2+(-49).*x[:,1]+(-50).*x[:,1].^2+(-49).*x[:,2]+(-50).*
77
x[:,2].^2+2.*t.*(47+50.*x[:,1]+50.*x[:,2])+exp.(25.*(1+(-2).*t).^2).*(22+
88
100.*t.^2+49.*x[:,1]+50.*x[:,1].^2+49.*x[:,2]+50.*x[:,2].^2+(-2).*t.*(49+50.*x[:,1]+50.*x[:,2])))
9+
T = 2
10+
dx = 1//2^(3)
11+
dt = 1//2^(9)
12+
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
913
"""
1014
Example problem defined by the solution:
1115
```math
@@ -14,13 +18,45 @@ u(x,y,t)=\\frac{1}{10}(1-\\exp(-100(t-\\frac{1}{2})^2))\\exp(-25((x-t+0.5)^2 + (
1418
1519
This will have a mound which moves across the screen. Good animation test.
1620
"""
17-
prob_femheat_moving = HeatProblem(analytic_moving,Du,f)
18-
21+
prob_femheat_moving = HeatProblem(analytic_moving,Du,f,fem_mesh)
22+
23+
N = 2 #Number of different dt to solve at, 2 for test speed
24+
topdt = 6 # 1//2^(topdt-1) is the max dt. Small for test speed
25+
dts = 1.//2.^(topdt-1:-1:N)
26+
dxs = 1//2^(5) * ones(dts) #Run at 2^-7 for best plot
27+
probs = [HeatProblem(analytic_moving,Du,f,parabolic_squaremesh([0 1 0 1],dxs[i],dts[i],1,:dirichlet)) for i in eachindex(dts)]
28+
cs_femheat_moving_dt = ConvergenceSetup(probs,dts)
29+
dxs = 1//2^(4) * ones(dts) #Run at 2^-7 for best plot
30+
probs = [HeatProblem(analytic_moving,Du,f,parabolic_squaremesh([0 1 0 1],dxs[i],dts[i],1,:dirichlet)) for i in eachindex(dts)]
31+
cs_femheat_moving_faster_dt = ConvergenceSetup(probs,dts)
32+
33+
#Not good plots, but quick for unit tests
34+
dxs = 1.//2.^(2:-1:1)
35+
dts = 1//2^(6) * ones(dxs) #Run at 2^-7 for best plot
36+
probs = [HeatProblem(analytic_moving,Du,f,parabolic_squaremesh([0 1 0 1],dxs[i],dts[i],1,:dirichlet)) for i in eachindex(dts)]
37+
cs_femheat_moving_dx = ConvergenceSetup(probs,dxs)
38+
39+
T = 1
40+
dx = 1//2^(3)
41+
dt = 1//2^(7)
42+
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
43+
"""
44+
Example problem defined by the solution:
45+
```math
46+
u(x,y,t)=\\frac{1}{10}(1-\\exp(-100(t-\\frac{1}{2})^2))\\exp(-25((x-t+0.5)^2 + (y-t+0.5)^2))
47+
```
1948
49+
This will have a mound which moves across the screen. Good animation test.
50+
"""
51+
prob_femheat_moving7 = HeatProblem(analytic_moving,Du,f,fem_mesh)
2052

2153
analytic_diffuse(t,x) = exp.(-10((x[:,1]-.5).^2 + (x[:,2]-.5).^2 )-t)
2254
f = (t,x) -> exp.(-t-5*(1-2x[:,1]+2x[:,1].^2 - 2x[:,2] +2x[:,2].^2)).*(-161 + 400*(x[:,1] - x[:,1].^2 + x[:,2] - x[:,2].^2))
2355
Du = (t,x) -> -20[analytic_diffuse(t,x).*(x[:,1]-.5) analytic_diffuse(t,x).*(x[:,2]-.5)]
56+
T = 1
57+
dx = 1//2^(3)
58+
dt = 1//2^(7)
59+
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
2460
"""
2561
Example problem defined by the solution:
2662
@@ -30,48 +66,75 @@ u(x,y,t)=\\exp(-10((x-\\frac{1}{2})^2 + (y-\\frac{1}{2})^2 )-t)
3066
3167
This is a Gaussian centered at ``(\\frac{1}{2},\\frac{1}{2})`` which diffuses over time.
3268
"""
33-
prob_femheat_diffuse = HeatProblem(analytic_diffuse,Du,f)
69+
prob_femheat_diffuse = HeatProblem(analytic_diffuse,Du,f,fem_mesh)
3470

3571

3672
f = (t,x) -> zeros(size(x,1))
3773
u0 = (x) -> float((abs.(x[:,1]-.5) .< 1e-6) & (abs.(x[:,2]-.5) .< 1e-6)) #Only mass at middle of (0,1)^2
74+
T = 1//2^(5)
75+
dx = 1//2^(3)
76+
dt = 1//2^(9)
77+
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
3878
"""
3979
Example problem which starts with a Dirac δ cenetered at (0.5,0.5) and solves with ``f=gD=0``.
4080
This gives the Green's function solution.
4181
"""
42-
prob_femheat_pure = HeatProblem(u0,f)
82+
prob_femheat_pure = HeatProblem(u0,f,fem_mesh)
4383

84+
T = 1//2^(5)
85+
dt = 1//2^(11)
86+
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
87+
"""
88+
Example problem which starts with a Dirac δ cenetered at (0.5,0.5) and solves with ``f=gD=0``.
89+
This gives the Green's function solution.
90+
"""
91+
prob_femheat_pure11 = HeatProblem(u0,f,fem_mesh)
4492

4593
f = (t,x,u) -> ones(size(x,1)) - .5u
4694
u0 = (x) -> zeros(size(x,1))
95+
T = 1
96+
dx = 1//2^(3)
97+
dt = 1//2^(7)
98+
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
4799
"""
48100
Homogenous reaction-diffusion problem which starts with 0 and solves with ``f(u)=1-u/2``
49101
"""
50-
prob_femheat_birthdeath = HeatProblem(u0,f)
102+
prob_femheat_birthdeath = HeatProblem(u0,f,fem_mesh)
51103

52104

53105
f = (t,x,u) -> [ones(size(x,1))-.5u[:,1] ones(size(x,1))-u[:,2]]
54106
u0 = (x) -> ones(size(x,1),2).*[.5 .5] # size (x,2), 2 meaning 2 variables
107+
T = 5
108+
dx = 1/2^(1)
109+
dt = 1/2^(7)
110+
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
55111
"""
56112
Homogenous reaction-diffusion which starts at 1/2 and solves the system ``f(u)=1-u/2`` and ``f(v)=1-v``
57113
"""
58-
prob_femheat_birthdeathsystem = HeatProblem(u0,f)
114+
prob_femheat_birthdeathsystem = HeatProblem(u0,f,fem_mesh)
115+
116+
f = (t,x,u) -> [ones(size(x,1))-.5u[:,1] .5u[:,1]-u[:,2]]
117+
u0 = (x) -> ones(size(x,1),2).*[.5 .5] # size (x,2), 2 meaning 2 variables
118+
T = 5
119+
dx = 1/2^(1)
120+
dt = 1/2^(7)
121+
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
122+
"""
123+
Homogenous reaction-diffusion which starts with 1/2 and solves the system ``f(u)=1-u/2`` and ``f(v)=.5u-v``
124+
"""
125+
prob_femheat_birthdeathinteractingsystem = HeatProblem(u0,f,fem_mesh)
59126

127+
#=
60128
f = (t,x,u) -> [zeros(size(x,1)) zeros(size(x,1))]
61129
u0 = (x) -> [float((abs.(x[:,1]-.5) .< 1e-6) & (abs.(x[:,2]-.5) .< 1e-6)) float((abs.(x[:,1]-.5) .< 1e-6) & (abs.(x[:,2]-.5) .< 1e-6))] # size (x,2), 2 meaning 2 variables
62130
"""
63131
Example problem which solves the homogeneous Heat equation with all mass starting at (1/2,1/2) with two different diffusion constants,
64132
``D₁=0.01`` and ``D₂=0.001``. Good animation test.
65133
"""
66-
prob_femheat_diffusionconstants = HeatProblem(u0,f,D=[.01 .001])
67-
68-
f = (t,x,u) -> [ones(size(x,1))-.5u[:,1] .5u[:,1]-u[:,2]]
69-
u0 = (x) -> ones(size(x,1),2).*[.5 .5] # size (x,2), 2 meaning 2 variables
70-
"""
71-
Homogenous reaction-diffusion which starts with 1/2 and solves the system ``f(u)=1-u/2`` and ``f(v)=.5u-v``
72-
"""
73-
prob_femheat_birthdeathinteractingsystem = HeatProblem(u0,f)
134+
prob_femheat_diffusionconstants = HeatProblem(u0,f,fem_mesh,D=[.01 .001])
135+
=#
74136

137+
#=
75138
"""
76139
`heatProblemExample_grayscott(;ρ=.03,k=.062,D=[1e-3 .5e-3])`
77140
@@ -127,57 +190,79 @@ function heatProblemExample_gierermeinhardt(;a=1,α=1,D=[0.01 1.0],ubar=1,vbar=0
127190
u0(x) = [uss*ones(size(x,1))+startNoise*rand(size(x,1)) vss*ones(size(x,1))] # size (x,2), 2 meaning 2 variables
128191
return(HeatProblem(u0,f,D=D))
129192
end
193+
=#
130194

131195
f = (t,x,u) -> ones(size(x,1)) - .5u
132196
u0 = (x) -> zeros(size(x,1))
133197
σ = (t,x,u) -> 1u.^2
198+
T = 5
199+
dx = 1//2^(3)
200+
dt = 1//2^(5)
201+
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
134202
"""
135203
Homogenous stochastic reaction-diffusion problem which starts with 0
136204
and solves with ``f(u)=1-u/2`` with noise ``σ(u)=10u^2``
137205
"""
138-
prob_femheat_stochasticbirthdeath = HeatProblem(u0,f,σ=σ)
206+
prob_femheat_stochasticbirthdeath = HeatProblem(u0,f,fem_mesh,σ=σ)
207+
208+
dx = 1//2^(1)
209+
dt = 1//2^(1)
210+
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
211+
prob_femheat_stochasticbirthdeath_fast = HeatProblem(u0,f,fem_mesh,σ=σ)
139212

140213
## Poisson
141214

142215
f = (x) -> sin.(2π.*x[:,1]).*cos.(2π.*x[:,2])
143216
analytic = (x) -> sin.(2π.*x[:,1]).*cos.(2π.*x[:,2])/(8π*π)
144217
Du = (x) -> [cos.(2*pi.*x[:,1]).*cos.(2*pi.*x[:,2])./(4*pi) -sin.(2π.*x[:,1]).*sin.(2π.*x[:,2])./(4π)]
218+
dx = 1//2^(5)
219+
fem_mesh = notime_squaremesh([0 1 0 1],dx,:dirichlet)
145220
"""
146221
Problem defined by the solution: ``u(x,y)= \\sin(2πx)\\cos(2πy)/(8π^2)``
147222
"""
148-
prob_poisson_wave = PoissonProblem(f,analytic,Du)
223+
prob_poisson_wave = PoissonProblem(f,analytic,Du,fem_mesh)
224+
225+
dxs = 1.//2.^(4:-1:2) # 4 for testing, use 7 for good graph
226+
probs = [PoissonProblem(f,analytic,Du,notime_squaremesh([0 1 0 1],dx,:dirichlet)) for dx in dxs]
227+
cs_fempoisson_wave = ConvergenceSetup(probs,dts)
149228

150229
σ = (x) -> 5 #Additive noise
230+
dx = 1//2^(5)
231+
fem_mesh = notime_squaremesh([0 1 0 1],dx,:dirichlet)
151232
"""
152233
Problem with deterministic solution: ``u(x,y)= \\sin(2πx)\\cos(2πy)/(8π^2)``
153234
and additive noise ``σ(x,y)=5``
154235
"""
155-
prob_poisson_noisywave = PoissonProblem(f,analytic,Du,σ=σ)
236+
prob_poisson_noisywave = PoissonProblem(f,analytic,Du,fem_mesh,σ=σ)
156237

157238
f = (x,u) -> ones(size(x,1)) - .5u
239+
dx = 1//2^(3)
240+
fem_mesh = notime_squaremesh([0 1 0 1],dx,:neumann)
158241
"""
159242
Nonlinear Poisson equation with ``f(u)=1-u/2``.
160243
Corresponds to the steady state of a humogenous reaction-diffusion equation
161244
with the same ``f``.
162245
"""
163-
prob_poisson_birthdeath = PoissonProblem(f,numvars=1)
246+
prob_poisson_birthdeath = PoissonProblem(f,fem_mesh,numvars=1)
164247

165248
f = (x,u) -> [ones(size(x,1))-.5u[:,1] ones(size(x,1))-u[:,2]]
166249
u0 = (x) -> .5*ones(size(x,1),2) # size (x,2), 2 meaning 2 variables
167-
250+
dx = 1//2^(1)
251+
fem_mesh = notime_squaremesh([0 1 0 1],dx,:neumann)
168252
"""
169253
Nonlinear Poisson equation with ``f(u)=1-u/2`` and ``f(v)=1-v`` and initial
170254
condition homogenous 1/2. Corresponds to the steady state of a humogenous
171255
reaction-diffusion equation with the same ``f``.
172256
"""
173-
prob_poisson_birthdeathsystem = PoissonProblem(f,u0=u0)
257+
prob_poisson_birthdeathsystem = PoissonProblem(f,fem_mesh,u0=u0)
174258

175259
f = (x,u) -> [ones(size(x,1))-.5u[:,1] .5u[:,1]-u[:,2]]
176260
u0 = (x) -> ones(size(x,1),2).*[.5 .5] # size (x,2), 2 meaning 2 variables
177-
261+
dx = 1//2^(1)
262+
fem_mesh = notime_squaremesh([0 1 0 1],dx,:neumann)
178263
"""
179264
Nonlinear Poisson equation with ``f(u)=1-u/2`` and ``f(v)=.5u-v`` and initial
180265
condition homogenous 1/2. Corresponds to the steady state of a humogenous
181266
reaction-diffusion equation with the same ``f``.
182267
"""
183-
prob_poisson_birthdeathinteractingsystem = PoissonProblem(f,u0=u0)
268+
prob_poisson_birthdeathinteractingsystem = PoissonProblem(f,fem_mesh,u0=u0)

src/premade_meshes.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
###Example Meshes
3+
34
pkgdir = dirname(@__FILE__)
45
meshes_location = "premade_meshes.jld"
56
"`meshExample_bunny()` : Returns a 3D SimpleMesh."

0 commit comments

Comments
 (0)