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
548a4c34
authored
Sep 14, 2022
by
Jigyasa Watwani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log log plot and calculation of slope
parent
28e5d062
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
6 deletions
euler_error/diffusion_fixed_domain_euler_errors.py
euler_error/diffusion_fixed_domain_euler_errors.py
View file @
548a4c34
...
...
@@ -3,6 +3,10 @@ import numpy as np
import
matplotlib.pyplot
as
plt
from
matplotlib.widgets
import
Slider
import
progressbar
from
scipy.optimize
import
curve_fit
def
linear_func
(
x
,
a
,
b
):
return
a
*
x
+
b
df
.
set_log_level
(
df
.
LogLevel
.
ERROR
)
df
.
parameters
[
'form_compiler'
][
'optimize'
]
=
True
...
...
@@ -40,8 +44,8 @@ def advection_diffusion(Nx, L, Nt, tmax, D):
return
c_array
# parameters
Nx
,
L
,
D
,
tmax
=
64
,
1.0
,
0.1
,
1.0
nt_array
=
np
.
array
([
50
,
100
,
200
,
400
,
600
,
800
,
1600
])
Nx
,
L
,
D
,
tmax
=
10
,
1
,
1
,
1
nt_array
=
np
.
array
([
50
,
100
,
200
,
400
,
800
,
1600
])
dt_array
=
tmax
/
nt_array
mesh
=
df
.
IntervalMesh
(
Nx
,
0
,
L
)
x
=
mesh
.
coordinates
()[:,
0
]
...
...
@@ -59,9 +63,12 @@ for i in range(0, len(nt_array)):
c
=
advection_diffusion
(
Nx
,
L
,
nt_array
[
i
],
tmax
,
D
)
error
[
i
]
=
np
.
max
(
np
.
abs
(
c
-
c_exact
))
popt
,
pcov
=
curve_fit
(
linear_func
,
np
.
log
(
dt_array
),
np
.
log
(
error
))
print
(
'The slope of the graph of log(error) vs log(dt) is'
,
popt
[
0
])
fig
,
ax
=
plt
.
subplots
(
1
)
ax
.
plot
(
dt_array
,
error
,
'bo'
)
ax
.
set_xlabel
(
'$dt$'
)
ax
.
set_ylabel
(
'error'
)
plt
.
show
()
ax
.
loglog
(
dt_array
,
error
,
'bo'
)
ax
.
set_xlabel
(
'log(dt)'
)
ax
.
set_ylabel
(
'log(error)'
)
ax
.
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