Mondaic
This API reference is not for the latest stable Salvus version.

salvus.mesh.unstructured_mesh

A class to handle unstructured meshes. Some functions are restricted to special mesh types (Quadrilateral in 2D or Hexahedral in 3D).

Classes

UnstructuredMesh

class UnstructuredMesh(builtins.object):
    def __init__(
        self,
        points: numpy.ndarray,
        connectivity: numpy.ndarray,
        scale: float = 1.0,
        check_connectivity_shape: bool = True,
    ):
        ...

Create an UnstructuredMesh from points and connectivity arrays.

Parameters
  • points numpy.ndarray — Nodes of the mesh, array with shape (number of points, number of dimensions)
  • connectivity numpy.ndarray — Connectivity of the mesh defining the elements in the mesh listing all nodes in tensorized order. Can include higher order tensorized elements and should have shape (number of elements, (shape order + 1) ** (number of dimensions)).
  • scale float — A scaling of the mesh that is only applied to the points array ob writing to file.
  • check_connectivity_shape bool — Check the connectivity shape, only needed internally. expert
Attributes
edges_per_element int

Number or edges on each element.

element_nodal_fields Dict[str, numpy.ndarray]

Element nodal fields.

element_nodes_shape Tuple[int, ...]

Return the shape of the element nodes array.

Useful for initializing element nodal fields.

Returns: The shape of the element nodes.

elemental_scalar_fields Dict[str, numpy.ndarray]

Element scalar fields.

first_order_connectivity numpy.ndarray

First order connectivity constructed from the corner points in case the shape mapping order is larger than 1.

max_dist_abc float

Maximum distance of the absorbing damping layer from the edge of the domain.

ndim int

Number of space dimensions. For now either 2 or 3.

nelem int

Number of elements in the mesh.

nelemental_fields int

Number of elemental fields.

nglobal_arrays int

Number of global arrays.

nglobal_strings int

Number of global strings.

nglobal_variables int

Number of global variables.

nnodal_fields int

Number of nodal fields.

nodes_per_element int

Number of nodes per element, e. g. 4 for first order Quads and 8 for first order Hex.

npoint int

Number of points / nodes in the mesh

nside_sets int

Number of side sets.

shape_order int

Shape mapping order, i.e. the number of points in each direction in the tensorized elements - 1.

topological_facets numpy.ndarray

Get an array of node ids corresponding to each facet in the mesh.

The facets returned here are “topological” in that they only consider the mesh’s first-order connectivity. Returns an array of shape (n_elem, n_facet_per_elem, n_nodes_per_facet). Facet ordering is as followings:

2D Quad: bottom, top, right, left. 3D Hex: Left, right, bottom, top, back, front.

Methods
from_exodus()
def from_exodus(filename: Union[str, pathlib.Path]) -> UnstructuredMesh:
    ...

Read unstructured mesh from exodus file. Only supports first order quads or hexes.

Parameters
  • filename Union[str, pathlib.Path] — File to open.
Returns UnstructuredMesh
from_h5()
def from_h5(
    filename: Union[str, pathlib.Path], read_data: bool = True
) -> UnstructuredMesh:
    ...

Read unstructured mesh from an h5 file, as written by salvus.mesh.UnstructuredMesh.write_h5.

Note that nodal fields are not yet supported in this filetype.

Parameters
  • filename Union[str, pathlib.Path] — File to open.
  • read_data bool — read the elemental and element nodal data
Returns UnstructuredMesh
add_dem_2D()
def add_dem_2D(
    self,
    x: numpy.ndarray,
    dem: numpy.ndarray,
    y0: float = 0.0,
    y1: float = inf,
    yref: Optional[float] = None,
    kx: int = 3,
    ky: int = 1,
    name: Optional[str] = None,
    mode: str = "cartesian",
) -> None:
    ...

Add topography by vertically stretching the domain in the region [y0, y1] - points below y0 are kept fixed, points above y1 are moved as the DEM, points in between are interpolated and the full DEM is applied to points at yref.

Usage: first call add_dem_2D for each boundary that is to be perturbed and finally call apply_dem to add the perturbation to the mesh coordinates.

Parameters
  • x numpy.ndarray — horizontal coordinates of the DEM. Angle in radians for spherical models.
  • dem numpy.ndarray — the DEM sampled at the coordinates x
  • y0 float — vertical coordinate, at which the stretching begins, can be -np.infty for cartesian meshes.
  • y1 float — vertical coordinate, at which the stretching ends, can be np.infty
  • yref Optional[float] — vertical coordinate, at which the topography should be applied, e.g. z-coordinate of the surface for surface topography. Defaults to the max y coordinate / radius in case at least one of y0, y1 are finite.
  • kx int — horizontal degree of the spline interpolation
  • ky int — vertical degree of the spline interpolation
  • name Optional[str] — name of this topography to refer to it in UnstructuredMesh.apply_dem()
  • mode str — interpolation mode, either ‘cartesian’ or ‘spherical’
Returns None
add_dem_3D()
def add_dem_3D(
    self,
    x: numpy.ndarray,
    y: numpy.ndarray,
    dem: numpy.ndarray,
    z0: float = 0.0,
    z1: float = inf,
    zref: Optional[float] = None,
    khorizontal: int = 3,
    mode: str = "cartesian",
    name: Optional[str] = None,
) -> None:
    ...

Add topography by vertically stretching the domain in the region [z0, z1] - points below z0 and above z1 are kept fixed, points in between are linearly interpolated and the full DEM is applied to points at zref.

Usage: first call add_dem_3D for each boundary that is to be perturbed and finally call apply_dem to add the perturbation to the mesh coordinates.

The DEM can be either structured or unstructured, this is determined from the shapes of x and y.

See scipy.interpolate.RectBivariateSpline for structured Spline interpolation and scipy.interpolate.LinearNDInterpolator (khorizontal=1) or scipy.interpolate.CloughTocher2DInterpolator (khorizontal=3) for more information on the unstructured interpolation. For full sphere interpolation refer to scipy.interpolate.RectSphereBivariateSpline

Parameters
  • x numpy.ndarray — x coordinates of the DEM (colatitude in spherical models in radians). Either 1D for structured data or 2D for unstructured data
  • y numpy.ndarray — y coordinates of the DEM (longitude in spherical modes in radians). Either 1D for structured data or 2D for unstructured data
  • dem numpy.ndarray — the DEM sampled at the coordinates x and y
  • z0 float — Vertical coordinate at which the stretching begins. Can be -np.infty to just move all points below zref with the DEM.
  • z1 float — Vertical coordinate at which the stretching ends. Can be np.infty to just move all points above zref with the DEM
  • zref Optional[float] — Vertical coordinates at which the DEM will be applied. It will linear interpolate between full stretching and no stretching between zref and z0 as well as zref and z1 respectively.
  • khorizontal int — horizontal degree of the spline interpolation. For unstructured data either 1 or 3.
  • mode str — interpolation mode, either ‘cartesian’, ‘spherical’ or ‘spherical_full’
  • name Optional[str] — name of this topography to refer to it in UnstructuredMesh.apply_dem()
Returns None
add_dem_cylindrical()
def add_dem_cylindrical(
    self,
    phi: numpy.ndarray,
    z: numpy.ndarray,
    dem: numpy.ndarray,
    r0: float = 0.0,
    r1: float = inf,
    rref: Optional[float] = None,
    kx: int = 3,
    ky: int = 3,
    name: Optional[str] = None,
) -> None:
    ...

Add topography for cylindrical meshes where the axis of the cylinder is aligned with the z component. The DEM radially stretches the domain in the region of (x,y)-radii in [r0, r1] - points below r0 are kept fixed, points above r1 are moved as the DEM, points in between are interpolated and the full DEM is applied to points at rref.

Usage: first call add_dem_cylindrical for each boundary that is to be perturbed and finally call apply_dem to add the perturbation to the mesh coordinates.

Parameters
  • phi numpy.ndarray — Angle in the x-y-plane of the DEM in radians.
  • z numpy.ndarray — z-coordinates of the DEM.
  • dem numpy.ndarray — the DEM sampled at the coordinates (phi,z)
  • r0 float — radius in x-y-plane at which the stretching begins
  • r1 float — radius in x-y-plane at which the stretching ends, can be infinity
  • rref Optional[float] — radius in x-y-plane at which the topography should be applied
  • kx int — horizontal degree of the spline interpolation
  • ky int — vertical degree of the spline interpolation
  • name Optional[str] — name of this topography to refer to it in UnstructuredMesh.apply_dem()
Returns None
add_ellipticity()
def add_ellipticity(
    self,
    ellipticity: Union[str, float, numpy.ndarray, Callable] = "WGS84",
    points: Optional[numpy.ndarray] = None,
    scale: float = 1.0,
) -> None:
    ...

Add ellipticity by radial stretching the domain.

Usage: first call add_ellipticity and add_dem_2D/3D and finally call apply_dem to add the perturbation to the mesh coordinates.

Parameters
  • ellipticity Union[str, float, numpy.ndarray, Callable] — ellipticity at the surface or as a function of radius. If its a callback function it wil be called with the radius
  • points Optional[numpy.ndarray] — An optional array to use for the mesh points, rather than using the stored points. Useful, for instance, when one wants to ensure that the points used for the ellpticity computation are normalized.
  • scale float — Scale the radius by this value.
Returns None
apply_dem()
def apply_dem(self, names: Optional[List[str]] = None) -> None:
    ...

Apply the previously added DEMs.

Parameters
  • names Optional[List[str]] — Names of the DEMs to apply. Defaults to all added ones.
Returns None
apply_element_mask()
def apply_element_mask(
    self,
    mask: numpy.ndarray,
    return_node_map: bool = False,
    side_sets: Optional[str, List[str]] = None,
) -> Union[UnstructuredMesh, Tuple[UnstructuredMesh, numpy.ndarray]]:
    ...

Apply an element mask to the mesh, retaining elements only that are set true in the mask.

Parameters
  • mask numpy.ndarray — The mask as boolean array.
  • return_node_map bool — Return a node map together with the new mesh object, to be used to map nodal fields to the set of nodes that are retained in the mesh.
  • side_sets Optional[str, List[str]] — list of side set names to which the mask should be directly connected. All elements not connected to the side sets are retained. Can be used to avoid cavities in the mask.
Returns Union[UnstructuredMesh, Tuple[UnstructuredMesh, numpy.ndarray]]
attach_field()
def attach_field(self, name: str, data: numpy.ndarray) -> None:
    ...

store data on either the elements or the nodes (determined by the shape of data).

Parameters
  • name str — name of the field
  • data numpy.ndarray — data to store. 1D numpy array, with size of either nelem or npoint.
Returns None
attach_global_variable()
def attach_global_variable(
    self, name: str, data: Union[float, str, numpy.ndarray]
) -> None:
    ...

store global mesh variable.

Parameters
  • name str — name of the variable
  • data Union[float, str, numpy.ndarray] — data to store
Returns None
change_tensor_order()
def change_tensor_order(
    self,
    tensor_order: Optional[int, numpy.int32, numpy.int64] = None,
    interpolation_mode: str = "linear",
    interpolation_kwargs: Optional[Dict] = None,
    make_unique_points: bool = True,
    tensor_node_locations: Optional[numpy.ndarray] = None,
) -> None:
    ...

Change the tensor order of the mesh’s elements by going from linear to higher order elements.

Please be aware that this will delete any potentially set element nodal fields and nodal fields. Elemental fields and side sets will be retained.

New grid points are created by interpolating the existing corner points. This function supports a variety of interpolation modes (some of which require extra kwargs to set as part of the interpolation_kwargs dictionary):

  • "linear": The default. Perform a bi/trilinear interpolation. No extra keyword arguments are supported or required for this mode.
  • "spherical": Linearly interpolate in radial direction, and apply spherical linear interpolation (slerp) laterally. The center of the sphere is always considered to be at the origin of the coordinate system. Supported additional keywords:
  • "r1_spherical": Apply slerp only for radii >= r1_spherical, default: 0.0.
  • "r0_spherical": Apply bi/trilinear interpolation for radii < r0_spherical, default: 0.0.

If r1_spherical > r0_spherical intermediate radii will linearly interpolate between both modes.

  • "cylindrical": Linearly interpolate radially and along the last dimension. Slerp in the middle dimension. Only defined in 3D, for 2D point symmetry use "spherical". Supported additional keywords:
  • "r1_cylindrical": Apply slerp only for radii >= r1_cylindrical, default: 0.0.
  • "r0_cylindrical": Apply bi/trilinear interpolation for radii < r0_cylindrical, default: 0.0.

If r1_cylindrical > r0_cylindrical intermediate radii will linearly interpolate between both modes.

  • "SmoothieSEM": Special interpolation mode for spherical SmoothieSEM mesh that preserves the cylindrical “inner core”. Supported additional keywords: "r0_spherical", "r1_spherical", "r0_cylindrical", and "r1_cylindrical" with the same meaning as for the other interpolation modes.
Parameters
  • tensor_order Optional[int, numpy.int32, numpy.int64] — Desired new tensor order of the elements.
  • interpolation_mode str — How to interpolate the location of the new grid points. See above description.
  • interpolation_kwargs Optional[Dict] — Extra keyword arguments for the chosen interpolation mode. See above description.
  • make_unique_points bool — Remove duplicate points. Make sure to have a reason if you set this to False.
  • tensor_node_locations Optional[numpy.ndarray] — Locations of the tensor nodes. Defaults to the GLL locations of the chosen tensor order. In almost all cases you will not have to change this.
Returns None
compute_dt()
def compute_dt(
    self,
    vp: Union[numpy.ndarray, float],
    courant_number: float = 1.0,
    min_gll_point_distance: float = 1.0,
    fast: bool = True,
    return_hmin_elemnodes: bool = False,
) -> Union[
    Tuple[float, numpy.ndarray], Tuple[float, numpy.ndarray, numpy.ndarray]
]:
    ...

estimate the time step based on the Courant criterion and the edgelengths of the elements.

Parameters
  • vp Union[numpy.ndarray, float] — scaled p-wave velocity for each element
  • courant_number float — Courant number
  • min_gll_point_distance float — min_gll_point_distance
  • fast bool — fast
  • return_hmin_elemnodes bool — return_hmin_elemnodes
Returns Union[Tuple[float, numpy.ndarray], Tuple[float, numpy.ndarray, numpy.ndarray]]
compute_mesh_quality()
def compute_mesh_quality(
    self, quality_measure: str = "edge_aspect_ratio"
) -> numpy.ndarray:
    ...

compute mesh quality

Parameters
  • quality_measure str — one of 'edge_aspect_ratio' or 'equiangular_skewness'
Returns numpy.ndarray
compute_resolved_frequency()
def compute_resolved_frequency(
    self, vmin: numpy.ndarray, elements_per_wavelength: float
) -> Tuple[float, numpy.ndarray]:
    ...

estimate the highest resolved frequency: vmin / hmax / elements_per_wavelength

Parameters
  • vmin numpy.ndarray — scaled minimum velocity for each element
  • elements_per_wavelength float — number of elements needed to resolve one wavelength
Returns Tuple[float, numpy.ndarray]
copy()
def copy(self) -> UnstructuredMesh:
    ...

Return a deep copy of the object.

Returns UnstructuredMesh
define_side_set()
def define_side_set(
    self,
    name: str,
    element_ids: Optional[numpy.ndarray] = None,
    side_ids: Optional[numpy.ndarray] = None,
    side_set: Optional[
        Tuple[numpy.ndarray, numpy.ndarray], Set[Tuple[int, int]]
    ] = None,
) -> None:
    ...

define a set of edges (2D) or faces (3D) with a name.

Either provide element_ids AND side_ids, or the side set as a python set as created by UnstructuredMesh.get_side_set()

Parameters
  • name str — name of the side set
  • element_ids Optional[numpy.ndarray] — element ids of the sides
  • side_ids Optional[numpy.ndarray] — side ids of the sides
  • side_set Optional[Tuple[numpy.ndarray, numpy.ndarray], Set[Tuple[int, int]]] — set of tuples with element id and side id
Returns None
extrude()
def extrude(
    self,
    offsets: numpy.ndarray,
    scale: Optional[numpy.ndarray] = None,
    rotation: Optional[numpy.ndarray] = None,
    center: Optional[numpy.ndarray] = None,
) -> UnstructuredMesh:
    ...

Extrude a 2D mesh to create a 3D mesh. Each extruded 2D mesh can be offset, scaled and rotated copies of the original.

Parameters
  • offsets numpy.ndarray — offsets, either in the new dimension or all 3 dimension, shape is (nextrude, ) or (nextrude, 3)
  • scale Optional[numpy.ndarray] — scaling factor for each extruded copy, relative to the center, shape is (nextrude,)
  • rotation Optional[numpy.ndarray] — rotation of each extruded copy in terms of euler angles relative to the center, shape is (nextrude, 3)
  • center Optional[numpy.ndarray] — center coordinates for rotation, defaults to the center of mass of the original 2D mesh, shape is (3,)
Returns UnstructuredMesh
extrude_side_set()
def extrude_side_set(
    self,
    side_set: str,
    offsets: numpy.ndarray,
    scale: Optional[numpy.ndarray] = None,
    rotation: Optional[numpy.ndarray] = None,
    center: Optional[numpy.ndarray] = None,
) -> UnstructuredMesh:
    ...

Extrude a side set to add new elements to the mesh.

Parameters
  • side_set str — name of the side set
  • offsets numpy.ndarray — offsets, either in the new dimension or all 3 dimension, shape is (nextrude, ) or (nextrude, 3)
  • scale Optional[numpy.ndarray] — scaling factor for each extruded copy, relative to the center, shape is (nextrude,)
  • rotation Optional[numpy.ndarray] — rotation of each extruded copy in terms of euler angles relative to the center, shape is (nextrude, 3)
  • center Optional[numpy.ndarray] — center coordinates for rotation, defaults to the center of mass of the original 2D mesh, shape is (3,)
Returns UnstructuredMesh
extrude_side_set_2D()
def extrude_side_set_2D(
    self,
    side_set: str,
    offsets: numpy.ndarray,
    direction: Optional[str] = None,
) -> UnstructuredMesh:
    ...

Extrude a side set of a 2D mesh and append new elements. Currently, the functionality is limited to cartesian meshes with side sets that are aligned with the coordinate axis.

Parameters
  • side_set str — name of the side set
  • offsets numpy.ndarray — offsets, either in the new dimension or all 3 dimension, shape is (nextrude, ) or (nextrude, 3)
  • direction Optional[str] — Optional axis of extrusion if offsets is a one-dimensional array. Must be x or y.
Returns UnstructuredMesh
find_side_sets()
def find_side_sets(
    self, mode: str = "cartesian", tolerance: float = 1e-08
) -> None:
    ...

Find surfaces of simple box or spherical meshes in 2 or 3 dimension based on the node locations. Needs to be called before appling the DEM or space mapping. Assuming 3D hexahedral meshes, where the surface elements are all quads or 2D quadrilateral meshes, where the surface elements are lines.

Use UnstructuredMesh.find_surface() for more complex shapes.

Parameters
  • mode str — the side sets to be found depend on the shape of the mesh, should be one of “cartesian”, “cylindrical”, “spherical_full”, “spherical_chunk”, “spherical_chunk_z”, “spherical_full_axisem” or “spherical_SmoothieSEM”.
  • tolerance float — Floating point tolerance to assume a node is on a given side.
Returns None
find_side_sets_generic()
def find_side_sets_generic(
    self,
    name: str,
    distance: Union[Callable[[numpy.ndarray], numpy.ndarray], numpy.ndarray],
    tolerance: float = 1e-08,
    attach_side_set: bool = True,
) -> Optional[Tuple[numpy.ndarray, numpy.ndarray]]:
    ...

Define side sets based on a callback function for the distance to that surface.

Parameters
  • name str — Name of the new side set.
  • distance Union[Callable[[numpy.ndarray], numpy.ndarray], numpy.ndarray] — Callback function taking in points and returning a distance.
  • tolerance float — Point with a distance beneath this are part of the side set.
  • attach_side_set bool — If true, add the side set to the mesh, othewise return the side set elements and sides.
Returns Optional[Tuple[numpy.ndarray, numpy.ndarray]]
find_surface()
def find_surface(self, side_set_name: str = "surface") -> None:
    ...

find the surface of the mesh, i.e. all element sides that don’t touch another element side.

Parameters
  • side_set_name str — Name to give to the found surface.
Returns None
get_element_centroid()
def get_element_centroid(self, spherical: bool = False) -> numpy.ndarray:
    ...

Compute the centroids of all elements on the fly from the nodes of the mesh. Useful to determine which domain in a layered medium an element belongs to or to compute elemental properties from the model. For spherical meshes, correct spherical mapping may be used.

Parameters
  • spherical bool — Assume spherical mesh.
Returns numpy.ndarray
get_element_centroid_radius()
def get_element_centroid_radius(self) -> numpy.ndarray:
    ...

Compute the centroids of all elements on the fly from the nodes of the mesh. Usefull to determine which domain in a layered medium an element belongs to or to compute elemental properties from the model. This function computes the spherical radius directly and is hence more memory efficient than UnstructuredMesh.get_element_centroid()

Returns numpy.ndarray
get_element_directions()
def get_element_directions(self) -> Tuple[numpy.ndarray, ...]:
    ...

compute vectors that point into the reference coordinate direction in the center of the element. These need not be orthogonal.

Returns Tuple[numpy.ndarray, ...]
get_element_nodes()
def get_element_nodes(self) -> numpy.ndarray:
    ...

Get duplicated nodes, i.e. an array with shape (nelem, nodes_per_element, ndim) containing the node locations for all elements for all nodes. This can be significant in terms of memory requirements.

Returns numpy.ndarray
get_side_set()
def get_side_set(self, name: str) -> Set[Tuple[int, int]]:
    ...

returns a side set as a python set, which is useful for logical operations on side sets.

Parameters
  • name str — Name of the side set.
Returns Set[Tuple[int, int]]
get_side_set_facet_nodes()
def get_side_set_facet_nodes(
    self, name: str
) -> Tuple[numpy.ndarray, numpy.ndarray]:
    ...

Get the tensorized nodes along a side set.

Note that this function respects the tensor order of the mesh, and will therefore return nodes equivalent to a tensorized quad in 3-D and all the nodes along an edge in 2-D.

Parameters
  • name str — The name of the side set.
Returns Tuple[numpy.ndarray, numpy.ndarray] — A tuple of two values: 1st value: The tensorized nodes along the side set, with the shape (n_elem_on_side_set, n_points_per_facet, n_dim). 2st value: The global element nodes indices corresponding to the returned tensorized points.
get_side_set_nodes()
def get_side_set_nodes(self, name: str) -> numpy.ndarray:
    ...

return side set node ids as array

Parameters
  • name str — Name of the side set.
Returns numpy.ndarray
map_nodal_fields_to_element_nodal()
def map_nodal_fields_to_element_nodal(self) -> None:
    ...

Map all nodal fields to element nodal and reset the nodal fields dictionary. To be used to store such data using UnstructuredMesh.write_h5

Returns None
plot()
def plot(
    self,
    show: bool = True,
    linewidths: float = 0.5,
    scatter: bool = False,
    elemental_data: Optional[numpy.ndarray] = None,
    element_node_data: Optional[numpy.ndarray] = None,
    figure: Optional[matplotlib.figure.Figure] = None,
    clim: Optional[Dict] = None,
) -> Optional[matplotlib.figure.Figure]:
    ...

Plot the unstructured mesh.

Parameters
  • show bool — Show the plot.
  • linewidths float — line width
  • scatter bool — scatter, otherwise plot lines
  • elemental_data Optional[numpy.ndarray] — elemental data
  • element_node_data Optional[numpy.ndarray] — element nodal data
  • figure Optional[matplotlib.figure.Figure] — The figure to plot into if given
  • clim Optional[Dict] — Norm limits for the colormap scaling.
Returns Optional[matplotlib.figure.Figure]
plot_quality()
def plot_quality(
    self,
    quality_measure: str = "edge_aspect_ratio",
    show: bool = True,
    hist_kwargs: Dict = {},
    compute_quality_kwargs: Dict = {},
) -> Optional[matplotlib.figure.Figure]:
    ...

Plot the mesh quality.

Parameters
  • quality_measure str — Quality measure to plot.
  • show bool — Show plot or not.
  • hist_kwargs Dict — hist_kwargs
  • compute_quality_kwargs Dict — compute_quality_kwargs
Returns Optional[matplotlib.figure.Figure]
refine_locally()
def refine_locally(
    self,
    mask: numpy.ndarray,
    refinement_level: int = 1,
    hierarchical_map: Optional[numpy.ndarray] = None,
    refinement_style: str = "unstable",
    interpolation_mode: str = "linear",
    interpolation_kwargs: Optional[Dict] = None,
    reinterpolate_nodal_fields: bool = False,
    unique_points_tolerance: int = 12,
) -> Optional[numpy.ndarray]:
    ...

Refine the mesh locally using various refinement templates.

New grid points are created by interpolating the existing corner points. This function supports a variety of interpolation modes (some of which require extra kwargs to set as part of the interpolation_kwargs dictionary):

  • "linear": The default. Perform a bi/trilinear interpolation. No extra keyword arguments are supported or required for this mode.
  • "spherical": Linearly interpolate radially, slerp laterally. The center of the sphere is always considered to be at the origin of the coordinate system. Supported additional keywords: "r0_spherical" and "r1_spherical". Don’t slerp < r0, slerp => r0, and linearly interpolate between both modes in between.
  • "cylindrical": Linearly interpolate radially and along the last dimension. Slerp in the middle dimension. Only makes sense in 3D, for 2D point symmetry use "spherical" Supported additional keywords: "r0_cylindrical" and "r1_cylindrical". Don’t slerp < r0, slerp => r0, and linearly interpolate between both modes in between.
  • "SmoothieSEM": Special for SmoothieSEM, only for expert usage.
Parameters
  • mask numpy.ndarray — Mark either elements, nodes or edges to refine, boolean array with shape (nelem,), (npoint,) or (nelem, edges_per_element)
  • refinement_level int — Refinement level, can only be larger than 1 for stable schemes and an elemental mask.
  • hierarchical_map Optional[numpy.ndarray] — Pass a hierarchical map to keep track of which element in a coarser mesh the newly created elements belong to
  • refinement_style str — Choose the refinement style, currently available in 2D are ‘stable’, ‘unstable’, ‘stable_convex’ and ‘unstable_convex’, in 3D ‘unstable_unidir’, ‘unstable’, ‘stable_convex’, ‘unstable_convex’, ‘unstable_convex_dir’, ‘unstable_dir’. Here stable refers to maintaining the angles in multilevel refinements, convexity refers to the region in the mesh in terms of its connectivity (which may be different to its geometric shape for non-rectilinar meshes) and directionality refers to isotropic or anisotropic refinements (where the latter need an edge based refinement mask).
  • interpolation_mode str — How to interpolate the location of the new grid points. See above description.
  • interpolation_kwargs Optional[Dict] — Extra keyword arguments for the chosen interpolation mode. See above description.
  • reinterpolate_nodal_fields bool — map nodal fields to the newly created nodes using linear interpolation
  • unique_points_tolerance int — The number of decimal digits used to determine unique points in the refined mesh.
Returns Optional[numpy.ndarray]
rotate_coordinates()
def rotate_coordinates(self, euler_angles: numpy.ndarray) -> None:
    ...

Rotate the nodes coordinates around the origin.

Parameters
  • euler_angles numpy.ndarray — Euler-angles to rotate around.
Returns None
write_binary_vtk()
def write_binary_vtk(self, filename: Union[str, pathlib.Path]) -> None:
    ...

Write a binary VTK file.

Please note that this method currently writes the mesh without any attached material parameters. The advantage of using this output format is that ParaView can visualize high-order shapes (e.g. curved elements) in that format.

Parameters
  • filename Union[str, pathlib.Path] — Filename. Make sure it uses a .vtu extension so ParaView recognizes it.
Returns None
write_exodus()
def write_exodus(
    self,
    filename: Union[str, pathlib.Path],
    overwrite: bool = True,
    title: Optional[str] = None,
    compression: Optional[Tuple[str, int]] = None,
) -> None:
    ...

write mesh to exodus file

Parameters
  • filename Union[str, pathlib.Path] — filename of the meshfile
  • overwrite bool — overwrite if the file already exists
  • title Optional[str] — title of the mesh, defaults to filename
  • compression Optional[Tuple[str, int]] — Turn on compression. Pass a tuple of (method, option), e.g. ("gzip", 2). Slows down writing a lot but the resulting files are potentially much smaller.
Returns None
write_h5()
def write_h5(
    self,
    filename: Union[str, pathlib.Path],
    datatype: Type[numpy.number] = numpy.float64,
    compression: Optional[Tuple[str, int]] = None,
    mode: str = "model",
    write_chunk_size: int = 10000,
    overwrite: bool = True,
    periodic_bcs: Optional[List[Tuple[str, str]]] = None,
) -> None:
    ...

Write the mesh to an h5 file with xdmf descriptor.

Parameters
  • filename Union[str, pathlib.Path] — Filename.
  • datatype Type[numpy.number] — Datatype to write.
  • compression Optional[Tuple[str, int]] — Turn on compression. Pass a tuple of (method, option), e.g. ("gzip", 2). Slows down writing a lot but the resulting files are potentially much smaller.
  • mode str — one of "all", "model", "skeleton" or "minimal". Controls the content of the mesh file and whether an xdmf file is added. ‘all’: largest file size, multiple block xdmf file and faster reading from file with UnstructuredMesh.from_h5() ‘model’: all data to view the model, single block xdmf file for easy opening in paraview ‘skeleton’: only the first order connectivity can be viewed ‘minimal’: smallest file size, no xdmf.
  • write_chunk_size int — HDF5 chunk size in bytes.
  • overwrite bool — Potentially overwrite an existing file.
  • periodic_bcs Optional[List[Tuple[str, str]]] — Pass a tuple of side sets that you would like to make periodic. For example: [("x0", "x1"), ("z0", "z1)]. This option will only work if the mesh has been derived from the StructuredGrid3D.cube() class.
Returns None
write_legacy_vtk()
def write_legacy_vtk(
    self,
    filename: Union[str, pathlib.Path],
    volume: bool = True,
    side_sets: List[str] = ["x0", "x1", "y0", "y1", "z0", "z1"],
) -> None:
    ...

Write the mesh to a legacy vtk file, meant for visulization with the GUI. In 3D, only writes the hull.

Parameters
  • filename Union[str, pathlib.Path] — filename
  • volume bool — Also write volumetric data.
  • side_sets List[str] — Side sets to write if volume is False.
Returns None
write_vtp()
def write_vtp(
    self,
    filename: Union[str, pathlib.Path],
    side_sets: List[str] = ["x0", "x1", "y0", "y1", "z0", "z1"],
) -> None:
    ...

Write the mesh to a vtp file, meant for visulization with the GUI. In 3D, only writes the hull.

Parameters
  • filename Union[str, pathlib.Path] — filename
  • side_sets List[str] — Side sets to write.
Returns None