Skip to content

Commit 2c68bcf

Browse files
u0 to array
1 parent 1057bf2 commit 2c68bcf

File tree

1 file changed

+47
-38
lines changed

1 file changed

+47
-38
lines changed

src/fem_premade_problems.jl

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ f = (t,x) -> (-5).*exp.((-25).*((3/2)+6.*t.^2+x[:,1]+x[:,1].^2+x[:,2]+x[:,2].^2+
99
T = 2
1010
dx = 1//2^(3)
1111
dt = 1//2^(9)
12-
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
12+
mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
1313
"""
1414
Example problem defined by the solution:
1515
```math
@@ -18,7 +18,7 @@ u(x,y,t)=\\frac{1}{10}(1-\\exp(-100(t-\\frac{1}{2})^2))\\exp(-25((x-t+0.5)^2 + (
1818
1919
This will have a mound which moves across the screen. Good animation test.
2020
"""
21-
prob_femheat_moving = HeatProblem(analytic_moving,Du,f,fem_mesh)
21+
prob_femheat_moving = HeatProblem(analytic_moving,Du,f,mesh)
2222

2323
N = 2 #Number of different dt to solve at, 2 for test speed
2424
topdt = 6 # 1//2^(topdt-1) is the max dt. Small for test speed
@@ -39,7 +39,7 @@ cs_femheat_moving_dx = ConvergenceSetup(probs,dxs)
3939
T = 1
4040
dx = 1//2^(3)
4141
dt = 1//2^(7)
42-
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
42+
mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
4343
"""
4444
Example problem defined by the solution:
4545
```math
@@ -48,15 +48,15 @@ u(x,y,t)=\\frac{1}{10}(1-\\exp(-100(t-\\frac{1}{2})^2))\\exp(-25((x-t+0.5)^2 + (
4848
4949
This will have a mound which moves across the screen. Good animation test.
5050
"""
51-
prob_femheat_moving7 = HeatProblem(analytic_moving,Du,f,fem_mesh)
51+
prob_femheat_moving7 = HeatProblem(analytic_moving,Du,f,mesh)
5252

5353
analytic_diffuse(t,x) = exp.(-10((x[:,1]-.5).^2 + (x[:,2]-.5).^2 )-t)
5454
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))
5555
Du = (t,x) -> -20[analytic_diffuse(t,x).*(x[:,1]-.5) analytic_diffuse(t,x).*(x[:,2]-.5)]
5656
T = 1
5757
dx = 1//2^(3)
5858
dt = 1//2^(7)
59-
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
59+
mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
6060
"""
6161
Example problem defined by the solution:
6262
@@ -66,63 +66,68 @@ u(x,y,t)=\\exp(-10((x-\\frac{1}{2})^2 + (y-\\frac{1}{2})^2 )-t)
6666
6767
This is a Gaussian centered at ``(\\frac{1}{2},\\frac{1}{2})`` which diffuses over time.
6868
"""
69-
prob_femheat_diffuse = HeatProblem(analytic_diffuse,Du,f,fem_mesh)
69+
prob_femheat_diffuse = HeatProblem(analytic_diffuse,Du,f,mesh)
7070

7171

7272
f = (t,x) -> zeros(size(x,1))
73-
u0 = (x) -> float((abs.(x[:,1]-.5) .< 1e-6) & (abs.(x[:,2]-.5) .< 1e-6)) #Only mass at middle of (0,1)^2
73+
u0_func = (x) -> float((abs.(x[:,1]-.5) .< 1e-6) & (abs.(x[:,2]-.5) .< 1e-6)) #Only mass at middle of (0,1)^2
7474
T = 1//2^(5)
7575
dx = 1//2^(3)
7676
dt = 1//2^(9)
77-
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
77+
mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
78+
u0 = u0_func(mesh.node)
7879
"""
7980
Example problem which starts with a Dirac δ cenetered at (0.5,0.5) and solves with ``f=gD=0``.
8081
This gives the Green's function solution.
8182
"""
82-
prob_femheat_pure = HeatProblem(u0,f,fem_mesh)
83+
prob_femheat_pure = HeatProblem(u0,f,mesh)
8384

8485
T = 1//2^(5)
8586
dt = 1//2^(11)
86-
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
87+
mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:dirichlet)
88+
u0 = u0_func(mesh.node)
8789
"""
8890
Example problem which starts with a Dirac δ cenetered at (0.5,0.5) and solves with ``f=gD=0``.
8991
This gives the Green's function solution.
9092
"""
91-
prob_femheat_pure11 = HeatProblem(u0,f,fem_mesh)
93+
prob_femheat_pure11 = HeatProblem(u0,f,mesh)
9294

9395
f = (t,x,u) -> ones(size(x,1)) - .5u
94-
u0 = (x) -> zeros(size(x,1))
96+
u0_func = (x) -> zeros(size(x,1))
9597
T = 1
9698
dx = 1//2^(3)
9799
dt = 1//2^(7)
98-
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
100+
mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
101+
u0 = u0_func(mesh.node)
99102
"""
100103
Homogenous reaction-diffusion problem which starts with 0 and solves with ``f(u)=1-u/2``
101104
"""
102-
prob_femheat_birthdeath = HeatProblem(u0,f,fem_mesh)
105+
prob_femheat_birthdeath = HeatProblem(u0,f,mesh)
103106

104107

105108
f = (t,x,u) -> [ones(size(x,1))-.5u[:,1] ones(size(x,1))-u[:,2]]
106-
u0 = (x) -> ones(size(x,1),2).*[.5 .5] # size (x,2), 2 meaning 2 variables
109+
u0_func = (x) -> ones(size(x,1),2).*[.5 .5] # size (x,2), 2 meaning 2 variables
107110
T = 5
108111
dx = 1/2^(1)
109112
dt = 1/2^(7)
110-
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
113+
mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
114+
u0 = u0_func(mesh.node)
111115
"""
112116
Homogenous reaction-diffusion which starts at 1/2 and solves the system ``f(u)=1-u/2`` and ``f(v)=1-v``
113117
"""
114-
prob_femheat_birthdeathsystem = HeatProblem(u0,f,fem_mesh)
118+
prob_femheat_birthdeathsystem = HeatProblem(u0,f,mesh)
115119

116120
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
121+
u0_func = (x) -> ones(size(x,1),2).*[.5 .5] # size (x,2), 2 meaning 2 variables
118122
T = 5
119123
dx = 1/2^(1)
120124
dt = 1/2^(7)
121-
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
125+
mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
126+
u0 = u0_func(mesh.node)
122127
"""
123128
Homogenous reaction-diffusion which starts with 1/2 and solves the system ``f(u)=1-u/2`` and ``f(v)=.5u-v``
124129
"""
125-
prob_femheat_birthdeathinteractingsystem = HeatProblem(u0,f,fem_mesh)
130+
prob_femheat_birthdeathinteractingsystem = HeatProblem(u0,f,mesh)
126131

127132
#=
128133
f = (t,x,u) -> [zeros(size(x,1)) zeros(size(x,1))]
@@ -131,7 +136,7 @@ u0 = (x) -> [float((abs.(x[:,1]-.5) .< 1e-6) & (abs.(x[:,2]-.5) .< 1e-6)) float(
131136
Example problem which solves the homogeneous Heat equation with all mass starting at (1/2,1/2) with two different diffusion constants,
132137
``D₁=0.01`` and ``D₂=0.001``. Good animation test.
133138
"""
134-
prob_femheat_diffusionconstants = HeatProblem(u0,f,fem_mesh,D=[.01 .001])
139+
prob_femheat_diffusionconstants = HeatProblem(u0,f,mesh,D=[.01 .001])
135140
=#
136141

137142
#=
@@ -193,76 +198,80 @@ end
193198
=#
194199

195200
f = (t,x,u) -> ones(size(x,1)) - .5u
196-
u0 = (x) -> zeros(size(x,1))
201+
u0_func = (x) -> zeros(size(x,1))
197202
σ = (t,x,u) -> 1u.^2
198203
T = 5
199204
dx = 1//2^(3)
200205
dt = 1//2^(5)
201-
fem_mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
206+
mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
207+
u0 = u0_func(mesh.node)
202208
"""
203209
Homogenous stochastic reaction-diffusion problem which starts with 0
204210
and solves with ``f(u)=1-u/2`` with noise ``σ(u)=10u^2``
205211
"""
206-
prob_femheat_stochasticbirthdeath = HeatProblem(u0,f,fem_mesh=σ)
212+
prob_femheat_stochasticbirthdeath = HeatProblem(u0,f,mesh=σ)
207213

208214
dx = 1//2^(1)
209215
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,σ=σ)
216+
mesh = parabolic_squaremesh([0 1 0 1],dx,dt,T,:neumann)
217+
u0 = u0_func(mesh.node)
218+
prob_femheat_stochasticbirthdeath_fast = HeatProblem(u0,f,mesh,σ=σ)
212219

213220
## Poisson
214221

215222
f = (x) -> sin.(2π.*x[:,1]).*cos.(2π.*x[:,2])
216223
analytic = (x) -> sin.(2π.*x[:,1]).*cos.(2π.*x[:,2])/(8π*π)
217224
Du = (x) -> [cos.(2*pi.*x[:,1]).*cos.(2*pi.*x[:,2])./(4*pi) -sin.(2π.*x[:,1]).*sin.(2π.*x[:,2])./(4π)]
218225
dx = 1//2^(5)
219-
fem_mesh = notime_squaremesh([0 1 0 1],dx,:dirichlet)
226+
mesh = notime_squaremesh([0 1 0 1],dx,:dirichlet)
220227
"""
221228
Problem defined by the solution: ``u(x,y)= \\sin(2πx)\\cos(2πy)/(8π^2)``
222229
"""
223-
prob_poisson_wave = PoissonProblem(f,analytic,Du,fem_mesh)
230+
prob_poisson_wave = PoissonProblem(f,analytic,Du,mesh)
224231

225232
dxs = 1.//2.^(4:-1:2) # 4 for testing, use 7 for good graph
226233
probs = [PoissonProblem(f,analytic,Du,notime_squaremesh([0 1 0 1],dx,:dirichlet)) for dx in dxs]
227234
cs_fempoisson_wave = ConvergenceSetup(probs,dts)
228235

229236
σ = (x) -> 5 #Additive noise
230237
dx = 1//2^(5)
231-
fem_mesh = notime_squaremesh([0 1 0 1],dx,:dirichlet)
238+
mesh = notime_squaremesh([0 1 0 1],dx,:dirichlet)
232239
"""
233240
Problem with deterministic solution: ``u(x,y)= \\sin(2πx)\\cos(2πy)/(8π^2)``
234241
and additive noise ``σ(x,y)=5``
235242
"""
236-
prob_poisson_noisywave = PoissonProblem(f,analytic,Du,fem_mesh=σ)
243+
prob_poisson_noisywave = PoissonProblem(f,analytic,Du,mesh=σ)
237244

238245
f = (x,u) -> ones(size(x,1)) - .5u
239246
dx = 1//2^(3)
240-
fem_mesh = notime_squaremesh([0 1 0 1],dx,:neumann)
247+
mesh = notime_squaremesh([0 1 0 1],dx,:neumann)
241248
"""
242249
Nonlinear Poisson equation with ``f(u)=1-u/2``.
243250
Corresponds to the steady state of a humogenous reaction-diffusion equation
244251
with the same ``f``.
245252
"""
246-
prob_poisson_birthdeath = PoissonProblem(f,fem_mesh,numvars=1)
253+
prob_poisson_birthdeath = PoissonProblem(f,mesh,numvars=1)
247254

248255
f = (x,u) -> [ones(size(x,1))-.5u[:,1] ones(size(x,1))-u[:,2]]
249-
u0 = (x) -> .5*ones(size(x,1),2) # size (x,2), 2 meaning 2 variables
256+
u0_func = (x) -> .5*ones(size(x,1),2) # size (x,2), 2 meaning 2 variables
250257
dx = 1//2^(1)
251-
fem_mesh = notime_squaremesh([0 1 0 1],dx,:neumann)
258+
mesh = notime_squaremesh([0 1 0 1],dx,:neumann)
259+
u0 = u0_func(mesh.node)
252260
"""
253261
Nonlinear Poisson equation with ``f(u)=1-u/2`` and ``f(v)=1-v`` and initial
254262
condition homogenous 1/2. Corresponds to the steady state of a humogenous
255263
reaction-diffusion equation with the same ``f``.
256264
"""
257-
prob_poisson_birthdeathsystem = PoissonProblem(f,fem_mesh,u0=u0)
265+
prob_poisson_birthdeathsystem = PoissonProblem(f,mesh,u0=u0)
258266

259267
f = (x,u) -> [ones(size(x,1))-.5u[:,1] .5u[:,1]-u[:,2]]
260-
u0 = (x) -> ones(size(x,1),2).*[.5 .5] # size (x,2), 2 meaning 2 variables
268+
u0_func = (x) -> ones(size(x,1),2).*[.5 .5] # size (x,2), 2 meaning 2 variables
261269
dx = 1//2^(1)
262-
fem_mesh = notime_squaremesh([0 1 0 1],dx,:neumann)
270+
mesh = notime_squaremesh([0 1 0 1],dx,:neumann)
271+
u0 = u0_func(mesh.node)
263272
"""
264273
Nonlinear Poisson equation with ``f(u)=1-u/2`` and ``f(v)=.5u-v`` and initial
265274
condition homogenous 1/2. Corresponds to the steady state of a humogenous
266275
reaction-diffusion equation with the same ``f``.
267276
"""
268-
prob_poisson_birthdeathinteractingsystem = PoissonProblem(f,fem_mesh,u0=u0)
277+
prob_poisson_birthdeathinteractingsystem = PoissonProblem(f,mesh,u0=u0)

0 commit comments

Comments
 (0)