Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jigyasa Watwani
/
growth-pattern-control
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1a71fc46
authored
Sep 09, 2022
by
Jigyasa Watwani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
max error scaling linearly with dt
parent
f83b6210
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
47 deletions
diffusion/diffusion_moving_domain.py
diffusion/diffusion_moving_domain.py
View file @
1a71fc46
...
@@ -7,61 +7,61 @@ import progressbar
...
@@ -7,61 +7,61 @@ import progressbar
df
.
set_log_level
(
df
.
LogLevel
.
ERROR
)
df
.
set_log_level
(
df
.
LogLevel
.
ERROR
)
df
.
parameters
[
'form_compiler'
][
'optimize'
]
=
True
df
.
parameters
[
'form_compiler'
][
'optimize'
]
=
True
Nx
,
L
,
D
,
tmax
,
dt
=
32
,
1.0
,
0.1
,
2.0
,
0.05
def
advection_diffusion
(
Nx
,
L
,
Nt
,
tmax
,
D
):
Nt
=
int
(
tmax
/
dt
)
# mesh, function space, function, test function
mesh
=
df
.
IntervalMesh
(
Nx
,
0
,
L
)
SFS
=
df
.
FunctionSpace
(
mesh
,
'P'
,
1
)
c
=
df
.
Function
(
SFS
)
tc
=
df
.
TestFunction
(
SFS
)
mesh
=
df
.
IntervalMesh
(
Nx
,
0
,
L
)
# x and t arrays
x
=
mesh
.
coordinates
()[:,
0
]
x
=
mesh
.
coordinates
()[:,
0
]
times
=
np
.
linspace
(
0
,
tmax
,
Nt
+
1
)
times
=
np
.
linspace
(
0
,
tmax
,
Nt
+
1
)
dt
=
times
[
1
]
-
times
[
0
]
SFS
=
df
.
FunctionSpace
(
mesh
,
'P'
,
1
)
# initial condition
c
=
df
.
Function
(
SFS
)
c0
=
df
.
Function
(
SFS
)
tc
=
df
.
TestFunction
(
SFS
)
c0
.
interpolate
(
df
.
Expression
(
'1 + 0.1 * cos(2*pi*x[0]/L)'
,
pi
=
np
.
pi
,
L
=
L
,
degree
=
1
))
c0
=
df
.
Function
(
SFS
)
c0
.
interpolate
(
df
.
Expression
(
'1 + 0.1 * cos(2*pi*x[0]/L)'
,
pi
=
np
.
pi
,
L
=
L
,
degree
=
1
))
# arrays
c_array
=
np
.
zeros
((
Nt
+
1
,
Nx
+
1
))
c_array
[
0
]
=
c0
.
compute_vertex_values
(
mesh
)
c_exact
=
np
.
zeros
((
Nt
+
1
,
Nx
+
1
))
# form
for
i
in
range
(
Nt
+
1
):
cform
=
(
df
.
inner
((
c
-
c0
)
/
dt
,
tc
)
c_exact
[
i
]
=
1
+
0.1
*
np
.
cos
(
2
*
np
.
pi
*
x
/
L
)
*
np
.
exp
(
-
4
*
np
.
pi
**
2
*
D
*
times
[
i
]
/
L
**
2
)
+
D
*
df
.
inner
(
df
.
nabla_grad
(
c
),
df
.
nabla_grad
(
tc
)))
*
df
.
dx
c_array
=
np
.
zeros
((
Nt
+
1
,
Nx
+
1
))
# solve
c_array
[
0
]
=
c0
.
compute_vertex_values
(
mesh
)
for
i
in
progressbar
.
progressbar
(
range
(
1
,
Nt
+
1
)):
df
.
solve
(
cform
==
0
,
c
)
c0
.
assign
(
c
)
c_array
[
i
]
=
c0
.
compute_vertex_values
(
mesh
)
cform
=
(
df
.
inner
((
c
-
c0
)
/
dt
,
tc
)
return
c_array
+
D
*
df
.
inner
(
df
.
nabla_grad
(
c
),
df
.
nabla_grad
(
tc
)))
*
df
.
dx
for
i
in
progressbar
.
progressbar
(
range
(
1
,
Nt
+
1
)):
# parameters
df
.
solve
(
cform
==
0
,
c
)
Nx
,
L
,
D
,
tmax
=
64
,
1.0
,
0.1
,
1.0
c0
.
assign
(
c
)
nt_array
=
np
.
array
([
50
,
100
,
200
,
400
,
600
,
800
,
1600
])
c_array
[
i
]
=
c0
.
compute_vertex_values
(
mesh
)
dt_array
=
tmax
/
nt_array
mesh
=
df
.
IntervalMesh
(
Nx
,
0
,
L
)
x
=
mesh
.
coordinates
()[:,
0
]
fig
,
(
ax
,
ax1
)
=
plt
.
subplots
(
2
,
1
)
# error array
fig
.
suptitle
(
r'$N_x =
%
d, \Delta t =
%4.3
f$'
%
(
Nx
,
dt
))
error
=
np
.
zeros
(
len
(
nt_array
))
cplot
,
=
ax
.
plot
(
x
,
c_array
[
0
],
'ro'
,
mfc
=
'none'
,
ms
=
6
,
label
=
'Numerics'
)
ceplot
,
=
ax
.
plot
(
x
,
c_exact
[
0
],
label
=
'Exact'
)
ax
.
set_xlabel
(
r'$x$'
)
ax
.
set_ylabel
(
r'$c(x,t)$'
)
ax
.
legend
(
loc
=
1
)
error
=
c_array
-
c_exact
for
i
in
range
(
0
,
len
(
nt_array
)):
print
(
np
.
max
(
error
))
err_plot
,
=
ax1
.
plot
(
x
,
error
[
0
],
'bo'
,
mfc
=
'none'
,
ms
=
6
)
# exact solution
ax1
.
set_ylim
(
np
.
min
(
error
),
np
.
max
(
error
))
c_exact
=
np
.
zeros
((
nt_array
[
i
]
+
1
,
Nx
+
1
))
ax1
.
set_xlabel
(
r'$x$'
)
times
=
np
.
linspace
(
0
,
tmax
,
nt_array
[
i
]
+
1
)
ax1
.
set_ylabel
(
r'$c(x,t)-c_{\rm exact}(x,t)$'
)
for
j
in
range
(
nt_array
[
i
]
+
1
):
c_exact
[
j
]
=
1
+
0.1
*
np
.
cos
(
2
*
np
.
pi
*
x
/
L
)
*
np
.
exp
(
-
4
*
np
.
pi
**
2
*
D
*
times
[
j
]
/
L
**
2
)
c
=
advection_diffusion
(
Nx
,
L
,
nt_array
[
i
],
tmax
,
D
)
error
[
i
]
=
np
.
max
(
np
.
abs
(
c
-
c_exact
))
def
update
(
val
):
fig
,
ax
=
plt
.
subplots
(
1
)
ti
=
(
abs
(
times
-
val
))
.
argmin
()
ax
.
plot
(
dt_array
,
error
,
'bo'
)
cplot
.
set_ydata
(
c_array
[
ti
])
ax
.
set_xlabel
(
'$dt$'
)
ceplot
.
set_ydata
(
c_exact
[
ti
])
ax
.
set_ylabel
(
'error'
)
plt
.
show
()
err_plot
.
set_ydata
(
error
[
ti
])
plt
.
draw
()
sax
=
plt
.
axes
([
0.1
,
0.92
,
0.7
,
0.025
])
sl
=
Slider
(
sax
,
't'
,
times
.
min
(),
times
.
max
(),
valinit
=
times
.
min
())
sl
.
on_changed
(
update
)
plt
.
show
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment