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
9b8ec60e
Commit
9b8ec60e
authored
8 months ago
by
Philipp Suffa
Browse files
Options
Downloads
Patches
Plain Diff
Small change to reduce code duplication
parent
fc2bd74e
No related branches found
No related tags found
1 merge request
!179
Implements a getter function for the strain rate tensor
Pipeline
#69268
passed
8 months ago
Stage: pretest
Stage: test
Stage: docs
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lbmpy/macroscopic_value_kernels.py
+19
-35
19 additions, 35 deletions
src/lbmpy/macroscopic_value_kernels.py
with
19 additions
and
35 deletions
src/lbmpy/macroscopic_value_kernels.py
+
19
−
35
View file @
9b8ec60e
...
@@ -11,25 +11,29 @@ from lbmpy.relaxationrates import get_shear_relaxation_rate
...
@@ -11,25 +11,29 @@ from lbmpy.relaxationrates import get_shear_relaxation_rate
from
lbmpy.utils
import
second_order_moment_tensor
from
lbmpy.utils
import
second_order_moment_tensor
def
pdf_initialization_assignments
(
lb_method
,
density
,
velocity
,
pdfs
,
def
get_field_accesses
(
lb_method
,
pdfs
,
streaming_pattern
,
previous_timestep
,
pre_collision_pdfs
):
streaming_pattern
=
'
pull
'
,
previous_timestep
=
Timestep
.
BOTH
,
set_pre_collision_pdfs
=
False
):
"""
Assignments to initialize the pdf field with equilibrium
"""
if
isinstance
(
pdfs
,
Field
):
if
isinstance
(
pdfs
,
Field
):
accessor
=
get_accessor
(
streaming_pattern
,
previous_timestep
)
accessor
=
get_accessor
(
streaming_pattern
,
previous_timestep
)
if
set_
pre_collision_pdfs
:
if
pre_collision_pdfs
:
field_accesses
=
accessor
.
read
(
pdfs
,
lb_method
.
stencil
)
field_accesses
=
accessor
.
read
(
pdfs
,
lb_method
.
stencil
)
else
:
else
:
field_accesses
=
accessor
.
write
(
pdfs
,
lb_method
.
stencil
)
field_accesses
=
accessor
.
write
(
pdfs
,
lb_method
.
stencil
)
elif
streaming_pattern
==
'
pull
'
and
not
set_
pre_collision_pdfs
:
elif
streaming_pattern
==
'
pull
'
and
not
pre_collision_pdfs
:
field_accesses
=
pdfs
field_accesses
=
pdfs
else
:
else
:
raise
ValueError
(
"
Invalid value of pdfs: A PDF field reference is required to derive
"
raise
ValueError
(
"
Invalid value of pdfs: A PDF field reference is required to derive
"
+
f
"
initialization assignments for streaming pattern
{
streaming_pattern
}
.
"
)
+
f
"
initialization assignments for streaming pattern
{
streaming_pattern
}
.
"
)
return
field_accesses
def
pdf_initialization_assignments
(
lb_method
,
density
,
velocity
,
pdfs
,
streaming_pattern
=
'
pull
'
,
previous_timestep
=
Timestep
.
BOTH
,
set_pre_collision_pdfs
=
False
):
"""
Assignments to initialize the pdf field with equilibrium
"""
field_accesses
=
get_field_accesses
(
lb_method
,
pdfs
,
streaming_pattern
,
previous_timestep
,
set_pre_collision_pdfs
)
if
isinstance
(
density
,
Field
):
if
isinstance
(
density
,
Field
):
density
=
density
.
center
density
=
density
.
center
if
isinstance
(
velocity
,
Field
):
if
isinstance
(
velocity
,
Field
):
velocity
=
velocity
.
center_vector
velocity
=
velocity
.
center_vector
...
@@ -44,17 +48,9 @@ def pdf_initialization_assignments(lb_method, density, velocity, pdfs,
...
@@ -44,17 +48,9 @@ def pdf_initialization_assignments(lb_method, density, velocity, pdfs,
def
macroscopic_values_getter
(
lb_method
,
density
,
velocity
,
pdfs
,
def
macroscopic_values_getter
(
lb_method
,
density
,
velocity
,
pdfs
,
streaming_pattern
=
'
pull
'
,
previous_timestep
=
Timestep
.
BOTH
,
streaming_pattern
=
'
pull
'
,
previous_timestep
=
Timestep
.
BOTH
,
use_pre_collision_pdfs
=
False
):
use_pre_collision_pdfs
=
False
):
if
isinstance
(
pdfs
,
Field
):
accessor
=
get_accessor
(
streaming_pattern
,
previous_timestep
)
field_accesses
=
get_field_accesses
(
lb_method
,
pdfs
,
streaming_pattern
,
previous_timestep
,
use_pre_collision_pdfs
)
if
use_pre_collision_pdfs
:
field_accesses
=
accessor
.
read
(
pdfs
,
lb_method
.
stencil
)
else
:
field_accesses
=
accessor
.
write
(
pdfs
,
lb_method
.
stencil
)
elif
streaming_pattern
==
'
pull
'
and
not
use_pre_collision_pdfs
:
field_accesses
=
pdfs
else
:
raise
ValueError
(
"
Invalid value of pdfs: A PDF field reference is required to derive
"
+
f
"
getter assignments for streaming pattern
{
streaming_pattern
}
.
"
)
cqc
=
lb_method
.
conserved_quantity_computation
cqc
=
lb_method
.
conserved_quantity_computation
assert
not
(
velocity
is
None
and
density
is
None
)
assert
not
(
velocity
is
None
and
density
is
None
)
output_spec
=
{}
output_spec
=
{}
...
@@ -68,21 +64,10 @@ def macroscopic_values_getter(lb_method, density, velocity, pdfs,
...
@@ -68,21 +64,10 @@ def macroscopic_values_getter(lb_method, density, velocity, pdfs,
macroscopic_values_setter
=
pdf_initialization_assignments
macroscopic_values_setter
=
pdf_initialization_assignments
def
strain_rate_tensor_getter
(
lb_method
,
strain_rate_tensor
,
pdfs
,
streaming_pattern
=
'
pull
'
,
def
strain_rate_tensor_getter
(
lb_method
,
strain_rate_tensor
,
pdfs
,
streaming_pattern
=
'
pull
'
,
previous_timestep
=
Timestep
.
BOTH
,
use_pre_collision_pdfs
=
False
):
previous_timestep
=
Timestep
.
BOTH
,
use_pre_collision_pdfs
=
False
):
if
isinstance
(
pdfs
,
Field
):
field_accesses
=
get_field_accesses
(
lb_method
,
pdfs
,
streaming_pattern
,
previous_timestep
,
use_pre_collision_pdfs
)
accessor
=
get_accessor
(
streaming_pattern
,
previous_timestep
)
if
use_pre_collision_pdfs
:
field_accesses
=
accessor
.
read
(
pdfs
,
lb_method
.
stencil
)
else
:
field_accesses
=
accessor
.
write
(
pdfs
,
lb_method
.
stencil
)
elif
streaming_pattern
==
'
pull
'
and
not
use_pre_collision_pdfs
:
field_accesses
=
pdfs
else
:
raise
ValueError
(
"
Invalid value of pdfs: A PDF field reference is required to derive
"
+
f
"
getter assignments for streaming pattern
{
streaming_pattern
}
.
"
)
if
isinstance
(
strain_rate_tensor
,
Field
):
if
isinstance
(
strain_rate_tensor
,
Field
):
strain_rate_tensor
=
strain_rate_tensor
.
center_vector
strain_rate_tensor
=
strain_rate_tensor
.
center_vector
...
@@ -91,16 +76,15 @@ def strain_rate_tensor_getter(lb_method, strain_rate_tensor, pdfs,streaming_patt
...
@@ -91,16 +76,15 @@ def strain_rate_tensor_getter(lb_method, strain_rate_tensor, pdfs,streaming_patt
equilibrium
=
lb_method
.
equilibrium_distribution
equilibrium
=
lb_method
.
equilibrium_distribution
rho
=
equilibrium
.
density
if
equilibrium
.
compressible
else
equilibrium
.
background_density
rho
=
equilibrium
.
density
if
equilibrium
.
compressible
else
equilibrium
.
background_density
f_neq
=
sp
.
Matrix
([
field_accesses
[
i
]
for
i
in
range
(
lb_method
.
stencil
.
Q
)])
-
lb_method
.
get_equilibrium_terms
()
f_neq
=
sp
.
Matrix
([
field_accesses
[
i
]
for
i
in
range
(
lb_method
.
stencil
.
Q
)])
-
lb_method
.
get_equilibrium_terms
()
pi
=
second_order_moment_tensor
(
f_neq
,
lb_method
.
stencil
)
pi
=
second_order_moment_tensor
(
f_neq
,
lb_method
.
stencil
)
strain_rate_tensor_equ
=
-
1.5
*
(
omega_s
/
rho
)
*
pi
strain_rate_tensor_equ
=
-
1.5
*
(
omega_s
/
rho
)
*
pi
assignments
=
[
Assignment
(
strain_rate_tensor
[
i
*
lb_method
.
stencil
.
D
+
j
],
strain_rate_tensor_equ
[
i
,
j
])
for
i
in
range
(
lb_method
.
stencil
.
D
)
for
j
in
range
(
lb_method
.
stencil
.
D
)]
assignments
=
[
Assignment
(
strain_rate_tensor
[
i
*
lb_method
.
stencil
.
D
+
j
],
strain_rate_tensor_equ
[
i
,
j
])
for
i
in
range
(
lb_method
.
stencil
.
D
)
for
j
in
range
(
lb_method
.
stencil
.
D
)]
return
assignments
return
assignments
def
compile_macroscopic_values_getter
(
lb_method
,
output_quantities
,
pdf_arr
=
None
,
def
compile_macroscopic_values_getter
(
lb_method
,
output_quantities
,
pdf_arr
=
None
,
ghost_layers
=
1
,
iteration_slice
=
None
,
ghost_layers
=
1
,
iteration_slice
=
None
,
field_layout
=
'
numpy
'
,
target
=
Target
.
CPU
,
field_layout
=
'
numpy
'
,
target
=
Target
.
CPU
,
...
...
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