Skip to content
Snippets Groups Projects
Commit afc933d9 authored by Martin Bauer's avatar Martin Bauer
Browse files

lbmpy geometry: documentation and tests

parent 1fcc24b8
No related merge requests found
import pystencils.sympy_gmpy_bug_workaround """Module to generate stencil kernels in C or CUDA using sympy expressions and call them as Python functions"""
from pystencils.field import Field, FieldType from . import sympy_gmpy_bug_workaround
from pystencils.data_types import TypedSymbol from .field import Field, FieldType
from pystencils.slicing import make_slice from .data_types import TypedSymbol
from pystencils.kernelcreation import create_kernel, create_indexed_kernel from .slicing import make_slice
from pystencils.display_utils import show_code, to_dot from .kernelcreation import create_kernel, create_indexed_kernel
from pystencils.assignment_collection import AssignmentCollection from .display_utils import show_code, to_dot
from pystencils.assignment import Assignment from .assignment_collection import AssignmentCollection
from pystencils.sympyextensions import SymbolCreator from .assignment import Assignment
from .sympyextensions import SymbolCreator
__all__ = ['Field', 'FieldType', __all__ = ['Field', 'FieldType',
'TypedSymbol', 'TypedSymbol',
......
...@@ -153,7 +153,7 @@ class Field(object): ...@@ -153,7 +153,7 @@ class Field(object):
@staticmethod @staticmethod
def create_fixed_size(field_name: str, shape: Tuple[int, ...], index_dimensions: int = 0, def create_fixed_size(field_name: str, shape: Tuple[int, ...], index_dimensions: int = 0,
dtype=np.float64, layout: str = 'numpy', strides: Optional[Sequence[int]]=None) -> 'Field': dtype=np.float64, layout: str = 'numpy', strides: Optional[Sequence[int]] = None) -> 'Field':
""" """
Creates a field with fixed sizes i.e. can be called only with arrays of the same size and layout Creates a field with fixed sizes i.e. can be called only with arrays of the same size and layout
...@@ -192,7 +192,7 @@ class Field(object): ...@@ -192,7 +192,7 @@ class Field(object):
def __init__(self, field_name, field_type, dtype, layout, shape, strides): def __init__(self, field_name, field_type, dtype, layout, shape, strides):
"""Do not use directly. Use static create* methods""" """Do not use directly. Use static create* methods"""
self._fieldName = field_name self._field_name = field_name
assert isinstance(field_type, FieldType) assert isinstance(field_type, FieldType)
self.field_type = field_type self.field_type = field_type
self._dtype = create_type(dtype) self._dtype = create_type(dtype)
...@@ -218,7 +218,7 @@ class Field(object): ...@@ -218,7 +218,7 @@ class Field(object):
@property @property
def name(self) -> str: def name(self) -> str:
return self._fieldName return self._field_name
@property @property
def spatial_shape(self) -> Tuple[int, ...]: def spatial_shape(self) -> Tuple[int, ...]:
...@@ -249,7 +249,7 @@ class Field(object): ...@@ -249,7 +249,7 @@ class Field(object):
return self._dtype return self._dtype
def __repr__(self): def __repr__(self):
return self._fieldName return self._field_name
def neighbor(self, coord_id, offset): def neighbor(self, coord_id, offset):
offset_list = [0] * self.spatial_dimensions offset_list = [0] * self.spatial_dimensions
...@@ -294,7 +294,7 @@ class Field(object): ...@@ -294,7 +294,7 @@ class Field(object):
return Field.Access(self, center)(*args, **kwargs) return Field.Access(self, center)(*args, **kwargs)
def __hash__(self): def __hash__(self):
return hash((self._layout, self.shape, self.strides, self._dtype, self.field_type, self._fieldName)) return hash((self._layout, self.shape, self.strides, self._dtype, self.field_type, self._field_name))
def __eq__(self, other): def __eq__(self, other):
self_tuple = (self.shape, self.strides, self.name, self.dtype, self.field_type) self_tuple = (self.shape, self.strides, self.name, self.dtype, self.field_type)
...@@ -576,8 +576,7 @@ def offset_component_to_direction_string(coordinate_id: int, value: int) -> str: ...@@ -576,8 +576,7 @@ def offset_component_to_direction_string(coordinate_id: int, value: int) -> str:
""" """
name_components = (('W', 'E'), # west, east name_components = (('W', 'E'), # west, east
('S', 'N'), # south, north ('S', 'N'), # south, north
('B', 'T'), # bottom, top ('B', 'T')) # bottom, top
)
if value == 0: if value == 0:
result = "" result = ""
elif value < 0: elif value < 0:
......
...@@ -14,3 +14,5 @@ try: ...@@ -14,3 +14,5 @@ try:
"MPMATH_NOGMPY=1") "MPMATH_NOGMPY=1")
except ImportError: except ImportError:
pass pass
__all__ = []
...@@ -27,8 +27,8 @@ def image_to_vtk(path, cell_data, origin=(0.0, 0.0, 0.0), spacing=(1.0, 1.0, 1.0 ...@@ -27,8 +27,8 @@ def image_to_vtk(path, cell_data, origin=(0.0, 0.0, 0.0), spacing=(1.0, 1.0, 1.0
>>> with TemporaryDirectory() as tmp_dir: >>> with TemporaryDirectory() as tmp_dir:
... path = os.path.join(tmp_dir, 'out') ... path = os.path.join(tmp_dir, 'out')
... size = (20, 20, 20) ... size = (20, 20, 20)
... res_file = image_to_vtk(path, cell_data={'scalar': np.zeros(size), ... res_file = image_to_vtk(path, cell_data={'vector': (np.ones(size), np.ones(size), np.ones(size)),
... 'vector': (np.ones(size), np.ones(size), np.ones(size)) ... 'scalar': np.zeros(size)
... }) ... })
""" """
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment