Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions pvgridder/core/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ class MeshStackBase(MeshBase):
Base mesh.
axis : int, default 2
Stacking axis.
bottom_up : bool, default True
If True, assume items are stacked from bottom to top.
default_group : str, optional
Default group name.
ignore_groups : Sequence[str], optional
Expand All @@ -270,6 +272,7 @@ def __init__(
| pv.StructuredGrid
| pv.UnstructuredGrid,
axis: int = 2,
bottom_up: bool = True,
default_group: Optional[str] = None,
ignore_groups: Optional[Sequence[str]] = None,
) -> None:
Expand All @@ -288,6 +291,7 @@ def __init__(
super().__init__(default_group, ignore_groups)
self._mesh = mesh.copy()
self._axis = axis
self._bottom_up = bottom_up
self._transition_flag = False

def add(
Expand All @@ -308,9 +312,10 @@ def add(
arg : scalar | Callable | pyvista.DataSet
New item to add to stack:

- if scalar, all points of the previous items are translated by *arg* along
the stacking axis. If it's the first item of the stack, set the
coordinates of the points of the base mesh to *arg* along stacking axis.
- if scalar, all points of the previous items are translated by *abs(arg)*
along the stacking axis in the direction given by *bottom_up*. If it's
the first item of the stack, set the coordinates of the points of the
base mesh to *arg* along stacking axis.

- if Callable, must be in the form ``f(x, y, z) -> xyz`` where ``x``,
``y``, ``z`` are the coordinates of the points of the base mesh, and
Expand Down Expand Up @@ -377,6 +382,8 @@ def add(
mesh.points[:, self.axis] = arg

else:
arg = abs(arg)
arg *= 1.0 if self.bottom_up else -1.0
mesh = self.items[-1].mesh.copy()
mesh.points[:, self.axis] += arg

Expand Down Expand Up @@ -411,7 +418,8 @@ def add(
return self

def generate_mesh(
self, tolerance: float = 1.0e-8
self,
tolerance: float = 1.0e-8,
) -> pv.StructuredGrid | pv.UnstructuredGrid:
"""
Generate mesh by stacking all items.
Expand Down Expand Up @@ -445,6 +453,9 @@ def generate_mesh(
- item2.thickness
)

if not self.bottom_up:
shift *= -1.0

if item2.priority < item1.priority:
item2.mesh.points[:, self.axis] = np.where(
shift < 0.0,
Expand Down Expand Up @@ -564,3 +575,8 @@ def mesh(self) -> pv.PolyData | pv.StructuredGrid | pv.UnstructuredGrid:
def axis(self) -> int:
"""Return stacking axis."""
return self._axis

@property
def bottom_up(self) -> bool:
"""Return whether the stacking is from bottom to top."""
return self._bottom_up
10 changes: 8 additions & 2 deletions pvgridder/core/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class MeshStack2D(MeshStackBase):

axis : int, default 2
Stacking axis.
bottom_up : bool, default True
If True, assume items are stacked from bottom to top.
default_group : str, optional
Default group name.
ignore_groups : Sequence[str], optional
Expand All @@ -44,6 +46,7 @@ def __init__(
self,
mesh: pv.PolyData | ArrayLike,
axis: int = 2,
bottom_up: bool = True,
default_group: Optional[str] = None,
ignore_groups: Optional[Sequence[str]] = None,
) -> None:
Expand All @@ -61,7 +64,7 @@ def __init__(
else:
lines = split_lines(mesh)[0]

super().__init__(lines, axis, default_group, ignore_groups)
super().__init__(lines, axis, bottom_up, default_group, ignore_groups)

def _extrude(self, *args) -> pv.StructuredGrid:
"""Extrude a line."""
Expand Down Expand Up @@ -121,6 +124,8 @@ class MeshStack3D(MeshStackBase):
Base mesh.
axis : int, default 2
Stacking axis.
bottom_up : bool, default True
If True, assume items are stacked from bottom to top.
default_group : str, optional
Default group name.
ignore_groups : Sequence[str], optional
Expand All @@ -138,6 +143,7 @@ def __init__(
| pv.StructuredGrid
| pv.UnstructuredGrid,
axis: int = 2,
bottom_up: bool = True,
default_group: Optional[str] = None,
ignore_groups: Optional[Sequence[str]] = None,
) -> None:
Expand All @@ -155,7 +161,7 @@ def __init__(
"invalid mesh, input mesh should be a 2D structured grid or an unstructured grid"
)

super().__init__(mesh, axis, default_group, ignore_groups)
super().__init__(mesh, axis, bottom_up, default_group, ignore_groups)

def add_plane(
self,
Expand Down