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
6f648932
authored
Oct 06, 2022
by
Jigyasa Watwani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
only exponential growth
parent
eb55fab5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
moving_domain/moving_heat_equation_analytical.py
moving_domain/moving_heat_equation_analytical.py
View file @
6f648932
...
...
@@ -48,7 +48,7 @@ def advection_diffusion(Nx, L, Nt, tmax, D, alpha):
return
c_array
,
x_array
# plot c(x,t) numerical and analytical for given dt
dx
,
L
,
dt
,
tmax
,
D
,
alpha
=
0.0
01
,
1
,
0.001
,
1
,
0.01
,
0.1
dx
,
L
,
dt
,
tmax
,
D
,
alpha
=
0.0
1
,
1
,
0.01
,
20
,
0.01
,
0.1
Nx
=
int
(
L
/
dx
)
Nt
=
int
(
tmax
/
dt
)
x
=
advection_diffusion
(
Nx
,
L
,
Nt
,
tmax
,
D
,
alpha
)[
1
]
...
...
@@ -58,18 +58,17 @@ c_exact = np.zeros((Nt+1, Nx+1))
times
=
np
.
linspace
(
0
,
tmax
,
Nt
+
1
)
for
j
in
range
(
Nt
+
1
):
l
=
L
*
np
.
exp
(
alpha
*
times
[
j
])
if
alpha
==
0
:
beta
=
-
D
*
np
.
pi
**
2
*
times
[
j
]
/
L
**
2
c_exact
[
j
]
=
1
+
0.2
*
np
.
cos
(
np
.
pi
*
x
[
j
]
/
L
)
*
np
.
exp
(
beta
)
else
:
l
=
L
*
np
.
exp
(
alpha
*
times
[
j
])
beta
=
(
-
D
*
np
.
pi
**
2
/
(
2
*
alpha
*
L
**
2
))
*
(
1
-
np
.
exp
(
-
2
*
alpha
*
times
[
j
]))
c_exact
[
j
]
=
np
.
exp
(
-
alpha
*
times
[
j
])
*
(
1
+
0.2
*
np
.
cos
(
np
.
pi
*
x
[
j
]
/
l
)
*
np
.
exp
(
beta
))
c_exact
[
j
]
=
np
.
exp
(
-
alpha
*
times
[
j
])
*
(
1
+
0.2
*
np
.
cos
(
np
.
pi
*
x
[
j
]
/
l
)
*
np
.
exp
(
beta
))
# numerical solution
c
=
advection_diffusion
(
Nx
,
L
,
Nt
,
tmax
,
D
,
alpha
)[
0
]
fig
,
(
ax
,
ax1
)
=
plt
.
subplots
(
2
,
1
,
figsize
=
(
8
,
6
))
fig
,
(
ax
,
ax1
)
=
plt
.
subplots
(
2
,
1
,
figsize
=
(
8
,
6
))
ax
.
set_xlabel
(
r'$x$'
)
ax
.
set_ylabel
(
r'$c(x,t)$'
)
ax
.
set_xlim
(
np
.
min
(
x
),
np
.
max
(
x
)
+
2
)
...
...
@@ -79,13 +78,13 @@ cplot, = ax.plot(x[0], c[0], '--',label = 'Numerical solution')
cexactplot
,
=
ax
.
plot
(
x
[
0
],
c_exact
[
0
],
label
=
'Exact solution'
)
error
=
np
.
abs
(
c
-
c_exact
)
print
(
'dt
=
%6.3
f, max error =
%6.5
f'
%
(
tmax
/
Nt
,
np
.
max
(
error
)))
print
(
'dt
=
%6.3
f, max error =
%6.5
f'
%
(
tmax
/
Nt
,
np
.
max
(
error
)))
errorplot
,
=
ax1
.
plot
(
x
[
0
],
error
[
0
],
'bo'
,
mfc
=
'none'
)
ax1
.
set_ylabel
(
r'$|c(x,t) - c_{exact}(x,t)|$'
)
ax1
.
set_xlabel
(
'$x$'
)
ax1
.
set_xlim
(
np
.
min
(
x
),
np
.
max
(
x
)
+
2
)
ax1
.
set_ylim
([
np
.
min
(
error
)
-
1
,
np
.
max
(
error
)
+
1
])
def
update
(
value
):
ti
=
np
.
abs
(
times
-
value
)
.
argmin
()
cplot
.
set_xdata
(
x
[
ti
])
...
...
@@ -104,5 +103,13 @@ slider = Slider(sax, r'$t/\tau$', min(times), max(times),
slider
.
drawon
=
False
slider
.
on_changed
(
update
)
ax
.
legend
(
loc
=
0
)
fig
,
ax2
=
plt
.
subplots
(
1
,
1
,
figsize
=
(
8
,
6
))
ax2
.
semilogy
(
times
,
c
[:,
0
],
label
=
'$c_{num}(0,t)$'
)
if
alpha
==
0
:
ax2
.
semilogy
(
times
,
1
+
0.2
*
np
.
exp
(
-
D
*
np
.
pi
**
2
*
times
/
L
**
2
),
label
=
'$c_{an}(0,t)$'
)
else
:
ax2
.
semilogy
(
times
,
np
.
exp
(
-
alpha
*
times
)
*
(
1
+
0.2
*
np
.
exp
(
-
D
*
(
np
.
pi
**
2
/
(
2
*
alpha
*
L
**
2
))
*
(
1
-
np
.
exp
(
-
2
*
alpha
*
times
)))),
label
=
'$c_{an}(0,t)$'
)
ax2
.
legend
()
plt
.
show
()
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