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
ff7e21dd
authored
Sep 27, 2022
by
Jigyasa Watwani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
solution plot, error plot for fixed dt
parent
ceefbb2e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
moving_domain/moving_heat_equation_analytical.py
moving_domain/moving_heat_equation_analytical.py
View file @
ff7e21dd
...
@@ -54,30 +54,45 @@ x = advection_diffusion(Nx, L, Nt, tmax, D, alpha)[1]
...
@@ -54,30 +54,45 @@ x = advection_diffusion(Nx, L, Nt, tmax, D, alpha)[1]
# exact solution
# exact solution
c_exact
=
np
.
zeros
((
Nt
+
1
,
Nx
+
1
))
c_exact
=
np
.
zeros
((
Nt
+
1
,
Nx
+
1
))
times
=
np
.
linspace
(
0
,
tmax
,
Nt
+
1
)
times
=
np
.
linspace
(
0
,
tmax
,
Nt
+
1
)
for
j
in
range
(
Nt
+
1
):
for
j
in
range
(
Nt
+
1
):
l
=
L
*
np
.
exp
(
alpha
*
times
[
j
])
if
alpha
==
0
:
if
alpha
==
0
:
c_exact
[
j
]
=
1
+
0.2
*
np
.
cos
(
np
.
pi
*
x
[
j
]
/
L
)
*
np
.
exp
(
-
np
.
pi
**
2
*
D
*
times
[
j
]
/
L
**
2
)
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
:
else
:
c_exact
[
j
]
=
1
+
0.2
*
np
.
cos
(
np
.
pi
*
x
[
j
]
*
np
.
exp
(
-
alpha
*
times
[
j
])
/
L
)
*
np
.
exp
(
-
np
.
pi
**
2
*
D
*
(
1
-
np
.
exp
(
-
2
*
alpha
*
times
[
j
]))
/
(
2
*
alpha
*
L
**
2
))
*
np
.
exp
(
-
alpha
*
times
[
j
])
beta
=
(
-
D
*
np
.
pi
**
2
/
(
2
*
alpha
*
L
**
2
))
*
(
1
-
np
.
exp
(
-
2
*
alpha
*
times
[
j
]))
c_exact
[
j
]
=
1
+
0.2
*
np
.
cos
(
np
.
pi
*
x
[
j
]
/
l
)
*
np
.
exp
(
-
alpha
*
times
[
j
])
*
np
.
exp
(
beta
)
c
=
advection_diffusion
(
Nx
,
L
,
Nt
,
tmax
,
D
,
alpha
)[
0
]
c
=
advection_diffusion
(
Nx
,
L
,
Nt
,
tmax
,
D
,
alpha
)[
0
]
times
=
np
.
linspace
(
0
,
tmax
,
Nt
+
1
)
times
=
np
.
linspace
(
0
,
tmax
,
Nt
+
1
)
fig
,
ax
=
plt
.
subplots
(
1
,
1
,
figsize
=
(
8
,
6
))
fig
,
(
ax
,
ax1
)
=
plt
.
subplots
(
2
,
1
,
figsize
=
(
8
,
6
))
ax
.
set_xlabel
(
r'$x$'
)
ax
.
set_xlabel
(
r'$x$'
)
ax
.
set_ylabel
(
r'$c(x,t)$'
)
ax
.
set_ylabel
(
r'$c(x,t)$'
)
ax
.
set_xlim
(
np
.
min
(
x
)
-
2
,
np
.
max
(
x
)
+
2
)
ax
.
set_xlim
(
np
.
min
(
x
),
np
.
max
(
x
)
+
2
)
ax
.
set_ylim
(
np
.
min
(
c
)
-
2
,
np
.
max
(
c
)
+
2
)
ax
.
set_ylim
(
min
(
np
.
min
(
c
),
np
.
min
(
c_exact
))
-
1
,
max
(
np
.
max
(
c
),
np
.
max
(
c_exact
))
+
1
)
cplot
,
=
ax
.
plot
(
x
[
0
],
c
[
0
],
'go'
,
mfc
=
'none'
,
label
=
'Numerical solution'
)
cexactplot
,
=
ax
.
plot
(
x
[
0
],
c_exact
[
0
],
label
=
'Exact solution'
)
cplot
,
=
ax
.
plot
(
x
[
0
],
c
[
0
],
'go'
,
ms
=
1
)
error
=
np
.
abs
(
c
-
c_exact
)
cexactplot
,
=
ax
.
plot
(
x
[
0
],
c_exact
[
0
])
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
):
def
update
(
value
):
ti
=
np
.
abs
(
times
-
value
)
.
argmin
()
ti
=
np
.
abs
(
times
-
value
)
.
argmin
()
cplot
.
set_xdata
(
x
[
ti
])
cplot
.
set_xdata
(
x
[
ti
])
cplot
.
set_ydata
(
c
[
ti
])
cplot
.
set_ydata
(
c
[
ti
])
cexactplot
.
set_xdata
(
x
[
ti
])
cexactplot
.
set_xdata
(
x
[
ti
])
cexactplot
.
set_ydata
(
c_exact
[
ti
])
cexactplot
.
set_ydata
(
c_exact
[
ti
])
errorplot
.
set_xdata
(
x
[
ti
])
errorplot
.
set_ydata
(
error
[
ti
])
plt
.
draw
()
plt
.
draw
()
sax
=
plt
.
axes
([
0.1
,
0.92
,
0.7
,
0.02
])
sax
=
plt
.
axes
([
0.1
,
0.92
,
0.7
,
0.02
])
...
@@ -86,5 +101,6 @@ slider = Slider(sax, r'$t/\tau$', min(times), max(times),
...
@@ -86,5 +101,6 @@ slider = Slider(sax, r'$t/\tau$', min(times), max(times),
fc
=
'#999999'
)
fc
=
'#999999'
)
slider
.
drawon
=
False
slider
.
drawon
=
False
slider
.
on_changed
(
update
)
slider
.
on_changed
(
update
)
ax
.
legend
(
loc
=
0
)
plt
.
show
()
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