@@ -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+
6
6
x[:,2 ]))).* ((- 20 )+ (- 100 ). * t.^ 2 + (- 49 ). * x[:,1 ]+ (- 50 ). * x[:,1 ]. ^ 2 + (- 49 ). * x[:,2 ]+ (- 50 ). *
7
7
x[:,2 ]. ^ 2 + 2. * t.* (47 + 50. * x[:,1 ]+ 50. * x[:,2 ])+ exp .(25. * (1 + (- 2 ). * t). ^ 2 ).* (22 +
8
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
+ 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 )
9
13
"""
10
14
Example problem defined by the solution:
11
15
```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 + (
14
18
15
19
This will have a mound which moves across the screen. Good animation test.
16
20
"""
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
+ ```
19
48
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)
20
52
21
53
analytic_diffuse (t,x) = exp .(- 10 ((x[:,1 ]- .5 ). ^ 2 + (x[:,2 ]- .5 ). ^ 2 )- t)
22
54
f = (t,x) -> exp .(- t- 5 * (1 - 2 x[:,1 ]+ 2 x[:,1 ]. ^ 2 - 2 x[:,2 ] + 2 x[:,2 ]. ^ 2 )).* (- 161 + 400 * (x[:,1 ] - x[:,1 ]. ^ 2 + x[:,2 ] - x[:,2 ]. ^ 2 ))
23
55
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 )
24
60
"""
25
61
Example problem defined by the solution:
26
62
@@ -30,48 +66,75 @@ u(x,y,t)=\\exp(-10((x-\\frac{1}{2})^2 + (y-\\frac{1}{2})^2 )-t)
30
66
31
67
This is a Gaussian centered at ``(\\ frac{1}{2},\\ frac{1}{2})`` which diffuses over time.
32
68
"""
33
- prob_femheat_diffuse = HeatProblem (analytic_diffuse,Du,f)
69
+ prob_femheat_diffuse = HeatProblem (analytic_diffuse,Du,f,fem_mesh )
34
70
35
71
36
72
f = (t,x) -> zeros (size (x,1 ))
37
73
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 )
38
78
"""
39
79
Example problem which starts with a Dirac δ cenetered at (0.5,0.5) and solves with ``f=gD=0``.
40
80
This gives the Green's function solution.
41
81
"""
42
- prob_femheat_pure = HeatProblem (u0,f)
82
+ prob_femheat_pure = HeatProblem (u0,f,fem_mesh )
43
83
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)
44
92
45
93
f = (t,x,u) -> ones (size (x,1 )) - .5 u
46
94
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 )
47
99
"""
48
100
Homogenous reaction-diffusion problem which starts with 0 and solves with ``f(u)=1-u/2``
49
101
"""
50
- prob_femheat_birthdeath = HeatProblem (u0,f)
102
+ prob_femheat_birthdeath = HeatProblem (u0,f,fem_mesh )
51
103
52
104
53
105
f = (t,x,u) -> [ones (size (x,1 ))- .5 u[:,1 ] ones (size (x,1 ))- u[:,2 ]]
54
106
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 )
55
111
"""
56
112
Homogenous reaction-diffusion which starts at 1/2 and solves the system ``f(u)=1-u/2`` and ``f(v)=1-v``
57
113
"""
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 ))- .5 u[:,1 ] .5 u[:,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)
59
126
127
+ #=
60
128
f = (t,x,u) -> [zeros(size(x,1)) zeros(size(x,1))]
61
129
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
62
130
"""
63
131
Example problem which solves the homogeneous Heat equation with all mass starting at (1/2,1/2) with two different diffusion constants,
64
132
``D₁=0.01`` and ``D₂=0.001``. Good animation test.
65
133
"""
66
- prob_femheat_diffusionconstants = HeatProblem (u0,f,D= [.01 .001 ])
67
-
68
- f = (t,x,u) -> [ones (size (x,1 ))- .5 u[:,1 ] .5 u[:,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
+ =#
74
136
137
+ #=
75
138
"""
76
139
`heatProblemExample_grayscott(;ρ=.03,k=.062,D=[1e-3 .5e-3])`
77
140
@@ -127,57 +190,79 @@ function heatProblemExample_gierermeinhardt(;a=1,α=1,D=[0.01 1.0],ubar=1,vbar=0
127
190
u0(x) = [uss*ones(size(x,1))+startNoise*rand(size(x,1)) vss*ones(size(x,1))] # size (x,2), 2 meaning 2 variables
128
191
return(HeatProblem(u0,f,D=D))
129
192
end
193
+ =#
130
194
131
195
f = (t,x,u) -> ones (size (x,1 )) - .5 u
132
196
u0 = (x) -> zeros (size (x,1 ))
133
197
σ = (t,x,u) -> 1 u.^ 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 )
134
202
"""
135
203
Homogenous stochastic reaction-diffusion problem which starts with 0
136
204
and solves with ``f(u)=1-u/2`` with noise ``σ(u)=10u^2``
137
205
"""
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,σ= σ)
139
212
140
213
# # Poisson
141
214
142
215
f = (x) -> sin .(2 π.* x[:,1 ]).* cos .(2 π.* x[:,2 ])
143
216
analytic = (x) -> sin .(2 π.* x[:,1 ]).* cos .(2 π.* x[:,2 ])/ (8 π* π)
144
217
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 )
145
220
"""
146
221
Problem defined by the solution: ``u(x,y)= \\ sin(2πx)\\ cos(2πy)/(8π^2)``
147
222
"""
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)
149
228
150
229
σ = (x) -> 5 # Additive noise
230
+ dx = 1 // 2 ^ (5 )
231
+ fem_mesh = notime_squaremesh ([0 1 0 1 ],dx,:dirichlet )
151
232
"""
152
233
Problem with deterministic solution: ``u(x,y)= \\ sin(2πx)\\ cos(2πy)/(8π^2)``
153
234
and additive noise ``σ(x,y)=5``
154
235
"""
155
- prob_poisson_noisywave = PoissonProblem (f,analytic,Du,σ= σ)
236
+ prob_poisson_noisywave = PoissonProblem (f,analytic,Du,fem_mesh, σ= σ)
156
237
157
238
f = (x,u) -> ones (size (x,1 )) - .5 u
239
+ dx = 1 // 2 ^ (3 )
240
+ fem_mesh = notime_squaremesh ([0 1 0 1 ],dx,:neumann )
158
241
"""
159
242
Nonlinear Poisson equation with ``f(u)=1-u/2``.
160
243
Corresponds to the steady state of a humogenous reaction-diffusion equation
161
244
with the same ``f``.
162
245
"""
163
- prob_poisson_birthdeath = PoissonProblem (f,numvars= 1 )
246
+ prob_poisson_birthdeath = PoissonProblem (f,fem_mesh, numvars= 1 )
164
247
165
248
f = (x,u) -> [ones (size (x,1 ))- .5 u[:,1 ] ones (size (x,1 ))- u[:,2 ]]
166
249
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 )
168
252
"""
169
253
Nonlinear Poisson equation with ``f(u)=1-u/2`` and ``f(v)=1-v`` and initial
170
254
condition homogenous 1/2. Corresponds to the steady state of a humogenous
171
255
reaction-diffusion equation with the same ``f``.
172
256
"""
173
- prob_poisson_birthdeathsystem = PoissonProblem (f,u0= u0)
257
+ prob_poisson_birthdeathsystem = PoissonProblem (f,fem_mesh, u0= u0)
174
258
175
259
f = (x,u) -> [ones (size (x,1 ))- .5 u[:,1 ] .5 u[:,1 ]- u[:,2 ]]
176
260
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 )
178
263
"""
179
264
Nonlinear Poisson equation with ``f(u)=1-u/2`` and ``f(v)=.5u-v`` and initial
180
265
condition homogenous 1/2. Corresponds to the steady state of a humogenous
181
266
reaction-diffusion equation with the same ``f``.
182
267
"""
183
- prob_poisson_birthdeathinteractingsystem = PoissonProblem (f,u0= u0)
268
+ prob_poisson_birthdeathinteractingsystem = PoissonProblem (f,fem_mesh, u0= u0)
0 commit comments