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
Markus Holzer
lbmpy
Commits
eb8adcdf
Commit
eb8adcdf
authored
3 years ago
by
Frederik Hennig
Committed by
Markus Holzer
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Stream-Only Kernel Fixes
parent
a6e35ca6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lbmpy/updatekernels.py
+24
-20
24 additions, 20 deletions
lbmpy/updatekernels.py
lbmpy_tests/test_update_kernel.py
+25
-14
25 additions, 14 deletions
lbmpy_tests/test_update_kernel.py
with
49 additions
and
34 deletions
lbmpy/updatekernels.py
+
24
−
20
View file @
eb8adcdf
...
@@ -55,11 +55,28 @@ def create_lbm_kernel(collision_rule, input_field, output_field, accessor):
...
@@ -55,11 +55,28 @@ def create_lbm_kernel(collision_rule, input_field, output_field, accessor):
return
result
return
result
def
create_stream_only_kernel
(
stencil
,
numpy_arr
=
None
,
src_field_name
=
"
src
"
,
dst_field_name
=
"
dst
"
,
def
create_stream_only_kernel
(
stencil
,
src_field
,
dst_field
,
accessor
=
StreamPullTwoFieldsAccessor
()):
generic_layout
=
'
numpy
'
,
generic_field_type
=
np
.
float64
,
accessor
=
StreamPullTwoFieldsAccessor
()):
"""
Creates a stream kernel, without collision.
"""
Creates a stream kernel, without collision.
Args:
stencil: lattice Boltzmann stencil which is used
src_field: Field the pre-streaming values are read from
dst_field: Field the post-streaming values are written to
accessor: Field accessor which is used to create the update rule. See
'
fieldaccess.PdfFieldAccessor
'
Returns:
AssignmentCollection of the stream only update rule
"""
temporary_symbols
=
sp
.
symbols
(
f
'
tmp_:
{
len
(
stencil
)
}
'
)
subexpressions
=
[
Assignment
(
tmp
,
acc
)
for
tmp
,
acc
in
zip
(
temporary_symbols
,
accessor
.
read
(
src_field
,
stencil
))]
main_assignments
=
[
Assignment
(
acc
,
tmp
)
for
acc
,
tmp
in
zip
(
accessor
.
write
(
dst_field
,
stencil
),
temporary_symbols
)]
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:
Args:
stencil: lattice Boltzmann stencil which is used
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
numpy_arr: numpy array which containes the pdf field data. If no numpy array is provided the symbolic field
...
@@ -68,11 +85,12 @@ def create_stream_only_kernel(stencil, numpy_arr=None, src_field_name="src", dst
...
@@ -68,11 +85,12 @@ def create_stream_only_kernel(stencil, numpy_arr=None, src_field_name="src", dst
dst_field_name: name of the destination field.
dst_field_name: name of the destination field.
generic_layout: data layout. for example
'
fzyx
'
of
'
zyxf
'
.
generic_layout: data layout. for example
'
fzyx
'
of
'
zyxf
'
.
generic_field_type: field data type.
generic_field_type: field data type.
accessor: Field accessor which is used to create the update rule. See
'
fieldaccess.PdfFieldAccessor
'
Returns:
Returns:
AssignmentCollection of the stream only update rule
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
])
dim
=
len
(
stencil
[
0
])
if
numpy_arr
is
None
:
if
numpy_arr
is
None
:
src
=
Field
.
create_generic
(
src_field_name
,
dim
,
index_shape
=
(
len
(
stencil
),),
src
=
Field
.
create_generic
(
src_field_name
,
dim
,
index_shape
=
(
len
(
stencil
),),
...
@@ -82,22 +100,7 @@ def create_stream_only_kernel(stencil, numpy_arr=None, src_field_name="src", dst
...
@@ -82,22 +100,7 @@ def create_stream_only_kernel(stencil, numpy_arr=None, src_field_name="src", dst
else
:
else
:
src
=
Field
.
create_from_numpy_array
(
src_field_name
,
numpy_arr
,
index_dimensions
=
1
)
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
)
dst
=
Field
.
create_from_numpy_array
(
dst_field_name
,
numpy_arr
,
index_dimensions
=
1
)
return
create_stream_only_kernel
(
stencil
,
src
,
dst
,
accessor
=
StreamPullTwoFieldsAccessor
())
eqs
=
[
Assignment
(
a
,
b
)
for
a
,
b
in
zip
(
accessor
.
write
(
dst
,
stencil
),
accessor
.
read
(
src
,
stencil
))]
return
AssignmentCollection
(
eqs
,
[])
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.
For parameters see function ``create_stream_pull_collide_kernel``
"""
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
)
return
create_stream_only_kernel
(
stencil
,
numpy_arr
=
numpy_arr
,
src_field_name
=
src_field_name
,
dst_field_name
=
dst_field_name
,
generic_layout
=
generic_layout
,
generic_field_type
=
generic_field_type
,
accessor
=
StreamPullTwoFieldsAccessor
())
def
create_stream_pull_with_output_kernel
(
lb_method
,
src_field
,
dst_field
,
output
):
def
create_stream_pull_with_output_kernel
(
lb_method
,
src_field
,
dst_field
,
output
):
...
@@ -114,6 +117,7 @@ def create_stream_pull_with_output_kernel(lb_method, src_field, dst_field, outpu
...
@@ -114,6 +117,7 @@ def create_stream_pull_with_output_kernel(lb_method, src_field, dst_field, outpu
return
LbmCollisionRule
(
lb_method
,
main_eqs
,
subexpressions
,
return
LbmCollisionRule
(
lb_method
,
main_eqs
,
subexpressions
,
simplification_hints
=
output_eq_collection
.
simplification_hints
)
simplification_hints
=
output_eq_collection
.
simplification_hints
)
# ---------------------------------- Pdf array creation for various layouts --------------------------------------------
# ---------------------------------- Pdf array creation for various layouts --------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
lbmpy_tests/test_update_kernel.py
+
25
−
14
View file @
eb8adcdf
...
@@ -3,27 +3,38 @@ import pytest
...
@@ -3,27 +3,38 @@ import pytest
import
pystencils
as
ps
import
pystencils
as
ps
from
lbmpy.stencils
import
get_stencil
from
lbmpy.stencils
import
get_stencil
from
lbmpy.fieldaccess
import
StreamPullTwoFieldsAccessor
,
StreamPushTwoFieldsAccessor
,
\
from
lbmpy.advanced_streaming.utility
import
get_timesteps
,
streaming_patterns
,
get_accessor
,
is_inplace
,
AccessPdfValues
AAOddTimeStepAccessor
,
AAEvenTimeStepAccessor
,
EsoTwistOddTimeStepAccessor
,
EsoTwistEvenTimeStepAccessor
from
lbmpy.updatekernels
import
create_stream_only_kernel
from
lbmpy.updatekernels
import
create_stream_only_kernel
from
pystencils
import
create_kernel
@pytest.mark.parametrize
(
'
accessor
'
,
[
StreamPullTwoFieldsAccessor
(),
StreamPushTwoFieldsAccessor
(),
@pytest.mark.parametrize
(
'
streaming_pattern
'
,
streaming_patterns
)
AAOddTimeStepAccessor
(),
AAEvenTimeStepAccessor
(),
def
test_stream_only_kernel
(
streaming_pattern
):
EsoTwistOddTimeStepAccessor
(),
EsoTwistEvenTimeStepAccessor
()])
def
test_stream_only_kernel
(
accessor
):
domain_size
=
(
4
,
4
)
domain_size
=
(
4
,
4
)
stencil
=
get_stencil
(
"
D2Q9
"
)
stencil
=
get_stencil
(
"
D2Q9
"
)
dh
=
ps
.
create_data_handling
(
domain_size
,
default_target
=
'
cpu
'
)
dh
=
ps
.
create_data_handling
(
domain_size
,
default_target
=
'
cpu
'
)
pdfs
=
dh
.
add_array
(
'
pdfs
'
,
values_per_cell
=
len
(
stencil
))
pdfs_tmp
=
dh
.
add_array_like
(
'
pdfs_tmp
'
,
'
pdfs
'
)
src
=
dh
.
add_array
(
'
src
'
,
values_per_cell
=
len
(
stencil
))
for
t
in
get_timesteps
(
streaming_pattern
):
dh
.
fill
(
'
src
'
,
0.0
,
ghost_layers
=
True
)
accessor
=
get_accessor
(
streaming_pattern
,
t
)
src
=
pdfs
dst
=
pdfs
if
is_inplace
(
streaming_pattern
)
else
pdfs_tmp
dst
=
dh
.
add_array_like
(
'
dst
'
,
'
src
'
)
dh
.
fill
(
src
.
name
,
0.0
)
dh
.
fill
(
'
dst
'
,
0.0
,
ghost_layers
=
True
)
dh
.
fill
(
dst
.
name
,
0.0
)
pull
=
create_stream_only_kernel
(
stencil
,
None
,
src
.
name
,
dst
.
name
,
accessor
=
accessor
)
stream_kernel
=
create_stream_only_kernel
(
stencil
,
src
,
dst
,
accessor
=
accessor
)
stream_func
=
create_kernel
(
stream_kernel
).
compile
()
for
i
,
eq
in
enumerate
(
pull
.
main_assignments
):
# Check functionality
assert
eq
.
rhs
.
offsets
==
accessor
.
read
(
src
,
stencil
)[
i
].
offsets
acc_in
=
AccessPdfValues
(
stencil
,
streaming_dir
=
'
in
'
,
accessor
=
accessor
)
assert
eq
.
lhs
.
offsets
==
accessor
.
write
(
dst
,
stencil
)[
i
].
offsets
for
i
in
range
(
len
(
stencil
)):
\ No newline at end of file
acc_in
.
write_pdf
(
dh
.
cpu_arrays
[
src
.
name
],
(
1
,
1
),
i
,
i
)
dh
.
run_kernel
(
stream_func
)
acc_out
=
AccessPdfValues
(
stencil
,
streaming_dir
=
'
out
'
,
accessor
=
accessor
)
for
i
in
range
(
len
(
stencil
)):
assert
acc_out
.
read_pdf
(
dh
.
cpu_arrays
[
dst
.
name
],
(
1
,
1
),
i
)
==
i
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