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
ae9f769e
Commit
ae9f769e
authored
4 years ago
by
Markus Holzer
Committed by
Michael Kuron
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Generalize stream only kernel
parent
d77c86e0
No related branches found
No related tags found
1 merge request
!74
Generalize stream only kernel
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lbmpy/updatekernels.py
+31
-7
31 additions, 7 deletions
lbmpy/updatekernels.py
lbmpy_tests/phasefield/test_phasefield.py
+1
-1
1 addition, 1 deletion
lbmpy_tests/phasefield/test_phasefield.py
lbmpy_tests/test_update_kernel.py
+29
-0
29 additions, 0 deletions
lbmpy_tests/test_update_kernel.py
with
61 additions
and
8 deletions
lbmpy/updatekernels.py
+
31
−
7
View file @
ae9f769e
import
numpy
as
np
import
sympy
as
sp
import
warnings
from
lbmpy.fieldaccess
import
StreamPullTwoFieldsAccessor
from
lbmpy.methods.abstractlbmethod
import
LbmCollisionRule
...
...
@@ -54,13 +55,24 @@ def create_lbm_kernel(collision_rule, input_field, output_field, accessor):
return
result
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-pull kernel, without collision.
def
create_stream_only_kernel
(
stencil
,
numpy_arr
=
None
,
src_field_name
=
"
src
"
,
dst_field_name
=
"
dst
"
,
generic_layout
=
'
numpy
'
,
generic_field_type
=
np
.
float64
,
accessor
=
StreamPullTwoFieldsAccessor
()):
"""
Creates a stream kernel, without collision.
For parameters see function ``create_stream_pull_collide_kernel``
"""
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.
accessor: Field accessor which is used to create the update rule. See
'
fieldaccess.PdfFieldAccessor
'
Returns:
AssignmentCollection of the stream only update rule
"""
dim
=
len
(
stencil
[
0
])
if
numpy_arr
is
None
:
src
=
Field
.
create_generic
(
src_field_name
,
dim
,
index_shape
=
(
len
(
stencil
),),
...
...
@@ -71,15 +83,27 @@ def create_stream_pull_only_kernel(stencil, numpy_arr=None, src_field_name="src"
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
)
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
):
stencil
=
lb_method
.
stencil
cqc
=
lb_method
.
conserved_quantity_computation
streamed
=
sp
.
symbols
(
"
streamed_:
%d
"
%
(
len
(
stencil
)
,)
)
streamed
=
sp
.
symbols
(
f
"
streamed_:
{
len
(
stencil
)
}
"
)
accessor
=
StreamPullTwoFieldsAccessor
()
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
)
...
...
This diff is collapsed.
Click to expand it.
lbmpy_tests/phasefield/test_phasefield.py
+
1
−
1
View file @
ae9f769e
...
...
@@ -88,7 +88,7 @@ def test_neumann_angle():
sc
.
run
(
10000
)
angles
=
liquid_lens_neumann_angles
(
sc
.
concentration
[:,
:,
:])
assert
sum
(
angles
)
==
360
np
.
testing
.
assert_almost_equal
(
sum
(
angles
)
,
360
)
analytic_angles
=
analytic_neumann_angles
([
0.01
,
0.02
,
kappa3
])
for
ref
,
simulated
in
zip
(
analytic_angles
,
angles
):
...
...
This diff is collapsed.
Click to expand it.
lbmpy_tests/test_update_kernel.py
0 → 100644
+
29
−
0
View file @
ae9f769e
import
pytest
import
pystencils
as
ps
from
lbmpy.stencils
import
get_stencil
from
lbmpy.fieldaccess
import
StreamPullTwoFieldsAccessor
,
StreamPushTwoFieldsAccessor
,
\
AAOddTimeStepAccessor
,
AAEvenTimeStepAccessor
,
EsoTwistOddTimeStepAccessor
,
EsoTwistEvenTimeStepAccessor
from
lbmpy.updatekernels
import
create_stream_only_kernel
@pytest.mark.parametrize
(
'
accessor
'
,
[
StreamPullTwoFieldsAccessor
(),
StreamPushTwoFieldsAccessor
(),
AAOddTimeStepAccessor
(),
AAEvenTimeStepAccessor
(),
EsoTwistOddTimeStepAccessor
(),
EsoTwistEvenTimeStepAccessor
()])
def
test_stream_only_kernel
(
accessor
):
domain_size
=
(
4
,
4
)
stencil
=
get_stencil
(
"
D2Q9
"
)
dh
=
ps
.
create_data_handling
(
domain_size
,
default_target
=
'
cpu
'
)
src
=
dh
.
add_array
(
'
src
'
,
values_per_cell
=
len
(
stencil
))
dh
.
fill
(
'
src
'
,
0.0
,
ghost_layers
=
True
)
dst
=
dh
.
add_array_like
(
'
dst
'
,
'
src
'
)
dh
.
fill
(
'
dst
'
,
0.0
,
ghost_layers
=
True
)
pull
=
create_stream_only_kernel
(
stencil
,
None
,
src
.
name
,
dst
.
name
,
accessor
=
accessor
)
for
i
,
eq
in
enumerate
(
pull
.
main_assignments
):
assert
eq
.
rhs
.
offsets
==
accessor
.
read
(
src
,
stencil
)[
i
].
offsets
assert
eq
.
lhs
.
offsets
==
accessor
.
write
(
dst
,
stencil
)[
i
].
offsets
\ No newline at end of file
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