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
926941c1
authored
Aug 30, 2022
by
Jigyasa Watwani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correct analytical solution
parent
a2801d4f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
12 deletions
moving_domain/moving_heat_equation_analytical.py
moving_domain/moving_heat_equation_analytical.py
View file @
926941c1
...
@@ -7,17 +7,15 @@ df.set_log_level(df.LogLevel.ERROR)
...
@@ -7,17 +7,15 @@ df.set_log_level(df.LogLevel.ERROR)
df
.
parameters
[
'form_compiler'
][
'optimize'
]
=
True
df
.
parameters
[
'form_compiler'
][
'optimize'
]
=
True
# parameters
# parameters
k
=
1.0
alpha
=
1.0
T
=
1
T
=
1
dt
=
0.001
dt
=
0.001
L
=
1
L
0
=
1
D
=
1.0
D
=
1.0
Nx
=
2000
Nx
=
2000
Nt
=
1000
Nt
=
1000
t
=
np
.
linspace
(
0
,
T
,
Nt
)
t
=
np
.
linspace
(
0
,
T
,
Nt
)
# diffusion and advection
# diffusion and advection
def
diffusion
(
c
,
tc
):
def
diffusion
(
c
,
tc
):
return
(
D
*
df
.
inner
(
c
.
dx
(
0
),
tc
.
dx
(
0
)))
return
(
D
*
df
.
inner
(
c
.
dx
(
0
),
tc
.
dx
(
0
)))
...
@@ -27,17 +25,17 @@ def advection(c, tc, v):
...
@@ -27,17 +25,17 @@ def advection(c, tc, v):
return
(
df
.
inner
((
u
*
c
)
.
dx
(
0
),
tc
))
return
(
df
.
inner
((
u
*
c
)
.
dx
(
0
),
tc
))
# create mesh
# create mesh
mesh
=
df
.
IntervalMesh
(
Nx
,
0
,
L
)
mesh
=
df
.
IntervalMesh
(
Nx
,
0
,
L
0
)
x
=
mesh
.
coordinates
()
x
=
mesh
.
coordinates
()
# v = df.Constant(1.0)
# v = df.Constant(1.0)
v
=
df
.
Expression
(
'
k*x[0]'
,
k
=
k
,
degree
=
1
)
v
=
df
.
Expression
(
'
alpha*x[0]'
,
alpha
=
alpha
,
degree
=
1
)
# create function space
# create function space
conc_element
=
df
.
FiniteElement
(
'P'
,
mesh
.
ufl_cell
(),
1
)
conc_element
=
df
.
FiniteElement
(
'P'
,
mesh
.
ufl_cell
(),
1
)
function_space
=
df
.
FunctionSpace
(
mesh
,
conc_element
)
function_space
=
df
.
FunctionSpace
(
mesh
,
conc_element
)
# initial condition
# initial condition
c0
=
df
.
interpolate
(
df
.
Expression
(
'1 + 0.2*cos(pi*x[0]/L
)'
,
pi
=
np
.
pi
,
L
=
L
,
degree
=
1
),
function_space
)
c0
=
df
.
interpolate
(
df
.
Expression
(
'1 + 0.2*cos(pi*x[0]/L
0)'
,
pi
=
np
.
pi
,
L0
=
L0
,
degree
=
1
),
function_space
)
c0_array
=
c0
.
compute_vertex_values
(
mesh
)
c0_array
=
c0
.
compute_vertex_values
(
mesh
)
# define variational problem
# define variational problem
...
@@ -71,10 +69,10 @@ for n in progressbar.progressbar(range(1, len(t))):
...
@@ -71,10 +69,10 @@ for n in progressbar.progressbar(range(1, len(t))):
c_exact
=
np
.
zeros
((
len
(
t
),
len
(
x
)))
c_exact
=
np
.
zeros
((
len
(
t
),
len
(
x
)))
for
i
in
range
(
len
(
t
)):
for
i
in
range
(
len
(
t
)):
xprime
=
x_array
[
0
]
*
np
.
exp
(
-
k
*
t
[
i
])
/
L
xprime
=
x_array
[
0
]
/
(
L0
*
np
.
exp
(
alpha
*
t
[
i
]))
tprime
=
(
D
/
(
2
*
k
*
L
**
2
))
*
(
1
-
np
.
exp
(
-
2
*
k
*
t
[
i
]))
tprime
=
(
D
/
(
2
*
alpha
*
L0
**
2
))
*
(
1
-
np
.
exp
(
-
2
*
alpha
*
t
[
i
]))
# int = ((2*k**2*L**2)/(D**2))*(np.exp(-4*k*t[i])-1
)
int
=
np
.
exp
(
-
alpha
*
t
[
i
]
)
c_exact
[
i
]
=
np
.
exp
(
-
k
*
t
[
i
])
*
(
1
+
0.2
*
np
.
cos
(
np
.
pi
*
xprime
)
*
np
.
exp
(
-
np
.
pi
**
2
*
tprime
))
c_exact
[
i
]
=
int
*
(
1
+
0.2
*
np
.
cos
(
np
.
pi
*
xprime
)
*
np
.
exp
(
-
np
.
pi
**
2
*
tprime
))
# plot c(x,t) computed numerically
# plot c(x,t) computed numerically
fig
,
ax_comp
=
plt
.
subplots
(
1
,
1
,
figsize
=
(
8
,
6
))
fig
,
ax_comp
=
plt
.
subplots
(
1
,
1
,
figsize
=
(
8
,
6
))
...
@@ -83,7 +81,7 @@ ax_comp.set_ylabel(r'$c(x,t)$')
...
@@ -83,7 +81,7 @@ ax_comp.set_ylabel(r'$c(x,t)$')
ax_comp
.
set_xlim
(
np
.
min
(
x_array
)
-
1
,
np
.
max
(
x_array
)
+
1
)
ax_comp
.
set_xlim
(
np
.
min
(
x_array
)
-
1
,
np
.
max
(
x_array
)
+
1
)
ax_comp
.
set_ylim
(
np
.
min
(
c_array
)
-
1
,
np
.
max
(
c_array
)
+
1
)
ax_comp
.
set_ylim
(
np
.
min
(
c_array
)
-
1
,
np
.
max
(
c_array
)
+
1
)
cplot
,
=
ax_comp
.
plot
(
x_array
[
0
],
c0_array
)
cplot
,
=
ax_comp
.
plot
(
x_array
[
0
],
c0_array
)
c_exactplot
,
=
ax_comp
.
plot
(
x_array
[
0
],
c_exact
[
0
],
'ro'
,
markevery
=
50
)
c_exactplot
,
=
ax_comp
.
plot
(
x_array
[
0
],
c_exact
[
0
],
'ro'
,
marke
rsize
=
3
,
marke
very
=
50
)
def
update
(
value
):
def
update
(
value
):
ti
=
np
.
abs
(
t
-
value
)
.
argmin
()
ti
=
np
.
abs
(
t
-
value
)
.
argmin
()
...
...
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