Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils
Commits
3fe1aaf4
Commit
3fe1aaf4
authored
4 years ago
by
Michael Kuron
Browse files
Options
Downloads
Patches
Plain Diff
Volume-of-fluid: properly parametrize tests
parent
1b309654
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!163
Volume-of-Fluid: better tests and make it actually work
Pipeline
#25210
passed
4 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/fd/finitevolumes.py
+2
-2
2 additions, 2 deletions
pystencils/fd/finitevolumes.py
pystencils_tests/test_fvm.py
+23
-8
23 additions, 8 deletions
pystencils_tests/test_fvm.py
with
25 additions
and
10 deletions
pystencils/fd/finitevolumes.py
+
2
−
2
View file @
3fe1aaf4
...
...
@@ -202,12 +202,12 @@ def VOF(j: ps.field.Field, v: ps.field.Field, ρ: ps.field.Field):
"""
Volume-of-fluid discretization of advection
Args:
j: the staggered field to write the fluxes to. Needs to have D2Q9/D3Q27 stencil.
j: the staggered field to write the fluxes to. Should have a D2Q9/D3Q27 stencil. Other stencils work too, but
incur a small error (D2Q5/D3Q7: v^2, D3Q19: v^3).
v: the flow velocity field
ρ: the quantity to advect
"""
assert
ps
.
FieldType
.
is_staggered
(
j
)
assert
j
.
index_shape
[
0
]
==
(
3
**
j
.
spatial_dimensions
)
//
2
fluxes
=
[[]
for
i
in
range
(
j
.
index_shape
[
0
])]
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_fvm.py
+
23
−
8
View file @
3fe1aaf4
...
...
@@ -6,8 +6,7 @@ from itertools import product
from
scipy.optimize
import
curve_fit
@pytest.mark.parametrize
(
"
dim
"
,
[
2
,
3
])
def
test_advection_diffusion
(
dim
:
int
):
def
advection_diffusion
(
dim
:
int
):
# parameters
if
dim
==
2
:
L
=
(
32
,
32
)
...
...
@@ -100,26 +99,42 @@ def test_advection_diffusion(dim: int):
sim_density
.
reshape
(
-
1
),
p0
=
target
)
assert
np
.
isclose
(
popt
[
0
],
time
,
rtol
=
0.
05
)
assert
np
.
isclose
(
popt
[
1
],
D
,
rtol
=
0.
05
)
assert
np
.
isclose
(
popt
[
0
],
time
,
rtol
=
0.
1
)
assert
np
.
isclose
(
popt
[
1
],
D
,
rtol
=
0.
1
)
assert
np
.
allclose
(
calc_density
,
sim_density
,
atol
=
1e-4
)
for
vel
in
product
(
*
[[
0
,
-
0.047
,
0.041
],
[
0
,
-
0.031
,
0.023
],
[
0
,
-
0.017
,
0.011
]][:
dim
]):
run
(
np
.
array
(
vel
),
time
)
return
lambda
v
:
run
(
np
.
array
(
v
),
time
)
advection_diffusion
.
runners
=
{}
@pytest.mark.parametrize
(
"
velocity
"
,
list
(
product
([
0
,
-
0.047
,
0.041
],
[
0
,
-
0.031
,
0.023
])))
def
test_advection_diffusion_2d
(
velocity
):
if
2
not
in
advection_diffusion
.
runners
:
advection_diffusion
.
runners
[
2
]
=
advection_diffusion
(
2
)
advection_diffusion
.
runners
[
2
](
velocity
)
@pytest.mark.parametrize
(
"
velocity
"
,
list
(
product
([
0
,
-
0.047
,
0.041
],
[
0
,
-
0.031
,
0.023
],
[
0
,
-
0.017
,
0.011
])))
def
test_advection_diffusion_3d
(
velocity
):
if
3
not
in
advection_diffusion
.
runners
:
advection_diffusion
.
runners
[
3
]
=
advection_diffusion
(
3
)
advection_diffusion
.
runners
[
3
](
velocity
)
def
VOF2
(
j
:
ps
.
field
.
Field
,
v
:
ps
.
field
.
Field
,
ρ
:
ps
.
field
.
Field
,
simplify
=
True
):
"""
Volume-of-fluid discretization of advection
Args:
j: the staggered field to write the fluxes to. Needs to have D2Q9/D3Q27 stencil.
j: the staggered field to write the fluxes to. Should have a D2Q9/D3Q27 stencil. Other stencils work too, but
incur a small error (D2Q5/D3Q7: v^2, D3Q19: v^3).
v: the flow velocity field
ρ: the quantity to advect
simplify: whether to simplify the generated expressions (slow, but makes them much more readable and faster)
"""
dim
=
j
.
spatial_dimensions
assert
ps
.
FieldType
.
is_staggered
(
j
)
assert
j
.
index_shape
[
0
]
==
(
3
**
dim
)
//
2
def
assume_velocity
(
e
):
if
not
simplify
:
...
...
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