salvus.mesh.algorithms.dual
Functions for constructing dual meshes from unstructured primal meshes.
Functions
construct_chord()
construct_chord()def construct_chord(
facet: Facet2D | Facet3D, elm_idx: types.int_, dual: sp_sparse.csr_array
) -> Chord: ...Construct a chord from a dual mesh.
For more information on chords and their utility in 2- and 3-D, see:
Peter Murdoch, Steven Benzley, Ted Blacker, Scott A. Mitchell, The
spatial twist continuum: A connectivity based method for representing
all-hexahedral finite element meshes, Finite Elements in Analysis and
Design, Volume 28, Issue 2, 1997.facetFacet2D | Facet3D — The facet to start the chord from.elm_idxtypes.int_ — The index of the starting element.dualsp_sparse.csr_array — The dual mesh adjacency matrix.
construct_dual()
construct_dual()def construct_dual(
n_dim: int, connectivity: npt.NDArray
) -> sp_sparse.csr_array: ...Construct the dual mesh connectivity from the primal mesh connectivity.
The dual mesh is constructed using element centers of the primal mesh as vertices, and connects these vertices across shared facets.
n_dimint — The number of spatial dimensions.connectivitynpt.NDArray — The primal mesh connectivity array.
stack_along_chord()
stack_along_chord()def stack_along_chord(
chord: Chord, section: npt.NDArray, n_lay_per_elm: types.int_ = 1
) -> tuple[npt.NDArray, npt.NDArray]: ...Stack degrees of freedom (DOFs) along a mesh chord.
DOFs will be stacked along n_lay_per_elm tangent planes within each
element, with the 1st layer coinciding with the element’s facet DOFs. The
returned arrays are is four dimensional with shape (n_elm, 2, n_lay_per_elm, n_dof_per_fac), where:
- `n_elm` is the number of elements in the chord
- `2` corresponds to the two facets defining the chord
- `n_lay_per_elm` is the number of stacked layers per element
- `n_dof_per_fac` is the number of DOFs per facet
With respect to the ordering of the returned arrays:
- The first axis indexes elements along the chord
- The second axis indexes the entry and exit facet, respectively
- The third axis indexes layers within each element, sorted from
the target facet inwards
- The fourth axis indexes DOFs along each facet, in tensor product
ordering
For example, in 2-D with n_lay_per_elm = 2, the stacking order is as
follows on a 2-element quad mesh, with a chord moving from element 0 to
element 1:
+-----------------+
| s(1, 1, 0, :) |
| s(1, 1, 1, :) |
| |
| |
| s(1, 0, 1, :) |
| s(1, 0, 0, :) |
+-----------------+
| s(0, 1, 0, :) |
| s(0, 1, 1, :) |
| |
| |
| s(0, 0, 1, :) |
| s(0, 0, 0, :) |
+-----------------+
and each occurrence of s in the above indexes all the DOFs along a plane tangent to the closet horizontal facet.
Two arrays are returned. The first contains the local DOF indices within
each element, while the second contains the corresponding global DOF
indices from the provided section array. When using these arrays to index
fields, the following is equivalent:
Local indexing array (loc_stack):
np.take_along_axis(
local_field[chord.elements],
loc_stack.reshape(chord.n_elm, -1)[..., np.newaxis],
axis=1
)
where the trailing np.newaxis for the reshape is used to broadcast over
field components (exclude this part if the field is scalar).
Global indexing array (glb_stack):
global_field[glb_stack]
where global_field is a continuous global vector defined over the mesh.
In particular, the following equality holds:
np.take_along_axis(
mesh.get_element_nodes()[chord.elements],
loc_stack.reshape(chord.n_elm, -1)[..., np.newaxis],
axis=1,
) == mesh.points[glb_stack].reshape(chord.n_elm, -1, mesh.ndim)chordChord — The chord to stack along.sectionnpt.NDArray — The global -> local section (typically a mesh’s connectivity).n_lay_per_elmtypes.int_ — The number of DOF layers within each element.
(loc_stack, glb_stack) containing the local and global stacked DOF indices, respectively.Classes
Chord
Chordclass Chord(builtins.object):
def __init__(
self, n_dim: typing.Literal[2, 3], chord: npt.NDArray
) -> None: ...A chord is an array of elements that are related via shared facets.
For more information on chords and their utility in 2- and 3-D, see:
Peter Murdoch, Steven Benzley, Ted Blacker, Scott A. Mitchell, The
spatial twist continuum: A connectivity based method for representing
all-hexahedral finite element meshes, Finite Elements in Analysis and
Design, Volume 28, Issue 2, 1997.n_dimtyping.Literal[2, 3] — The number of spatial dimensions.chordnpt.NDArray — The chord as a 2-D array with each row containing and element_index and outgoing facet index pair.
elements npt.NDArray
elements npt.NDArrayGet the element indices along the chord.
facets npt.NDArray
facets npt.NDArrayGet the facet indices along the chord.
local_facets npt.NDArray
local_facets npt.NDArrayGet the local facets along the chord.
n_elm int
n_elm intGet the number of elements in the chord.
Facet2D
Facet2Dclass Facet2D(enum.IntEnum):
def __init__(self): ...Facet enumeration for 2D elements.
Facet3D
Facet3Dclass Facet3D(enum.IntEnum):
def __init__(self): ...Facet enumeration for 3D elements.