Skip to content

Commit

Permalink
add mesh runouts
Browse files Browse the repository at this point in the history
  • Loading branch information
adtzlr committed Aug 15, 2022
1 parent e13c305 commit f6563d1
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions felupe/mesh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
sweep,
mirror,
triangulate,
runouts,
)
from ._convert import (
convert,
Expand Down
65 changes: 65 additions & 0 deletions felupe/mesh/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,68 @@ def triangulate(points, cells, cell_type, mode=3):
cells_new = cells_new.reshape(-1, cells_new.shape[-1])

return points, cells_new, cell_type_new


@mesh_or_data
def runouts(
points,
cells,
cell_type,
values=[0.1, 0.1],
centerpoint=[0, 0, 0],
axis=0,
exponent=5,
):
"""Add simple rubber-runouts for realistic rubber-metal structures.
Parameters
----------
points : list or ndarray
Original point coordinates.
cells : list or ndarray
Original point-connectivity of cells.
cell_type : str
A string in VTK-convention that specifies the cell type.
values : list or ndarray, optional
Relative amount of runouts (per coordinate) perpendicular to the axis
(default is 10% per coordinate, i.e. [0.1, 0.1]).
centerpoint: list or ndarray, optional
Center-point coordinates (default is [0, 0, 0]).
axis: int or None, optional
Axis (default is 0).
exponent: int, optional
Positive exponent to control the shape of the runout. The higher
the exponent, the steeper the transition (default is 5).
Returns
-------
points : ndarray
Modified point coordinates.
cells : ndarray
Modified point-connectivity of cells.
cell_type : str or None
A string in VTK-convention that specifies the cell type.
"""

dim = points.shape[1]
runout_along = {0: [1, 2], 1: [0, 2], 2: [0, 1]}

centerpoint = np.array(centerpoint, dtype=float)[:dim]
values = np.array(values, dtype=float)[:dim]

points_new = points - centerpoint
top = points[:, axis].max()
bottom = points[:, axis].min()

# check symmetry
if top == centerpoint[axis] or bottom == centerpoint[axis]:
half_height = top - bottom
else:
half_height = (top - bottom) / 2

for i, coord in enumerate(runout_along[axis][: dim - 1]):

factor = (abs(points_new[:, axis]) / half_height) ** exponent
points_new[:, coord] *= 1 + factor * values[i]

return points_new + centerpoint, cells, cell_type
17 changes: 17 additions & 0 deletions tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,24 @@ def test_triangulate():
n = fe.mesh.triangulate(m, mode=-1)


def test_runouts():

m = fe.Rectangle(n=3)

n = fe.mesh.runouts(m, values=[0.0], axis=0, centerpoint=[0, 0])
assert n.points[:, 1].max() == m.points[:, 1].max()

n = fe.mesh.runouts(m, values=[0.1], axis=0, centerpoint=[0, 0])
assert n.points[:, 1].max() == m.points[:, 1].max() * 1.1

x = [0.5, 0.5]
n = fe.mesh.runouts(m, values=[0.1], axis=0, centerpoint=x)
assert (n.points - x)[:, 1].min() == (m.points - x)[:, 1].min() * 1.1
assert (n.points - x)[:, 1].max() == (m.points - x)[:, 1].max() * 1.1


if __name__ == "__main__":
test_meshes()
test_mirror()
test_triangulate()
test_runouts()

0 comments on commit f6563d1

Please sign in to comment.