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
Frederik Hennig
lbmpy
Commits
14984e2b
Commit
14984e2b
authored
Nov 01, 2020
by
Frederik Hennig
Browse files
API update for creationfunctions
parent
3a19fa24
Pipeline
#27654
waiting for manual action with stage
in 24 minutes and 2 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lbmpy/creationfunctions.py
View file @
14984e2b
...
...
@@ -176,10 +176,7 @@ from copy import copy
import
sympy
as
sp
import
lbmpy.forcemodels
as
forcemodels
from
lbmpy.fieldaccess
import
(
AAEvenTimeStepAccessor
,
AAOddTimeStepAccessor
,
CollideOnlyInplaceAccessor
,
EsoTwistEvenTimeStepAccessor
,
EsoTwistOddTimeStepAccessor
,
PdfFieldAccessor
,
PeriodicTwoFieldsAccessor
,
StreamPullTwoFieldsAccessor
,
StreamPushTwoFieldsAccessor
)
from
lbmpy.fieldaccess
import
CollideOnlyInplaceAccessor
,
PdfFieldAccessor
,
PeriodicTwoFieldsAccessor
from
lbmpy.fluctuatinglb
import
add_fluctuations_to_collision_rule
from
lbmpy.methods
import
(
create_mrt_orthogonal
,
create_mrt_raw
,
create_srt
,
create_trt
,
create_trt_kbc
)
from
lbmpy.methods.creationfunctions
import
create_generic_mrt
...
...
@@ -192,6 +189,7 @@ from lbmpy.simplificationfactory import create_simplification_strategy
from
lbmpy.stencils
import
get_stencil
from
lbmpy.turbulence_models
import
add_smagorinsky_model
from
lbmpy.updatekernels
import
create_lbm_kernel
,
create_stream_pull_with_output_kernel
from
lbmpy.advanced_streaming.utility
import
Timestep
,
get_accessor
from
pystencils
import
Assignment
,
AssignmentCollection
,
create_kernel
from
pystencils.cache
import
disk_cache_no_fallback
from
pystencils.data_types
import
collate_types
...
...
@@ -264,28 +262,19 @@ def create_lb_update_rule(collision_rule=None, optimization={}, **kwargs):
dst_field
=
src_field
.
new_field_with_different_name
(
params
[
'temporary_field_name'
])
kernel_type
=
params
[
'kernel_type'
]
if
isinstance
(
kernel_type
,
PdfFieldAccessor
):
accessor
=
kernel_type
return
create_lbm_kernel
(
collision_rule
,
src_field
,
dst_field
,
accessor
)
elif
params
[
'kernel_type'
]
==
'stream_pull_collide'
:
accessor
=
StreamPullTwoFieldsAccessor
if
any
(
opt_params
[
'builtin_periodicity'
]):
accessor
=
PeriodicTwoFieldsAccessor
(
opt_params
[
'builtin_periodicity'
],
ghost_layers
=
1
)
return
create_lbm_kernel
(
collision_rule
,
src_field
,
dst_field
,
accessor
)
elif
params
[
'kernel_type'
]
==
'stream_pull_only'
:
if
kernel_type
==
'stream_pull_only'
:
return
create_stream_pull_with_output_kernel
(
lb_method
,
src_field
,
dst_field
,
params
[
'output'
])
else
:
kernel_type_to_accessor
=
{
'collide_only'
:
CollideOnlyInplaceAccessor
,
'collide_stream_push'
:
StreamPushTwoFieldsAccessor
,
'esotwist_even'
:
EsoTwistEvenTimeStepAccessor
,
'esotwist_odd'
:
EsoTwistOddTimeStepAccessor
,
'aa_even'
:
AAEvenTimeStepAccessor
,
'aa_odd'
:
AAOddTimeStepAccessor
,
}
try
:
accessor
=
kernel_type_to_accessor
[
kernel_type
]()
except
KeyError
:
if
kernel_type
==
'default_stream_collide'
:
if
params
[
'streaming_pattern'
]
==
'pull'
and
any
(
opt_params
[
'builtin_periodicity'
]):
accessor
=
PeriodicTwoFieldsAccessor
(
opt_params
[
'builtin_periodicity'
],
ghost_layers
=
1
)
else
:
accessor
=
get_accessor
(
params
[
'streaming_pattern'
],
params
[
'timestep'
])
elif
kernel_type
==
'collide_only'
:
accessor
=
CollideOnlyInplaceAccessor
elif
isinstance
(
kernel_type
,
PdfFieldAccessor
):
accessor
=
kernel_type
else
:
raise
ValueError
(
"Invalid value of parameter 'kernel_type'"
,
params
[
'kernel_type'
])
return
create_lbm_kernel
(
collision_rule
,
src_field
,
dst_field
,
accessor
)
...
...
@@ -341,7 +330,7 @@ def create_lb_collision_rule(lb_method=None, optimization={}, **kwargs):
if
'split_groups'
in
collision_rule
.
simplification_hints
:
collision_rule
.
simplification_hints
[
'split_groups'
][
0
].
append
(
sp
.
Symbol
(
"smagorinsky_omega"
))
if
params
[
'output'
]
and
params
[
'kernel_type'
]
==
'stream_
pull_
collide'
:
if
params
[
'output'
]
and
params
[
'kernel_type'
]
==
'
default_
stream_collide'
and
params
[
'streaming_pattern'
]
==
'pull'
:
cqc
=
lb_method
.
conserved_quantity_computation
output_eqs
=
cqc
.
output_equations_from_pdfs
(
lb_method
.
pre_collision_pdf_symbols
,
params
[
'output'
])
collision_rule
=
collision_rule
.
new_merged
(
output_eqs
)
...
...
@@ -540,7 +529,9 @@ def update_with_default_parameters(params, opt_params=None, fail_on_unknown_para
'velocity_input'
:
None
,
'density_input'
:
None
,
'kernel_type'
:
'stream_pull_collide'
,
'kernel_type'
:
'default_stream_collide'
,
'streaming_pattern'
:
'pull'
,
'timestep'
:
Timestep
.
BOTH
,
'field_name'
:
'src'
,
'temporary_field_name'
:
'dst'
,
...
...
@@ -584,6 +575,22 @@ def update_with_default_parameters(params, opt_params=None, fail_on_unknown_para
del
params
[
'relaxation_rate'
]
# for backwards compatibility
if
'kernel_type'
in
params
:
kernel_type_to_streaming_pattern
=
{
'stream_pull_collide'
:
(
'pull'
,
Timestep
.
BOTH
),
'collide_stream_push'
:
(
'push'
,
Timestep
.
BOTH
),
'aa_even'
:
(
'aa'
,
Timestep
.
EVEN
),
'aa_odd'
:
(
'aa'
,
Timestep
.
ODD
),
'esotwist_even'
:
(
'esotwist'
,
Timestep
.
EVEN
),
'esotwist_odd'
:
(
'esotwist'
,
Timestep
.
ODD
)
}
kernel_type
=
params
[
'kernel_type'
]
if
kernel_type
in
kernel_type_to_streaming_pattern
.
keys
():
params
[
'kernel_type'
]
=
'default_stream_collide'
params
[
'streaming_pattern'
],
params
[
'timestep'
]
=
kernel_type_to_streaming_pattern
[
kernel_type
]
if
'pdf_arr'
in
opt_params
:
arr
=
opt_params
[
'pdf_arr'
]
opt_params
[
'field_size'
]
=
tuple
(
e
-
2
for
e
in
arr
.
shape
[:
-
1
])
...
...
lbmpy_tests/advanced_streaming/test_fully_periodic_flow.py
View file @
14984e2b
...
...
@@ -71,7 +71,8 @@ def test_fully_periodic_flow(target, stencil, streaming_pattern):
method_params
=
{
'stencil'
:
stencil
,
'method'
:
'srt'
,
'relaxation_rate'
:
1.0
'relaxation_rate'
:
1.0
,
'streaming_pattern'
:
streaming_pattern
}
optimization
=
{
...
...
@@ -86,23 +87,10 @@ def test_fully_periodic_flow(target, stencil, streaming_pattern):
lb_method
=
lb_collision
.
method
lb_kernels
=
[]
if
inplace
:
lb_kernels
.
append
(
create_lb_function
(
collision_rule
=
lb_collision
,
optimization
=
optimization
,
kernel_type
=
streaming_pattern
+
'_even'
,
**
method_params
))
lb_kernels
.
append
(
create_lb_function
(
collision_rule
=
lb_collision
,
optimization
=
optimization
,
kernel_type
=
streaming_pattern
+
'_odd'
,
**
method_params
))
else
:
if
streaming_pattern
==
'pull'
:
kernel_type
=
'stream_pull_collide'
elif
streaming_pattern
==
'push'
:
kernel_type
=
'collide_stream_push'
for
t
in
timesteps
:
lb_kernels
.
append
(
create_lb_function
(
collision_rule
=
lb_collision
,
optimization
=
optimization
,
kernel_type
=
kernel_type
,
timestep
=
t
,
**
method_params
))
# Macroscopic Values
...
...
lbmpy_tests/advanced_streaming/test_periodic_pipe_with_force.py
View file @
14984e2b
...
...
@@ -75,7 +75,8 @@ class PeriodicPipeFlow:
'method'
:
'srt'
,
'relaxation_rate'
:
1.0
,
'force_model'
:
'guo'
,
'force'
:
self
.
force
'force'
:
self
.
force
,
'streaming_pattern'
:
streaming_pattern
}
optimization
=
{
...
...
@@ -90,23 +91,10 @@ class PeriodicPipeFlow:
self
.
lb_method
=
self
.
lb_collision
.
method
self
.
lb_kernels
=
[]
if
self
.
inplace
:
self
.
lb_kernels
.
append
(
create_lb_function
(
collision_rule
=
self
.
lb_collision
,
optimization
=
optimization
,
kernel_type
=
self
.
streaming_pattern
+
'_even'
,
**
method_params
))
self
.
lb_kernels
.
append
(
create_lb_function
(
collision_rule
=
self
.
lb_collision
,
optimization
=
optimization
,
kernel_type
=
self
.
streaming_pattern
+
'_odd'
,
**
method_params
))
else
:
if
self
.
streaming_pattern
==
'pull'
:
kernel_type
=
'stream_pull_collide'
elif
self
.
streaming_pattern
==
'push'
:
kernel_type
=
'collide_stream_push'
for
t
in
self
.
timesteps
:
self
.
lb_kernels
.
append
(
create_lb_function
(
collision_rule
=
self
.
lb_collision
,
optimization
=
optimization
,
kernel_type
=
kernel_type
,
timestep
=
t
,
**
method_params
))
# Macroscopic Values
...
...
@@ -135,7 +123,7 @@ class PeriodicPipeFlow:
# Boundary Handling
self
.
wall
=
wall_boundary
self
.
bh
=
LatticeBoltzmannBoundaryHandling
(
self
.
lb_method
,
self
.
dh
,
self
.
pdfs
.
name
,
self
.
lb_method
,
self
.
dh
,
self
.
pdfs
.
name
,
streaming_pattern
=
self
.
streaming_pattern
,
target
=
self
.
target
)
self
.
bh
.
set_boundary
(
boundary_obj
=
self
.
wall
,
mask_callback
=
self
.
mask_callback
)
...
...
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