Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
steldermann_test_wheel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ingo Steldermann
steldermann_test_wheel
Commits
233fd6fb
Commit
233fd6fb
authored
1 year ago
by
Ingo Steldermann
Browse files
Options
Downloads
Patches
Plain Diff
initial commit
parents
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
README.md
+3
-0
3 additions, 0 deletions
README.md
fd_solver.py
+111
-0
111 additions, 0 deletions
fd_solver.py
with
115 additions
and
0 deletions
.gitignore
0 → 100644
+
1
−
0
View file @
233fd6fb
venv/
This diff is collapsed.
Click to expand it.
README.md
0 → 100644
+
3
−
0
View file @
233fd6fb
# A wheel to rule them all...
This is a test wheel on how to get scikit-fdiff usable in pyodide.
This diff is collapsed.
Click to expand it.
fd_solver.py
0 → 100644
+
111
−
0
View file @
233fd6fb
r
"""
One dimension shallow water, dam break case.
============================================
This validation example use the shallow water equation to
model a dam sudden break. The two part of the domain have different
fluid depth and are separated by a well. A a certain instant, the wall
disappear, leading to a discontinuity wave in direction of the lower depth,
and a rarefaction wave in direction of the higher depth.
The model reads as
.. math::
\begin{cases}
\frac{\partial h}{\partial t} + \frac{\partial h}{\partial x} &= 0 \\
\frac{\partial u}{\partial t} + u\,\frac{\partial u}{\partial x} &= -g\,\frac{\partial h}{\partial x}
\end{cases}
and the results are validated on the Randall J. LeVeque book (LeVeque, R. (2002).
Finite Volume Methods for Hyperbolic Problems (Cambridge Texts in Applied Mathematics).
Cambridge: Cambridge University Press. doi:10.1017/CBO9780511791253).
"""
import
pylab
as
pl
import
pandas
as
pd
from
skfdiff
import
Model
,
Simulation
import
numpy
as
np
from
scipy.signal
import
savgol_filter
shallow_water
=
Model
([
"
-dx(h * u)
"
,
"
-upwind(u, u, x, 1) - dxh
"
],
[
"
h(x)
"
,
"
u(x)
"
])
###############################################################################
# Filter post-process
# -------------------
#
# As the discontinuity will be still harsh to handle by a "simple" finite
# difference solver (a finite volume solver is usually the tool you will need),
# we will use a gaussian filter that will be applied to the fluid height. This
# will smooth the oscillation (generated by numerical errors). This can be seen
# as a way to introduce numerical diffusion to the system, often done by adding
# a diffusion term in the model. The filter has to be carefully tuned (the same
# way an artificial diffusion has its coefficient diffusion carefully chosen)
# to smooth the numerical oscillation without affecting the physical behavior
# of the simulation.
def
filter_instabilities
(
simul
):
simul
.
fields
[
"
h
"
]
=
(
"
x
"
,),
savgol_filter
(
simul
.
fields
[
"
h
"
],
21
,
4
)
def
run
():
x
,
dx
=
np
.
linspace
(
-
5
,
5
,
1000
,
retstep
=
True
)
h
=
np
.
where
(
x
<
0
,
3
,
1
)
u
=
x
*
0
init_fields
=
shallow_water
.
Fields
(
x
=
x
,
h
=
h
,
u
=
u
)
simul
=
Simulation
(
shallow_water
,
t
=
0
,
dt
=
0.02
,
tmax
=
2
,
fields
=
init_fields
,
time_stepping
=
False
,
id
=
"
dambreak
"
,
)
simul
.
add_post_process
(
"
filter
"
,
filter_instabilities
)
container
=
simul
.
attach_container
()
simul
.
run
()
return
container
data
=
container
.
data
.
sel
(
t
=
[
0
,
0.5
,
2
],
method
=
"
nearest
"
)
return
data
def
plot
(
data
):
fig
,
axs
=
pl
.
subplots
(
2
,
2
,
sharex
=
"
all
"
,
figsize
=
(
5.5
,
2.5
))
for
i
,
t
in
enumerate
(
data
.
t
):
if
i
==
1
:
continue
if
i
==
2
:
pl
.
sca
(
axs
[
i
-
1
,
0
])
else
:
pl
.
sca
(
axs
[
i
,
0
])
data
.
sel
(
t
=
t
).
h
.
plot
(
color
=
"
black
"
,
label
=
"
Sol.
"
)
ref_data
=
pd
.
read_csv
(
"
valid_randall/dam_h%i.csv
"
%
i
)
pl
.
scatter
(
ref_data
.
x
,
ref_data
.
h
,
color
=
"
red
"
,
marker
=
"
.
"
,
label
=
"
Ref.
"
)
pl
.
title
(
""
)
pl
.
ylabel
(
r
"
$h$
"
)
pl
.
xlim
(
-
5
,
5
)
pl
.
ylim
(
0.5
,
4
)
if
i
==
0
:
pl
.
legend
()
if
i
==
2
:
pl
.
sca
(
axs
[
i
-
1
,
1
])
else
:
pl
.
sca
(
axs
[
i
,
1
])
(
data
.
sel
(
t
=
t
).
h
*
data
.
sel
(
t
=
t
).
u
).
plot
(
color
=
"
black
"
,
label
=
"
Sol.
"
)
ref_data
=
pd
.
read_csv
(
"
valid_randall/dam_hu%i.csv
"
%
i
)
pl
.
scatter
(
ref_data
.
x
,
ref_data
.
h
,
color
=
"
red
"
,
marker
=
"
.
"
,
label
=
"
Ref.
"
)
pl
.
title
(
""
)
pl
.
ylabel
(
r
"
$u\,h$
"
)
pl
.
xlim
(
-
5
,
5
)
pl
.
ylim
(
-
0.5
,
1.5
)
pl
.
tight_layout
()
pl
.
show
()
return
fig
run
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment