Fill a 2d-Quad Mesh between two 1d-Line Meshes, embedded in 2d-space, or a 3d-Hexahedron Mesh between two 2d-Quad Meshes, embedded in 3d-space, by expansion.
A mesh with points, cells and optional a specified cell type.
Parameters:
points (ndarray) – Array with point coordinates of shape (npoints,dim).
cells (ndarray) – Array with cell connectivities of shape (ncells,points_per_cell).
cell_type (str or None, optional) – An optional string in VTK-convention that specifies the cell type (default is
None). Necessary when a mesh is saved to a file.
Notes
The points-array is of shape (npoints,dim), as denoted in Eq. (1).
A mesh provides several useful attributes, like the dimension, the number of
points, number of cells, number of deegrees of freedom, points connected to cells
and points not connected to cells.
A circular shaped 2d-mesh with quads and n points on the circumferential edge of a 45-degree section. 90-degree sections are placed at given angles in degree.
Add midpoints on edges for given points and cells and update cell_type
accordingly.
Parameters:
cell_type (str or None, optional) – A string in VTK-convention that specifies the new cell type (default is None).
If None, the cell type is chosen automatically.
Add midpoints on faces for given points and cells and update cell_type
accordingly.
Parameters:
cell_type (str or None, optional) – A string in VTK-convention that specifies the new cell type (default is
None). If None, the cell type is chosen automatically.
Add midpoints on volumes for given points and cells and update cell_type
accordingly.
Parameters:
cell_type (str or None, optional) – A string in VTK-convention that specifies the new cell type (default is None).
If None, the cell type is chosen automatically.
Returns:
A new mesh with inserted midpoints on cell volumes.
Add simple rubber-runouts for realistic rubber-metal structures.
Parameters:
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).
mask (list or None, optional) – List of points to be considered (default is None).
normalize (bool, optional) – Normalize the runouts to create indents, i.e. maintain the original shape at the
ends (default is False).
Convert a mesh to a given order. Only conversions to order=0 and
order=2 are supported. This function supports meshes with cell types
"triangle", "tetra", "quad" and "hexahedron".
Parameters:
order (int, optional) – The order of the converted mesh (default is 0). If 0, the points-array will
be of shape (ncells,dim). If 0 and calc_points is True, the mean of
all points per cell is evaluated. If 0 and calc_points is False, the
points array is filled with zeros. If 2, at least midpoints on cell edges
are added to the mesh. If 2 and calc_midfaces is True, midpoints on cell
faces are also added. If 2 and calc_midvolumes is True, midpoints on
cell volumes are also added. Raises an error if not 0 or 2.
calc_points (bool, optional) – Flag to return the mean of all points per cell if order=0 (default is
False). If False, the points-array is filled with zeros.
calc_midfaces (bool, optional) – Flag to add midpoints on cell faces if order=2 (default is False).
calc_midvolumes (bool, optional) – Flag to add midpoints on cell volumes if order=2 (default is False).
Return a new instance of a Mesh with disconnected cells. Optionally, the
points-per-cell may be specified (must be lower or equal the number of points-
per-cell of the original Mesh). If the Mesh is to be used as a dual Mesh, then
the point-coordinates do not have to be re-created because they are not used.
Create a new dual mesh with given points per cell.
Parameters:
points_per_cell (int or None, optional) – Number of points per cell, must be equal or lower than cells.shape[1] (
default is None). If None, all points per cell are considered for the dual
mesh.
disconnect (bool, optional) – A flag to disconnect the mesh (each cell has its own points). Default is
True.
calc_points (bool, optional) – A flag to calculate the point coordinates for the dual mesh (default is
False). If False, the points array is filled with zeros.
offset (int, optional) – An offset to be added to the cells array (default is 0).
npoints (int or None, optional) – Number of points for the dual mesh. If the given number of points is greater
than npoints*points_per_cell, then the missing points are added to the
points array (filled with zeros). Default is None.
Expand a 0d-Point to a 1d-Line, a 1d-Line to a 2d-Quad or a 2d-Quad to a
3d-Hexahedron Mesh.
Parameters:
n (int, optional) – Number of n-point repetitions or (n-1)-cell repetitions, default is 11. Must
be greater than 0.
z (float or ndarray, optional) – Total expand dimension as float (edge length in expand direction is z / n),
default is 1. Optionally, if an array is passed these entries are taken as
expansion and n is ignored.
axis (int, optional) – Axis of expansion (default is -1).
expand_dim (bool, optional) – Expand the dimension of the point coordinates (default is True).
Extrude a 1d-Line to a 2d-Quad or a 2d-Quad to a 3d-Hexahedron Mesh along a
given path. Optionally, the section is interpolated between the mesh and another
mesh.
Parameters:
path (felupe.Mesh or ndarray) – A line-mesh or an array of point coordinates, which defines the path. The
points of the path define the positions of the extruded sections. The cells
of a line-mesh must be ordered consecutively along the path.
other_mesh (felupe.Mesh or None, optional) – Another line- or quad-mesh with equal cells and number of points, also
located at the start of the path (default is None). If given, the section is
linearly interpolated between the mesh (at the start) and the other mesh (at
the end of the path) w.r.t. the normalized arc length of the path.
The section is transported along the path by rotation-minimizing frames, i.e.
the section is not twisted around the path. The section is not required to be
perpendicular to the path. Instead, the (initial) orientation of the section
w.r.t. the tangent of the path is preserved. The mesh must be located at the
start of the path.
Examples
Extrude a circular section along a helix. The section is not perpendicular to
the path, it is tilted by 20 degrees.
Fill a 2d-Quad Mesh between two 1d-Line Meshes, embedded in 2d-space, or a
3d-Hexahedron Mesh between two 2d-Quad Meshes, embedded in 3d-space, by expansion.
Both meshes must have equal number of points and cells. The cells-array is taken
from the first mesh.
Parameters:
other_mesh (felupe.Mesh) – The other line- or quad-mesh.
n (int or ndarray) – Number of n-point repetitions or (n-1)-cell repetitions,
(default is 11). If an array is given, then its values are used for the
relative positions in a reference configuration (-1, 1) between the two meshes.
Fill a 2d-Quad Mesh between two 1d-Line Meshes, embedded in 2d-space, or a 3d-Hexahedron Mesh between two 2d-Quad Meshes, embedded in 3d-space, by expansion.
Return point ids for points which are close to a given value.
Parameters:
value (float, list or ndarray) – Scalar value or point coordinates.
fun (callable, optional) – The function used to compare the points to the given value, i.e. with a
function signature fun(mesh.points,value,**kwargs). Default is
numpy.isclose().
mode (callable, optional) – A callable used to combine the search results, either numpy.any() or
numpy.all().
**kwargs (dict, optional) – Additional keyword arguments for fun(mesh.points,value,**kwargs).
Returns:
Array with point ids.
Return type:
ndarray
Examples
Get point ids at given coordinates for a mesh with duplicate points.
Two quad meshes to be merged overlap some points. Merge these duplicated
points and update the cells.
>>> importfelupeasfem>>>>>> rect1=fem.Rectangle(n=11)>>> rect2=fem.Rectangle(a=(0.9,0),b=(1.9,1),n=11)>>> rect2<felupe Mesh object> Number of points: 121 Number of cells: quad: 100
Each mesh contains 121 points and 100 cells. These two meshes are now stored in a
MeshContainer.
>>> container=fem.MeshContainer([rect1,rect2])>>> container<felupe mesh container object> Number of points: 242 Number of cells: quad: 100 quad: 100
Modify the corners of a regular rectangle (quad) or cube (hexahedron)
inplace. Only the cells array is modified, the points array remains unchanged.
Parameters:
point_ids (ndarray or None, optional) – Array with point ids located at the corners which are modified (default is
None). If None, all corners are modified.
Notes
Description of the algorithm:
Get corner point ids.
For each corner point:
Get attached cell and find cell neighbours.
Get the shared point of the cell and its neighbours.
Get pair-wise shared points which are located on an edge.
A container which operates on a list of meshes with identical dimensions.
Parameters:
meshes (list of Mesh) – A list of meshes which are organized by the mesh container.
merge (bool, optional) – Flag to merge duplicate mesh points. This changes the cells arrays of the
meshes. Default is False.
decimals (int or None, optional) – Precision decimals for merging duplicated mesh points. Only relevant if
merge=True. Default is None.
Notes
All meshes are modified to refer to the same points array. By default, the points
arrays from the given list of meshes is concatenated and the cells arrays are
modified accordingly. Optionally, the points array may be merged on duplicated
points.
>>> importfelupeasfem>>> importpyvistaaspv>>>>>> grid=pv.UnstructuredGrid(pv.examples.hexbeamfile)>>> container=fem.MeshContainer.from_unstructured_grid(grid)>>>>>> container<felupe mesh container object> Number of points: 99 Number of cells: hexahedron: 40
A circular shaped 2d-mesh with quads and n points on the circumferential
edge of a 45-degree section. 90-degree sections are placed at given angles in
degree.
Parameters:
radius (float, optional) – Lower-left end point of the mesh (default is (0.0, 0.0)).
centerpoint (2-list of float, optional) – Coordinates of the origin where the circle is centered (default is [1.0, 1.0]).
n (int, optional) – Number of points per axis for a quarter of the embedded rectangle
(default is 2).
sections (list of int or float, optional) – Rotation angles in deg where quarter circles (sections) are placed (default is
[0, 90, 180, 270]).
value (float) – First shape parameter of the embedded rectangle (default is 0.15).
exponent (int) – Second shape parameter of the embedded rectangle (default is 2).
decimals (int) – Decimals used for rounding point coordinates to avoid non-connected sections
(default is 10).
Add midpoints on edges for given points and cells and update cell_type
accordingly.
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.
cell_type_new (str or None, optional) – A string in VTK-convention that specifies the new cell type (default is None).
If None, the cell type is chosen automatically.
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.
Examples
Convert a mesh of hexahedrons to quadratic hexahedrons by inserting midpoints on
the cell edges.
Add midpoints on faces for given points and cells and update cell_type
accordingly.
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.
cell_type_new (str or None, optional) – A string in VTK-convention that specifies the new cell type (default is None).
If None, the cell type is chosen automatically.
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.
Add midpoints on volumes for given points and cells and update cell_type
accordingly.
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.
cell_type_new (str or None, optional) – A string in VTK-convention that specifies the new cell type (default is None).
If None, the cell type is chosen automatically.
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.
Convert a mesh to a given order. Only conversions to order=0 and order=2
are supported. This function supports meshes with cell types "triangle",
"tetra", "quad" and "hexahedron".
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. Must be one of
"triangle", "tetra", "quad" or "hexahedron".
order (int, optional) – The order of the converted mesh (default is 0). If 0, the points-array will be
of shape (ncells,dim). If 0 and calc_points is True, the mean of all
points per cell is evaluated. If 0 and calc_points is False, the points
array is filled with zeros. If 2, at least midpoints on cell edges are added to
the mesh. If 2 and calc_midfaces is True, midpoints on cell faces are also
added. If 2 and calc_midvolumes is True, midpoints on cell volumes are also
added. Raises an error if not 0 or 2.
calc_points (bool, optional) – Flag to return the mean of all points per cell if order=0 (default is
False). If False, the points-array is filled with zeros.
calc_midfaces (bool, optional) – Flag to add midpoints on cell faces if order=2 (default is False).
calc_midvolumes (bool, optional) – Flag to add midpoints on cell volumes if order=2 (default is False).
Returns:
points (ndarray) – Modified point coordinates.
cells (list or ndarray) – Converted cells.
cell_type (str or None) – A string in VTK-convention that specifies the cell type.
Examples
Convert a mesh of hexahedrons to quadratic hexahedrons by inserting midpoints on
the cell edges.
Create a new dual mesh with given points per cell.
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.
points_per_cell (int or None, optional) – Number of points per cell, must be equal or lower than cells.shape[1] (
default is None). If None, all points per cell are considered for the dual mesh.
disconnect (bool, optional) – A flag to disconnect the mesh (each cell has its own points). Default is True.
calc_points (bool, optional) – A flag to calculate the point coordinates for the dual mesh (default is False).
If False, the points array is filled with zeros.
offset (int, optional) – An offset to be added to the cells array (default is 0).
npoints (int or None, optional) – Number of points for the dual mesh. If the given number of points is greater
than npoints*points_per_cell, then the missing points are added to the
points array (filled with zeros). Default is None.
Returns:
points (ndarray) – Modified point coordinates.
cells (list or ndarray) – Modified point-connectivity of cells.
cell_type (str or None) – A string in VTK-convention that specifies the cell type.
Notes
Note
The points array of the dual mesh always has a shape of
(npoints*points_per_cell,dim).
Expand a 0d-Point to a 1d-Line, a 1d-Line to a 2d-Quad or a 2d-Quad to a
3d-Hexahedron Mesh.
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.
n (int, optional) – Number of n-point repetitions or (n-1)-cell repetitions, default is 11. Must be
greater or equal 0.
z (float or ndarray, optional) – Total expansion as float (edge length in expand direction is
z/(n-1)), default is 1. Optionally, if an array is passed these entries
are taken as expansion and n is ignored.
axis (int, optional) – Axis of expansion (default is -1).
expand_dim (bool, optional) – Expand the dimension of the point coordinates (default is True).
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.
Extrude a 1d-Line to a 2d-Quad or a 2d-Quad to a 3d-Hexahedron Mesh along a
given path. Optionally, the section is interpolated between the mesh and another
mesh.
Parameters:
mesh (felupe.Mesh) – A line- or quad-mesh (the section) in its position at the start of the path.
path (felupe.Mesh or ndarray) – A line-mesh or an array of point coordinates, which defines the path. The
points of the path define the positions of the extruded sections. The cells of
a line-mesh must be ordered consecutively along the path.
other_mesh (felupe.Mesh or None, optional) – Another line- or quad-mesh with equal cells and number of points, also located
at the start of the path (default is None). If given, the section is linearly
interpolated between the mesh (at the start) and the other mesh (at the end of
the path) w.r.t. the normalized arc length of the path.
The section is transported along the path by rotation-minimizing frames [1]_,
i.e. the section is not twisted around the path. The section is not required to be
perpendicular to the path. Instead, the (initial) orientation of the section w.r.t.
the tangent of the path is preserved. The tangents are evaluated as the normalized
mean of the two adjacent segment directions at each point of the path. For each
point \(\boldsymbol{p}_i\) of the path, the points of the section are given by
Eq. (5)
where \(\boldsymbol{Q}_i\) is the rotation matrix from the frame at the start
to the frame at the \(i\)-th point of the path.
Note
The mesh must be located at the start of the path. The path must not contain
duplicate consecutive points. Duplicate points of closed paths are not merged.
If the mesh is a line-mesh and both the mesh and the path are embedded in 2d-space,
the extruded quad-mesh is also embedded in 2d-space. Otherwise, the extruded mesh
is embedded in 3d-space. The cells of the extruded mesh are flipped, if required,
to ensure positive cell volumes (for meshes embedded in 2d-space with quads and for
hexahedrons).
Examples
Extrude a circular section along a helix. The section is not perpendicular to the
path, it is tilted by 20 degrees.
Fill a 2d-Quad Mesh between two 1d-Line Meshes, embedded in 2d-space, or a 3d-Hexahedron Mesh between two 2d-Quad Meshes, embedded in 3d-space, by expansion.
Fill a 2d-Quad Mesh between two 1d-Line Meshes, embedded in 2d-space, or a
3d-Hexahedron Mesh between two 2d-Quad Meshes, embedded in 3d-space, by expansion.
Both meshes must have equal number of points and cells. The cells-array is taken
from the first mesh.
other_mesh (felupe.Mesh) – The other line- or quad-mesh.
n (int or ndarray) – Number of n-point repetitions or (n-1)-cell repetitions,
(default is 11). If an array is given, then its values are used for the
relative positions in a reference configuration (-1, 1) between the two meshes.
Fill a 2d-Quad Mesh between two 1d-Line Meshes, embedded in 2d-space, or a 3d-Hexahedron Mesh between two 2d-Quad Meshes, embedded in 3d-space, by expansion.
xi (ndarray) – Points at which to interpolate data. If axis is None, a normalized curve-
progress must be provided (\(0 \le \xi \le 1\)).
axis (int or None, optional) – The axis of the points at which the data will be interpolated. If None, a
normalized curve-progress is used. Default is None.
**kwargs (dict, optional) – Optional keyword arguments are passed to the Interpolator.
Returns:
A new line mesh with interpolated points. The attribute points_derivative
holds the derivatives of the independent variable w.r.t. the dependent
variable(s).
file_format (str or None, optional) – The file format of the mesh file (default is None).
cellblock (list of int or None, optional) – Read only a subset of the cellblocks from the mesh file (default is None). If
None, all cell blocks are added to the MeshContainer.
dim (int or None, optional) – If provided, the dimension to trim the points array to (default is None). If
None, the points array is unchanged.
merge (bool, optional) – Flag to merge duplicate mesh points. This changes the cells arrays of the
meshes. Default is False.
decimals (float or None, optional) – Precision decimals for merging duplicated mesh points. Only relevant if
merge=True. Default is None.
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).
mask (list or None, optional) – List of points to be considered (default is None).
normalize (bool, optional) – Normalize the runouts to create indents, i.e. maintain the original shape at the
ends (default is False).
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.
The points-array is taken from the first mesh. The points-arrays of all
meshes must be identical. The cells-array of the stacked mesh is created by
a vertical stack of the cells-arrays.
Examples
Two quad meshes with identical point arrays should be stacked into a single mesh.