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
fb03ba0c
Commit
fb03ba0c
authored
Nov 02, 2020
by
Frederik Hennig
Browse files
Deprecation of old boundary API
parent
fe2b7f9c
Pipeline
#27673
waiting for manual action with stage
in 24 minutes and 3 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lbmpy/boundaries/boundaryconditions.py
View file @
fb03ba0c
...
...
@@ -7,8 +7,8 @@ from lbmpy.simplificationfactory import create_simplification_strategy
from
lbmpy.advanced_streaming.indexing
import
NeighbourOffsetArrays
class
Boundary
:
"""Base class
for
all boundar
y classes that use the AdvancedStreamingBoundaryIndexing
"""
class
Lb
Boundary
:
"""Base class
that
all boundar
ies should derive from
"""
inner_or_boundary
=
True
single_link
=
False
...
...
@@ -69,7 +69,7 @@ class Boundary:
# end class Boundary
class
NoSlip
(
Boundary
):
class
NoSlip
(
Lb
Boundary
):
def
__init__
(
self
,
name
=
None
):
"""Set an optional name here, to mark boundaries, for example for force evaluations"""
...
...
@@ -94,7 +94,7 @@ class NoSlip(Boundary):
# end class NoSlip
class
UBB
(
Boundary
):
class
UBB
(
Lb
Boundary
):
"""Velocity bounce back boundary condition, enforcing specified velocity at obstacle"""
def
__init__
(
self
,
velocity
,
adapt_velocity_to_force
=
False
,
dim
=
None
,
name
=
None
):
...
...
@@ -135,7 +135,7 @@ class UBB(Boundary):
direction
=
dir_symbol
assert
self
.
dim
==
lb_method
.
dim
,
\
f
"Dimension of UBB (
{
self
.
dim
}
) does not match dimension of method (
{
lb_method
.
dim
}
)"
f
"Dimension of UBB (
{
self
.
dim
}
) does not match dimension of method (
{
lb_method
.
dim
}
)"
neighbor_offset
=
NeighbourOffsetArrays
.
neighbour_offset
(
direction
,
lb_method
.
stencil
)
...
...
@@ -174,7 +174,7 @@ class UBB(Boundary):
# end class UBB
class
FixedDensity
(
Boundary
):
class
FixedDensity
(
Lb
Boundary
):
def
__init__
(
self
,
density
,
name
=
None
):
if
name
is
None
:
...
...
@@ -221,7 +221,7 @@ class FixedDensity(Boundary):
# end class FixedDensity
class
NeumannByCopy
(
Boundary
):
class
NeumannByCopy
(
Lb
Boundary
):
def
get_additional_code_nodes
(
self
,
lb_method
):
return
[
NeighbourOffsetArrays
(
lb_method
.
stencil
)]
...
...
@@ -240,7 +240,7 @@ class NeumannByCopy(Boundary):
# end class NeumannByCopy
class
StreamInConstant
(
Boundary
):
class
StreamInConstant
(
Lb
Boundary
):
def
__init__
(
self
,
constant
,
name
=
None
):
super
(
StreamInConstant
,
self
).
__init__
(
name
)
self
.
_constant
=
constant
...
...
@@ -260,3 +260,60 @@ class StreamInConstant(Boundary):
def
__eq__
(
self
,
other
):
return
type
(
other
)
==
StreamInConstant
# end class StreamInConstant
# ------------------------- Old, Deprecated Implementation -------------------------
class
Boundary
:
inner_or_boundary
=
True
single_link
=
False
def
__init__
(
self
,
name
=
None
):
from
lbmpy.boundaries.boundaryhandling
import
deprecation_message
deprecation_message
()
self
.
_name
=
name
def
__call__
(
self
,
pdf_field
,
direction_symbol
,
lb_method
,
index_field
):
"""
This function defines the boundary behavior and must therefore be implemented by all boundaries.
Here the boundary is defined as a list of sympy equations, from which a boundary kernel is generated.
Args:
pdf_field: pystencils field describing the pdf. The current cell is cell next to the boundary,
which is influenced by the boundary cell i.e. has a link from the boundary cell to
itself.
direction_symbol: a sympy symbol that can be used as index to the pdf_field. It describes
the direction pointing from the fluid to the boundary cell
lb_method: an instance of the LB method used. Use this to adapt the boundary to the method
(e.g. compressibility)
index_field: the boundary index field that can be used to retrieve and update boundary data
Returns:
:return: list of sympy equations
"""
raise
NotImplementedError
(
"Boundary class has to overwrite __call__"
)
@
property
def
additional_data
(
self
):
"""Return a list of (name, type) tuples for additional data items required in this boundary
These data items can either be initialized in separate kernel see additional_data_kernel_init or by
Python callbacks - see additional_data_callback """
return
[]
@
property
def
additional_data_init_callback
(
self
):
"""Return a callback function called with a boundary data setter object and returning a dict of
data-name to data for each element that should be initialized"""
return
None
@
property
def
name
(
self
):
if
self
.
_name
:
return
self
.
_name
else
:
return
type
(
self
).
__name__
@
name
.
setter
def
name
(
self
,
new_value
):
self
.
_name
=
new_value
lbmpy/boundaries/boundaryhandling.py
View file @
fb03ba0c
...
...
@@ -62,7 +62,7 @@ class LatticeBoltzmannBoundaryHandling(BoundaryHandling):
return
self
.
_boundary_object_to_boundary_info
[
boundary_obj
].
flag
def
_create_boundary_kernel
(
self
,
symbolic_field
,
symbolic_index_field
,
boundary_obj
,
prev_timestep
=
Timestep
.
BOTH
):
return
create_
advanced_streaming
_boundary_kernel
(
return
create_
lattice_boltzmann
_boundary_kernel
(
symbolic_field
,
symbolic_index_field
,
self
.
_lb_method
,
boundary_obj
,
prev_timestep
=
prev_timestep
,
streaming_pattern
=
self
.
_streaming_pattern
,
target
=
self
.
_target
,
openmp
=
self
.
_openmp
)
...
...
@@ -173,9 +173,14 @@ class LbmWeightInfo(CustomCodeNode):
# end class LbmWeightInfo
def
create_advanced_streaming_boundary_kernel
(
pdf_field
,
index_field
,
lb_method
,
boundary_functor
,
prev_timestep
=
Timestep
.
BOTH
,
streaming_pattern
=
'pull'
,
target
=
'cpu'
,
openmp
=
True
,
**
kernel_creation_args
):
def
create_lattice_boltzmann_boundary_kernel
(
pdf_field
,
index_field
,
lb_method
,
boundary_functor
,
prev_timestep
=
Timestep
.
BOTH
,
streaming_pattern
=
'pull'
,
target
=
'cpu'
,
openmp
=
True
,
**
kernel_creation_args
):
from
lbmpy.boundaries.boundaryconditions
import
Boundary
as
OldBoundary
if
isinstance
(
boundary_functor
,
OldBoundary
):
return
create_lattice_boltzmann_boundary_kernel_old
(
pdf_field
,
index_field
,
lb_method
,
boundary_functor
,
target
=
target
,
openmp
=
openmp
,
**
kernel_creation_args
)
index_dtype
=
index_field
.
dtype
.
numpy_dtype
.
fields
[
'dir'
][
0
]
offsets_dtype
=
index_field
.
dtype
.
numpy_dtype
.
fields
[
'x'
][
0
]
indexing
=
BetweenTimestepsIndexing
(
...
...
@@ -200,3 +205,28 @@ def create_advanced_streaming_boundary_kernel(pdf_field, index_field, lb_method,
kernel
.
body
.
insert_front
(
node
)
kernel
.
body
.
insert_front
(
index_arrs_node
)
return
kernel
# ----------------------------- Old, Deprecated Implementation -----------------------
def
deprecation_message
():
import
warnings
deprecation_message
=
"The old code generation scheme for LB boundaries has been deprecated. "
\
+
"Please update your boundary implementation to derive from ``LbBoundary`` "
\
+
"and use the new implementation scheme based on `BetweenTimestepsIndexing`."
warnings
.
simplefilter
(
'always'
,
DeprecationWarning
)
warnings
.
warn
(
deprecation_message
,
DeprecationWarning
,
stacklevel
=
2
)
warnings
.
simplefilter
(
'default'
,
DeprecationWarning
)
def
create_lattice_boltzmann_boundary_kernel_old
(
pdf_field
,
index_field
,
lb_method
,
boundary_functor
,
target
=
'cpu'
,
openmp
=
True
,
**
kernel_creation_args
):
deprecation_message
()
from
pystencils.boundaries.boundaryhandling
import
BoundaryOffsetInfo
elements
=
[
BoundaryOffsetInfo
(
lb_method
.
stencil
),
LbmWeightInfo
(
lb_method
)]
index_arr_dtype
=
index_field
.
dtype
.
numpy_dtype
dir_symbol
=
TypedSymbol
(
"dir"
,
index_arr_dtype
.
fields
[
'dir'
][
0
])
elements
+=
[
Assignment
(
dir_symbol
,
index_field
[
0
](
'dir'
))]
elements
+=
boundary_functor
(
pdf_field
=
pdf_field
,
direction_symbol
=
dir_symbol
,
lb_method
=
lb_method
,
index_field
=
index_field
)
return
create_indexed_kernel
(
elements
,
[
index_field
],
target
=
target
,
cpu_openmp
=
openmp
,
**
kernel_creation_args
)
lbmpy_tests/advanced_streaming/test_advanced_streaming_noslip.py
View file @
fb03ba0c
...
...
@@ -3,7 +3,7 @@ import sympy as sp
from
lbmpy.advanced_streaming
import
Timestep
from
lbmpy.boundaries
import
NoSlip
from
lbmpy.boundaries.boundaryhandling
import
create_
advanced_streaming
_boundary_kernel
from
lbmpy.boundaries.boundaryhandling
import
create_
lattice_boltzmann
_boundary_kernel
from
lbmpy.advanced_streaming.utility
import
even_accessors
,
odd_accessors
,
streaming_patterns
,
inverse_dir_index
,
AccessPdfValues
from
lbmpy.creationfunctions
import
create_lb_method
from
lbmpy.stencils
import
get_stencil
...
...
@@ -48,12 +48,12 @@ def test_advanced_streaming_noslip_single_cell(stencil, streaming_pattern, prev_
shape
=
(
TypedSymbol
(
"indexVectorSize"
,
create_type
(
np
.
int64
)),
1
),
strides
=
(
1
,
1
))
index_vector
=
np
.
array
([
pos
+
(
d
,)
for
d
in
range
(
q
)
],
dtype
=
index_struct_dtype
)
flex_
ast
=
create_
advanced_streaming
_boundary_kernel
(
pdf_field
,
ast
=
create_
lattice_boltzmann
_boundary_kernel
(
pdf_field
,
index_field
,
lb_method
,
noslip
,
prev_timestep
=
prev_timestep
,
streaming_pattern
=
streaming_pattern
)
flex_kernel
=
flex_
ast
.
compile
()
flex_kernel
=
ast
.
compile
()
flex_kernel
(
pdfs
=
pdfs
,
indexVector
=
index_vector
,
indexVectorSize
=
len
(
index_vector
))
...
...
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