Skip to content

Commit 03ce773

Browse files
Add premades
1 parent fcf3d78 commit 03ce773

9 files changed

+915
-3
lines changed

REQUIRE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
julia 0.5
2+
ParameterizedFunctions
3+
OrdinaryDiffEq
4+
StochasticDiffEq
5+
FiniteElementDiffEq
6+
JLD

src/DiffEqProblemLibrary.jl

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
module DiffEqProblemLibrary
22

3-
# package code goes here
3+
using OrdinaryDiffEq, StochasticDiffEq, ParameterizedFunctions,
4+
FiniteElementDiffEq, AlgebraicDiffEq, JLD
5+
include("ode_premade_problems.jl")
6+
include("dae_premade_problems.jl")
7+
include("sde_premade_problems.jl")
8+
include("fem_premade_problems.jl")
9+
include("premade_meshes.jl")
10+
11+
#ODE Example Problems
12+
export prob_ode_linear, prob_ode_bigfloatlinear, prob_ode_2Dlinear,
13+
prob_ode_large2Dlinear, prob_ode_bigfloat2Dlinear, prob_ode_rigidbody,
14+
prob_ode_2Dlinear_notinplace, prob_ode_vanderpol, prob_ode_vanderpol_stiff,
15+
prob_ode_lorenz, prob_ode_rober, prob_ode_threebody
16+
17+
#SDE Example Problems
18+
export prob_sde_wave, prob_sde_linear, prob_sde_cubic, prob_sde_2Dlinear, prob_sde_lorenz,
19+
prob_sde_2Dlinear, prob_sde_additive, prob_sde_additivesystem, oval2ModelExample
20+
21+
#DAE Example Problems
22+
export prob_dae_resrob
23+
24+
#FEM Example Problems
25+
export prob_femheat_moving, prob_femheat_pure, prob_femheat_diffuse,
26+
prob_poisson_wave, prob_poisson_noisywave, prob_femheat_birthdeath,
27+
prob_poisson_birthdeath, prob_femheat_stochasticbirthdeath,
28+
prob_stokes_homogenous, prob_stokes_dirichletzero, prob_poisson_birthdeathsystem,
29+
prob_poisson_birthdeathinteractingsystem, prob_femheat_birthdeathinteractingsystem,
30+
prob_femheat_birthdeathsystem, prob_femheat_diffusionconstants,
31+
heatProblemExample_grayscott,heatProblemExample_gierermeinhardt
32+
33+
#Example Meshes
34+
export meshExample_bunny, meshExample_flowpastcylindermesh, meshExample_lakemesh,
35+
meshExample_Lshapemesh, meshExample_Lshapeunstructure, meshExample_oilpump,
36+
meshExample_wavymesh, meshExample_wavyperturbmesh
437

538
end # module

src/dae_premade_problems.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
### DAE Problems
2+
3+
f = function (tres, y, yp, r)
4+
r[1] = -0.04*y[1] + 1.0e4*y[2]*y[3]
5+
r[2] = -r[1] - 3.0e7*y[2]*y[2] - yp[2]
6+
r[1] -= yp[1]
7+
r[3] = y[1] + y[2] + y[3] - 1.0
8+
end
9+
u₀ = [1.0, 0, 0]
10+
du₀ = [-0.04, 0.04, 0.0]
11+
"DAE residual form for the Robertson model"
12+
prob_dae_resrob = DAEProblem(f,u₀,du₀)

src/fem_premade_problems.jl

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
### Finite Element Examples
2+
3+
analytic_moving(t,x) = 0.1*(1-exp.(-100*(t-0.5).^2)).*exp.(-25((x[:,1]-t+0.5).^2 + (x[:,2]-t+0.5).^2))
4+
Du = (t,x) -> -50[analytic_moving(t,x).*(0.5-t+x[:,1]) analytic_moving(t,x).*(0.5-t+x[:,2])]
5+
f = (t,x) -> (-5).*exp.((-25).*((3/2)+6.*t.^2+x[:,1]+x[:,1].^2+x[:,2]+x[:,2].^2+(-2).*t.*(3+x[:,1]+
6+
x[:,2]))).*((-20)+(-100).*t.^2+(-49).*x[:,1]+(-50).*x[:,1].^2+(-49).*x[:,2]+(-50).*
7+
x[:,2].^2+2.*t.*(47+50.*x[:,1]+50.*x[:,2])+exp.(25.*(1+(-2).*t).^2).*(22+
8+
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+
"""
10+
Example problem defined by the solution:
11+
```math
12+
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))
13+
```
14+
15+
This will have a mound which moves across the screen. Good animation test.
16+
"""
17+
prob_femheat_moving = HeatProblem(analytic_moving,Du,f)
18+
19+
20+
21+
analytic_diffuse(t,x) = exp.(-10((x[:,1]-.5).^2 + (x[:,2]-.5).^2 )-t)
22+
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))
23+
Du = (t,x) -> -20[analytic_diffuse(t,x).*(x[:,1]-.5) analytic_diffuse(t,x).*(x[:,2]-.5)]
24+
"""
25+
Example problem defined by the solution:
26+
27+
```math
28+
u(x,y,t)=\\exp(-10((x-\\frac{1}{2})^2 + (y-\\frac{1}{2})^2 )-t)
29+
```
30+
31+
This is a Gaussian centered at ``(\\frac{1}{2},\\frac{1}{2})`` which diffuses over time.
32+
"""
33+
prob_femheat_diffuse = HeatProblem(analytic_diffuse,Du,f)
34+
35+
36+
f = (t,x) -> zeros(size(x,1))
37+
u₀ = (x) -> float((abs.(x[:,1]-.5) .< 1e-6) & (abs.(x[:,2]-.5) .< 1e-6)) #Only mass at middle of (0,1)^2
38+
"""
39+
Example problem which starts with a Dirac δ cenetered at (0.5,0.5) and solves with ``f=gD=0``.
40+
This gives the Green's function solution.
41+
"""
42+
prob_femheat_pure = HeatProblem(u₀,f)
43+
44+
45+
f = (t,x,u) -> ones(size(x,1)) - .5u
46+
u₀ = (x) -> zeros(size(x,1))
47+
"""
48+
Homogenous reaction-diffusion problem which starts with 0 and solves with ``f(u)=1-u/2``
49+
"""
50+
prob_femheat_birthdeath = HeatProblem(u₀,f)
51+
52+
53+
f = (t,x,u) -> [ones(size(x,1))-.5u[:,1] ones(size(x,1))-u[:,2]]
54+
u₀ = (x) -> ones(size(x,1),2).*[.5 .5] # size (x,2), 2 meaning 2 variables
55+
"""
56+
Homogenous reaction-diffusion which starts at 1/2 and solves the system ``f(u)=1-u/2`` and ``f(v)=1-v``
57+
"""
58+
prob_femheat_birthdeathsystem = HeatProblem(u₀,f)
59+
60+
f = (t,x,u) -> [zeros(size(x,1)) zeros(size(x,1))]
61+
u₀ = (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
62+
"""
63+
Example problem which solves the homogeneous Heat equation with all mass starting at (1/2,1/2) with two different diffusion constants,
64+
``D₁=0.01`` and ``D₂=0.001``. Good animation test.
65+
"""
66+
prob_femheat_diffusionconstants = HeatProblem(u₀,f,D=[.01 .001])
67+
68+
f = (t,x,u) -> [ones(size(x,1))-.5u[:,1] .5u[:,1]-u[:,2]]
69+
u₀ = (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(u₀,f)
74+
75+
"""
76+
`heatProblemExample_grayscott(;ρ=.03,k=.062,D=[1e-3 .5e-3])`
77+
78+
The Gray-Scott equations with quasi-random initial conditions. The reaction equations
79+
are given by:
80+
81+
```math
82+
\\begin{align}
83+
u_t &= uv^2 + ρ(1-v) \\\\
84+
v_t &= uv^2 - (ρ+k)v
85+
\\end{align}
86+
```
87+
"""
88+
function heatProblemExample_grayscott(;ρ=.03,k=.062,D=[1e-3 .5e-3])
89+
f₁(t,x,u) = u[:,1].*u[:,2].*u[:,2] + ρ*(1-u[:,2])
90+
f₂(t,x,u) = u[:,1].*u[:,2].*u[:,2] -+k).*u[:,2]
91+
f(t,x,u) = [f₁(t,x,u) f₂(t,x,u)]
92+
u₀(x) = [ones(size(x,1))+rand(size(x,1)) .25.*float(((.2.<x[:,1].<.6) &
93+
(.2.<x[:,2].<.6)) | ((.85.<x[:,1]) & (.85.<x[:,2])))] # size (x,2), 2 meaning 2 variables
94+
return(HeatProblem(u₀,f,D=D))
95+
end
96+
97+
"""
98+
`heatProblemExample_gierermeinhardt(;a=1,α=1,D=[0.01 1.0],ubar=1,vbar=0,β=10,startNoise=0.01)`
99+
100+
The Gierer-Meinhardt equations wtih quasi-random initial perturbations.
101+
102+
```math
103+
\\begin{align}
104+
u_t &= \\frac{au}{v^2} + \\bar{u} -αu \\\\
105+
v_t &= au^2 + \\bar{v} - βv
106+
\\end{align}
107+
```
108+
109+
The equation starts at the steady state
110+
111+
```math
112+
\\begin{align}
113+
u_{ss} &= \\frac{\\bar{u}+β}{α} \\\\
114+
v_{ss} &= \\frac{α}{β} u_{ss}^2
115+
\\end{align}
116+
```
117+
118+
with a bit of noise.
119+
120+
"""
121+
function heatProblemExample_gierermeinhardt(;a=1=1,D=[0.01 1.0],ubar=1,vbar=0=10,startNoise=0.01)
122+
f₁(t,x,u) = a*u[:,1].*u[:,1]./u[:,2] + ubar - α*u[:,1]
123+
f₂(t,x,u) = a*u[:,1].*u[:,1] + vbar -β.*u[:,2]
124+
f(t,x,u) = [f₁(t,x,u) f₂(t,x,u)]
125+
uss = (ubar +β)/α
126+
vss =/β)*uss.^2
127+
u₀(x) = [uss*ones(size(x,1))+startNoise*rand(size(x,1)) vss*ones(size(x,1))] # size (x,2), 2 meaning 2 variables
128+
return(HeatProblem(u₀,f,D=D))
129+
end
130+
131+
f = (t,x,u) -> ones(size(x,1)) - .5u
132+
u₀ = (x) -> zeros(size(x,1))
133+
σ = (t,x,u) -> 1u.^2
134+
"""
135+
Homogenous stochastic reaction-diffusion problem which starts with 0
136+
and solves with ``f(u)=1-u/2`` with noise ``σ(u)=10u^2``
137+
"""
138+
prob_femheat_stochasticbirthdeath = HeatProblem(u₀,f,σ=σ)
139+
140+
## Poisson
141+
142+
f = (x) -> sin.(2π.*x[:,1]).*cos.(2π.*x[:,2])
143+
analytic = (x) -> sin.(2π.*x[:,1]).*cos.(2π.*x[:,2])/(8π*π)
144+
Du = (x) -> [cos.(2*pi.*x[:,1]).*cos.(2*pi.*x[:,2])./(4*pi) -sin.(2π.*x[:,1]).*sin.(2π.*x[:,2])./(4π)]
145+
"""
146+
Problem defined by the solution: ``u(x,y)= \\sin(2πx)\\cos(2πy)/(8π^2)``
147+
"""
148+
prob_poisson_wave = PoissonProblem(f,analytic,Du)
149+
150+
σ = (x) -> 5 #Additive noise
151+
"""
152+
Problem with deterministic solution: ``u(x,y)= \\sin(2πx)\\cos(2πy)/(8π^2)``
153+
and additive noise ``σ(x,y)=5``
154+
"""
155+
prob_poisson_noisywave = PoissonProblem(f,analytic,Du,σ=σ)
156+
157+
f = (x,u) -> ones(size(x,1)) - .5u
158+
"""
159+
Nonlinear Poisson equation with ``f(u)=1-u/2``.
160+
Corresponds to the steady state of a humogenous reaction-diffusion equation
161+
with the same ``f``.
162+
"""
163+
prob_poisson_birthdeath = PoissonProblem(f,numvars=1)
164+
165+
f = (x,u) -> [ones(size(x,1))-.5u[:,1] ones(size(x,1))-u[:,2]]
166+
u₀ = (x) -> .5*ones(size(x,1),2) # size (x,2), 2 meaning 2 variables
167+
168+
"""
169+
Nonlinear Poisson equation with ``f(u)=1-u/2`` and ``f(v)=1-v`` and initial
170+
condition homogenous 1/2. Corresponds to the steady state of a humogenous
171+
reaction-diffusion equation with the same ``f``.
172+
"""
173+
prob_poisson_birthdeathsystem = PoissonProblem(f,u₀=u₀)
174+
175+
f = (x,u) -> [ones(size(x,1))-.5u[:,1] .5u[:,1]-u[:,2]]
176+
u₀ = (x) -> ones(size(x,1),2).*[.5 .5] # size (x,2), 2 meaning 2 variables
177+
178+
"""
179+
Nonlinear Poisson equation with ``f(u)=1-u/2`` and ``f(v)=.5u-v`` and initial
180+
condition homogenous 1/2. Corresponds to the steady state of a humogenous
181+
reaction-diffusion equation with the same ``f``.
182+
"""
183+
prob_poisson_birthdeathinteractingsystem = PoissonProblem(f,u₀=u₀)

0 commit comments

Comments
 (0)