Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
lbmpy
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
lbmpy
Commits
884428ee
Commit
884428ee
authored
4 years ago
by
Helen Schottenhamml
Committed by
Michael Kuron
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix: momentum density calculation
parent
7df9ca58
No related branches found
No related tags found
1 merge request
!42
Fix: momentum density calculation
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lbmpy/forcemodels.py
+22
-0
22 additions, 0 deletions
lbmpy/forcemodels.py
lbmpy/methods/conservedquantitycomputation.py
+2
-2
2 additions, 2 deletions
lbmpy/methods/conservedquantitycomputation.py
lbmpy_tests/test_force.py
+37
-0
37 additions, 0 deletions
lbmpy_tests/test_force.py
with
61 additions
and
2 deletions
lbmpy/forcemodels.py
+
22
−
0
View file @
884428ee
...
...
@@ -113,6 +113,9 @@ class Simple:
def
macroscopic_velocity_shift
(
self
,
density
):
return
default_velocity_shift
(
density
,
self
.
_force
)
def
macroscopic_momentum_density_shift
(
self
,
density
):
return
default_momentum_density_shift
(
self
.
_force
)
class
Luo
:
r
"""
Force model by Luo :cite:`luo1993lattice`.
...
...
@@ -135,6 +138,9 @@ class Luo:
def
macroscopic_velocity_shift
(
self
,
density
):
return
default_velocity_shift
(
density
,
self
.
_force
)
def
macroscopic_momentum_density_shift
(
self
,
density
):
return
default_momentum_density_shift
(
self
.
_force
)
class
Guo
:
r
"""
...
...
@@ -155,6 +161,9 @@ class Guo:
def
macroscopic_velocity_shift
(
self
,
density
):
return
default_velocity_shift
(
density
,
self
.
_force
)
def
macroscopic_momentum_density_shift
(
self
,
density
):
return
default_momentum_density_shift
(
self
.
_force
)
def
equilibrium_velocity_shift
(
self
,
density
):
return
default_velocity_shift
(
density
,
self
.
_force
)
...
...
@@ -187,6 +196,9 @@ class Schiller:
def
macroscopic_velocity_shift
(
self
,
density
):
return
default_velocity_shift
(
density
,
self
.
_force
)
def
macroscopic_momentum_density_shift
(
self
,
density
):
return
default_momentum_density_shift
(
self
.
_force
)
class
Buick
:
r
"""
...
...
@@ -208,6 +220,9 @@ class Buick:
def
macroscopic_velocity_shift
(
self
,
density
):
return
default_velocity_shift
(
density
,
self
.
_force
)
def
macroscopic_momentum_density_shift
(
self
,
density
):
return
default_momentum_density_shift
(
self
.
_force
)
def
equilibrium_velocity_shift
(
self
,
density
):
return
default_velocity_shift
(
density
,
self
.
_force
)
...
...
@@ -231,9 +246,16 @@ class EDM:
def
macroscopic_velocity_shift
(
self
,
density
):
return
default_velocity_shift
(
density
,
self
.
_force
)
def
macroscopic_momentum_density_shift
(
self
,
density
):
return
default_momentum_density_shift
(
self
.
_force
)
# -------------------------------- Helper functions ------------------------------------------------------------------
def
default_velocity_shift
(
density
,
force
):
return
[
f_i
/
(
2
*
density
)
for
f_i
in
force
]
def
default_momentum_density_shift
(
force
):
return
[
f_i
/
2
for
f_i
in
force
]
This diff is collapsed.
Click to expand it.
lbmpy/methods/conservedquantitycomputation.py
+
2
−
2
View file @
884428ee
...
...
@@ -207,8 +207,8 @@ class DensityVelocityComputation(AbstractConservedQuantityComputation):
mom_density_eq_coll
=
get_equations_for_zeroth_and_first_order_moment
(
self
.
_stencil
,
pdfs
,
self
.
_symbolOrder0
,
self
.
_symbolsOrder1
)
mom_density_eq_coll
=
apply_force_model_shift
(
'
macroscopic_
veloc
ity_shift
'
,
dim
,
mom_density_eq_coll
,
self
.
_forceModel
,
self
.
_compressible
)
mom_density_eq_coll
=
apply_force_model_shift
(
'
macroscopic_
momentum_dens
ity_shift
'
,
dim
,
mom_density_eq_coll
,
self
.
_forceModel
,
self
.
_compressible
)
for
sym
,
val
in
zip
(
momentum_density_output_symbols
,
mom_density_eq_coll
.
main_assignments
[
1
:]):
main_assignments
.
append
(
Assignment
(
sym
,
val
.
rhs
))
if
'
moment0
'
in
output_quantity_names_to_symbols
:
...
...
This diff is collapsed.
Click to expand it.
lbmpy_tests/test_force.py
+
37
−
0
View file @
884428ee
...
...
@@ -155,3 +155,40 @@ def test_modes(stencil, force_model):
elif
force_model
==
"
simple
"
:
# All other moments should be zero
assert
list
(
force_moments
[
dim
+
1
:])
==
[
0
]
*
(
len
(
stencil
)
-
(
dim
+
1
))
@pytest.mark.parametrize
(
"
force_model
"
,
force_models
)
def
test_momentum_density_shift
(
force_model
):
target
=
'
cpu
'
stencil
=
get_stencil
(
'
D2Q9
'
)
domain_size
=
(
4
,
4
)
dh
=
ps
.
create_data_handling
(
domain_size
=
domain_size
,
default_target
=
target
)
rho
=
dh
.
add_array
(
'
rho
'
,
values_per_cell
=
1
)
dh
.
fill
(
'
rho
'
,
0.0
,
ghost_layers
=
True
)
velField
=
dh
.
add_array
(
'
velField
'
,
values_per_cell
=
dh
.
dim
)
dh
.
fill
(
'
velField
'
,
0.0
,
ghost_layers
=
True
)
momentum_density
=
dh
.
add_array
(
'
momentum_density
'
,
values_per_cell
=
dh
.
dim
)
dh
.
fill
(
'
momentum_density
'
,
0.0
,
ghost_layers
=
True
)
src
=
dh
.
add_array
(
'
src
'
,
values_per_cell
=
len
(
stencil
))
dh
.
fill
(
'
src
'
,
0.0
,
ghost_layers
=
True
)
method
=
create_lb_method
(
method
=
"
srt
"
,
compressible
=
True
,
force_model
=
force_model
,
force
=
[
1
,
2
])
momentum_density_symbols
=
sp
.
symbols
(
"
md_:2
"
)
cqc
=
method
.
conserved_quantity_computation
momentum_density_getter
=
cqc
.
output_equations_from_pdfs
(
src
.
center_vector
,
{
'
density
'
:
rho
.
center
,
'
momentum_density
'
:
momentum_density
.
center_vector
})
momentum_density_ast
=
ps
.
create_kernel
(
momentum_density_getter
,
target
=
dh
.
default_target
)
momentum_density_kernel
=
momentum_density_ast
.
compile
()
dh
.
run_kernel
(
momentum_density_kernel
)
assert
np
.
sum
(
dh
.
gather_array
(
momentum_density
.
name
)[:,
:,
0
])
==
np
.
prod
(
domain_size
)
/
2
assert
np
.
sum
(
dh
.
gather_array
(
momentum_density
.
name
)[:,
:,
1
])
==
np
.
prod
(
domain_size
)
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