Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Markus Holzer
lbmpy
Commits
f317ef5b
Commit
f317ef5b
authored
Aug 10, 2021
by
Markus Holzer
Browse files
Updated update kernels
parent
84bfe3ac
Changes
1
Hide whitespace changes
Inline
Side-by-side
lbmpy/updatekernels.py
View file @
f317ef5b
...
...
@@ -9,6 +9,7 @@ from pystencils.field import create_numpy_array_with_layout, layout_string_to_tu
from
pystencils.simp
import
add_subexpressions_for_field_reads
from
pystencils.sympyextensions
import
fast_subs
# -------------------------------------------- LBM Kernel Creation -----------------------------------------------------
...
...
@@ -18,14 +19,14 @@ def create_lbm_kernel(collision_rule, src_field, dst_field=None, accessor=Stream
Args:
collision_rule: instance of LbmCollisionRule, defining the collision step
src_field: field used for reading pdf values
dst_field: field used for writing pdf values if accessor.is_inplace th
is parameter is ignor
ed
dst_field: field used for writing pdf values if
None and
accessor.is_inplace th
e src_field is us
ed
accessor: instance of PdfFieldAccessor, defining where to read and write values
to create e.g. a fused stream-collide kernel See 'fieldaccess.PdfFieldAccessor'
Returns:
LbmCollisionRule where pre- and post collision symbols have been replaced
"""
if
accessor
.
is_inplace
:
if
accessor
.
is_inplace
and
dst_field
is
None
:
dst_field
=
src_field
if
not
accessor
.
is_inplace
and
dst_field
is
None
:
...
...
@@ -63,14 +64,14 @@ def create_stream_only_kernel(stencil, src_field, dst_field=None, accessor=Strea
Args:
stencil: lattice Boltzmann stencil which is used in the form of a tuple of tuples
src_field: field used for reading pdf values
dst_field: field used for writing pdf values if accessor.is_inplace th
is parameter is ignor
ed
dst_field: field used for writing pdf values if
None and
accessor.is_inplace th
e src_field is us
ed
accessor: instance of PdfFieldAccessor, defining where to read and write values
to create e.g. a fused stream-collide kernel See 'fieldaccess.PdfFieldAccessor'
Returns:
AssignmentCollection of the stream only update rule
"""
if
accessor
.
is_inplace
:
if
accessor
.
is_inplace
and
dst_field
is
None
:
dst_field
=
src_field
if
not
accessor
.
is_inplace
and
dst_field
is
None
:
...
...
@@ -82,36 +83,6 @@ def create_stream_only_kernel(stencil, src_field, dst_field=None, accessor=Strea
return
AssignmentCollection
(
main_assignments
,
subexpressions
=
subexpressions
)
def
create_stream_pull_only_kernel
(
stencil
,
numpy_arr
=
None
,
src_field_name
=
"src"
,
dst_field_name
=
"dst"
,
generic_layout
=
'numpy'
,
generic_field_type
=
np
.
float64
):
"""Creates a stream kernel with the pull scheme, without collision.
Args:
stencil: lattice Boltzmann stencil which is used
numpy_arr: numpy array which containes the pdf field data. If no numpy array is provided the symbolic field
accesses are created with 'Field.create_generic'. Otherwise 'Field.create_from_numpy_array' is used.
src_field_name: name of the source field.
dst_field_name: name of the destination field.
generic_layout: data layout. for example 'fzyx' of 'zyxf'.
generic_field_type: field data type.
Returns:
AssignmentCollection of the stream only update rule
"""
warnings
.
warn
(
"This function is depricated. Please use create_stream_only_kernel. If no PdfFieldAccessor is "
"provided to this function a standard StreamPullTwoFieldsAccessor is used "
,
DeprecationWarning
)
dim
=
len
(
stencil
[
0
])
if
numpy_arr
is
None
:
src
=
Field
.
create_generic
(
src_field_name
,
dim
,
index_shape
=
(
len
(
stencil
),),
layout
=
generic_layout
,
dtype
=
generic_field_type
)
dst
=
Field
.
create_generic
(
dst_field_name
,
dim
,
index_shape
=
(
len
(
stencil
),),
layout
=
generic_layout
,
dtype
=
generic_field_type
)
else
:
src
=
Field
.
create_from_numpy_array
(
src_field_name
,
numpy_arr
,
index_dimensions
=
1
)
dst
=
Field
.
create_from_numpy_array
(
dst_field_name
,
numpy_arr
,
index_dimensions
=
1
)
return
create_stream_only_kernel
(
stencil
,
src
,
dst
,
accessor
=
StreamPullTwoFieldsAccessor
())
def
create_stream_pull_with_output_kernel
(
lb_method
,
src_field
,
dst_field
=
None
,
output
=
None
,
accessor
=
StreamPullTwoFieldsAccessor
()):
"""Creates a stream kernel, without collision but macroscopic quantaties like density or velocity can be calculated.
...
...
@@ -138,7 +109,7 @@ def create_stream_pull_with_output_kernel(lb_method, src_field, dst_field=None,
cqc
=
lb_method
.
conserved_quantity_computation
streamed
=
sp
.
symbols
(
f
"streamed_:
{
len
(
stencil
)
}
"
)
stream_assignments
=
[
Assignment
(
a
,
b
)
for
a
,
b
in
zip
(
streamed
,
accessor
.
read
(
src_field
,
stencil
))]
output_eq_collection
=
cqc
.
output_equations_from_pdfs
(
streamed
,
output
)
if
output
\
output_eq_collection
=
cqc
.
output_equations_from_pdfs
(
streamed
,
output
)
if
output
\
else
AssignmentCollection
(
main_assignments
=
[])
write_eqs
=
[
Assignment
(
a
,
b
)
for
a
,
b
in
zip
(
accessor
.
write
(
dst_field
,
stencil
),
streamed
)]
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment