https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
AutomaticMortarGeneration Class Reference

This class is a container/interface for the objects involved in automatic generation of mortar spaces. More...

#include <AutomaticMortarGeneration.h>

Inheritance diagram for AutomaticMortarGeneration:
[legend]

Classes

struct  MsmSubdomainStats
 Statistics for one primary-secondary subdomain pair. More...
 

Public Types

using MortarFilterIter = std::unordered_map< dof_id_type, std::set< Elem *, CompareDofObjectsByID > >::const_iterator
 

Public Member Functions

 AutomaticMortarGeneration (MooseApp &app, MeshBase &mesh_in, const std::pair< BoundaryID, BoundaryID > &boundary_key, const std::pair< SubdomainID, SubdomainID > &subdomain_key, bool on_displaced, bool periodic, const bool debug, const bool correct_edge_dropping, const Real minimum_projection_angle, const Mortar3DSubpatchPlane mortar_3d_subpatch_plane, const MortarSegmentTriangulationMode triangulation_mode, const bool triangulate_triangles, const Mortar3DQuadraturePointMapping mortar_3d_qp_mapping=Mortar3DQuadraturePointMapping::NORMAL_PROJECTION)
 Must be constructed with a reference to the Mesh we are generating mortar spaces for.
 
void buildNodeToElemMaps ()
 Once the secondary_requested_boundary_ids and primary_requested_boundary_ids containers have been filled in, call this function to build node-to-Elem maps for the lower-dimensional elements.
 
void computeNodalGeometry ()
 Computes and stores the nodal normal/tangent vectors in a local data structure instead of using the ExplicitSystem/NumericVector approach.
 
void projectSecondaryNodes ()
 Project secondary nodes (find xi^(2) values) to the closest points on the primary surface.
 
void projectPrimaryNodes ()
 (Inverse) project primary nodes to the points on the secondary surface where they would have come from (find (xi^(1) values)).
 
void buildMortarSegmentMesh ()
 Builds the mortar segment mesh once the secondary and primary node projections have been completed.
 
void buildMortarSegmentMesh3d ()
 Builds the mortar segment mesh once the secondary and primary node projections have been completed.
 
std::vector< MsmSubdomainStats > computeMsmStatistics ()
 Computes mortar segment mesh statistics and returns one entry per subdomain pair.
 
void msmStatistics ()
 Prints mortar segment mesh statistics to console (calls computeMsmStatistics internally)
 
void clear ()
 Clears the mortar segment mesh and accompanying data structures.
 
void meshChanged ()
 Invalidates the cached MSM node/element ID starting offset so that the next call to buildMortarSegmentMesh3d() recomputes it via allgather.
 
bool onDisplaced () const
 returns whether this object is on the displaced mesh
 
std::vector< Point > getNodalNormals (const Elem &secondary_elem) const
 
std::array< MooseUtils::SemidynamicVector< Point, 9 >, 2 > getNodalTangents (const Elem &secondary_elem) const
 Compute the two nodal tangents, which are built on-the-fly.
 
void computeADNodalNormals (const std::function< ADPoint(const Node &)> &coordinate, std::unordered_map< const Node *, ADRealVectorValue > &nodal_normals) const
 Build the normalized JxW-weighted secondary nodal normals from AD nodal coordinates.
 
std::map< unsigned int, unsigned int > getSecondaryIpToLowerElementMap (const Elem &lower_secondary_elem) const
 Compute on-the-fly mapping from secondary interior parent nodes to lower dimensional nodes.
 
std::map< unsigned int, unsigned int > getPrimaryIpToLowerElementMap (const Elem &primary_elem, const Elem &primary_elem_ip, const Elem &lower_secondary_elem) const
 Compute on-the-fly mapping from primary interior parent nodes to its corresponding lower dimensional nodes.
 
std::vector< Point > getNormals (const Elem &secondary_elem, const std::vector< Point > &xi1_pts) const
 Compute the normals at given reference points on a secondary element.
 
std::vector< Point > getNormals (const Elem &secondary_elem, const std::vector< Real > &oned_xi1_pts) const
 Compute the normals at given reference points on a secondary element.
 
const Elem * getSecondaryLowerdElemFromSecondaryElem (dof_id_type secondary_elem_id) const
 Return lower dimensional secondary element given its interior parent.
 
void computeInactiveLMNodes ()
 Get list of secondary nodes that don't contribute to interaction with any primary element.
 
void computeIncorrectEdgeDroppingInactiveLMNodes ()
 Computes inactive secondary nodes when incorrect edge dropping behavior is enabled (any node touching a partially or fully dropped element is dropped)
 
void computeInactiveLMElems ()
 Get list of secondary elems without any corresponding primary elements.
 
const std::unordered_map< dof_id_type, std::unordered_set< dof_id_type > > & mortarInterfaceCoupling () const
 
void requestNonlocalSecondaryCouplings ()
 Request that every process receive the mortar interface couplings of the nonlocal secondary lower-dimensional elements that point-neighbor ghosting reads for its local elements: the point neighbors of its local secondary elements and of the secondary elements coupled to its local elements.
 
const std::pair< BoundaryID, BoundaryID > & primarySecondaryBoundaryIDPair () const
 
const MeshBase & mortarSegmentMesh () const
 
const std::unordered_map< const Elem *, MortarSegmentInfo > & mortarSegmentMeshElemToInfo () const
 
int dim () const
 
Mortar3DQuadraturePointMapping mortar3DQpMapping () const
 Return the 3D mortar quadrature-point mapping method.
 
const MortarSegmentReferencePoints & mortarSegmentReferencePoints (const Elem &mortar_segment_elem) const
 Return the parent-face reference coordinates for a mortar segment.
 
const std::unordered_set< const Node * > & getInactiveLMNodes () const
 
const std::unordered_set< const Elem * > & getInactiveLMElems () const
 
bool incorrectEdgeDropping () const
 
std::vector< MortarFilterIter > secondariesToMortarSegments (const Node &node) const
 
const std::unordered_map< dof_id_type, std::set< Elem *, CompareDofObjectsByID > > & secondariesToMortarSegments () const
 
const std::set< SubdomainID > & secondaryIPSubIDs () const
 
const std::set< SubdomainID > & primaryInternalSubIDs () const
 
const std::unordered_map< dof_id_type, std::vector< const Elem * > > & nodesToSecondaryElem () const
 
void initOutput ()
 initialize mortar-mesh based output
 

Static Public Member Functions

static const Elem & primaryInteriorParentOrSelf (const Elem &lower_primary_elem)
 

Public Attributes

const ConsoleStream _console
 An instance of helper class to write streams to the Console objects.
 

Static Public Attributes

static const std::string system_name
 The name of the nodal normals system.
 

Private Member Functions

void outputMortarMesh ()
 Write the mortar segment mesh to exodus.
 
std::string mortarInterfaceName () const
 
void buildCouplingInformation ()
 build the _mortar_interface_coupling data
 
void projectSecondaryNodesSinglePair (SubdomainID lower_dimensional_primary_subdomain_id, SubdomainID lower_dimensional_secondary_subdomain_id)
 Helper function responsible for projecting secondary nodes onto primary elements for a single primary/secondary pair.
 
void projectPrimaryNodesSinglePair (SubdomainID lower_dimensional_primary_subdomain_id, SubdomainID lower_dimensional_secondary_subdomain_id)
 Helper function used internally by AutomaticMortarGeneration::project_primary_nodes().
 
bool processAlignedNodes (const Node &secondary_node, const Node &primary_node, const std::vector< const Elem * > *secondary_node_neighbors, const std::vector< const Elem * > *primary_node_neighbors, const VectorValue< Real > &nodal_normal, const Elem &candidate_element, std::set< const Elem * > &rejected_element_candidates)
 Process aligned nodes.
 

Private Attributes

MooseApp & _app
 The Moose app.
 
MeshBase & _mesh
 Reference to the mesh stored in equation_systems.
 
std::set< BoundaryID > _secondary_requested_boundary_ids
 The boundary ids corresponding to all the secondary surfaces.
 
std::set< BoundaryID > _primary_requested_boundary_ids
 The boundary ids corresponding to all the primary surfaces.
 
std::vector< std::pair< BoundaryID, BoundaryID > > _primary_secondary_boundary_id_pairs
 A list of primary/secondary boundary id pairs corresponding to each side of the mortar interface.
 
std::unordered_map< dof_id_type, std::vector< const Elem * > > _nodes_to_secondary_elem_map
 Map from nodes to connected lower-dimensional elements on the secondary/primary subdomains.
 
std::unordered_map< dof_id_type, std::vector< const Elem * > > _nodes_to_primary_elem_map
 
std::unordered_map< std::pair< const Node *, const Elem * >, std::pair< Real, const Elem * > > _secondary_node_and_elem_to_xi2_primary_elem
 Similar to the map above, but associates a (Secondary Node, Secondary Elem) pair to a (xi^(2), primary Elem) pair.
 
std::map< std::tuple< dof_id_type, const Node *, const Elem * >, std::pair< Real, const Elem * > > _primary_node_and_elem_to_xi1_secondary_elem
 Same type of container, but for mapping (Primary Node ID, Primary Node, Primary Elem) -> (xi^(1), Secondary Elem) where they are inverse-projected along the nodal normal direction.
 
std::unique_ptr< MeshBase > _mortar_segment_mesh
 1D Mesh of mortar segment elements which gets built by the call to build_mortar_segment_mesh().
 
std::unordered_map< const Elem *, MortarSegmentInfo > _msm_elem_to_info
 Map between Elems in the mortar segment mesh and their info structs.
 
std::unordered_map< const Elem *, unsigned int > _lower_elem_to_side_id
 Keeps track of the mapping between lower-dimensional elements and the side_id of the interior_parent which they are.
 
std::vector< std::pair< SubdomainID, SubdomainID > > _primary_secondary_subdomain_id_pairs
 A list of primary/secondary subdomain id pairs corresponding to each side of the mortar interface.
 
std::set< SubdomainID > _secondary_boundary_subdomain_ids
 The secondary/primary lower-dimensional boundary subdomain ids are the secondary/primary boundary ids.
 
std::set< SubdomainID > _primary_boundary_subdomain_ids
 
std::unordered_map< dof_id_type, std::unordered_set< dof_id_type > > _mortar_interface_coupling
 Used by the AugmentSparsityOnInterface functor to determine whether a given Elem is coupled to any others across the gap, and to explicitly set up the dependence between interior_parent() elements on the secondary side and their lower-dimensional sides which are on the interface.
 
std::unordered_map< const Node *, Point > _secondary_node_to_nodal_normal
 Container for storing the nodal normal vector associated with each secondary node.
 
std::unordered_map< const Node *, std::array< Point, 2 > > _secondary_node_to_hh_nodal_tangents
 Container for storing the nodal tangent/binormal vectors associated with each secondary node (Householder approach).
 
std::unordered_map< dof_id_type, const Elem * > _secondary_element_to_secondary_lowerd_element
 Map from full dimensional secondary element id to lower dimensional secondary element.
 
std::unordered_set< const Node * > _inactive_local_lm_nodes
 List of inactive lagrange multiplier nodes owned by this processor (for nodal variables)
 
std::unordered_set< const Elem * > _inactive_local_lm_elems
 List of inactive lagrange multiplier nodes (for elemental variables)
 
std::unordered_map< dof_id_type, std::set< Elem *, CompareDofObjectsByID > > _secondary_elems_to_mortar_segments
 We maintain a mapping from lower-dimensional secondary elements in the original mesh to (sets of) elements in mortar_segment_mesh.
 
std::set< SubdomainID > _secondary_ip_sub_ids
 All the secondary interior parent subdomain IDs associated with the mortar mesh.
 
std::set< SubdomainID > _primary_internal_sub_ids
 All the subdomain IDs of the primary interior associated with the mortar mesh (see primaryInternalSubIDs())
 
const bool _debug
 Whether to print debug output.
 
const bool _on_displaced
 Whether this object is on the displaced mesh.
 
const bool _periodic
 Whether this object will be generating a mortar segment mesh for periodic constraints.
 
const bool _distributed
 Whether the mortar segment mesh is distributed.
 
bool _nonlocal_secondary_couplings = false
 Whether buildCouplingInformation() also gathers the couplings of nonlocal secondary lower-dimensional elements.
 
Real _newton_tolerance = 1e-12
 Newton solve tolerance for node projections.
 
Real _xi_tolerance = 1e-6
 Tolerance for checking projection xi values.
 
const bool _correct_edge_dropping
 Flag to enable regressed treatment of edge dropping where all LM DoFs on edge dropping element are strongly set to 0.
 
const Real _minimum_projection_angle
 Parameter to control which angle (in degrees) is admissible for the creation of mortar segments.
 
const Mortar3DSubpatchPlane _mortar_3d_subpatch_plane
 Method used to define the local projection planes for 3D secondary subpatches.
 
const MortarSegmentTriangulationMode _triangulation_mode
 Triangulation mode used for clipped 3D mortar polygons.
 
const bool _triangulate_triangles
 Whether already-triangular clipped polygons should still be centroid-subdivided.
 
const Mortar3DQuadraturePointMapping _mortar_3d_qp_mapping
 Method used to map 3D mortar segment quadrature points to primary and secondary faces.
 
std::unordered_map< const Elem *, MortarSegmentReferencePoints > _msm_elem_to_reference_points
 Reference-coordinate data used only by the reference-interpolation mapping mode.
 
std::unique_ptr< InputParameters > _output_params
 Storage for the input parameters used by the mortar nodal geometry output.
 
std::optional< dof_id_type > _msm_node_id_start
 Cached per-rank starting ID for 3D MSM nodes/elements.
 
std::unordered_set< dof_id_type > _projected_secondary_nodes
 Debugging container for printing information about fraction of successful projections for secondary nodes.
 
std::unordered_set< dof_id_type > _failed_secondary_node_projections
 Secondary nodes that failed to project.
 

Friends

class MortarNodalGeometryOutput
 
class AugmentSparsityOnInterface
 

Detailed Description

This class is a container/interface for the objects involved in automatic generation of mortar spaces.

Definition at line 133 of file AutomaticMortarGeneration.h.

Member Typedef Documentation

◆ MortarFilterIter

using AutomaticMortarGeneration::MortarFilterIter = std::unordered_map<dof_id_type, std::set<Elem *, CompareDofObjectsByID> >::const_iterator

Definition at line 448 of file AutomaticMortarGeneration.h.

Constructor & Destructor Documentation

◆ AutomaticMortarGeneration()

AutomaticMortarGeneration::AutomaticMortarGeneration ( MooseApp &  app,
MeshBase &  mesh_in,
const std::pair< BoundaryID, BoundaryID > &  boundary_key,
const std::pair< SubdomainID, SubdomainID > &  subdomain_key,
bool  on_displaced,
bool  periodic,
const bool  debug,
const bool  correct_edge_dropping,
const Real  minimum_projection_angle,
const Mortar3DSubpatchPlane  mortar_3d_subpatch_plane,
const MortarSegmentTriangulationMode  triangulation_mode,
const bool  triangulate_triangles,
const Mortar3DQuadraturePointMapping  mortar_3d_qp_mapping = Mortar3DQuadraturePointMapping::NORMAL_PROJECTION 
)

Must be constructed with a reference to the Mesh we are generating mortar spaces for.

Definition at line 221 of file AutomaticMortarGeneration.C.

236 _app(app),
237 _mesh(mesh_in),
238 _debug(debug),
239 _on_displaced(on_displaced),
240 _periodic(periodic),
241 // 3D mortar always builds the mortar segment mesh distributedly (each rank adds only its local
242 // secondary elements). For 2D, we ghost the entire mortar interface when displaced, so
243 // displaced meshes are always replicated; otherwise follow the parent mesh.
244 _distributed(_mesh.mesh_dimension() == 3 ? true : (!_on_displaced && !_mesh.is_replicated())),
245 _correct_edge_dropping(correct_edge_dropping),
246 _minimum_projection_angle(minimum_projection_angle),
247 _mortar_3d_subpatch_plane(mortar_3d_subpatch_plane),
248 _triangulation_mode(triangulation_mode),
249 _triangulate_triangles(triangulate_triangles),
250 _mortar_3d_qp_mapping(mortar_3d_qp_mapping)
251{
252 _primary_secondary_boundary_id_pairs.push_back(boundary_key);
253 _primary_requested_boundary_ids.insert(boundary_key.first);
254 _secondary_requested_boundary_ids.insert(boundary_key.second);
255 _primary_secondary_subdomain_id_pairs.push_back(subdomain_key);
256 _primary_boundary_subdomain_ids.insert(subdomain_key.first);
257 _secondary_boundary_subdomain_ids.insert(subdomain_key.second);
258
259 if (_distributed)
261 std::make_unique<DistributedMesh>(_mesh.comm(), _mesh.spatial_dimension());
262 else
264 std::make_unique<ReplicatedMesh>(_mesh.comm(), _mesh.spatial_dimension());
265}
std::set< BoundaryID > _secondary_requested_boundary_ids
The boundary ids corresponding to all the secondary surfaces.
const Mortar3DQuadraturePointMapping _mortar_3d_qp_mapping
Method used to map 3D mortar segment quadrature points to primary and secondary faces.
std::vector< std::pair< BoundaryID, BoundaryID > > _primary_secondary_boundary_id_pairs
A list of primary/secondary boundary id pairs corresponding to each side of the mortar interface.
const bool _periodic
Whether this object will be generating a mortar segment mesh for periodic constraints.
std::set< SubdomainID > _secondary_boundary_subdomain_ids
The secondary/primary lower-dimensional boundary subdomain ids are the secondary/primary boundary ids...
const bool _correct_edge_dropping
Flag to enable regressed treatment of edge dropping where all LM DoFs on edge dropping element are st...
const Mortar3DSubpatchPlane _mortar_3d_subpatch_plane
Method used to define the local projection planes for 3D secondary subpatches.
MeshBase & _mesh
Reference to the mesh stored in equation_systems.
const bool _debug
Whether to print debug output.
std::vector< std::pair< SubdomainID, SubdomainID > > _primary_secondary_subdomain_id_pairs
A list of primary/secondary subdomain id pairs corresponding to each side of the mortar interface.
std::unique_ptr< MeshBase > _mortar_segment_mesh
1D Mesh of mortar segment elements which gets built by the call to build_mortar_segment_mesh().
const bool _on_displaced
Whether this object is on the displaced mesh.
const bool _distributed
Whether the mortar segment mesh is distributed.
const bool _triangulate_triangles
Whether already-triangular clipped polygons should still be centroid-subdivided.
std::set< SubdomainID > _primary_boundary_subdomain_ids
const MortarSegmentTriangulationMode _triangulation_mode
Triangulation mode used for clipped 3D mortar polygons.
std::set< BoundaryID > _primary_requested_boundary_ids
The boundary ids corresponding to all the primary surfaces.
const Real _minimum_projection_angle
Parameter to control which angle (in degrees) is admissible for the creation of mortar segments.
An inteface for the _console for outputting to the Console object.

Member Function Documentation

◆ buildCouplingInformation()

void AutomaticMortarGeneration::buildCouplingInformation ( )
private

build the _mortar_interface_coupling data

Definition at line 1557 of file AutomaticMortarGeneration.C.

1558{
1559 std::unordered_map<processor_id_type, std::vector<std::pair<dof_id_type, dof_id_type>>>
1560 coupling_info;
1561
1562 // Loop over the msm_elem_to_info object and build a bi-directional
1563 // multimap from secondary elements to the primary Elems which they are
1564 // coupled to and vice-versa. This is used in the
1565 // AugmentSparsityOnInterface functor to determine whether a given
1566 // secondary Elem is coupled across the mortar interface to a primary
1567 // element.
1568 for (const auto & pr : _msm_elem_to_info)
1569 {
1570 const Elem * secondary_elem = pr.second.secondary_elem;
1571 const Elem * primary_elem = pr.second.primary_elem;
1572 const Elem & primary_interior_elem = primaryInteriorParentOrSelf(*primary_elem);
1573
1574 // Every process owning a row on a secondary node or either volume parent needs the complete
1575 // secondary face-star coupling, including when that process also owns the lower-dimensional
1576 // face.
1577 std::set<processor_id_type> secondary_face_coupling_processors{
1578 secondary_elem->processor_id(),
1579 secondary_elem->interior_parent()->processor_id(),
1580 primary_interior_elem.processor_id()};
1581 for (const auto n : secondary_elem->node_index_range())
1582 secondary_face_coupling_processors.insert(secondary_elem->node_ptr(n)->processor_id());
1583
1584 // LowerSecondary
1585 for (const auto processor : secondary_face_coupling_processors)
1586 coupling_info[processor].emplace_back(secondary_elem->id(),
1587 secondary_elem->interior_parent()->id());
1588
1589 // LowerPrimary
1590 for (const auto processor : secondary_face_coupling_processors)
1591 coupling_info[processor].emplace_back(secondary_elem->id(), primary_interior_elem.id());
1592
1593 // Lower-LowerDimensionalPrimary
1594 for (const auto processor : secondary_face_coupling_processors)
1595 coupling_info[processor].emplace_back(secondary_elem->id(), primary_elem->id());
1596
1597 // SecondaryLower
1598 coupling_info[secondary_elem->interior_parent()->processor_id()].emplace_back(
1599 secondary_elem->interior_parent()->id(), secondary_elem->id());
1600
1601 // SecondaryPrimary
1602 coupling_info[secondary_elem->interior_parent()->processor_id()].emplace_back(
1603 secondary_elem->interior_parent()->id(), primary_interior_elem.id());
1604
1605 // PrimaryLower
1606 coupling_info[primary_interior_elem.processor_id()].emplace_back(primary_interior_elem.id(),
1607 secondary_elem->id());
1608
1609 // PrimarySecondary
1610 coupling_info[primary_interior_elem.processor_id()].emplace_back(
1611 primary_interior_elem.id(), secondary_elem->interior_parent()->id());
1612 }
1613
1614 // A face pair may produce several mortar segments. Remove repeated entries before communication.
1615 for (auto & [_, couplings] : coupling_info)
1616 {
1617 std::sort(couplings.begin(), couplings.end());
1618 couplings.erase(std::unique(couplings.begin(), couplings.end()), couplings.end());
1619 }
1620
1621 // Push the coupling information
1622 auto action_functor =
1623 [this](processor_id_type,
1624 const std::vector<std::pair<dof_id_type, dof_id_type>> & coupling_info)
1625 {
1626 for (auto [i, j] : coupling_info)
1627 _mortar_interface_coupling[i].insert(j);
1628 };
1629 TIMPI::push_parallel_vector_data(_mesh.comm(), coupling_info, action_functor);
1630
1632 return;
1633
1634 // The push above sends a secondary lower-dimensional element's couplings only to the processes
1635 // owning it, its nodes, or its segments' volume parents. Some consumers (e.g. penalty contact)
1636 // apply a secondary node's constraint on every process that contributes to it, not only on the
1637 // node's owner. The weighted gap at a node shared by a local element E and a nonlocal element F
1638 // carries the derivatives of the primary elements coupled to F, and the process owning E (or a
1639 // volume parent coupled to E) applies that gap to its own rows. When AugmentSparsityOnInterface
1640 // ghosts point neighbors, it reads the couplings of F to add those primary columns to the rows.
1641 // For a local element, it reads the couplings of the point neighbors of the element's own
1642 // secondary lower-dimensional elements and of the secondary elements coupled to it (e.g. those
1643 // paired with a local primary element), so pull the couplings of those point neighbors from
1644 // their owners, which hold the complete sets after the push
1645 const auto is_secondary = [this](const Elem * const elem)
1646 { return _secondary_boundary_subdomain_ids.count(elem->subdomain_id()); };
1647 const auto pid = _mesh.processor_id();
1648 std::unordered_set<const Elem *> secondary_elems_read;
1649 for (const auto secondary_subdomain_id : _secondary_boundary_subdomain_ids)
1650 for (const Elem * const secondary_elem :
1651 as_range(_mesh.active_subdomain_elements_begin(secondary_subdomain_id),
1652 _mesh.active_subdomain_elements_end(secondary_subdomain_id)))
1653 if (secondary_elem->processor_id() == pid ||
1654 secondary_elem->interior_parent()->processor_id() == pid)
1655 secondary_elems_read.insert(secondary_elem);
1656 for (const auto & [elem_id, coupled_elem_ids] : _mortar_interface_coupling)
1657 if (const Elem * const elem = _mesh.query_elem_ptr(elem_id);
1658 elem && elem->processor_id() == pid)
1659 for (const auto coupled_elem_id : coupled_elem_ids)
1660 if (const Elem * const coupled_elem = _mesh.query_elem_ptr(coupled_elem_id);
1661 coupled_elem && is_secondary(coupled_elem))
1662 secondary_elems_read.insert(coupled_elem);
1663
1664 std::unordered_set<const Elem *> secondary_elems_queried;
1665 std::unordered_map<processor_id_type, std::vector<dof_id_type>> secondary_elems_to_query;
1666 for (const Elem * const secondary_elem : secondary_elems_read)
1667 {
1668 std::set<const Elem *> point_neighbors;
1669 secondary_elem->find_point_neighbors(point_neighbors);
1670 point_neighbors.insert(secondary_elem);
1671 for (const Elem * const neigh : point_neighbors)
1672 if (neigh->active() && is_secondary(neigh) && neigh->processor_id() != pid &&
1673 secondary_elems_queried.insert(neigh).second)
1674 secondary_elems_to_query[neigh->processor_id()].push_back(neigh->id());
1675 }
1676
1677 auto gather_functor = [this](processor_id_type,
1678 const std::vector<dof_id_type> & secondary_elem_ids,
1679 std::vector<std::vector<dof_id_type>> & coupled_elem_ids)
1680 {
1681 coupled_elem_ids.resize(secondary_elem_ids.size());
1682 for (const auto i : index_range(secondary_elem_ids))
1683 if (const auto it = _mortar_interface_coupling.find(secondary_elem_ids[i]);
1684 it != _mortar_interface_coupling.end())
1685 coupled_elem_ids[i].assign(it->second.begin(), it->second.end());
1686 };
1687 auto act_on_data_functor = [this](processor_id_type,
1688 const std::vector<dof_id_type> & secondary_elem_ids,
1689 const std::vector<std::vector<dof_id_type>> & coupled_elem_ids)
1690 {
1691 for (const auto i : index_range(secondary_elem_ids))
1692 _mortar_interface_coupling[secondary_elem_ids[i]].insert(coupled_elem_ids[i].begin(),
1693 coupled_elem_ids[i].end());
1694 };
1695 std::vector<dof_id_type> * example = nullptr;
1697 _mesh.comm(), secondary_elems_to_query, gather_functor, act_on_data_functor, example);
1698}
for(PetscInt i=0;i< nvars;++i)
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
bool _nonlocal_secondary_couplings
Whether buildCouplingInformation() also gathers the couplings of nonlocal secondary lower-dimensional...
std::unordered_map< dof_id_type, std::unordered_set< dof_id_type > > _mortar_interface_coupling
Used by the AugmentSparsityOnInterface functor to determine whether a given Elem is coupled to any ot...
std::unordered_map< const Elem *, MortarSegmentInfo > _msm_elem_to_info
Map between Elems in the mortar segment mesh and their info structs.
static const Elem & primaryInteriorParentOrSelf(const Elem &lower_primary_elem)
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition KokkosUtils.h:40
void pull_parallel_vector_data(const Communicator &comm, const MapToVectors &queries, GatherFunctor &gather_data, const ActionFunctor &act_on_data, const datum *example)
uint8_t processor_id_type
void push_parallel_vector_data(const Communicator &comm, MapToVectors &&data, const ActionFunctor &act_on_data)
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
auto index_range(const T &sizable)

Referenced by buildMortarSegmentMesh(), and buildMortarSegmentMesh3d().

◆ buildMortarSegmentMesh()

void AutomaticMortarGeneration::buildMortarSegmentMesh ( )

Builds the mortar segment mesh once the secondary and primary node projections have been completed.

Inputs:

  • mesh
  • primary_node_and_elem_to_xi1_secondary_elem
  • secondary_node_and_elem_to_xi2_primary_elem
  • nodes_to_primary_elem_map

Outputs:

  • mortar_segment_mesh
  • msm_elem_to_info

Defined in the file build_mortar_segment_mesh.C.

This was a change to how inactive LM DoFs are handled. Now mortar segment elements are not used in assembly if there is no corresponding primary element and inactive LM DoFs (those with no contribution to an active primary element) are zeroed.

Definition at line 493 of file AutomaticMortarGeneration.C.

494{
495 using std::abs;
496
497 dof_id_type local_id_index = 0;
498 std::size_t node_unique_id_offset = 0;
499
500 // Create an offset by the maximum number of mortar segment elements that can be created *plus*
501 // the number of lower-dimensional secondary subdomain elements. Recall that the number of mortar
502 // segments created is a function of node projection, *and* that if we split elems we will delete
503 // that elem which has already taken a unique id
504 for (const auto & pr : _primary_secondary_boundary_id_pairs)
505 {
506 const auto primary_bnd_id = pr.first;
507 const auto secondary_bnd_id = pr.second;
508 const auto num_primary_nodes =
509 std::distance(_mesh.bid_nodes_begin(primary_bnd_id), _mesh.bid_nodes_end(primary_bnd_id));
510 const auto num_secondary_nodes = std::distance(_mesh.bid_nodes_begin(secondary_bnd_id),
511 _mesh.bid_nodes_end(secondary_bnd_id));
512 mooseAssert(num_primary_nodes,
513 "There are no primary nodes on boundary ID "
514 << primary_bnd_id << ". Does that bondary ID even exist on the mesh?");
515 mooseAssert(num_secondary_nodes,
516 "There are no secondary nodes on boundary ID "
517 << secondary_bnd_id << ". Does that bondary ID even exist on the mesh?");
518
519 node_unique_id_offset += num_primary_nodes + 2 * num_secondary_nodes;
520 }
521
522 // 1.) Add all lower-dimensional secondary side elements as the "initial" mortar segments.
523 for (MeshBase::const_element_iterator el = _mesh.active_elements_begin(),
524 end_el = _mesh.active_elements_end();
525 el != end_el;
526 ++el)
527 {
528 const Elem * secondary_elem = *el;
529
530 // If this is not one of the lower-dimensional secondary side elements, go on to the next one.
531 if (!this->_secondary_boundary_subdomain_ids.count(secondary_elem->subdomain_id()))
532 continue;
533
534 std::vector<Node *> new_nodes;
535 for (MooseIndex(secondary_elem->n_nodes()) n = 0; n < secondary_elem->n_nodes(); ++n)
536 {
537 new_nodes.push_back(_mortar_segment_mesh->add_point(
538 secondary_elem->point(n), secondary_elem->node_id(n), secondary_elem->processor_id()));
539 Node * const new_node = new_nodes.back();
540 new_node->set_unique_id(new_node->id() + node_unique_id_offset);
541 }
542
543 std::unique_ptr<Elem> new_elem;
544 if (secondary_elem->default_order() == SECOND)
545 new_elem = std::make_unique<Edge3>();
546 else
547 new_elem = std::make_unique<Edge2>();
548
549 new_elem->processor_id() = secondary_elem->processor_id();
550 new_elem->subdomain_id() = secondary_elem->subdomain_id();
551 new_elem->set_id(local_id_index++);
552 new_elem->set_unique_id(new_elem->id());
553
554 for (MooseIndex(new_elem->n_nodes()) n = 0; n < new_elem->n_nodes(); ++n)
555 new_elem->set_node(n, new_nodes[n]);
556
557 Elem * new_elem_ptr = _mortar_segment_mesh->add_elem(new_elem.release());
558
559 // The xi^(1) values for this mortar segment are initially -1 and 1.
560 MortarSegmentInfo msinfo;
561 msinfo.xi1_a = -1;
562 msinfo.xi1_b = +1;
563 msinfo.secondary_elem = secondary_elem;
564
565 auto new_container_it0 = _secondary_node_and_elem_to_xi2_primary_elem.find(
566 std::make_pair(secondary_elem->node_ptr(0), secondary_elem)),
567 new_container_it1 = _secondary_node_and_elem_to_xi2_primary_elem.find(
568 std::make_pair(secondary_elem->node_ptr(1), secondary_elem));
569
570 bool new_container_node0_found =
571 (new_container_it0 != _secondary_node_and_elem_to_xi2_primary_elem.end()),
572 new_container_node1_found =
573 (new_container_it1 != _secondary_node_and_elem_to_xi2_primary_elem.end());
574
575 const Elem * node0_primary_candidate = nullptr;
576 const Elem * node1_primary_candidate = nullptr;
577
578 if (new_container_node0_found)
579 {
580 const auto & xi2_primary_elem_pair = new_container_it0->second;
581 msinfo.xi2_a = xi2_primary_elem_pair.first;
582 node0_primary_candidate = xi2_primary_elem_pair.second;
583 }
584
585 if (new_container_node1_found)
586 {
587 const auto & xi2_primary_elem_pair = new_container_it1->second;
588 msinfo.xi2_b = xi2_primary_elem_pair.first;
589 node1_primary_candidate = xi2_primary_elem_pair.second;
590 }
591
592 // If both node0 and node1 agree on the primary element they are
593 // projected into, then this mortar segment fits entirely within
594 // a single primary element, and we can go ahead and set the
595 // msinfo.primary_elem pointer now.
596 if (node0_primary_candidate == node1_primary_candidate)
597 msinfo.primary_elem = node0_primary_candidate;
598
599 // Associate this MSM elem with the MortarSegmentInfo.
600 _msm_elem_to_info.emplace(new_elem_ptr, msinfo);
601
602 // Maintain the mapping between secondary elems and mortar segment elems contained within them.
603 // Initially, only the original secondary_elem is present.
604 _secondary_elems_to_mortar_segments[secondary_elem->id()].insert(new_elem_ptr);
605 }
606
607 // 2.) Insert new nodes from primary side and split mortar segments as necessary.
609 {
610 auto key = pr.first;
611 auto val = pr.second;
612
613 const Node * primary_node = std::get<1>(key);
614 Real xi1 = val.first;
615 const Elem * secondary_elem = val.second;
616
617 // If this is an aligned node, we don't need to do anything.
618 if (abs(abs(xi1) - 1.) < _xi_tolerance)
619 continue;
620
621 auto && order = secondary_elem->default_order();
622
623 // Determine physical location of new point to be inserted.
624 Point new_pt(0);
625 for (MooseIndex(secondary_elem->n_nodes()) n = 0; n < secondary_elem->n_nodes(); ++n)
626 new_pt += Moose::fe_lagrange_1D_shape(order, n, xi1) * secondary_elem->point(n);
627
628 // Find the current mortar segment that will have to be split.
629 auto & mortar_segment_set = _secondary_elems_to_mortar_segments[secondary_elem->id()];
630 Elem * current_mortar_segment = nullptr;
631 MortarSegmentInfo * info = nullptr;
632
633 for (const auto & mortar_segment_candidate : mortar_segment_set)
634 {
635 try
636 {
637 info = &_msm_elem_to_info.at(mortar_segment_candidate);
638 }
639 catch (std::out_of_range &)
640 {
641 mooseError("MortarSegmentInfo not found for the mortar segment candidate");
642 }
643 if (info->xi1_a <= xi1 && xi1 <= info->xi1_b)
644 {
645 current_mortar_segment = mortar_segment_candidate;
646 break;
647 }
648 }
649
650 // Make sure we found one.
651 if (current_mortar_segment == nullptr)
652 mooseError("Unable to find appropriate mortar segment during linear search!");
653
654 // If node lands on endpoint of segment, don't split.
655 // Jacob: This condition was getting missed by the < comparison a few lines above. To fix it I
656 // just made it <= and put this condition in to handle equality different. It probably could be
657 // done with a tolerance but the the toleranced equality is already handled later when we drop
658 // segments with small volume.
659 if (info->xi1_a == xi1 || xi1 == info->xi1_b)
660 continue;
661
662 const auto new_id = _mortar_segment_mesh->max_node_id();
663 mooseAssert(_mortar_segment_mesh->comm().verify(new_id),
664 "new_id must be the same on all processes");
665 Node * const new_node =
666 _mortar_segment_mesh->add_point(new_pt, new_id, secondary_elem->processor_id());
667 new_node->set_unique_id(new_id + node_unique_id_offset);
668
669 // Reconstruct the nodal normal at xi1. This will help us
670 // determine the orientation of the primary elems relative to the
671 // new mortar segments.
672 const Point normal = getNormals(*secondary_elem, std::vector<Real>({xi1}))[0];
673
674 // Get the set of primary_node neighbors.
675 if (this->_nodes_to_primary_elem_map.find(primary_node->id()) ==
676 this->_nodes_to_primary_elem_map.end())
677 mooseError("We should already have built this primary node to elem pair!");
678 const std::vector<const Elem *> & primary_node_neighbors =
679 this->_nodes_to_primary_elem_map[primary_node->id()];
680
681 // Sanity check
682 if (primary_node_neighbors.size() == 0 || primary_node_neighbors.size() > 2)
683 mooseError("We must have either 1 or 2 primary side nodal neighbors, but we had ",
684 primary_node_neighbors.size());
685
686 // Primary Elem pointers which we will eventually assign to the
687 // mortar segments being created. We start by assuming
688 // primary_node_neighbor[0] is on the "left" and
689 // primary_node_neighbor[1]/"nothing" is on the "right" and then
690 // swap them if that's not the case.
691 const Elem * left_primary_elem = primary_node_neighbors[0];
692 const Elem * right_primary_elem =
693 (primary_node_neighbors.size() == 2) ? primary_node_neighbors[1] : nullptr;
694
696
697 // Storage for z-component of cross products for determining
698 // orientation.
699 std::array<Real, 2> secondary_node_cps;
700 std::vector<Real> primary_node_cps(primary_node_neighbors.size());
701
702 // Store z-component of left and right secondary node cross products with the nodal normal.
703 for (unsigned int nid = 0; nid < 2; ++nid)
704 secondary_node_cps[nid] = normal.cross(secondary_elem->point(nid) - new_pt)(2);
705
706 for (MooseIndex(primary_node_neighbors) mnn = 0; mnn < primary_node_neighbors.size(); ++mnn)
707 {
708 const Elem * primary_neigh = primary_node_neighbors[mnn];
709 Point opposite = (primary_neigh->node_ptr(0) == primary_node) ? primary_neigh->point(1)
710 : primary_neigh->point(0);
711 Point cp = normal.cross(opposite - new_pt);
712 primary_node_cps[mnn] = cp(2);
713 }
714
715 // We will verify that only 1 orientation is actually valid.
716 bool orientation1_valid = false, orientation2_valid = false;
717
718 if (primary_node_neighbors.size() == 2)
719 {
720 // 2 primary neighbor case
721 orientation1_valid = (secondary_node_cps[0] * primary_node_cps[0] > 0.) &&
722 (secondary_node_cps[1] * primary_node_cps[1] > 0.);
723
724 orientation2_valid = (secondary_node_cps[0] * primary_node_cps[1] > 0.) &&
725 (secondary_node_cps[1] * primary_node_cps[0] > 0.);
726 }
727 else if (primary_node_neighbors.size() == 1)
728 {
729 // 1 primary neighbor case
730 orientation1_valid = (secondary_node_cps[0] * primary_node_cps[0] > 0.);
731 orientation2_valid = (secondary_node_cps[1] * primary_node_cps[0] > 0.);
732 }
733 else
734 mooseError("Invalid primary node neighbors size ", primary_node_neighbors.size());
735
736 // Verify that both orientations are not simultaneously valid/invalid. If they are not, then we
737 // are going to throw an exception instead of erroring out since we can easily reach this point
738 // if we have one bad linear solve. It's better in general to catch the error and then try a
739 // smaller time-step
740 if (orientation1_valid && orientation2_valid)
741 throw MooseException(
742 "AutomaticMortarGeneration: Both orientations cannot simultaneously be valid.");
743
744 // We are going to treat the case where both orientations are invalid as a case in which we
745 // should not be splitting the mortar mesh to incorporate primary mesh elements.
746 // In practice, this case has appeared for very oblique projections, so we assume these cases
747 // will not be considered in mortar thermomechanical contact.
748 if (!orientation1_valid && !orientation2_valid)
749 {
750 static const auto invalid_orientation_id =
752 "AutomaticMortarGeneration",
753 "Unable to determine valid secondary-primary orientation. Consequently we will "
754 "consider projection of the primary node invalid and not split the mortar segment. "
755 "This situation can indicate there are very oblique projections between primary "
756 "(mortar) and secondary (non-mortar) surfaces for a good problem set up. It can also "
757 "mean your time step is too large.",
758 true);
759 _app.solutionInvalidity().flagInvalidSolutionInternal(invalid_orientation_id);
760 continue;
761 }
762
763 // Make an Elem on the left
764 std::unique_ptr<Elem> new_elem_left;
765 if (order == SECOND)
766 new_elem_left = std::make_unique<Edge3>();
767 else
768 new_elem_left = std::make_unique<Edge2>();
769
770 new_elem_left->processor_id() = current_mortar_segment->processor_id();
771 new_elem_left->subdomain_id() = current_mortar_segment->subdomain_id();
772 new_elem_left->set_id(local_id_index++);
773 new_elem_left->set_unique_id(new_elem_left->id());
774 new_elem_left->set_node(0, current_mortar_segment->node_ptr(0));
775 new_elem_left->set_node(1, new_node);
776
777 // Make an Elem on the right
778 std::unique_ptr<Elem> new_elem_right;
779 if (order == SECOND)
780 new_elem_right = std::make_unique<Edge3>();
781 else
782 new_elem_right = std::make_unique<Edge2>();
783
784 new_elem_right->processor_id() = current_mortar_segment->processor_id();
785 new_elem_right->subdomain_id() = current_mortar_segment->subdomain_id();
786 new_elem_right->set_id(local_id_index++);
787 new_elem_right->set_unique_id(new_elem_right->id());
788 new_elem_right->set_node(0, new_node);
789 new_elem_right->set_node(1, current_mortar_segment->node_ptr(1));
790
791 if (order == SECOND)
792 {
793 // left
794 Point left_interior_point(0);
795 Real left_interior_xi = (xi1 + info->xi1_a) / 2;
796
797 // This is eta for the current mortar segment that we're splitting
798 Real current_left_interior_eta =
799 (2. * left_interior_xi - info->xi1_a - info->xi1_b) / (info->xi1_b - info->xi1_a);
800
801 for (MooseIndex(current_mortar_segment->n_nodes()) n = 0;
802 n < current_mortar_segment->n_nodes();
803 ++n)
804 left_interior_point += Moose::fe_lagrange_1D_shape(order, n, current_left_interior_eta) *
805 current_mortar_segment->point(n);
806
807 const auto new_interior_left_id = _mortar_segment_mesh->max_node_id();
808 mooseAssert(_mortar_segment_mesh->comm().verify(new_interior_left_id),
809 "new_id must be the same on all processes");
810 Node * const new_interior_node_left = _mortar_segment_mesh->add_point(
811 left_interior_point, new_interior_left_id, new_elem_left->processor_id());
812 new_elem_left->set_node(2, new_interior_node_left);
813 new_interior_node_left->set_unique_id(new_interior_left_id + node_unique_id_offset);
814
815 // right
816 Point right_interior_point(0);
817 Real right_interior_xi = (xi1 + info->xi1_b) / 2;
818 // This is eta for the current mortar segment that we're splitting
819 Real current_right_interior_eta =
820 (2. * right_interior_xi - info->xi1_a - info->xi1_b) / (info->xi1_b - info->xi1_a);
821
822 for (MooseIndex(current_mortar_segment->n_nodes()) n = 0;
823 n < current_mortar_segment->n_nodes();
824 ++n)
825 right_interior_point += Moose::fe_lagrange_1D_shape(order, n, current_right_interior_eta) *
826 current_mortar_segment->point(n);
827
828 const auto new_interior_id_right = _mortar_segment_mesh->max_node_id();
829 mooseAssert(_mortar_segment_mesh->comm().verify(new_interior_id_right),
830 "new_id must be the same on all processes");
831 Node * const new_interior_node_right = _mortar_segment_mesh->add_point(
832 right_interior_point, new_interior_id_right, new_elem_right->processor_id());
833 new_elem_right->set_node(2, new_interior_node_right);
834 new_interior_node_right->set_unique_id(new_interior_id_right + node_unique_id_offset);
835 }
836
837 // If orientation 2 was valid, swap the left and right primaries.
838 if (orientation2_valid)
839 std::swap(left_primary_elem, right_primary_elem);
840
841 // Now that we know left_primary_elem and right_primary_elem, we can determine left_xi2 and
842 // right_xi2.
843 if (left_primary_elem)
844 left_xi2 = (primary_node == left_primary_elem->node_ptr(0)) ? -1 : +1;
845 if (right_primary_elem)
846 right_xi2 = (primary_node == right_primary_elem->node_ptr(0)) ? -1 : +1;
847
848 // Grab the MortarSegmentInfo object associated with this
849 // segment. We can use "at()" here since we want this to fail if
850 // current_mortar_segment is not found... Since we're going to
851 // erase this entry from the map momentarily, we make an actual
852 // copy rather than grabbing a reference.
853 auto msm_it = _msm_elem_to_info.find(current_mortar_segment);
854 if (msm_it == _msm_elem_to_info.end())
855 mooseError("MortarSegmentInfo not found for current_mortar_segment.");
856 MortarSegmentInfo current_msinfo = msm_it->second;
857
858 // add_left
859 {
860 Elem * msm_new_elem = _mortar_segment_mesh->add_elem(new_elem_left.release());
861
862 // Create new MortarSegmentInfo objects for new_elem_left
863 MortarSegmentInfo new_msinfo_left;
864
865 // The new MortarSegmentInfo info objects inherit their "outer"
866 // information from current_msinfo and the rest is determined by
867 // the Node being inserted.
868 new_msinfo_left.xi1_a = current_msinfo.xi1_a;
869 new_msinfo_left.xi2_a = current_msinfo.xi2_a;
870 new_msinfo_left.secondary_elem = secondary_elem;
871 new_msinfo_left.xi1_b = xi1;
872 new_msinfo_left.xi2_b = left_xi2;
873 new_msinfo_left.primary_elem = left_primary_elem;
874
875 // Add new msinfo objects to the map.
876 _msm_elem_to_info.emplace(msm_new_elem, new_msinfo_left);
877
878 // We need to insert new_elem_left in
879 // the mortar_segment_set for this secondary_elem.
880 mortar_segment_set.insert(msm_new_elem);
881 }
882
883 // add_right
884 {
885 Elem * msm_new_elem = _mortar_segment_mesh->add_elem(new_elem_right.release());
886
887 // Create new MortarSegmentInfo objects for new_elem_right
888 MortarSegmentInfo new_msinfo_right;
889
890 new_msinfo_right.xi1_b = current_msinfo.xi1_b;
891 new_msinfo_right.xi2_b = current_msinfo.xi2_b;
892 new_msinfo_right.secondary_elem = secondary_elem;
893 new_msinfo_right.xi1_a = xi1;
894 new_msinfo_right.xi2_a = right_xi2;
895 new_msinfo_right.primary_elem = right_primary_elem;
896
897 _msm_elem_to_info.emplace(msm_new_elem, new_msinfo_right);
898
899 mortar_segment_set.insert(msm_new_elem);
900 }
901
902 // Erase the MortarSegmentInfo object for current_mortar_segment from the map.
903 _msm_elem_to_info.erase(msm_it);
904
905 // current_mortar_segment must be erased from the
906 // mortar_segment_set since it has now been split.
907 mortar_segment_set.erase(current_mortar_segment);
908
909 // The original mortar segment has been split, so erase it from
910 // the mortar segment mesh.
911 _mortar_segment_mesh->delete_elem(current_mortar_segment);
912 }
913
914 // Remove all MSM elements without a primary contribution
920 for (auto msm_elem : _mortar_segment_mesh->active_element_ptr_range())
921 {
922 MortarSegmentInfo & msinfo = libmesh_map_find(_msm_elem_to_info, msm_elem);
923 Elem * primary_elem = const_cast<Elem *>(msinfo.primary_elem);
924 if (primary_elem == nullptr || abs(msinfo.xi2_a) > 1.0 + TOLERANCE ||
925 abs(msinfo.xi2_b) > 1.0 + TOLERANCE)
926 {
927 // Erase from secondary to msms map
928 auto it = _secondary_elems_to_mortar_segments.find(msinfo.secondary_elem->id());
929 mooseAssert(it != _secondary_elems_to_mortar_segments.end(),
930 "We should have found the element");
931 auto & msm_set = it->second;
932 msm_set.erase(msm_elem);
933 // We may be creating nodes with only one element neighbor where before this removal there
934 // were two. But the nodal normal used in computations will reflect the two-neighbor geometry.
935 // For a lower-d secondary mesh corner, that will imply the corner node will have a tilted
936 // normal vector (same for tangents) despite the mortar segment mesh not including its
937 // vertical neighboring element. It is the secondary element neighbors (not mortar segment
938 // mesh neighbors) that determine the nodal normal field.
939 if (msm_set.empty())
941
942 // Erase msinfo
943 _msm_elem_to_info.erase(msm_elem);
944
945 // Remove element from mortar segment mesh
946 _mortar_segment_mesh->delete_elem(msm_elem);
947 }
948 else
949 {
950 _secondary_ip_sub_ids.insert(msinfo.secondary_elem->interior_parent()->subdomain_id());
952 primaryInteriorParentOrSelf(*msinfo.primary_elem).subdomain_id());
953 }
954 }
955
956 std::unordered_set<Node *> msm_connected_nodes;
957
958 // Deleting elements may produce isolated nodes.
959 // Loops for identifying and removing such nodes from mortar segment mesh.
960 for (const auto & element : _mortar_segment_mesh->element_ptr_range())
961 for (auto & n : element->node_ref_range())
962 msm_connected_nodes.insert(&n);
963
964 for (const auto & node : _mortar_segment_mesh->node_ptr_range())
965 if (!msm_connected_nodes.count(node))
966 _mortar_segment_mesh->delete_node(node);
967
968#ifdef DEBUG
969 // Verify that all segments without primary contribution have been deleted
970 for (auto msm_elem : _mortar_segment_mesh->active_element_ptr_range())
971 {
972 const MortarSegmentInfo & msinfo = libmesh_map_find(_msm_elem_to_info, msm_elem);
973 mooseAssert(msinfo.primary_elem != nullptr,
974 "All mortar segment elements should have valid "
975 "primary element.");
976 }
977#endif
978
979 _mortar_segment_mesh->cache_elem_data();
980
981 // (Optionally) Write the mortar segment mesh to file for inspection
982 if (_debug)
984
986}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
unsigned int count
Definition MortarUtils.C:53
std::set< SubdomainID > _primary_internal_sub_ids
All the subdomain IDs of the primary interior associated with the mortar mesh (see primaryInternalSub...
std::unordered_map< dof_id_type, std::vector< const Elem * > > _nodes_to_primary_elem_map
Real _xi_tolerance
Tolerance for checking projection xi values.
void outputMortarMesh()
Write the mortar segment mesh to exodus.
void buildCouplingInformation()
build the _mortar_interface_coupling data
std::vector< Point > getNormals(const Elem &secondary_elem, const std::vector< Point > &xi1_pts) const
Compute the normals at given reference points on a secondary element.
std::set< SubdomainID > _secondary_ip_sub_ids
All the secondary interior parent subdomain IDs associated with the mortar mesh.
std::unordered_map< std::pair< const Node *, const Elem * >, std::pair< Real, const Elem * > > _secondary_node_and_elem_to_xi2_primary_elem
Similar to the map above, but associates a (Secondary Node, Secondary Elem) pair to a (xi^(2),...
std::map< std::tuple< dof_id_type, const Node *, const Elem * >, std::pair< Real, const Elem * > > _primary_node_and_elem_to_xi1_secondary_elem
Same type of container, but for mapping (Primary Node ID, Primary Node, Primary Elem) -> (xi^(1),...
std::unordered_map< dof_id_type, std::set< Elem *, CompareDofObjectsByID > > _secondary_elems_to_mortar_segments
We maintain a mapping from lower-dimensional secondary elements in the original mesh to (sets of) ele...
SolutionInvalidity & solutionInvalidity()
Get the SolutionInvalidity for this app.
Definition MooseApp.h:182
Provides a way for users to bail out of the current solve.
void flagInvalidSolutionInternal(const InvalidSolutionID _invalid_solution_id)
Increments solution invalid occurrences for each solution id.
InvalidSolutionID registerInvalidity(const std::string &object_type, const std::string &message, const bool warning)
Call to register an invalid calculation.
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
Definition EigenADReal.h:50
T fe_lagrange_1D_shape(const Order order, const unsigned int i, const T &xi)
MPI_Info info
uint8_t dof_id_type
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
SolutionInvalidityRegistry & getSolutionInvalidityRegistry()
Get the global SolutionInvalidityRegistry singleton.
Holds xi^(1), xi^(2), and other data for a given mortar segment.
const Elem * primary_elem
static const Real invalid_xi
const Elem * secondary_elem

Referenced by MortarInterfaceWarehouse::update().

◆ buildMortarSegmentMesh3d()

void AutomaticMortarGeneration::buildMortarSegmentMesh3d ( )

Builds the mortar segment mesh once the secondary and primary node projections have been completed.

Inputs:

  • mesh

Outputs:

  • mortar_segment_mesh
  • msm_elem_to_info

Step 1: Build mortar segments for all secondary elements

Step 1.1: Linearize secondary face elements

For first order face elements (Tri3 and Quad4) elements are simply linearized around center For second order (Tri6 and Quad9) and third order (Tri7) face elements, elements are sub-divided into four first order elements then each of the sub-elements is linearized around their respective centers For Quad8 elements, they are sub-divided into one quad and four triangle elements and each sub-element is linearized around their respective centers

Step 1.2: Coarse screening using a k-d tree to find nodes on the primary interface that are 'close to' a center point of the secondary element.

Step 1.3: Loop through primary candidate nodes, create mortar segments

Once an element with non-trivial projection onto secondary element identified, switch to breadth-first search (drop all current candidates and add only neighbors of elements with non-trivial overlap)

Step 1.3.2: Sub-divide primary element candidate, then project onto secondary sub-elements, perform polygon clipping, and triangulate to form mortar segments

Step 1.3.3: Create mortar segments and add to mortar segment mesh

Definition at line 1004 of file AutomaticMortarGeneration.C.

1005{
1006 const bool use_reference_interpolation =
1007 _mortar_3d_qp_mapping == Mortar3DQuadraturePointMapping::REFERENCE_INTERPOLATION;
1008
1009 // Add an integer flag to mortar segment mesh to keep track of which subelem
1010 // of second order primal elements mortar segments correspond to
1011 auto secondary_sub_elem = _mortar_segment_mesh->add_elem_integer("secondary_sub_elem");
1012 auto primary_sub_elem = _mortar_segment_mesh->add_elem_integer("primary_sub_elem");
1013
1014 // Assign globally unique node/element IDs via an exclusive prefix scan: each rank's bound is
1015 // local_secondary_sub_elems * visible_primary_sub_elems * 9, where 9 is the maximum nodes a
1016 // single secondary/primary sub-element pair can produce (8-vertex clipped polygon + center).
1017 // The result is cached and invalidated by meshChanged(), so the allgather only runs on topology
1018 // changes, not on every displaced-mesh residual update.
1019 if (!_msm_node_id_start.has_value())
1020 {
1021 dof_id_type local_secondary_sub_elems = 0, visible_primary_sub_elems = 0;
1022 for (const auto & [primary_sub_id, secondary_sub_id] : _primary_secondary_subdomain_id_pairs)
1023 {
1024 for (const auto * const el :
1025 _mesh.active_local_subdomain_elements_ptr_range(secondary_sub_id))
1026 local_secondary_sub_elems += el->n_sub_elem();
1027 for (const auto * const el : _mesh.active_subdomain_elements_ptr_range(primary_sub_id))
1028 visible_primary_sub_elems += el->n_sub_elem();
1029 }
1030 const dof_id_type per_rank_bound = local_secondary_sub_elems * visible_primary_sub_elems * 9;
1031 std::vector<dof_id_type> per_rank_bounds;
1032 _mesh.comm().allgather(per_rank_bound, per_rank_bounds);
1033 dof_id_type start = 0;
1034 for (const auto r : make_range(_mesh.processor_id()))
1035 start += per_rank_bounds[r];
1036 _msm_node_id_start = start;
1037 }
1038 dof_id_type next_node_id = *_msm_node_id_start;
1039 // Element IDs use the same starting offset: node and element IDs are separately numbered, and
1040 // element count per clip (n triangles) is always <= node count (n+1), so per_rank_bound covers
1041 // both.
1042 dof_id_type next_elem_id = next_node_id;
1043
1044 // Loop through mortar secondary and primary pairs to create mortar segment mesh between each
1045 for (const auto & pr : _primary_secondary_subdomain_id_pairs)
1046 {
1047 const auto primary_subd_id = pr.first;
1048 const auto secondary_subd_id = pr.second;
1049
1050 // Build k-d tree for use in Step 1.2 for primary interface coarse screening
1051 NanoflannMeshSubdomainAdaptor<3> mesh_adaptor(_mesh, primary_subd_id);
1052 subdomain_kd_tree_t kd_tree(
1053 3, mesh_adaptor, nanoflann::KDTreeSingleIndexAdaptorParams(/*max leaf=*/10));
1054
1055 // Construct the KD tree.
1056 kd_tree.buildIndex();
1057
1058 // Return the unoriented geometric normal of a linearized subpatch. These expressions are the
1059 // TRI3 and QUAD4 mapping tangents evaluated at the reference center, equivalent to evaluating
1060 // the first-order finite-element normal there without constructing a temporary element.
1061 auto get_sub_elem_geometric_normal = [](const std::vector<Point> & nodes)
1062 {
1063 Point dxdxi;
1064 Point dxdeta;
1065 if (nodes.size() == 3)
1066 {
1067 dxdxi = nodes[1] - nodes[0];
1068 dxdeta = nodes[2] - nodes[0];
1069 }
1070 else if (nodes.size() == 4)
1071 {
1072 // Bilinear center tangents define one normal for the full quad instead of selecting one of
1073 // the two diagonal triangle normals.
1074 dxdxi = 0.25 * (nodes[1] + nodes[2] - nodes[0] - nodes[3]);
1075 dxdeta = 0.25 * (nodes[2] + nodes[3] - nodes[0] - nodes[1]);
1076 }
1077 else
1078 mooseError("GEOMETRIC_NORMAL 3D mortar subpatch plane construction only supports "
1079 "triangular and quadrilateral subpatches, but received ",
1080 nodes.size(),
1081 " nodes.");
1082
1083 Point geometric_normal = dxdxi.cross(dxdeta);
1084 const auto normal_norm = geometric_normal.norm();
1085 // The cross product has units of area, so compare it with the product of tangent lengths.
1086 // Their ratio is the sine of the included angle and is independent of the mesh length scale.
1087 if (normal_norm <= TOLERANCE * dxdxi.norm() * dxdeta.norm())
1088 mooseError("GEOMETRIC_NORMAL 3D mortar subpatch plane construction encountered a "
1089 "degenerate subpatch.");
1090
1091 geometric_normal /= normal_norm;
1092 return geometric_normal;
1093 };
1094
1098 for (MeshBase::const_element_iterator el = _mesh.active_local_elements_begin(),
1099 end_el = _mesh.active_local_elements_end();
1100 el != end_el;
1101 ++el)
1102 {
1103 const Elem * secondary_side_elem = *el;
1104
1105 const Real secondary_volume = secondary_side_elem->volume();
1106
1107 // If this Elem is not in the current secondary subdomain, go on to the next one.
1108 if (secondary_side_elem->subdomain_id() != secondary_subd_id)
1109 continue;
1110
1111 auto [secondary_elem_to_msm_map_it, insertion_happened] =
1112 _secondary_elems_to_mortar_segments.emplace(secondary_side_elem->id(),
1113 std::set<Elem *, CompareDofObjectsByID>{});
1114 libmesh_ignore(insertion_happened);
1115 auto & secondary_to_msm_element_set = secondary_elem_to_msm_map_it->second;
1116
1117 std::vector<std::unique_ptr<MortarSegmentHelper>> mortar_segment_helper(
1118 secondary_side_elem->n_sub_elem());
1119 const auto nodal_normals = getNodalNormals(*secondary_side_elem);
1120
1131 for (auto sel : make_range(secondary_side_elem->n_sub_elem()))
1132 {
1133 // Get indices of sub-element nodes in element
1134 const auto sub_elem_nodes =
1135 Moose::Mortar::getMortarSubElementNodeIndices(*secondary_side_elem, sel);
1136
1137 // Secondary sub-element center, normal, and nodes
1138 Point center;
1139 Point normal;
1140 std::vector<Point> nodes(sub_elem_nodes.size());
1141
1142 // Collect the sub-element points and evaluate its center and averaged nodal normal.
1143 for (auto iv : make_range(sub_elem_nodes.size()))
1144 {
1145 const auto n = sub_elem_nodes[iv];
1146 nodes[iv] = secondary_side_elem->point(n);
1147 center += secondary_side_elem->point(n);
1148 normal += nodal_normals[n];
1149 }
1150 center /= sub_elem_nodes.size();
1151 normal = normal.unit();
1152
1153 if (_mortar_3d_subpatch_plane == Mortar3DSubpatchPlane::GEOMETRIC_NORMAL)
1154 {
1155 const Point averaged_normal = normal;
1156 normal = get_sub_elem_geometric_normal(nodes);
1157 if (normal * averaged_normal < 0)
1158 normal *= -1;
1159 }
1160
1161 if (use_reference_interpolation)
1162 {
1163 std::vector<Point> sub_elem_reference_points;
1164 sub_elem_reference_points.reserve(sub_elem_nodes.size());
1165 for (const auto node_index : sub_elem_nodes)
1166 sub_elem_reference_points.push_back(secondary_side_elem->master_point(node_index));
1167
1168 mortar_segment_helper[sel] =
1169 std::make_unique<MortarSegmentHelper>(std::move(nodes),
1170 std::move(sub_elem_reference_points),
1171 center,
1172 normal,
1175 }
1176 else
1177 mortar_segment_helper[sel] = std::make_unique<MortarSegmentHelper>(
1178 std::move(nodes), center, normal, _triangulation_mode, _triangulate_triangles);
1179 }
1180
1186 // Search point for performing Nanoflann (k-d tree) searches.
1187 // In each case we use the center point of the original element (not sub-elements for second
1188 // order elements). This is to do search for all sub-elements simultaneously
1189 std::array<Real, 3> query_pt;
1190 Point center_point;
1191 switch (secondary_side_elem->type())
1192 {
1193 case TRI3:
1194 case QUAD4:
1195 center_point = mortar_segment_helper[0]->center();
1196 query_pt = {{center_point(0), center_point(1), center_point(2)}};
1197 break;
1198 case TRI6:
1199 case TRI7:
1200 center_point = mortar_segment_helper[1]->center();
1201 query_pt = {{center_point(0), center_point(1), center_point(2)}};
1202 break;
1203 case QUAD8:
1204 center_point = mortar_segment_helper[4]->center();
1205 query_pt = {{center_point(0), center_point(1), center_point(2)}};
1206 break;
1207 case QUAD9:
1208 center_point = secondary_side_elem->point(8);
1209 query_pt = {{center_point(0), center_point(1), center_point(2)}};
1210 break;
1211 default:
1212 mooseError(
1213 "Face element type: ", secondary_side_elem->type(), "not supported for 3D mortar");
1214 }
1215
1216 // The number of results we want to get. These results will only be used to find
1217 // a single element with non-trivial overlap, after an element is identified a breadth
1218 // first search is done on neighbors
1219 const std::size_t num_results = 3;
1220
1221 // Initialize result_set and do the search.
1222 std::vector<size_t> ret_index(num_results);
1223 std::vector<Real> out_dist_sqr(num_results);
1224 nanoflann::KNNResultSet<Real> result_set(num_results);
1225 result_set.init(&ret_index[0], &out_dist_sqr[0]);
1226 kd_tree.findNeighbors(result_set, &query_pt[0], nanoflann::SearchParameters());
1227
1228 // Initialize list of processed primary elements, we don't want to revisit processed elements
1229 std::set<const Elem *, CompareDofObjectsByID> processed_primary_elems;
1230
1231 // Initialize candidate set and flag for switching between coarse screening and breadth-first
1232 // search
1233 bool primary_elem_found = false;
1234 std::set<const Elem *, CompareDofObjectsByID> primary_elem_candidates;
1235 const bool use_geometric_subpatch_normals =
1236 _mortar_3d_subpatch_plane == Mortar3DSubpatchPlane::GEOMETRIC_NORMAL;
1237 // In geometric mode the projection-angle cutoff also rejects near-orthogonal subpatch pairs.
1238 // The absolute dot product below keeps opposing primary/secondary orientations admissible.
1239 const Real minimum_subpatch_normal_alignment =
1240 use_geometric_subpatch_normals ? std::sin(_minimum_projection_angle * libMesh::pi / 180.0)
1241 : 0.0;
1242
1243 // Loop candidate nodes (returned by Nanoflann) and add all adjoining elems to candidate set
1244 for (auto r : make_range(result_set.size()))
1245 {
1246 // Verify that the squared distance we compute is the same as nanoflann's
1247 mooseAssert(abs((_mesh.point(ret_index[r]) - center_point).norm_sq() - out_dist_sqr[r]) <=
1248 TOLERANCE,
1249 "Lower-dimensional element squared distance verification failed.");
1250
1251 // Get list of elems connected to node
1252 std::vector<const Elem *> & node_elems =
1253 this->_nodes_to_primary_elem_map.at(static_cast<dof_id_type>(ret_index[r]));
1254
1255 // Uniquely add elems to candidate set
1256 for (auto elem : node_elems)
1257 primary_elem_candidates.insert(elem);
1258 }
1259
1267 while (!primary_elem_candidates.empty())
1268 {
1269 const Elem * primary_elem_candidate = *primary_elem_candidates.begin();
1270
1271 // If we've already processed this candidate, we don't need to check it again.
1272 if (processed_primary_elems.count(primary_elem_candidate))
1273 {
1274 primary_elem_candidates.erase(primary_elem_candidate);
1275 continue;
1276 }
1277
1278 // Initialize set of nodes used to construct mortar segment elements
1279 std::vector<Point> nodal_points;
1280
1281 // Initialize map from mortar segment elements to nodes
1282 std::vector<std::vector<unsigned int>> elem_to_node_map;
1283
1284 // Initialize list of secondary and primary sub-elements that formed each mortar segment
1285 std::vector<std::pair<unsigned int, unsigned int>> sub_elem_map;
1286 std::vector<std::array<Point, 3>> elem_to_secondary_reference_points;
1287 std::vector<std::array<Point, 3>> elem_to_primary_reference_points;
1288
1293 for (auto p_el : make_range(primary_elem_candidate->n_sub_elem()))
1294 {
1295 // Get nodes of primary sub-elements
1296 const auto sub_elem_nodes =
1297 Moose::Mortar::getMortarSubElementNodeIndices(*primary_elem_candidate, p_el);
1298
1299 // Get list of primary sub-element vertex nodes
1300 std::vector<Point> primary_sub_elem(sub_elem_nodes.size());
1301 for (auto iv : make_range(sub_elem_nodes.size()))
1302 {
1303 const auto n = sub_elem_nodes[iv];
1304 primary_sub_elem[iv] = primary_elem_candidate->point(n);
1305 }
1306 Point primary_sub_elem_normal;
1307 if (use_geometric_subpatch_normals)
1308 primary_sub_elem_normal = get_sub_elem_geometric_normal(primary_sub_elem);
1309
1310 std::vector<Point> sub_elem_reference_points;
1311 if (use_reference_interpolation)
1312 {
1313 sub_elem_reference_points.reserve(sub_elem_nodes.size());
1314 for (const auto node_index : sub_elem_nodes)
1315 sub_elem_reference_points.push_back(primary_elem_candidate->master_point(node_index));
1316 }
1317
1318 // Loop through secondary sub-elements
1319 for (auto s_el : make_range(secondary_side_elem->n_sub_elem()))
1320 {
1321 // Nearby primary candidates can include adjacent corner faces. Those faces may clip to
1322 // numerical slivers, which we do not consider valid face-to-face mortar pairs for this
1323 // search.
1324 if (use_geometric_subpatch_normals &&
1325 std::abs(primary_sub_elem_normal * mortar_segment_helper[s_el]->normal()) <
1326 minimum_subpatch_normal_alignment)
1327 continue;
1328
1329 // Mortar segment helpers were defined for each secondary sub-element, they will:
1330 // 1. Project primary sub-element onto linearized secondary sub-element
1331 // 2. Clip projected primary sub-element against secondary sub-element
1332 // 3. Triangulate clipped polygon to form mortar segments
1333 //
1334 // Mortar segment helpers append a list of mortar segment nodes and connectivities that
1335 // can be directly used to build mortar segments
1336 const auto segments_before_helper = elem_to_node_map.size();
1337 if (use_reference_interpolation)
1338 mortar_segment_helper[s_el]->getMortarSegments(primary_sub_elem,
1339 sub_elem_reference_points,
1340 nodal_points,
1341 elem_to_node_map,
1342 elem_to_secondary_reference_points,
1343 elem_to_primary_reference_points,
1344 TOLERANCE * secondary_volume);
1345 else
1346 mortar_segment_helper[s_el]->getMortarSegments(
1347 primary_sub_elem, nodal_points, elem_to_node_map);
1348
1349 // Keep track of which secondary and primary sub-elements created segment
1350 for (auto i = segments_before_helper; i < elem_to_node_map.size(); ++i)
1351 sub_elem_map.push_back(std::make_pair(s_el, p_el));
1352 }
1353 }
1354
1355 // Mark primary element as processed and remove from candidate list
1356 processed_primary_elems.insert(primary_elem_candidate);
1357 primary_elem_candidates.erase(primary_elem_candidate);
1358
1359 // If overlap of polygons was non-trivial (created mortar segment elements)
1360 if (!elem_to_node_map.empty())
1361 {
1362 if (sub_elem_map.size() != elem_to_node_map.size())
1363 mooseError("The mortar segment subpatch map is not aligned with the mortar segment "
1364 "connectivity map.");
1365 if (use_reference_interpolation &&
1366 (elem_to_secondary_reference_points.size() != elem_to_node_map.size() ||
1367 elem_to_primary_reference_points.size() != elem_to_node_map.size()))
1368 mooseError("The mortar segment reference-point maps are not aligned with the mortar "
1369 "segment connectivity map.");
1370
1371 // Only overlap polygons large enough to become mortar segments may switch the candidate
1372 // search to breadth first.
1373 bool seed_breadth_first_search = false;
1374 std::vector<bool> retained_mortar_segments(elem_to_node_map.size(), false);
1375 for (const auto el : index_range(elem_to_node_map))
1376 {
1377 const auto & node_map = elem_to_node_map[el];
1378 if (node_map.size() != 3)
1379 mooseError(
1380 "Active mortar segments only supports TRI elements, 3 nodes expected but: ",
1381 node_map.size(),
1382 " provided.");
1383
1384 const Point e1 = nodal_points[node_map[1]] - nodal_points[node_map[0]];
1385 const Point e2 = nodal_points[node_map[2]] - nodal_points[node_map[0]];
1386 retained_mortar_segments[el] =
1387 0.5 * e1.cross(e2).norm() / secondary_volume >= TOLERANCE;
1388 seed_breadth_first_search = seed_breadth_first_search || retained_mortar_segments[el];
1389 }
1390
1391 if (seed_breadth_first_search)
1392 {
1393 // If this is the first element with a qualifying overlap, set flag. Candidates will
1394 // now be neighbors of elements that had qualifying overlap.
1395 if (!primary_elem_found)
1396 {
1397 primary_elem_found = true;
1398 primary_elem_candidates.clear();
1399 }
1400
1401 // Add neighbors to candidate list
1402 for (auto neighbor : primary_elem_candidate->neighbor_ptr_range())
1403 {
1404 // If not valid or not on lower dimensional secondary subdomain, skip
1405 if (neighbor == nullptr || neighbor->subdomain_id() != primary_subd_id)
1406 continue;
1407 // If already processed, skip
1408 if (processed_primary_elems.count(neighbor))
1409 continue;
1410 // Otherwise, add to candidates
1411 primary_elem_candidates.insert(neighbor);
1412 }
1413 }
1414
1418 std::vector<Node *> new_nodes;
1419 // Clipping can append points for triangles later rejected by the area tolerance. Add only
1420 // points referenced by retained triangles so the mortar mesh has no orphan nodes.
1421 std::vector<bool> retained_nodes(nodal_points.size(), false);
1422 for (const auto el : index_range(elem_to_node_map))
1423 if (retained_mortar_segments[el])
1424 for (const auto node : elem_to_node_map[el])
1425 retained_nodes[node] = true;
1426
1427 new_nodes.resize(nodal_points.size(), nullptr);
1428 for (const auto node : index_range(nodal_points))
1429 if (retained_nodes[node])
1430 new_nodes[node] = _mortar_segment_mesh->add_point(
1431 nodal_points[node], next_node_id++, secondary_side_elem->processor_id());
1432
1433 // Loop through triangular elements in map
1434 for (auto el : index_range(elem_to_node_map))
1435 {
1436 if (!retained_mortar_segments[el])
1437 continue;
1438
1439 std::unique_ptr<Elem> new_elem;
1440 if (elem_to_node_map[el].size() == 3)
1441 new_elem = std::make_unique<Tri3>();
1442 else
1443 mooseError("Active mortar segments only supports TRI elements, 3 nodes expected "
1444 "but: ",
1445 elem_to_node_map[el].size(),
1446 " provided.");
1447
1448 new_elem->processor_id() = secondary_side_elem->processor_id();
1449 new_elem->subdomain_id() = secondary_side_elem->subdomain_id();
1450 new_elem->set_id(next_elem_id++);
1451
1452 // Attach newly created nodes
1453 for (auto i : index_range(elem_to_node_map[el]))
1454 new_elem->set_node(i, new_nodes[elem_to_node_map[el][i]]);
1455
1456 // If element is smaller than tolerance, don't add to msm
1457 if (new_elem->volume() / secondary_volume < TOLERANCE)
1458 continue;
1459
1460 // Add elements to mortar segment mesh
1461 Elem * msm_new_elem = _mortar_segment_mesh->add_elem(new_elem.release());
1462
1463 msm_new_elem->set_extra_integer(secondary_sub_elem, sub_elem_map[el].first);
1464 msm_new_elem->set_extra_integer(primary_sub_elem, sub_elem_map[el].second);
1465
1466 // Fill out mortar segment info
1467 MortarSegmentInfo msinfo;
1468 msinfo.secondary_elem = secondary_side_elem;
1469 msinfo.primary_elem = primary_elem_candidate;
1470
1471 // Associate this MSM elem with the MortarSegmentInfo.
1472 _msm_elem_to_info.emplace(msm_new_elem, msinfo);
1473
1474 // Store reference data only for retained segments.
1475 if (use_reference_interpolation)
1476 {
1477 MortarSegmentReferencePoints reference_points{elem_to_secondary_reference_points[el],
1478 elem_to_primary_reference_points[el]};
1479 _msm_elem_to_reference_points.emplace(msm_new_elem, reference_points);
1480 }
1481
1482 // Add this mortar segment to the secondary elem to mortar segment map
1483 secondary_to_msm_element_set.insert(msm_new_elem);
1484
1485 _secondary_ip_sub_ids.insert(msinfo.secondary_elem->interior_parent()->subdomain_id());
1486 // Unlike for 2D, we always have a primary when building the mortar mesh so we don't
1487 // have to check for null
1489 primaryInteriorParentOrSelf(*msinfo.primary_elem).subdomain_id());
1490 }
1491 }
1492 // End loop through primary element candidates
1493 }
1494
1495 if (use_geometric_subpatch_normals)
1496 {
1497 // A geometric corner filter may intentionally leave individual subpatches uncovered. Warn
1498 // only when the complete secondary element failed to produce a retained segment.
1499 if (secondary_to_msm_element_set.empty())
1500 mooseDoOnce(
1501 mooseWarning("Some secondary elements on mortar interface were unable to identify"
1502 " a corresponding primary element; this may be expected depending on"
1503 " problem geometry but may indicate a failure of the element search"
1504 " or projection"));
1505 }
1506 else
1507 for (auto sel : make_range(secondary_side_elem->n_sub_elem()))
1508 if (mortar_segment_helper[sel]->remainder() == 1.0)
1509 mooseDoOnce(
1510 mooseWarning("Some secondary elements on mortar interface were unable to identify"
1511 " a corresponding primary element; this may be expected depending on"
1512 " problem geometry but may indicate a failure of the element search"
1513 " or projection"));
1514
1515 if (secondary_to_msm_element_set.empty())
1516 _secondary_elems_to_mortar_segments.erase(secondary_elem_to_msm_map_it);
1517 } // End loop through secondary elements
1518 } // End loop through mortar constraint pairs
1519
1520 mooseAssert(!use_reference_interpolation ||
1522 "Mortar segment info and reference-point maps must remain aligned.");
1523
1524 _mortar_segment_mesh->cache_elem_data();
1525
1526 // The mesh was built distributedly (each rank owns only its local elements), so mark it
1527 // as such so MeshSerializer correctly gathers it to proc 0 for Exodus output.
1528 _mortar_segment_mesh->set_distributed();
1529
1530 // Output mortar segment mesh
1531 if (_debug)
1532 {
1533 // If element is not triangular, increment subdomain id
1534 // (ExodusII does not support mixed element types in a single subdomain)
1535 for (const auto msm_el : _mortar_segment_mesh->active_local_element_ptr_range())
1536 if (msm_el->type() != TRI3)
1537 msm_el->subdomain_id()++;
1538
1540
1541 // Undo increment
1542 for (const auto msm_el : _mortar_segment_mesh->active_local_element_ptr_range())
1543 if (msm_el->type() != TRI3)
1544 msm_el->subdomain_id()--;
1545 }
1546
1548
1549 // Print mortar segment mesh statistics
1550 if (_debug)
1551 {
1552 msmStatistics();
1553 }
1554}
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345
Point center
Definition MortarUtils.C:58
nanoflann::KDTreeSingleIndexAdaptor< subdomain_adatper_t, NanoflannMeshSubdomainAdaptor< 3 >, 3 > subdomain_kd_tree_t
std::unordered_map< const Elem *, MortarSegmentReferencePoints > _msm_elem_to_reference_points
Reference-coordinate data used only by the reference-interpolation mapping mode.
void msmStatistics()
Prints mortar segment mesh statistics to console (calls computeMsmStatistics internally)
std::optional< dof_id_type > _msm_node_id_start
Cached per-rank starting ID for 3D MSM nodes/elements.
std::vector< Point > getNodalNormals(const Elem &secondary_elem) const
Special adaptor that works with subdomains of the Mesh.
std::vector< unsigned int > getMortarSubElementNodeIndices(const Elem &parent_elem, unsigned int sub_elem)
Return the node indices for a first-order sub-element of a parent face.
Definition MortarUtils.C:67
void libmesh_ignore(const Args &...)
const Real pi
IntRange< T > make_range(T beg, T end)
SearchParams SearchParameters
Parent-face reference coordinates associated with the vertices of one triangular mortar segment.

Referenced by MortarInterfaceWarehouse::update().

◆ buildNodeToElemMaps()

void AutomaticMortarGeneration::buildNodeToElemMaps ( )

Once the secondary_requested_boundary_ids and primary_requested_boundary_ids containers have been filled in, call this function to build node-to-Elem maps for the lower-dimensional elements.

Definition at line 337 of file AutomaticMortarGeneration.C.

338{
341 "Must specify secondary and primary boundary ids before building node-to-elem maps.");
342
343 // Construct nodes_to_secondary_elem_map
344 for (const auto & secondary_elem :
345 as_range(_mesh.active_elements_begin(), _mesh.active_elements_end()))
346 {
347 // If this is not one of the lower-dimensional secondary side elements, go on to the next one.
348 if (!this->_secondary_boundary_subdomain_ids.count(secondary_elem->subdomain_id()))
349 continue;
350
351 for (const auto & nd : secondary_elem->node_ref_range())
352 {
353 std::vector<const Elem *> & vec = _nodes_to_secondary_elem_map[nd.id()];
354 vec.push_back(secondary_elem);
355 }
356 }
357
358 // Construct nodes_to_primary_elem_map
359 for (const auto & primary_elem :
360 as_range(_mesh.active_elements_begin(), _mesh.active_elements_end()))
361 {
362 // If this is not one of the lower-dimensional primary side elements, go on to the next one.
363 if (!this->_primary_boundary_subdomain_ids.count(primary_elem->subdomain_id()))
364 continue;
365
366 for (const auto & nd : primary_elem->node_ref_range())
367 {
368 std::vector<const Elem *> & vec = _nodes_to_primary_elem_map[nd.id()];
369 vec.push_back(primary_elem);
370 }
371 }
372}
std::unordered_map< dof_id_type, std::vector< const Elem * > > _nodes_to_secondary_elem_map
Map from nodes to connected lower-dimensional elements on the secondary/primary subdomains.

Referenced by MortarInterfaceWarehouse::update().

◆ clear()

void AutomaticMortarGeneration::clear ( )

Clears the mortar segment mesh and accompanying data structures.

Definition at line 298 of file AutomaticMortarGeneration.C.

299{
301 _mortar_segment_mesh->clear();
306 _msm_elem_to_info.clear();
313 _secondary_ip_sub_ids.clear();
317}
std::unordered_map< const Node *, Point > _secondary_node_to_nodal_normal
Container for storing the nodal normal vector associated with each secondary node.
std::unordered_map< const Elem *, unsigned int > _lower_elem_to_side_id
Keeps track of the mapping between lower-dimensional elements and the side_id of the interior_parent ...
std::unordered_set< dof_id_type > _projected_secondary_nodes
Debugging container for printing information about fraction of successful projections for secondary n...
std::unordered_map< const Node *, std::array< Point, 2 > > _secondary_node_to_hh_nodal_tangents
Container for storing the nodal tangent/binormal vectors associated with each secondary node (Househo...
std::unordered_map< dof_id_type, const Elem * > _secondary_element_to_secondary_lowerd_element
Map from full dimensional secondary element id to lower dimensional secondary element.
std::unordered_set< dof_id_type > _failed_secondary_node_projections
Secondary nodes that failed to project.

Referenced by MortarInterfaceWarehouse::update().

◆ computeADNodalNormals()

void AutomaticMortarGeneration::computeADNodalNormals ( const std::function< ADPoint(const Node &)> &  coordinate,
std::unordered_map< const Node *, ADRealVectorValue > &  nodal_normals 
) const

Build the normalized JxW-weighted secondary nodal normals from AD nodal coordinates.

The coordinate functor adds displacement derivatives to each node's current coordinates, so the stored normal values and their derivatives use the same geometry state.

Definition at line 2098 of file AutomaticMortarGeneration.C.

2101{
2102 const auto dim = _mesh.mesh_dimension();
2103 mooseAssert(dim == 2 || dim == 3, "AD nodal normals are only valid for 2D or 3D mortar.");
2104
2105 libMesh::QNodal qface(dim - 1);
2106 const auto & qweights = qface.get_weights();
2107 const Real sign = _periodic ? -1 : 1;
2108
2109 std::unordered_map<const Node *, ADRealVectorValue> weighted_area_vectors;
2110 std::unordered_map<const Node *, Real> weighted_area_magnitudes;
2111
2112 // One face FE object per secondary element order, reused across elements of that order
2113 std::map<Order, std::unique_ptr<FEBase>> fe_faces;
2114
2115 // AD propagates coordinate derivatives through the parent-side area vectors and normalization.
2116 for (const auto secondary_subdomain_id : _secondary_boundary_subdomain_ids)
2117 for (const Elem * const secondary_elem :
2118 as_range(_mesh.active_subdomain_elements_begin(secondary_subdomain_id),
2119 _mesh.active_subdomain_elements_end(secondary_subdomain_id)))
2120 {
2121 const Elem * const interior_parent = secondary_elem->interior_parent();
2122 mooseAssert(interior_parent,
2123 "No interior parent exists for element "
2124 << secondary_elem->id()
2125 << ". There may be a problem with your sideset set-up.");
2126
2127 const Real element_size = secondary_elem->hmax();
2128 if (element_size <= 0)
2129 mooseError("Cannot compute an AD nodal normal for secondary mortar element ",
2130 secondary_elem->id(),
2131 " because it has a non-positive characteristic length.");
2132
2133 const auto side = interior_parent->which_side_am_i(secondary_elem);
2134 auto & fe_face = fe_faces[secondary_elem->default_order()];
2135 if (!fe_face)
2136 {
2137 fe_face = FEBase::build(dim, FEType(secondary_elem->default_order(), LAGRANGE));
2138 fe_face->attach_quadrature_rule(&qface);
2139 }
2140
2141 const auto & face_normals = fe_face->get_normals();
2142 const auto & face_points = fe_face->get_xyz();
2143 const auto & map_dpsidxi = fe_face->get_fe_map().get_dpsidxi();
2144 const auto * const map_dpsideta = dim == 3 ? &fe_face->get_fe_map().get_dpsideta() : nullptr;
2145
2146 fe_face->reinit(interior_parent, side);
2147
2148 const auto qpoint_to_secondary_node =
2149 MooseMeshUtils::nodalQuadraturePointToNodeMap(*secondary_elem, face_points);
2150
2151 mooseAssert(face_normals.size() == face_points.size() &&
2152 qweights.size() == face_points.size(),
2153 "Face nodal geometry vectors and quadrature weights must have the same size.");
2154
2155 // The parent-side map includes enriched face mappings such as TET14-to-TRI7.
2156 auto parent_side_elem = interior_parent->build_side_ptr(side);
2157 const unsigned int n_mapping_shape_functions =
2158 dim == 2 ? libMesh::FE<2, LAGRANGE>::n_dofs(parent_side_elem.get(),
2159 parent_side_elem->default_order())
2160 : libMesh::FE<3, LAGRANGE>::n_dofs(parent_side_elem.get(),
2161 parent_side_elem->default_order());
2162 if (map_dpsidxi.size() != n_mapping_shape_functions ||
2163 (map_dpsideta && map_dpsideta->size() != n_mapping_shape_functions))
2164 mooseError("The parent-side geometric map for secondary mortar element ",
2165 secondary_elem->id(),
2166 " of type ",
2167 libMesh::Utility::enum_to_string<ElemType>(secondary_elem->type()),
2168 " does not have one mapping shape function per element node.");
2169 mooseAssert(n_mapping_shape_functions <= parent_side_elem->n_nodes(),
2170 "The mapping basis must not index past the side element's nodes.");
2171
2172 std::vector<ADPoint> side_points;
2173 side_points.reserve(n_mapping_shape_functions);
2174 for (const auto side_node_index : make_range(n_mapping_shape_functions))
2175 side_points.push_back(coordinate(parent_side_elem->node_ref(side_node_index)));
2176
2177 for (const auto qp : index_range(face_points))
2178 {
2179 const auto secondary_node_index = qpoint_to_secondary_node[qp];
2180 const Node * const secondary_node = secondary_elem->node_ptr(secondary_node_index);
2181
2182 ADRealVectorValue tangent_xi;
2183 ADRealVectorValue tangent_eta;
2184 for (const auto side_node_index : make_range(n_mapping_shape_functions))
2185 {
2186 tangent_xi.add_scaled(side_points[side_node_index], map_dpsidxi[side_node_index][qp]);
2187 if (dim == 3)
2188 tangent_eta.add_scaled(side_points[side_node_index],
2189 (*map_dpsideta)[side_node_index][qp]);
2190 }
2191
2192 auto area_vector = dim == 2 ? ADRealVectorValue(tangent_xi(1), -tangent_xi(0), 0)
2193 : tangent_xi.cross(tangent_eta);
2194 const Real area = MetaPhysicL::raw_value(area_vector.norm());
2195 const Real degeneracy_tolerance =
2196 dim == 2 ? TOLERANCE * element_size : TOLERANCE * element_size * element_size;
2197 if (area <= degeneracy_tolerance)
2198 mooseError("Cannot compute an AD nodal normal on degenerate secondary mortar element ",
2199 secondary_elem->id(),
2200 ".");
2201
2202 // qweight * area_vector is equivalent to JxW * face_normal. Fix its orientation to the
2203 // Real-valued face normal because the incident-face set and orientation are not
2204 // differentiated.
2205 const Real orientation =
2206 MetaPhysicL::raw_value(area_vector) * face_normals[qp] < 0 ? -1 : 1;
2207
2208 weighted_area_vectors[secondary_node] += sign * orientation * qweights[qp] * area_vector;
2209 weighted_area_magnitudes[secondary_node] += std::abs(qweights[qp]) * area;
2210 }
2211 }
2212
2213 nodal_normals.clear();
2214 nodal_normals.reserve(weighted_area_vectors.size());
2215 for (auto & [secondary_node, weighted_area_vector] : weighted_area_vectors)
2216 {
2217 const Real weighted_area_vector_norm = MetaPhysicL::raw_value(weighted_area_vector.norm());
2218 const Real weighted_area_magnitude = libmesh_map_find(weighted_area_magnitudes, secondary_node);
2219 if (weighted_area_vector_norm <= TOLERANCE * weighted_area_magnitude)
2220 mooseError("Cannot compute a normalized AD nodal normal for secondary node ",
2221 secondary_node->id(),
2222 " because its incident face contributions cancel to a near-zero weighted normal.");
2223
2224 auto nodal_normal = weighted_area_vector.unit();
2225 const auto & stored_normal = libmesh_map_find(_secondary_node_to_nodal_normal, secondary_node);
2226 // Equivalent FE and AD evaluations of the same unit normal may differ through operation
2227 // ordering. The tolerance admits roundoff while detecting inconsistent geometry states.
2228 mooseAssert((MetaPhysicL::raw_value(nodal_normal) - stored_normal).norm() < 1e-10,
2229 "The stored and AD secondary nodal normals must use the same geometry state.");
2230 // Set the raw value from the stored contact direction while retaining the derivatives produced
2231 // by the equivalent AD area-vector calculation.
2232 for (const auto component : make_range(Moose::dim))
2233 nodal_normal(component).value() = stored_normal(component);
2234 nodal_normals.emplace(secondary_node, std::move(nodal_normal));
2235 }
2236}
libMesh::VectorValue< ADReal > ADRealVectorValue
AD Array typedefs.
Definition MooseTypes.h:412
unsigned int n_dofs(const ElemType t, const Order o)
LIBMESH_DEVICE_INLINE void add_scaled(const TypeVector< T2 > &, const T &)
auto raw_value(const Eigen::Map< T > &in)
std::vector< unsigned int > nodalQuadraturePointToNodeMap(const Elem &elem, const std::vector< Point > &q_points)
Match the points of a nodal quadrature rule (e.g.
KOKKOS_INLINE_FUNCTION T sign(T x)
Returns the sign of a value.
Definition KokkosUtils.h:26
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
const Elem & get(const ElemType type_in)
LIBMESH_DEVICE_INLINE auto norm(const T &a)
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
const dof_id_type n_nodes

Referenced by Moose::Mortar::ADNodalFrames::normal().

◆ computeInactiveLMElems()

void AutomaticMortarGeneration::computeInactiveLMElems ( )

Get list of secondary elems without any corresponding primary elements.

Used to enforce zero values on inactive DoFs of elemental variables.

Definition at line 1950 of file AutomaticMortarGeneration.C.

1951{
1952 // Mark all active secondary elements
1953 std::unordered_set<const Elem *> active_local_elems;
1954
1955 //****
1956 // Note that in 3D our trick to check whether an element has edge dropping needs loose tolerances
1957 // since the mortar segments are on the linearized element and comparing the volume of the
1958 // linearized element does not have the same volume as the warped element
1959 const Real tol = (dim() == 3) ? 0.1 : TOLERANCE;
1960
1961 std::unordered_map<const Elem *, Real> active_volume;
1962
1963 // Compute fraction of elements with corresponding primary elements
1965 for (const auto msm_elem : _mortar_segment_mesh->active_local_element_ptr_range())
1966 {
1967 const MortarSegmentInfo & msinfo = _msm_elem_to_info.at(msm_elem);
1968 const Elem * secondary_elem = msinfo.secondary_elem;
1969
1970 active_volume[secondary_elem] += msm_elem->volume();
1971 }
1972 //****
1973
1974 for (const auto msm_elem : _mortar_segment_mesh->active_local_element_ptr_range())
1975 {
1976 const MortarSegmentInfo & msinfo = _msm_elem_to_info.at(msm_elem);
1977 const Elem * secondary_elem = msinfo.secondary_elem;
1978
1979 //****
1981 if (abs(active_volume[secondary_elem] / secondary_elem->volume() - 1.0) > tol)
1982 continue;
1983 //****
1984
1985 active_local_elems.insert(secondary_elem);
1986 }
1987
1988 // Take complement of active elements in active local subdomain to get inactive local elements
1990 for (const auto & pr : _primary_secondary_subdomain_id_pairs)
1991 for (const auto el : _mesh.active_local_subdomain_elements_ptr_range(
1992 /*secondary_subd_id*/ pr.second))
1993 if (active_local_elems.find(el) == active_local_elems.end())
1994 _inactive_local_lm_elems.insert(el);
1995}
std::unordered_set< const Elem * > _inactive_local_lm_elems
List of inactive lagrange multiplier nodes (for elemental variables)

Referenced by MortarInterfaceWarehouse::update().

◆ computeInactiveLMNodes()

void AutomaticMortarGeneration::computeInactiveLMNodes ( )

Get list of secondary nodes that don't contribute to interaction with any primary element.

Used to enforce zero values on inactive DoFs of nodal variables.

Definition at line 1886 of file AutomaticMortarGeneration.C.

1887{
1889 {
1891 return;
1892 }
1893
1894 // Only the owner of a node zeroes its LM DoFs, but the owner need not own (or even ghost) any
1895 // secondary lower-dimensional element touching it. Each processor therefore sends every node of
1896 // its local secondary elements to the node's owner, flagged as active if a local mortar segment
1897 // touches it. A node is inactive if no processor flags it as active.
1898
1899 // List of active nodes on local secondary elements
1900 std::unordered_set<dof_id_type> active_local_nodes;
1901
1902 // Mark all active local nodes
1903 for (const auto msm_elem : _mortar_segment_mesh->active_local_element_ptr_range())
1904 {
1905 const MortarSegmentInfo & msinfo = _msm_elem_to_info.at(msm_elem);
1906 const Elem * secondary_elem = msinfo.secondary_elem;
1907
1908 for (auto n : make_range(secondary_elem->n_nodes()))
1909 active_local_nodes.insert(secondary_elem->node_id(n));
1910 }
1911
1912 // List of all nodes on local secondary elements
1913 std::unordered_set<dof_id_type> local_nodes;
1914 for (const auto & pr : _primary_secondary_subdomain_id_pairs)
1915 for (const auto el : _mesh.active_local_subdomain_elements_ptr_range(
1916 /*secondary_subd_id*/ pr.second))
1917 for (const auto n : make_range(el->n_nodes()))
1918 local_nodes.insert(el->node_id(n));
1919
1920 // Pairs of (node id, 1 if active on the sending processor and 0 otherwise)
1921 std::unordered_map<processor_id_type, std::vector<std::pair<dof_id_type, unsigned char>>>
1922 proc_to_nodes;
1923 for (const auto node_id : local_nodes)
1924 proc_to_nodes[_mesh.node_ptr(node_id)->processor_id()].emplace_back(
1925 node_id, active_local_nodes.count(node_id));
1926
1927 std::unordered_set<dof_id_type> candidate_nodes, active_nodes;
1928 auto action_functor = [&candidate_nodes, &active_nodes](
1929 const processor_id_type,
1930 const std::vector<std::pair<dof_id_type, unsigned char>> & sent_data)
1931 {
1932 for (const auto & [node_id, active] : sent_data)
1933 {
1934 candidate_nodes.insert(node_id);
1935 if (active)
1936 active_nodes.insert(node_id);
1937 }
1938 };
1939 TIMPI::push_parallel_vector_data(_mesh.comm(), proc_to_nodes, action_functor);
1940
1941 // Store the owned inactive nodes to use later to zero LM DoFs on inactive nodes
1943 for (const auto node_id : candidate_nodes)
1944 if (!active_nodes.count(node_id))
1945 _inactive_local_lm_nodes.insert(_mesh.node_ptr(node_id));
1946}
std::unordered_set< const Node * > _inactive_local_lm_nodes
List of inactive lagrange multiplier nodes owned by this processor (for nodal variables)
void computeIncorrectEdgeDroppingInactiveLMNodes()
Computes inactive secondary nodes when incorrect edge dropping behavior is enabled (any node touching...

Referenced by MortarInterfaceWarehouse::update().

◆ computeIncorrectEdgeDroppingInactiveLMNodes()

void AutomaticMortarGeneration::computeIncorrectEdgeDroppingInactiveLMNodes ( )

Computes inactive secondary nodes when incorrect edge dropping behavior is enabled (any node touching a partially or fully dropped element is dropped)

Definition at line 1830 of file AutomaticMortarGeneration.C.

1831{
1832 using std::abs;
1833
1834 // Note that in 3D our trick to check whether an element has edge dropping needs loose tolerances
1835 // since the mortar segments are on the linearized element and comparing the volume of the
1836 // linearized element does not have the same volume as the warped element
1837 const Real tol = (dim() == 3) ? 0.1 : TOLERANCE;
1838
1839 // List of inactive nodes on local secondary elements
1840 std::unordered_set<dof_id_type> inactive_node_ids;
1841
1842 std::unordered_map<const Elem *, Real> active_volume{};
1843
1844 for (const auto & pr : _primary_secondary_subdomain_id_pairs)
1845 for (const auto el : _mesh.active_subdomain_elements_ptr_range(pr.second))
1846 active_volume[el] = 0.;
1847
1848 // Compute fraction of elements with corresponding primary elements
1849 for (const auto msm_elem : _mortar_segment_mesh->active_local_element_ptr_range())
1850 {
1851 const MortarSegmentInfo & msinfo = _msm_elem_to_info.at(msm_elem);
1852 const Elem * secondary_elem = msinfo.secondary_elem;
1853
1854 active_volume[secondary_elem] += msm_elem->volume();
1855 }
1856
1857 // Mark all inactive local nodes
1858 for (const auto & pr : _primary_secondary_subdomain_id_pairs)
1859 // Loop through all elements on my processor
1860 for (const auto el : _mesh.active_local_subdomain_elements_ptr_range(pr.second))
1861 // If elem fully or partially dropped
1862 if (abs(active_volume[el] / el->volume() - 1.0) > tol)
1863 {
1864 // Add all nodes to list of inactive
1865 for (auto n : make_range(el->n_nodes()))
1866 inactive_node_ids.insert(el->node_id(n));
1867 }
1868
1869 // Only the owner of a node zeroes its LM DoFs, but the owner need not own (or even ghost) any
1870 // secondary lower-dimensional element touching it, so send each inactive node to its owner,
1871 // which takes the union
1872 std::unordered_map<processor_id_type, std::vector<dof_id_type>> proc_to_inactive_nodes;
1873 for (const auto node_id : inactive_node_ids)
1874 proc_to_inactive_nodes[_mesh.node_ptr(node_id)->processor_id()].push_back(node_id);
1875
1877 auto action_functor = [this](const processor_id_type, const std::vector<dof_id_type> & sent_data)
1878 {
1879 for (const auto node_id : sent_data)
1880 _inactive_local_lm_nodes.insert(_mesh.node_ptr(node_id));
1881 };
1882 TIMPI::push_parallel_vector_data(_mesh.comm(), proc_to_inactive_nodes, action_functor);
1883}
Real volume(const MeshBase &mesh, unsigned int dim=libMesh::invalid_uint)

Referenced by computeInactiveLMNodes().

◆ computeMsmStatistics()

std::vector< AutomaticMortarGeneration::MsmSubdomainStats > AutomaticMortarGeneration::computeMsmStatistics ( )

Computes mortar segment mesh statistics and returns one entry per subdomain pair.

Must be called collectively on all ranks.

Definition at line 1701 of file AutomaticMortarGeneration.C.

1702{
1703 std::vector<MsmSubdomainStats> result;
1707 std::unordered_map<dof_id_type, Real> primary_elems_to_volume;
1708
1709 for (const auto & [primary_subd_id, secondary_subd_id] : _primary_secondary_subdomain_id_pairs)
1710 {
1711 for (const auto * const secondary_el :
1712 _mesh.active_local_subdomain_element_ptr_range(secondary_subd_id))
1713 {
1714 secondary.push_back(secondary_el->volume());
1715 // We may not have projected onto a primary face in which case we may not have created mortar
1716 // segments
1717 if (auto it = _secondary_elems_to_mortar_segments.find(secondary_el->id());
1719 for (const auto * const msm_elem : it->second)
1720 {
1721 msm.push_back(msm_elem->volume());
1722 const auto & msm_info = libmesh_map_find(_msm_elem_to_info, msm_elem);
1723 // Now it's also possible that we didn't project onto a primary face and we *did* create
1724 // mortar segments
1725 if (msm_info.primary_elem)
1726 {
1727 if (msm_info.primary_elem->subdomain_id() != primary_subd_id)
1728 mooseError("Unhandled primary-secondary pairing when computing mortar segment "
1729 "statistics. This could happen if you have the same secondary "
1730 "lower-dimensional subdomain ID paired with multiple lower-dimensional "
1731 "primary subdomain IDs. Contact a MOOSE developer for help.");
1732 if (const auto [it, inserted] =
1733 primary_elems_to_volume.emplace(msm_info.primary_elem->id(), Real{});
1734 inserted)
1735 it->second = msm_info.primary_elem->volume();
1736 else
1737 mooseAssert(
1738 MooseUtils::absoluteFuzzyEqual(it->second, msm_info.primary_elem->volume()),
1739 "Volumes should be consistent");
1740 }
1741 }
1742 }
1743
1744 _mesh.comm().set_union(primary_elems_to_volume);
1745 _mesh.comm().allgather(cast_ref<std::vector<Real> &>(secondary));
1746 _mesh.comm().allgather(cast_ref<std::vector<Real> &>(msm));
1747 primary.reserve(primary_elems_to_volume.size());
1748 for (const auto [_, volume] : primary_elems_to_volume)
1749 primary.push_back(volume);
1750
1751 // An interface on which no mortar segments formed has empty primary and segment lists, for
1752 // which libMesh's maximum() and minimum() are undefined. Report 0, as median() does.
1753 const auto max_volume = [](const auto & volumes)
1754 { return volumes.empty() ? Real(0) : volumes.maximum(); };
1755 const auto min_volume = [](const auto & volumes)
1756 { return volumes.empty() ? Real(0) : volumes.minimum(); };
1757
1758 MsmSubdomainStats stats;
1759 stats.primary_subd_id = primary_subd_id;
1760 stats.secondary_subd_id = secondary_subd_id;
1761 stats.secondary_lower_n_elems = secondary.size();
1762 stats.secondary_lower_max_volume = max_volume(secondary);
1763 stats.secondary_lower_min_volume = min_volume(secondary);
1764 stats.secondary_lower_median_volume = secondary.median();
1765 stats.primary_lower_n_elems = primary.size();
1766 stats.primary_lower_max_volume = max_volume(primary);
1767 stats.primary_lower_min_volume = min_volume(primary);
1768 stats.primary_lower_median_volume = primary.median();
1769 stats.msm_n_elems = msm.size();
1770 stats.msm_max_volume = max_volume(msm);
1771 stats.msm_min_volume = min_volume(msm);
1772 stats.msm_median_volume = msm.median();
1773 result.push_back(stats);
1774
1775 primary.clear();
1776 secondary.clear();
1777 msm.clear();
1778 primary_elems_to_volume.clear();
1779 }
1780
1781 return result;
1782}

Referenced by msmStatistics().

◆ computeNodalGeometry()

void AutomaticMortarGeneration::computeNodalGeometry ( )

Computes and stores the nodal normal/tangent vectors in a local data structure instead of using the ExplicitSystem/NumericVector approach.

This design was triggered by the way that the GhostingFunctor operates, but I think it is a better/more efficient way to do it anyway.

The _periodic flag tells us whether we want to inward vs outward facing normals

Definition at line 1998 of file AutomaticMortarGeneration.C.

1999{
2000 // The dimension according to Mesh::mesh_dimension().
2001 const auto dim = _mesh.mesh_dimension();
2002
2003 mooseAssert(dim == 2 || dim == 3,
2004 "AutomaticMortarGeneration::computeNodalGeometry() is only valid for "
2005 "mortar constraints on 2D or 3D meshes.");
2006 // A nodal lower-dimensional nodal quadrature rule to be used on faces.
2007 libMesh::QNodal qface(dim - 1);
2008
2009 // A map from the node id to the attached elemental normals/weights evaluated at the node. Th
2010 // length of the vector will correspond to the number of elements attached to the node. If it is a
2011 // vertex node, for a 1D mortar mesh, the vector length will be two. If it is an interior node,
2012 // the vector will be length 1. The first member of the pair is that element's normal at the node.
2013 // The second member is that element's JxW at the node
2014 std::map<dof_id_type, std::vector<std::pair<Point, Real>>> node_to_normals_map;
2015
2017 Real sign = _periodic ? -1 : 1;
2018
2019 // First loop over lower-dimensional secondary side elements and compute/save the outward normal
2020 // for each one. We loop over all active elements currently, but this procedure could be
2021 // parallelized as well.
2022 for (MeshBase::const_element_iterator el = _mesh.active_elements_begin(),
2023 end_el = _mesh.active_elements_end();
2024 el != end_el;
2025 ++el)
2026 {
2027 const Elem * secondary_elem = *el;
2028
2029 // If this is not one of the lower-dimensional secondary side elements, go on to the next one.
2030 if (!_secondary_boundary_subdomain_ids.count(secondary_elem->subdomain_id()))
2031 continue;
2032
2033 // We will create an FE object and attach the nodal quadrature rule such that we can get out the
2034 // normals at the element nodes
2035 FEType nnx_fe_type(secondary_elem->default_order(), LAGRANGE);
2036 std::unique_ptr<FEBase> nnx_fe_face(FEBase::build(dim, nnx_fe_type));
2037 nnx_fe_face->attach_quadrature_rule(&qface);
2038 const auto & face_normals = nnx_fe_face->get_normals();
2039 const auto & face_points = nnx_fe_face->get_xyz();
2040
2041 const auto & JxW = nnx_fe_face->get_JxW();
2042
2043 // Which side of the parent are we? We need to know this to know
2044 // which side to reinit.
2045 const Elem * interior_parent = secondary_elem->interior_parent();
2046 mooseAssert(interior_parent,
2047 "No interior parent exists for element "
2048 << secondary_elem->id()
2049 << ". There may be a problem with your sideset set-up.");
2050
2051 // Map to get lower dimensional element from interior parent on secondary surface
2052 // This map can be used to provide a handle to methods in this class that need to
2053 // operate on lower dimensional elements.
2054 _secondary_element_to_secondary_lowerd_element.emplace(interior_parent->id(), secondary_elem);
2055
2056 // Look up which side of the interior parent secondary_elem is.
2057 auto s = interior_parent->which_side_am_i(secondary_elem);
2058
2059 // Reinit the face FE object on side s.
2060 nnx_fe_face->reinit(interior_parent, s);
2061
2062 // Match by physical location instead of assuming that parent-side nodal
2063 // quadrature ordering and lower-dimensional side-element node ordering are
2064 // identical.
2065 const auto qpoint_to_secondary_node =
2066 MooseMeshUtils::nodalQuadraturePointToNodeMap(*secondary_elem, face_points);
2067
2068 mooseAssert(face_normals.size() == face_points.size() && JxW.size() == face_points.size(),
2069 "Face nodal geometry vectors must have the same size.");
2070
2071 for (const auto qp : make_range(face_points.size()))
2072 {
2073 const auto n = qpoint_to_secondary_node[qp];
2074 auto & normals_and_weights_vec = node_to_normals_map[secondary_elem->node_id(n)];
2075 normals_and_weights_vec.push_back(std::make_pair(sign * face_normals[qp], JxW[qp]));
2076 }
2077 }
2078
2079 // Normalize the JxW-weighted sum of incident face normals at each secondary node.
2080 for (const auto & pr : node_to_normals_map)
2081 {
2082 // Compute normal vector
2083 const auto & node_id = pr.first;
2084 const auto & normals_and_weights_vec = pr.second;
2085
2086 Point nodal_normal;
2087 for (const auto & norm_and_weight : normals_and_weights_vec)
2088 nodal_normal += norm_and_weight.first * norm_and_weight.second;
2089 nodal_normal = nodal_normal.unit();
2090
2091 _secondary_node_to_nodal_normal[_mesh.node_ptr(node_id)] = nodal_normal;
2092 _secondary_node_to_hh_nodal_tangents[_mesh.node_ptr(node_id)] =
2093 Moose::Mortar::nodalTangents(nodal_normal, dim);
2094 }
2095}
std::array< Vector, 2 > nodalTangents(const Vector &normal, const unsigned int dim)
Construct the two tangent vectors used by mortar from a unit normal on a dim dimensional mesh.

Referenced by MortarInterfaceWarehouse::update().

◆ dim()

int AutomaticMortarGeneration::dim ( ) const
inline

◆ getInactiveLMElems()

const std::unordered_set< const Elem * > & AutomaticMortarGeneration::getInactiveLMElems ( ) const
inline
Returns
The list of secondary elems on which mortar constraint is not active

Definition at line 441 of file AutomaticMortarGeneration.h.

442 {
444 }

Referenced by ComputeMortarFunctor::operator()().

◆ getInactiveLMNodes()

const std::unordered_set< const Node * > & AutomaticMortarGeneration::getInactiveLMNodes ( ) const
inline
Returns
The set of nodes on which mortar constraints are not active

Definition at line 433 of file AutomaticMortarGeneration.h.

434 {
436 }

Referenced by ComputeMortarFunctor::operator()().

◆ getNodalNormals()

std::vector< Point > AutomaticMortarGeneration::getNodalNormals ( const Elem &  secondary_elem) const
Returns
The nodal normals associated with the provided secondary_elem

Definition at line 375 of file AutomaticMortarGeneration.C.

376{
377 std::vector<Point> nodal_normals(secondary_elem.n_nodes());
378 for (const auto n : make_range(secondary_elem.n_nodes()))
379 nodal_normals[n] = _secondary_node_to_nodal_normal.at(secondary_elem.node_ptr(n));
380
381 return nodal_normals;
382}

Referenced by buildMortarSegmentMesh3d(), getNormals(), Moose::Mortar::ADNodalFrames::interpolatedNormals(), and MortarConsumerInterface::setNormals().

◆ getNodalTangents()

std::array< MooseUtils::SemidynamicVector< Point, 9 >, 2 > AutomaticMortarGeneration::getNodalTangents ( const Elem &  secondary_elem) const

Compute the two nodal tangents, which are built on-the-fly.

Returns
The nodal tangents associated with the provided secondary_elem

Definition at line 435 of file AutomaticMortarGeneration.C.

436{
437 // MetaPhysicL will check if we ran out of allocated space.
438 MooseUtils::SemidynamicVector<Point, 9> nodal_tangents_one(0);
439 MooseUtils::SemidynamicVector<Point, 9> nodal_tangents_two(0);
440
441 for (const auto n : make_range(secondary_elem.n_nodes()))
442 {
443 const auto & tangent_vectors =
444 libmesh_map_find(_secondary_node_to_hh_nodal_tangents, secondary_elem.node_ptr(n));
445 nodal_tangents_one.push_back(tangent_vectors[0]);
446 nodal_tangents_two.push_back(tangent_vectors[1]);
447 }
448
449 return {{nodal_tangents_one, nodal_tangents_two}};
450}

◆ getNormals() [1/2]

std::vector< Point > AutomaticMortarGeneration::getNormals ( const Elem &  secondary_elem,
const std::vector< Point > &  xi1_pts 
) const

Compute the normals at given reference points on a secondary element.

Parameters
secondary_elemThe secondary element used to query for associated nodal normals
xi1_ptsThe reference points on the secondary element to evaluate the normals at. The points should only be non-zero in the zeroth entry because right now our mortar mesh elements are always 1D
Returns
The normals

Definition at line 464 of file AutomaticMortarGeneration.C.

466{
467 const auto mortar_dim = _mesh.mesh_dimension() - 1;
468 const auto num_qps = xi1_pts.size();
469 const auto nodal_normals = getNodalNormals(secondary_elem);
470 std::vector<Point> normals(num_qps);
471
472 for (const auto n : make_range(secondary_elem.n_nodes()))
473 for (const auto qp : make_range(num_qps))
474 {
475 const auto phi =
476 (mortar_dim == 1)
477 ? Moose::fe_lagrange_1D_shape(secondary_elem.default_order(), n, xi1_pts[qp](0))
478 : Moose::fe_lagrange_2D_shape(secondary_elem.type(),
479 secondary_elem.default_order(),
480 n,
481 cast_ref<const TypeVector<Real> &>(xi1_pts[qp]));
482 normals[qp] += phi * nodal_normals[n];
483 }
484
485 if (_periodic)
486 for (auto & normal : normals)
487 normal *= -1;
488
489 return normals;
490}
T fe_lagrange_2D_shape(const libMesh::ElemType type, const Order order, const unsigned int i, const VectorType< T > &p)

Referenced by buildMortarSegmentMesh(), getNormals(), and MortarConsumerInterface::setNormals().

◆ getNormals() [2/2]

std::vector< Point > AutomaticMortarGeneration::getNormals ( const Elem &  secondary_elem,
const std::vector< Real > &  oned_xi1_pts 
) const

Compute the normals at given reference points on a secondary element.

Parameters
secondary_elemThe secondary element used to query for associated nodal normals
1d_xi1_ptsThe reference points on the secondary element to evaluate the normals at. The "points" are single reals corresponding to xi because right now our mortar mesh elements are always 1D
Returns
The normals

Definition at line 453 of file AutomaticMortarGeneration.C.

455{
456 std::vector<Point> xi1_pts(oned_xi1_pts.size());
457 for (const auto qp : index_range(oned_xi1_pts))
458 xi1_pts[qp] = oned_xi1_pts[qp];
459
460 return getNormals(secondary_elem, xi1_pts);
461}

◆ getPrimaryIpToLowerElementMap()

std::map< unsigned int, unsigned int > AutomaticMortarGeneration::getPrimaryIpToLowerElementMap ( const Elem &  primary_elem,
const Elem &  primary_elem_ip,
const Elem &  lower_secondary_elem 
) const

Compute on-the-fly mapping from primary interior parent nodes to its corresponding lower dimensional nodes.

Returns
The map from primary interior parent nodes to its corresponding lower dimensional nodes

Definition at line 411 of file AutomaticMortarGeneration.C.

415{
416 std::map<unsigned int, unsigned int> primary_ip_i_to_lower_primary_i;
417
418 for (const auto i : make_range(lower_primary_elem.n_nodes()))
419 {
420 const auto & nd = lower_primary_elem.node_ref(i);
421 primary_ip_i_to_lower_primary_i[primary_elem.get_node_index(&nd)] = i;
422 }
423
424 return primary_ip_i_to_lower_primary_i;
425}

◆ getSecondaryIpToLowerElementMap()

std::map< unsigned int, unsigned int > AutomaticMortarGeneration::getSecondaryIpToLowerElementMap ( const Elem &  lower_secondary_elem) const

Compute on-the-fly mapping from secondary interior parent nodes to lower dimensional nodes.

Returns
The map from secondary interior parent nodes to lower dimensional nodes

Definition at line 395 of file AutomaticMortarGeneration.C.

396{
397 std::map<unsigned int, unsigned int> secondary_ip_i_to_lower_secondary_i;
398 const Elem * const secondary_ip = lower_secondary_elem.interior_parent();
399 mooseAssert(secondary_ip, "This should be non-null");
400
401 for (const auto i : make_range(lower_secondary_elem.n_nodes()))
402 {
403 const auto & nd = lower_secondary_elem.node_ref(i);
404 secondary_ip_i_to_lower_secondary_i[secondary_ip->get_node_index(&nd)] = i;
405 }
406
407 return secondary_ip_i_to_lower_secondary_i;
408}

◆ getSecondaryLowerdElemFromSecondaryElem()

const Elem * AutomaticMortarGeneration::getSecondaryLowerdElemFromSecondaryElem ( dof_id_type  secondary_elem_id) const

Return lower dimensional secondary element given its interior parent.

Helpful outside the mortar generation to locate mortar-related quantities.

Parameters
secondary_elem_idThe secondary interior parent element id used to query for associated lower dimensional element
Returns
The corresponding lower dimensional secondary element

Definition at line 385 of file AutomaticMortarGeneration.C.

387{
388 mooseAssert(_secondary_element_to_secondary_lowerd_element.count(secondary_elem_id),
389 "Map should locate secondary element");
390
391 return _secondary_element_to_secondary_lowerd_element.at(secondary_elem_id);
392}

◆ incorrectEdgeDropping()

bool AutomaticMortarGeneration::incorrectEdgeDropping ( ) const
inline

Definition at line 446 of file AutomaticMortarGeneration.h.

446{ return !_correct_edge_dropping; }

Referenced by ComputeMortarFunctor::operator()().

◆ initOutput()

void AutomaticMortarGeneration::initOutput ( )

initialize mortar-mesh based output

Definition at line 282 of file AutomaticMortarGeneration.C.

283{
284 if (!_debug)
285 return;
286
287 _output_params = std::make_unique<InputParameters>(MortarNodalGeometryOutput::validParams());
288 _output_params->set<AutomaticMortarGeneration *>("_amg") = this;
289 _output_params->set<FEProblemBase *>("_fe_problem_base") = &_app.feProblem();
291 _output_params->set<std::string>(MooseBase::name_param) =
292 "mortar_nodal_geometry_" + mortarInterfaceName();
293 _output_params->finalize("MortarNodalGeometryOutput");
294 _app.getOutputWarehouse().addOutput(std::make_shared<MortarNodalGeometryOutput>(*_output_params));
295}
This class is a container/interface for the objects involved in automatic generation of mortar spaces...
std::unique_ptr< InputParameters > _output_params
Storage for the input parameters used by the mortar nodal geometry output.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Base class for MOOSE-based applications.
Definition MooseApp.h:110
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition MooseApp.C:2452
FEProblemBase & feProblem() const
Definition MooseApp.C:1895
static const std::string name_param
The name of the parameter that contains the object name.
Definition MooseBase.h:55
static const std::string app_param
The name of the parameter that contains the MooseApp.
Definition MooseBase.h:59
static InputParameters validParams()
void addOutput(std::shared_ptr< Output > output)
Adds an existing output object to the warehouse.

◆ meshChanged()

void AutomaticMortarGeneration::meshChanged ( )
inline

Invalidates the cached MSM node/element ID starting offset so that the next call to buildMortarSegmentMesh3d() recomputes it via allgather.

Call this when mesh topology changes.

Definition at line 282 of file AutomaticMortarGeneration.h.

282{ _msm_node_id_start = std::nullopt; }

Referenced by MortarInterfaceWarehouse::meshChanged().

◆ mortar3DQpMapping()

Mortar3DQuadraturePointMapping AutomaticMortarGeneration::mortar3DQpMapping ( ) const
inline

Return the 3D mortar quadrature-point mapping method.

Definition at line 424 of file AutomaticMortarGeneration.h.

424{ return _mortar_3d_qp_mapping; }

Referenced by Moose::Mortar::loopOverMortarSegments().

◆ mortarInterfaceCoupling()

const std::unordered_map< dof_id_type, std::unordered_set< dof_id_type > > & AutomaticMortarGeneration::mortarInterfaceCoupling ( ) const
inline
Returns
The mortar interface coupling

Definition at line 388 of file AutomaticMortarGeneration.h.

389 {
391 }

◆ mortarInterfaceName()

std::string AutomaticMortarGeneration::mortarInterfaceName ( ) const
private
Returns
A string uniquely identifying this mortar interface

Definition at line 268 of file AutomaticMortarGeneration.C.

269{
270 std::vector<std::string> string_vec(_primary_secondary_boundary_id_pairs.size() * 2 + 1);
272 {
273 const auto [primary_bnd_id, secondary_bnd_id] = _primary_secondary_boundary_id_pairs[i];
274 string_vec[2 * i] = std::to_string(primary_bnd_id);
275 string_vec[2 * i + 1] = std::to_string(secondary_bnd_id);
276 }
277 string_vec.back() = _on_displaced ? "displaced" : "undisplaced";
278 return MooseUtils::join(string_vec, "_");
279}

Referenced by initOutput(), and outputMortarMesh().

◆ mortarSegmentMesh()

const MeshBase & AutomaticMortarGeneration::mortarSegmentMesh ( ) const
inline
Returns
The mortar segment mesh

Definition at line 411 of file AutomaticMortarGeneration.h.

411{ return *_mortar_segment_mesh; }

Referenced by Moose::Mortar::loopOverMortarSegments().

◆ mortarSegmentMeshElemToInfo()

const std::unordered_map< const Elem *, MortarSegmentInfo > & AutomaticMortarGeneration::mortarSegmentMeshElemToInfo ( ) const
inline
Returns
The mortar segment element to corresponding information

Definition at line 416 of file AutomaticMortarGeneration.h.

417 {
418 return _msm_elem_to_info;
419 }

Referenced by Moose::Mortar::loopOverMortarSegments().

◆ mortarSegmentReferencePoints()

const MortarSegmentReferencePoints & AutomaticMortarGeneration::mortarSegmentReferencePoints ( const Elem &  mortar_segment_elem) const

Return the parent-face reference coordinates for a mortar segment.

Definition at line 320 of file AutomaticMortarGeneration.C.

321{
322 if (_mortar_3d_qp_mapping != Mortar3DQuadraturePointMapping::REFERENCE_INTERPOLATION)
323 mooseError("Mortar segment reference points were requested for mortar segment element ",
324 mortar_segment_elem.id(),
325 ", but the reference-interpolation mapping mode is not enabled.");
326
327 const auto reference_points_it = _msm_elem_to_reference_points.find(&mortar_segment_elem);
328 if (reference_points_it == _msm_elem_to_reference_points.end())
329 mooseError("No reference-point record was found for mortar segment element ",
330 mortar_segment_elem.id(),
331 ". The mortar segment info and reference-point maps are not aligned.");
332
333 return reference_points_it->second;
334}

Referenced by Moose::Mortar::loopOverMortarSegments().

◆ msmStatistics()

void AutomaticMortarGeneration::msmStatistics ( )

Prints mortar segment mesh statistics to console (calls computeMsmStatistics internally)

Definition at line 1785 of file AutomaticMortarGeneration.C.

1786{
1787 const auto all_stats = computeMsmStatistics();
1788
1789 if (_mesh.processor_id() != 0)
1790 return;
1791
1792 Moose::out << "Mortar Interface Statistics:" << std::endl;
1793 for (const auto & stats : all_stats)
1794 {
1795 std::vector<std::string> col_names = {"mesh", "n_elems", "max", "min", "median"};
1796 std::vector<std::string> subds = {"secondary_lower", "primary_lower", "mortar_segment"};
1797 std::vector<size_t> n_elems = {
1798 stats.secondary_lower_n_elems, stats.primary_lower_n_elems, stats.msm_n_elems};
1799 std::vector<Real> maxs = {
1800 stats.secondary_lower_max_volume, stats.primary_lower_max_volume, stats.msm_max_volume};
1801 std::vector<Real> mins = {
1802 stats.secondary_lower_min_volume, stats.primary_lower_min_volume, stats.msm_min_volume};
1803 std::vector<Real> medians = {stats.secondary_lower_median_volume,
1804 stats.primary_lower_median_volume,
1805 stats.msm_median_volume};
1806
1807 FormattedTable table;
1808 table.clear();
1809 for (auto i : index_range(subds))
1810 {
1811 table.addRow(i);
1812 table.addData<std::string>(col_names[0], subds[i]);
1813 table.addData<size_t>(col_names[1], n_elems[i]);
1814 table.addData<Real>(col_names[2], maxs[i]);
1815 table.addData<Real>(col_names[3], mins[i]);
1816 table.addData<Real>(col_names[4], medians[i]);
1817 }
1818
1819 Moose::out << "secondary subdomain: " << stats.secondary_subd_id
1820 << " \tprimary subdomain: " << stats.primary_subd_id << std::endl;
1821 table.printTable(Moose::out, subds.size());
1822 }
1823}
std::vector< MsmSubdomainStats > computeMsmStatistics()
Computes mortar segment mesh statistics and returns one entry per subdomain pair.
This class is used for building, formatting, and outputting tables of numbers.
void printTable(std::ostream &out, unsigned int last_n_entries=0)
Methods for dumping the table to the stream - either by filename or by stream handle.
void addData(const std::string &name, const T &value)
Method for adding data to the output table.
void addRow(Real time)
Force a new row in the table with the passed in time.

Referenced by buildMortarSegmentMesh3d().

◆ nodesToSecondaryElem()

const std::unordered_map< dof_id_type, std::vector< const Elem * > > & AutomaticMortarGeneration::nodesToSecondaryElem ( ) const
inline
Returns
Map from node id to secondary lower-d element pointer

Definition at line 484 of file AutomaticMortarGeneration.h.

485 {
487 }

◆ onDisplaced()

bool AutomaticMortarGeneration::onDisplaced ( ) const
inline

returns whether this object is on the displaced mesh

Definition at line 287 of file AutomaticMortarGeneration.h.

287{ return _on_displaced; }

◆ outputMortarMesh()

void AutomaticMortarGeneration::outputMortarMesh ( )
private

Write the mortar segment mesh to exodus.

Definition at line 989 of file AutomaticMortarGeneration.C.

990{
991 ExodusII_IO mortar_segment_mesh_writer(*_mortar_segment_mesh);
992
993 // Default to non-HDF5 output for wider compatibility
994 mortar_segment_mesh_writer.set_hdf5_writing(false);
995
996 std::array<std::string, 3> file_pieces = {
997 _app.getOutputFileBase(/*for_non_moose_build_output=*/true),
999 "mortar_segment_mesh.e"};
1000 mortar_segment_mesh_writer.write(MooseUtils::join(file_pieces, "_"));
1001}
std::string getOutputFileBase(bool for_non_moose_build_output=false) const
Get the output file base name.
Definition MooseApp.C:1574

Referenced by buildMortarSegmentMesh(), and buildMortarSegmentMesh3d().

◆ primaryInteriorParentOrSelf()

const Elem & AutomaticMortarGeneration::primaryInteriorParentOrSelf ( const Elem &  lower_primary_elem)
static
Returns
The interior parent of a lower-dimensional primary element, or the element itself if it has no interior parent, e.g. when the primary side is a rigid surface mesh

Definition at line 428 of file AutomaticMortarGeneration.C.

429{
430 const Elem * const ip = lower_primary_elem.interior_parent();
431 return ip ? *ip : lower_primary_elem;
432}

Referenced by buildCouplingInformation(), buildMortarSegmentMesh(), buildMortarSegmentMesh3d(), and MortarInterfaceWarehouse::createMortarInterface().

◆ primaryInternalSubIDs()

const std::set< SubdomainID > & AutomaticMortarGeneration::primaryInternalSubIDs ( ) const
inline
Returns
All the subdomain IDs of the primary interior associated with the mortar mesh: those of the primary interior parents, and those of primary elements without an interior parent, which represent their own interior (e.g. a rigid surface)

Definition at line 479 of file AutomaticMortarGeneration.h.

Referenced by Moose::Mortar::setupMortarMaterials(), and MortarInterfaceWarehouse::update().

◆ primarySecondaryBoundaryIDPair()

const std::pair< BoundaryID, BoundaryID > & AutomaticMortarGeneration::primarySecondaryBoundaryIDPair ( ) const
inline
Returns
The primary-secondary boundary ID pair

Definition at line 714 of file AutomaticMortarGeneration.h.

715{
716 mooseAssert(_primary_secondary_boundary_id_pairs.size() == 1,
717 "We currently only support a single boundary pair per mortar generation object");
718
720}

Referenced by Moose::Mortar::loopOverMortarSegments(), and Moose::Mortar::setupMortarMaterials().

◆ processAlignedNodes()

bool AutomaticMortarGeneration::processAlignedNodes ( const Node &  secondary_node,
const Node &  primary_node,
const std::vector< const Elem * > *  secondary_node_neighbors,
const std::vector< const Elem * > *  primary_node_neighbors,
const VectorValue< Real > &  nodal_normal,
const Elem &  candidate_element,
std::set< const Elem * > &  rejected_element_candidates 
)
private

Process aligned nodes.

Returns
whether mortar segment(s) were created

Definition at line 2250 of file AutomaticMortarGeneration.C.

2258{
2259 if (!secondary_node_neighbors)
2260 secondary_node_neighbors = &libmesh_map_find(_nodes_to_secondary_elem_map, secondary_node.id());
2261 if (!primary_node_neighbors)
2262 primary_node_neighbors = &libmesh_map_find(_nodes_to_primary_elem_map, primary_node.id());
2263
2264 std::vector<bool> primary_elems_mapped(primary_node_neighbors->size(), false);
2265
2266 // Add entries to secondary_node_and_elem_to_xi2_primary_elem container.
2267 //
2268 // First, determine "on left" vs. "on right" orientation of the nodal neighbors.
2269 // There can be a max of 2 nodal neighbors, and we want to make sure that the
2270 // secondary nodal neighbor on the "left" is associated with the primary nodal
2271 // neighbor on the "left" and similarly for the "right". We use cross products to determine
2272 // alignment. In the below diagram, 'x' denotes a node, and connected '|' are lower dimensional
2273 // elements.
2274 // x
2275 // x |
2276 // | |
2277 // secondary x ----> x primary
2278 // | |
2279 // | x
2280 // x
2281 //
2282 // Looking at the aligned nodes, the secondary node first, if we pick the top secondary lower
2283 // dimensional element, then the cross product as written a few lines below points out of the
2284 // screen towards you. (Point in the direction of the secondary nodal normal, and then curl your
2285 // hand towards the secondary element's opposite node, then the thumb points in the direction of
2286 // the cross product). Doing the same with the aligned primary node, if we pick the top primary
2287 // element, then the cross product also points out of the screen. Because the cross products
2288 // point in the same direction (positive dot product), then we know to associate the
2289 // secondary-primary element pair. If we had picked the bottom primary element whose cross
2290 // product points into the screen, then clearly the cross products point in the opposite
2291 // direction and we don't have a match
2292 std::array<Real, 2> secondary_node_neighbor_cps, primary_node_neighbor_cps;
2293
2294 for (const auto nn : index_range(*secondary_node_neighbors))
2295 {
2296 const Elem * const secondary_neigh = (*secondary_node_neighbors)[nn];
2297 const Point opposite = (secondary_neigh->node_ptr(0) == &secondary_node)
2298 ? secondary_neigh->point(1)
2299 : secondary_neigh->point(0);
2300 const Point cp = nodal_normal.cross(opposite - secondary_node);
2301 secondary_node_neighbor_cps[nn] = cp(2);
2302 }
2303
2304 for (const auto nn : index_range(*primary_node_neighbors))
2305 {
2306 const Elem * const primary_neigh = (*primary_node_neighbors)[nn];
2307 const Point opposite = (primary_neigh->node_ptr(0) == &primary_node) ? primary_neigh->point(1)
2308 : primary_neigh->point(0);
2309 const Point cp = nodal_normal.cross(opposite - primary_node);
2310 primary_node_neighbor_cps[nn] = cp(2);
2311 }
2312
2313 // Associate secondary/primary elems on matching sides.
2314 bool found_match = false;
2315 for (const auto snn : index_range(*secondary_node_neighbors))
2316 for (const auto mnn : index_range(*primary_node_neighbors))
2317 if (secondary_node_neighbor_cps[snn] * primary_node_neighbor_cps[mnn] > 0)
2318 {
2319 found_match = true;
2320 if (primary_elems_mapped[mnn])
2321 continue;
2322 primary_elems_mapped[mnn] = true;
2323
2324 // Figure out xi^(2) value by looking at which node primary_node is
2325 // of the current primary node neighbor.
2326 const Real xi2 = (&primary_node == (*primary_node_neighbors)[mnn]->node_ptr(0)) ? -1 : +1;
2327 const auto secondary_key =
2328 std::make_pair(&secondary_node, (*secondary_node_neighbors)[snn]);
2329 const auto primary_val = std::make_pair(xi2, (*primary_node_neighbors)[mnn]);
2330 _secondary_node_and_elem_to_xi2_primary_elem.emplace(secondary_key, primary_val);
2331
2332 // Also map in the other direction.
2333 const Real xi1 =
2334 (&secondary_node == (*secondary_node_neighbors)[snn]->node_ptr(0)) ? -1 : +1;
2335
2336 const auto primary_key =
2337 std::make_tuple(primary_node.id(), &primary_node, (*primary_node_neighbors)[mnn]);
2338 const auto secondary_val = std::make_pair(xi1, (*secondary_node_neighbors)[snn]);
2339 _primary_node_and_elem_to_xi1_secondary_elem.emplace(primary_key, secondary_val);
2340 }
2341
2342 if (!found_match)
2343 {
2344 // There could be coincident nodes and this might be a bad primary candidate (see
2345 // issue #21680). Instead of giving up, let's try continuing
2346 rejected_elem_candidates.insert(&candidate_element);
2347 return false;
2348 }
2349
2350 // We need to handle the case where we've exactly projected a secondary node onto a
2351 // primary node, but our secondary node is at one of the secondary boundary face endpoints and
2352 // our primary node is not.
2353 if (secondary_node_neighbors->size() == 1 && primary_node_neighbors->size() == 2)
2354 for (const auto i : index_range(primary_elems_mapped))
2355 if (!primary_elems_mapped[i])
2356 {
2358 std::make_tuple(primary_node.id(), &primary_node, (*primary_node_neighbors)[i]),
2359 std::make_pair(1, nullptr));
2360 }
2361
2362 return found_match;
2363}
TypeVector< typename CompareTypes< T, T2 >::supertype > cross(const TypeVector< T2 > &v) const

Referenced by projectPrimaryNodesSinglePair(), and projectSecondaryNodesSinglePair().

◆ projectPrimaryNodes()

void AutomaticMortarGeneration::projectPrimaryNodes ( )

(Inverse) project primary nodes to the points on the secondary surface where they would have come from (find (xi^(1) values)).

Inputs:

  • The nodal normals values
  • mesh
  • nodes_to_secondary_elem_map

Outputs:

  • primary_node_and_elem_to_xi1_secondary_elem

Defined in the file project_primary_nodes.C.

Definition at line 2611 of file AutomaticMortarGeneration.C.

2612{
2613 // For each primary/secondary boundary id pair, call the
2614 // project_primary_nodes_single_pair() helper function.
2615 for (const auto & pr : _primary_secondary_subdomain_id_pairs)
2616 projectPrimaryNodesSinglePair(pr.first, pr.second);
2617}
void projectPrimaryNodesSinglePair(SubdomainID lower_dimensional_primary_subdomain_id, SubdomainID lower_dimensional_secondary_subdomain_id)
Helper function used internally by AutomaticMortarGeneration::project_primary_nodes().

Referenced by MortarInterfaceWarehouse::update().

◆ projectPrimaryNodesSinglePair()

void AutomaticMortarGeneration::projectPrimaryNodesSinglePair ( SubdomainID  lower_dimensional_primary_subdomain_id,
SubdomainID  lower_dimensional_secondary_subdomain_id 
)
private

Helper function used internally by AutomaticMortarGeneration::project_primary_nodes().

Definition at line 2620 of file AutomaticMortarGeneration.C.

2623{
2624 using std::abs;
2625
2626 // Build a Nanoflann object on the lower-dimensional secondary elements of the Mesh.
2627 NanoflannMeshSubdomainAdaptor<3> mesh_adaptor(_mesh, lower_dimensional_secondary_subdomain_id);
2628 subdomain_kd_tree_t kd_tree(
2629 3, mesh_adaptor, nanoflann::KDTreeSingleIndexAdaptorParams(/*max leaf=*/10));
2630
2631 // Construct the KD tree for lower-dimensional elements in the volume mesh.
2632 kd_tree.buildIndex();
2633
2634 std::unordered_set<dof_id_type> primary_nodes_visited;
2635
2636 for (const auto & primary_side_elem : _mesh.active_element_ptr_range())
2637 {
2638 // If this is not one of the lower-dimensional primary side elements, go on to the next one.
2639 if (primary_side_elem->subdomain_id() != lower_dimensional_primary_subdomain_id)
2640 continue;
2641
2642 // For each node on this side, find the nearest node on the secondary side using the KDTree,
2643 // then search in nearby elements for where it projects along the nodal normal direction.
2644 for (MooseIndex(primary_side_elem->n_vertices()) n = 0; n < primary_side_elem->n_vertices();
2645 ++n)
2646 {
2647 // Get a pointer to this node.
2648 const Node * primary_node = primary_side_elem->node_ptr(n);
2649
2650 // Get the nodal neighbors connected to this primary node.
2651 const std::vector<const Elem *> & primary_node_neighbors =
2652 _nodes_to_primary_elem_map.at(primary_node->id());
2653
2654 // Check whether we have already successfully inverse mapped this primary node (whether during
2655 // secondary node projection or now during primary node projection) or we have already failed
2656 // to inverse map this primary node (now during primary node projection), and then skip if
2657 // either of those things is true
2658 auto primary_key =
2659 std::make_tuple(primary_node->id(), primary_node, primary_node_neighbors[0]);
2660 if (!primary_nodes_visited.insert(primary_node->id()).second ||
2662 continue;
2663
2664 // Data structure for performing Nanoflann searches.
2665 Real query_pt[3] = {(*primary_node)(0), (*primary_node)(1), (*primary_node)(2)};
2666
2667 // The number of results we want to get. We'll look for a
2668 // "few" nearest nodes, hopefully that is enough to let us
2669 // figure out which lower-dimensional Elem on the secondary side
2670 // we are across from.
2671 const size_t num_results = 3;
2672
2673 // Initialize result_set and do the search.
2674 std::vector<size_t> ret_index(num_results);
2675 std::vector<Real> out_dist_sqr(num_results);
2676 nanoflann::KNNResultSet<Real> result_set(num_results);
2677 result_set.init(&ret_index[0], &out_dist_sqr[0]);
2678 kd_tree.findNeighbors(result_set, &query_pt[0], nanoflann::SearchParameters());
2679
2680 // If this flag gets set in the loop below, we can break out of the outer r-loop as well.
2681 bool projection_succeeded = false;
2682
2683 // Once we've rejected a candidate for a given
2684 // primary_node, there's no reason to check it
2685 // again.
2686 std::set<const Elem *> rejected_secondary_elem_candidates;
2687
2688 // Loop over the closest nodes, check whether the secondary node successfully projects into
2689 // either of the closest neighbors, stop when the projection succeeds.
2690 for (MooseIndex(result_set) r = 0; r < result_set.size(); ++r)
2691 {
2692 // Verify that the squared distance we compute is the same as nanoflann's
2693 mooseAssert(abs((_mesh.point(ret_index[r]) - *primary_node).norm_sq() - out_dist_sqr[r]) <=
2694 TOLERANCE,
2695 "Lower-dimensional element squared distance verification failed.");
2696
2697 // Get a reference to the vector of lower dimensional elements from the
2698 // nodes_to_secondary_elem_map.
2699 const std::vector<const Elem *> & secondary_elem_candidates =
2700 _nodes_to_secondary_elem_map.at(static_cast<dof_id_type>(ret_index[r]));
2701
2702 // Print the Elems connected to this node on the secondary mesh side.
2703 for (MooseIndex(secondary_elem_candidates) e = 0; e < secondary_elem_candidates.size(); ++e)
2704 {
2705 const Elem * secondary_elem_candidate = secondary_elem_candidates[e];
2706
2707 // If we've already rejected this candidate, we don't need to check it again.
2708 if (rejected_secondary_elem_candidates.count(secondary_elem_candidate))
2709 continue;
2710
2711 std::vector<Point> nodal_normals(secondary_elem_candidate->n_nodes());
2712 for (const auto n : make_range(secondary_elem_candidate->n_nodes()))
2713 nodal_normals[n] =
2714 _secondary_node_to_nodal_normal.at(secondary_elem_candidate->node_ptr(n));
2715
2716 // Use equation 2.4.6 from Bin Yang's dissertation to try and solve for
2717 // the position on the secondary element where this primary came from. This
2718 // requires a Newton iteration in general.
2719 DualNumber<Real> xi1_dn{0, 1}; // initial guess
2720 auto && order = secondary_elem_candidate->default_order();
2721 unsigned int current_iterate = 0, max_iterates = 10;
2722
2723 VectorValue<DualNumber<Real>> normals(0);
2724
2725 // Newton iteration loop - this to converge in 1 iteration when it
2726 // succeeds, and possibly two iterations when it converges to a
2727 // xi outside the reference element. I don't know any reason why it should
2728 // only take 1 iteration -- the Jacobian is not constant in general...
2729 do
2730 {
2731 VectorValue<DualNumber<Real>> x1(0);
2732 for (MooseIndex(secondary_elem_candidate->n_nodes()) n = 0;
2733 n < secondary_elem_candidate->n_nodes();
2734 ++n)
2735 {
2736 const auto phi = Moose::fe_lagrange_1D_shape(order, n, xi1_dn);
2737 x1 += phi * secondary_elem_candidate->point(n);
2738 normals += phi * nodal_normals[n];
2739 }
2740
2741 const auto u = x1 - (*primary_node);
2742
2743 const auto F = u(0) * normals(1) - u(1) * normals(0);
2744
2745 if (abs(F) < _newton_tolerance)
2746 break;
2747
2748 // Unlike for projection of nodal normals onto primary surfaces, we should never have a
2749 // case where the nodal normal is completely orthogonal to the secondary surface, so we
2750 // do not have to guard against F.derivatives() == 0 here
2751 Real dxi1 = -F.value() / F.derivatives();
2752
2753 xi1_dn += dxi1;
2754
2755 normals = 0;
2756 } while (++current_iterate < max_iterates);
2757
2758 Real xi1 = xi1_dn.value();
2759
2760 // Check for convergence to a valid solution... The last condition checks for obliqueness
2761 // of the projection
2762 if ((current_iterate < max_iterates) && (abs(xi1) <= 1. + _xi_tolerance) &&
2763 (abs((primary_side_elem->point(0) - primary_side_elem->point(1)).unit() *
2764 MetaPhysicL::raw_value(normals).unit()) <
2765 std::cos(_minimum_projection_angle * libMesh::pi / 180.0)))
2766 {
2767 if (abs(abs(xi1) - 1.) < _xi_tolerance)
2768 {
2769 // Special case: xi1=+/-1.
2770 // It is unlikely that we get here, because this primary node should already
2771 // have been mapped during the project_secondary_nodes() routine, but
2772 // there is still a chance since the tolerances are applied to
2773 // the xi coordinate and that value may be different on a primary element and a
2774 // secondary element since they may have different sizes. It's also possible that we
2775 // may reach this point if the solve has yielded a non-physical configuration such as
2776 // one block being pushed way out into space
2777 const Node & secondary_node = (xi1 < 0) ? secondary_elem_candidate->node_ref(0)
2778 : secondary_elem_candidate->node_ref(1);
2779 bool created_mortar_segment = false;
2780
2781 // If we have failed to project this secondary node, let's try again now
2782 if (_failed_secondary_node_projections.count(secondary_node.id()))
2783 created_mortar_segment = processAlignedNodes(secondary_node,
2784 *primary_node,
2785 nullptr,
2786 &primary_node_neighbors,
2787 MetaPhysicL::raw_value(normals),
2788 *secondary_elem_candidate,
2789 rejected_secondary_elem_candidates);
2790 else
2791 rejected_secondary_elem_candidates.insert(secondary_elem_candidate);
2792
2793 if (!created_mortar_segment)
2794 // We used to throw an exception in this scope but now that we support processing
2795 // aligned nodes within this primary node projection method, I don't see any harm in
2796 // simply rejecting the secondary element candidate in the case of failure and
2797 // continuing just as we do when projecting secondary nodes
2798 continue;
2799 }
2800 else // somewhere in the middle of the Elem
2801 {
2802 // Add entry to primary_node_and_elem_to_xi1_secondary_elem
2803 //
2804 // Note: we originally duplicated the map values for the keys (node, left_neighbor)
2805 // and (node, right_neighbor) but I don't think that should be necessary. Instead we
2806 // just do it for neighbor 0, but really maybe we don't even need to do that since
2807 // we can always look up the neighbors later given the Node... keeping it like this
2808 // helps to maintain the "symmetry" of the two containers.
2809 const Elem * neigh = primary_node_neighbors[0];
2810 for (MooseIndex(neigh->n_vertices()) nid = 0; nid < neigh->n_vertices(); ++nid)
2811 {
2812 const Node * neigh_node = neigh->node_ptr(nid);
2813 if (primary_node == neigh_node)
2814 {
2815 auto key = std::make_tuple(neigh_node->id(), neigh_node, neigh);
2816 auto val = std::make_pair(xi1, secondary_elem_candidate);
2818 }
2819 }
2820 }
2821
2822 projection_succeeded = true;
2823 break; // out of e-loop
2824 }
2825 else
2826 {
2827 // The current primary_point is not in this Elem, so keep track of the rejects.
2828 rejected_secondary_elem_candidates.insert(secondary_elem_candidate);
2829 }
2830 } // end e-loop over candidate elems
2831
2832 if (projection_succeeded)
2833 break; // out of r-loop
2834 } // r-loop
2835
2836 if (!projection_succeeded && _debug)
2837 {
2838 _console << "\nFailed to find point from which primary node "
2839 << cast_ref<const Point &>(*primary_node) << " was projected." << std::endl
2840 << std::endl;
2841 }
2842 } // loop over side nodes
2843 } // end loop over elements for finding where primary points would have projected from.
2844}
Real _newton_tolerance
Newton solve tolerance for node projections.
bool processAlignedNodes(const Node &secondary_node, const Node &primary_node, const std::vector< const Elem * > *secondary_node_neighbors, const std::vector< const Elem * > *primary_node_neighbors, const VectorValue< Real > &nodal_normal, const Elem &candidate_element, std::set< const Elem * > &rejected_element_candidates)
Process aligned nodes.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.

Referenced by projectPrimaryNodes().

◆ projectSecondaryNodes()

void AutomaticMortarGeneration::projectSecondaryNodes ( )

Project secondary nodes (find xi^(2) values) to the closest points on the primary surface.

Inputs:

  • The nodal normals values
  • mesh
  • nodes_to_primary_elem_map

Outputs:

  • secondary_node_and_elem_to_xi2_primary_elem

Defined in the file project_secondary_nodes.C.

Definition at line 2241 of file AutomaticMortarGeneration.C.

2242{
2243 // For each primary/secondary boundary id pair, call the
2244 // project_secondary_nodes_single_pair() helper function.
2245 for (const auto & pr : _primary_secondary_subdomain_id_pairs)
2246 projectSecondaryNodesSinglePair(pr.first, pr.second);
2247}
void projectSecondaryNodesSinglePair(SubdomainID lower_dimensional_primary_subdomain_id, SubdomainID lower_dimensional_secondary_subdomain_id)
Helper function responsible for projecting secondary nodes onto primary elements for a single primary...

Referenced by MortarInterfaceWarehouse::update().

◆ projectSecondaryNodesSinglePair()

void AutomaticMortarGeneration::projectSecondaryNodesSinglePair ( SubdomainID  lower_dimensional_primary_subdomain_id,
SubdomainID  lower_dimensional_secondary_subdomain_id 
)
private

Helper function responsible for projecting secondary nodes onto primary elements for a single primary/secondary pair.

Called by the class member AutomaticMortarGeneration::project_secondary_nodes().

Definition at line 2366 of file AutomaticMortarGeneration.C.

2369{
2370 using std::abs;
2371
2372 // Build the "subdomain" adaptor based KD Tree.
2373 NanoflannMeshSubdomainAdaptor<3> mesh_adaptor(_mesh, lower_dimensional_primary_subdomain_id);
2374 subdomain_kd_tree_t kd_tree(
2375 3, mesh_adaptor, nanoflann::KDTreeSingleIndexAdaptorParams(/*max leaf=*/10));
2376
2377 // Construct the KD tree.
2378 kd_tree.buildIndex();
2379
2380 for (MeshBase::const_element_iterator el = _mesh.active_elements_begin(),
2381 end_el = _mesh.active_elements_end();
2382 el != end_el;
2383 ++el)
2384 {
2385 const Elem * secondary_side_elem = *el;
2386
2387 // If this Elem is not in the current secondary subdomain, go on to the next one.
2388 if (secondary_side_elem->subdomain_id() != lower_dimensional_secondary_subdomain_id)
2389 continue;
2390
2391 // For each node on the lower-dimensional element, find the nearest
2392 // node on the primary side using the KDTree, then
2393 // search in nearby elements for where it projects
2394 // along the nodal normal direction.
2395 for (MooseIndex(secondary_side_elem->n_vertices()) n = 0; n < secondary_side_elem->n_vertices();
2396 ++n)
2397 {
2398 const Node * secondary_node = secondary_side_elem->node_ptr(n);
2399
2400 // Get the nodal neighbors for secondary_node, so we can check whether we've
2401 // already successfully projected it.
2402 const std::vector<const Elem *> & secondary_node_neighbors =
2403 this->_nodes_to_secondary_elem_map.at(secondary_node->id());
2404
2405 // Check whether we've already mapped this secondary node
2406 // successfully for all of its nodal neighbors.
2407 bool is_mapped = true;
2408 for (MooseIndex(secondary_node_neighbors) snn = 0; snn < secondary_node_neighbors.size();
2409 ++snn)
2410 {
2411 auto secondary_key = std::make_pair(secondary_node, secondary_node_neighbors[snn]);
2412 if (!_secondary_node_and_elem_to_xi2_primary_elem.count(secondary_key))
2413 {
2414 is_mapped = false;
2415 break;
2416 }
2417 }
2418
2419 // Go to the next node if this one has already been mapped.
2420 if (is_mapped)
2421 continue;
2422
2423 // Look up the new nodal normal value in the local storage, error if not found.
2424 Point nodal_normal = _secondary_node_to_nodal_normal.at(secondary_node);
2425
2426 // Data structure for performing Nanoflann searches.
2427 std::array<Real, 3> query_pt = {
2428 {(*secondary_node)(0), (*secondary_node)(1), (*secondary_node)(2)}};
2429
2430 // The number of results we want to get. We'll look for a
2431 // "few" nearest nodes, hopefully that is enough to let us
2432 // figure out which lower-dimensional Elem on the primary
2433 // side we are across from.
2434 const std::size_t num_results = 3;
2435
2436 // Initialize result_set and do the search.
2437 std::vector<size_t> ret_index(num_results);
2438 std::vector<Real> out_dist_sqr(num_results);
2439 nanoflann::KNNResultSet<Real> result_set(num_results);
2440 result_set.init(&ret_index[0], &out_dist_sqr[0]);
2441 kd_tree.findNeighbors(result_set, &query_pt[0], nanoflann::SearchParameters());
2442
2443 // If this flag gets set in the loop below, we can break out of the outer r-loop as well.
2444 bool projection_succeeded = false;
2445
2446 // Once we've rejected a candidate for a given secondary_node,
2447 // there's no reason to check it again.
2448 std::set<const Elem *> rejected_primary_elem_candidates;
2449
2450 // Loop over the closest nodes, check whether
2451 // the secondary node successfully projects into
2452 // either of the closest neighbors, stop when
2453 // the projection succeeds.
2454 for (MooseIndex(result_set) r = 0; r < result_set.size(); ++r)
2455 {
2456 // Verify that the squared distance we compute is the same as nanoflann'sFss
2457 mooseAssert(abs((_mesh.point(ret_index[r]) - *secondary_node).norm_sq() -
2458 out_dist_sqr[r]) <= TOLERANCE,
2459 "Lower-dimensional element squared distance verification failed.");
2460
2461 // Get a reference to the vector of lower dimensional elements from the
2462 // nodes_to_primary_elem_map.
2463 std::vector<const Elem *> & primary_elem_candidates =
2464 this->_nodes_to_primary_elem_map.at(static_cast<dof_id_type>(ret_index[r]));
2465
2466 // Search the Elems connected to this node on the primary mesh side.
2467 for (MooseIndex(primary_elem_candidates) e = 0; e < primary_elem_candidates.size(); ++e)
2468 {
2469 const Elem * primary_elem_candidate = primary_elem_candidates[e];
2470
2471 // If we've already rejected this candidate, we don't need to check it again.
2472 if (rejected_primary_elem_candidates.count(primary_elem_candidate))
2473 continue;
2474
2475 // Now generically solve for xi2
2476 const auto order = primary_elem_candidate->default_order();
2477 DualNumber<Real> xi2_dn{0, 1};
2478 unsigned int current_iterate = 0, max_iterates = 10;
2479
2480 // Newton loop
2481 do
2482 {
2483 VectorValue<DualNumber<Real>> x2(0);
2484 for (MooseIndex(primary_elem_candidate->n_nodes()) n = 0;
2485 n < primary_elem_candidate->n_nodes();
2486 ++n)
2487 x2 +=
2488 Moose::fe_lagrange_1D_shape(order, n, xi2_dn) * primary_elem_candidate->point(n);
2489 const auto u = x2 - (*secondary_node);
2490 const auto F = u(0) * nodal_normal(1) - u(1) * nodal_normal(0);
2491
2492 if (abs(F) < _newton_tolerance)
2493 break;
2494
2495 if (F.derivatives())
2496 {
2497 Real dxi2 = -F.value() / F.derivatives();
2498
2499 xi2_dn += dxi2;
2500 }
2501 else
2502 // It's possible that the secondary surface nodal normal is completely orthogonal to
2503 // the primary surface normal, in which case the derivative is 0. We know in this case
2504 // that the projection should be a failure
2505 current_iterate = max_iterates;
2506 } while (++current_iterate < max_iterates);
2507
2508 Real xi2 = xi2_dn.value();
2509
2510 // Check whether the projection worked. The last condition checks for obliqueness of the
2511 // projection
2512 //
2513 // We are projecting on one side first and the other side second. If we make the
2514 // tolerance bigger and remove the (5) factor we are going to continue to miss the
2515 // second projection and fall into the exception message in
2516 // projectPrimaryNodesSinglePair. What makes this modification to not fall in the
2517 // exception is that we are projecting on one side more xi than in the other. There
2518 // should be a better way of doing this by using actual distances and not parametric
2519 // coordinates. But I believe making the tolerance uniformly larger or smaller won't do
2520 // the trick here.
2521 if ((current_iterate < max_iterates) && (std::abs(xi2) <= 1. + 5 * _xi_tolerance) &&
2522 (abs((primary_elem_candidate->point(0) - primary_elem_candidate->point(1)).unit() *
2523 nodal_normal) < std::cos(_minimum_projection_angle * libMesh::pi / 180)))
2524 {
2525 // If xi2 == +1 or -1 then this secondary node mapped directly to a node on the primary
2526 // surface. This isn't as unlikely as you might think, it will happen if the meshes
2527 // on the interface start off being perfectly aligned. In this situation, we need to
2528 // associate the secondary node with two different elements (and two corresponding
2529 // xi^(2) values.
2530 if (abs(abs(xi2) - 1.) <= _xi_tolerance * 5.0)
2531 {
2532 const Node * primary_node = (xi2 < 0) ? primary_elem_candidate->node_ptr(0)
2533 : primary_elem_candidate->node_ptr(1);
2534 const bool created_mortar_segment =
2535 processAlignedNodes(*secondary_node,
2536 *primary_node,
2537 &secondary_node_neighbors,
2538 nullptr,
2539 nodal_normal,
2540 *primary_elem_candidate,
2541 rejected_primary_elem_candidates);
2542
2543 if (!created_mortar_segment)
2544 continue;
2545 }
2546 else // Point falls somewhere in the middle of the Elem.
2547 {
2548 // Add two entries to secondary_node_and_elem_to_xi2_primary_elem.
2549 for (MooseIndex(secondary_node_neighbors) nn = 0;
2550 nn < secondary_node_neighbors.size();
2551 ++nn)
2552 {
2553 const Elem * neigh = secondary_node_neighbors[nn];
2554 for (MooseIndex(neigh->n_vertices()) nid = 0; nid < neigh->n_vertices(); ++nid)
2555 {
2556 const Node * neigh_node = neigh->node_ptr(nid);
2557 if (secondary_node == neigh_node)
2558 {
2559 auto key = std::make_pair(neigh_node, neigh);
2560 auto val = std::make_pair(xi2, primary_elem_candidate);
2562 }
2563 }
2564 }
2565 }
2566
2567 projection_succeeded = true;
2568 break; // out of e-loop
2569 }
2570 else
2571 // The current secondary_node is not in this Elem, so keep track of the rejects.
2572 rejected_primary_elem_candidates.insert(primary_elem_candidate);
2573 }
2574
2575 if (projection_succeeded)
2576 break; // out of r-loop
2577 } // r-loop
2578
2579 if (!projection_succeeded)
2580 {
2581 _failed_secondary_node_projections.insert(secondary_node->id());
2582 if (_debug)
2583 _console << "Failed to find primary Elem into which secondary node "
2584 << cast_ref<const Point &>(*secondary_node) << ", id '" << secondary_node->id()
2585 << "', projects onto\n"
2586 << std::endl;
2587 }
2588 else if (_debug)
2589 _projected_secondary_nodes.insert(secondary_node->id());
2590 } // loop over side nodes
2591 } // end loop over lower-dimensional elements
2592
2593 if (_distributed)
2594 {
2595 if (_debug)
2596 _mesh.comm().set_union(_projected_secondary_nodes);
2597 _mesh.comm().set_union(_failed_secondary_node_projections);
2598 }
2599
2600 if (_debug)
2601 _console << "\n"
2602 << _projected_secondary_nodes.size() << " out of "
2604 << " secondary nodes were successfully projected\n"
2605 << std::endl;
2606}

Referenced by projectSecondaryNodes().

◆ requestNonlocalSecondaryCouplings()

void AutomaticMortarGeneration::requestNonlocalSecondaryCouplings ( )
inline

Request that every process receive the mortar interface couplings of the nonlocal secondary lower-dimensional elements that point-neighbor ghosting reads for its local elements: the point neighbors of its local secondary elements and of the secondary elements coupled to its local elements.

Consumers that apply a node's constraint on every process contributing to it, rather than only on the node's owner, need these couplings to preallocate the rows of their local elements.

Definition at line 401 of file AutomaticMortarGeneration.h.

◆ secondariesToMortarSegments() [1/2]

const std::unordered_map< dof_id_type, std::set< Elem *, CompareDofObjectsByID > > & AutomaticMortarGeneration::secondariesToMortarSegments ( ) const
inline
Returns
the lower dimensional secondary element ids and their associated mortar segment elements

Definition at line 464 of file AutomaticMortarGeneration.h.

465 {
467 }

◆ secondariesToMortarSegments() [2/2]

std::vector< AutomaticMortarGeneration::MortarFilterIter > AutomaticMortarGeneration::secondariesToMortarSegments ( const Node &  node) const
Returns
A vector of iterators that point to the lower dimensional secondary elements and their associated mortar segment elements that would have nonzero values for a Lagrange shape function associated with the provided node. This method may return an empty container if the node is away from the mortar mesh

Definition at line 2847 of file AutomaticMortarGeneration.C.

2848{
2849 auto secondary_it = _nodes_to_secondary_elem_map.find(node.id());
2850 if (secondary_it == _nodes_to_secondary_elem_map.end())
2851 return {};
2852
2853 const auto & secondary_elems = secondary_it->second;
2854 std::vector<MortarFilterIter> ret;
2855 ret.reserve(secondary_elems.size());
2856
2857 for (const auto i : index_range(secondary_elems))
2858 {
2859 auto * const secondary_elem = secondary_elems[i];
2860 auto msm_it = _secondary_elems_to_mortar_segments.find(secondary_elem->id());
2861 if (msm_it == _secondary_elems_to_mortar_segments.end())
2862 // We may have removed this element key from this map
2863 continue;
2864
2865 mooseAssert(secondary_elem->active(),
2866 "We loop over active elements when building the mortar segment mesh, so we golly "
2867 "well hope this is active.");
2868 mooseAssert(!msm_it->second.empty(),
2869 "We should have removed all secondaries from this map if they do not have any "
2870 "mortar segments associated with them.");
2871 ret.push_back(msm_it);
2872 }
2873
2874 return ret;
2875}

Referenced by MortarUserObjectThread::operator()(), and ComputeMortarFunctor::operator()().

◆ secondaryIPSubIDs()

const std::set< SubdomainID > & AutomaticMortarGeneration::secondaryIPSubIDs ( ) const
inline
Returns
All the secondary interior parent subdomain IDs associated with the mortar mesh

Definition at line 472 of file AutomaticMortarGeneration.h.

472{ return _secondary_ip_sub_ids; }

Referenced by Moose::Mortar::setupMortarMaterials(), and MortarInterfaceWarehouse::update().

Friends And Related Symbol Documentation

◆ AugmentSparsityOnInterface

friend class AugmentSparsityOnInterface
friend

Definition at line 710 of file AutomaticMortarGeneration.h.

◆ MortarNodalGeometryOutput

friend class MortarNodalGeometryOutput
friend

Definition at line 709 of file AutomaticMortarGeneration.h.

Member Data Documentation

◆ _app

MooseApp& AutomaticMortarGeneration::_app
private

The Moose app.

Definition at line 511 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh(), initOutput(), and outputMortarMesh().

◆ _console

const ConsoleStream ConsoleStreamInterface::_console
inherited

An instance of helper class to write streams to the Console objects.

Definition at line 31 of file ConsoleStreamInterface.h.

Referenced by IterationAdaptiveDT::acceptStep(), MaterialOutputAction::act(), MeshOnlyAction::act(), SetupDebugAction::act(), FEProblemBase::adaptMesh(), Adaptivity::adaptMesh(), PerfGraph::addToExecutionList(), SimplePredictor::apply(), SystemBase::applyScalingFactors(), MultiApp::backup(), FEProblemBase::backupMultiApps(), CoarsenedPiecewiseLinear::buildCoarsenedGrid(), DefaultSteadyStateConvergence::checkConvergence(), MeshDiagnosticsGenerator::checkElementOverlap(), MeshDiagnosticsGenerator::checkElementTypes(), MeshDiagnosticsGenerator::checkElementVolumes(), FEProblemBase::checkExceptionAndStopSolve(), SolverSystem::checkInvalidSolution(), MeshDiagnosticsGenerator::checkLocalJacobians(), MeshDiagnosticsGenerator::checkNonConformalMesh(), MeshDiagnosticsGenerator::checkNonConformalMeshFromAdaptivity(), MeshDiagnosticsGenerator::checkNonConformingFaces(), MeshDiagnosticsGenerator::checkNonMatchingEdges(), MeshDiagnosticsGenerator::checkNonPlanarSides(), MeshDiagnosticsGenerator::checkPolygons(), FEProblemBase::checkProblemIntegrity(), ReferenceResidualConvergence::checkResidualConvergence(), MeshDiagnosticsGenerator::checkSidesetsOrientation(), MeshDiagnosticsGenerator::checkWatertightNodesets(), MeshDiagnosticsGenerator::checkWatertightSidesets(), CoarsenSurfaceMeshAlongSidesetGenerator::coarsenAlongSidesets(), IterationAdaptiveDT::computeAdaptiveDT(), TransientBase::computeConstrainedDT(), DefaultMultiAppFixedPointConvergence::computeCustomConvergencePostprocessor(), NonlinearSystemBase::computeDamping(), FixedPointIterationAdaptiveDT::computeDT(), IterationAdaptiveDT::computeDT(), IterationAdaptiveDT::computeFailedDT(), IterationAdaptiveDT::computeInitialDT(), IterationAdaptiveDT::computeInterpolationDT(), FEProblemBase::computeLinearSystemTags(), LinearSystem::computeLinearSystemTags(), NonlinearSystemBase::computeScaling(), Problem::console(), TimeStepper::constrainStep(), IterationAdaptiveDT::constrainStep(), MultiApp::createApp(), FEProblemBase::execMultiApps(), FEProblemBase::execMultiAppTransfers(), Eigenvalue::execute(), SteadyBase::execute(), MFEMSteady::execute(), MessageFromInput::execute(), ActionWarehouse::executeActionsWithAction(), ActionWarehouse::executeAllActions(), MeshGeneratorSystem::executeMeshGenerators(), SidesetAroundSubdomainUpdater::finalize(), ElementQualityChecker::finalize(), FEProblemBase::finishMultiAppStep(), MeshRepairGenerator::fixOverlappingNodes(), SurfaceSubdomainsDelaunayRemesher::General2DDelaunay(), CoarsenBlockGenerator::generate(), CoarsenSurfaceMeshAlongSidesetGenerator::generate(), OrientSurfaceMeshGenerator::generate(), PolyLineMeshFollowingNodeSetGenerator::generate(), StitchMeshGenerator::generate(), MeshGenerator::generateInternal(), VariableCondensationPreconditioner::getDofToCondense(), InversePowerMethod::init(), NonlinearEigen::init(), FEProblemBase::initialAdaptMesh(), SubProblem::initialSetup(), EigenExecutionerBase::inversePowerIteration(), FEProblemBase::joinAndFinalize(), TransientBase::keepGoing(), IterationAdaptiveDT::limitDTByFunction(), IterationAdaptiveDT::limitDTToPostprocessorValue(), FEProblemBase::logAdd(), EigenExecutionerBase::makeBXConsistent(), Console::meshChanged(), SurfaceDelaunayGeneratorBase::meshNormalDeviation2D(), MooseBase::mooseDeprecated(), MooseBase::mooseDeprecatedNoTrace(), MooseBase::mooseInfo(), MooseBase::mooseWarning(), MooseBase::mooseWarningNonPrefixed(), NEML2Action::NEML2Action(), ReferenceResidualConvergence::nonlinearConvergenceSetup(), Console::output(), DOFMapOutput::output(), MaterialPropertyDebugOutput::output(), PerfGraphOutput::output(), ReporterDebugOutput::output(), SolutionInvalidityOutput::output(), VariableResidualNormsDebugOutput::output(), ControlOutput::outputActiveObjects(), ControlOutput::outputChangedControls(), ControlOutput::outputControls(), Console::outputInput(), WebServerControl::outputMessage(), Console::outputPostprocessors(), PseudoTimestep::outputPseudoTimestep(), Console::outputReporters(), DefaultMultiAppFixedPointConvergence::outputResidualNorm(), Console::outputScalarVariables(), Console::outputSystemInformation(), MooseBase::paramInfo(), FEProblemBase::possiblyRebuildGeomSearchPatches(), EigenExecutionerBase::postExecute(), AB2PredictorCorrector::postSolve(), DefaultMultiAppFixedPointConvergence::preLoop(), ActionWarehouse::printActionDependencySets(), BlockRestrictionDebugOutput::printBlockRestrictionGroups(), BlockRestrictionDebugOutput::printBlockRestrictionMap(), BlockRestrictionDebugOutput::printBoundaryRestrictionGroups(), SolutionInvalidity::printDebug(), EigenExecutionerBase::printEigenvalue(), PicardSolve::printFixedPointConvergenceHistory(), SecantSolve::printFixedPointConvergenceHistory(), SteffensenSolve::printFixedPointConvergenceHistory(), FixedPointSolve::printFixedPointConvergenceReason(), PerfGraphLivePrint::printLiveMessage(), MaterialPropertyDebugOutput::printMaterialMap(), PerfGraphLivePrint::printStats(), NEML2Action::printSummary(), projectPrimaryNodesSinglePair(), projectSecondaryNodesSinglePair(), CoarsenBlockGenerator::recursiveCoarsen(), SolutionTimeAdaptiveDT::rejectStep(), MultiApp::restore(), FEProblemBase::restoreMultiApps(), FEProblemBase::restoreSolutions(), NonlinearSystemBase::setInitialSolution(), MooseApp::setupOptions(), Checkpoint::shouldOutput(), SubProblem::showFunctorRequestors(), SubProblem::showFunctors(), FullSolveMultiApp::showStatusMessage(), FEProblemSolve::solve(), FixedPointSolve::solve(), LinearSystem::solve(), NonlinearSystem::solve(), AStableDirk4::solve(), ExplicitRK2::solve(), ExplicitTVDRK2::solve(), ImplicitMidpoint::solve(), LStableDirk2::solve(), LStableDirk3::solve(), LStableDirk4::solve(), EigenProblem::solve(), FixedPointSolve::solveStep(), TransientMultiApp::solveStep(), MeshRepairGenerator::splitNonConvexPolygons(), PerfGraphLivePrint::start(), WebServerControl::startServer(), AB2PredictorCorrector::step(), NonlinearEigen::takeStep(), TransientBase::takeStep(), MFEMTransient::takeStep(), TerminateChainControl::terminate(), SubProblem::timestepSetup(), FEProblemBase::updateMeshXFEM(), Convergence::verboseOutput(), Console::writeTimestepInformation(), Console::writeVariableNorms(), and FEProblemBase::~FEProblemBase().

◆ _correct_edge_dropping

const bool AutomaticMortarGeneration::_correct_edge_dropping
private

Flag to enable regressed treatment of edge dropping where all LM DoFs on edge dropping element are strongly set to 0.

Definition at line 671 of file AutomaticMortarGeneration.h.

Referenced by computeInactiveLMElems(), computeInactiveLMNodes(), and incorrectEdgeDropping().

◆ _debug

const bool AutomaticMortarGeneration::_debug
private

◆ _distributed

const bool AutomaticMortarGeneration::_distributed
private

Whether the mortar segment mesh is distributed.

Definition at line 655 of file AutomaticMortarGeneration.h.

Referenced by AutomaticMortarGeneration(), and projectSecondaryNodesSinglePair().

◆ _failed_secondary_node_projections

std::unordered_set<dof_id_type> AutomaticMortarGeneration::_failed_secondary_node_projections
private

Secondary nodes that failed to project.

Definition at line 707 of file AutomaticMortarGeneration.h.

Referenced by clear(), projectPrimaryNodesSinglePair(), and projectSecondaryNodesSinglePair().

◆ _inactive_local_lm_elems

std::unordered_set<const Elem *> AutomaticMortarGeneration::_inactive_local_lm_elems
private

List of inactive lagrange multiplier nodes (for elemental variables)

Definition at line 604 of file AutomaticMortarGeneration.h.

Referenced by computeInactiveLMElems(), and getInactiveLMElems().

◆ _inactive_local_lm_nodes

std::unordered_set<const Node *> AutomaticMortarGeneration::_inactive_local_lm_nodes
private

List of inactive lagrange multiplier nodes owned by this processor (for nodal variables)

Definition at line 601 of file AutomaticMortarGeneration.h.

Referenced by computeInactiveLMNodes(), computeIncorrectEdgeDroppingInactiveLMNodes(), and getInactiveLMNodes().

◆ _lower_elem_to_side_id

std::unordered_map<const Elem *, unsigned int> AutomaticMortarGeneration::_lower_elem_to_side_id
private

Keeps track of the mapping between lower-dimensional elements and the side_id of the interior_parent which they are.

Definition at line 569 of file AutomaticMortarGeneration.h.

Referenced by clear().

◆ _mesh

MeshBase& AutomaticMortarGeneration::_mesh
private

◆ _minimum_projection_angle

const Real AutomaticMortarGeneration::_minimum_projection_angle
private

Parameter to control which angle (in degrees) is admissible for the creation of mortar segments.

If set to a value close to zero, very oblique projections are allowed, which can result in mortar segments solving physics not meaningfully and overprojection of primary nodes onto the mortar segment mesh in extreme cases. This parameter is mostly intended for mortar mesh debugging purposes in 2D.

Definition at line 677 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh3d(), projectPrimaryNodesSinglePair(), and projectSecondaryNodesSinglePair().

◆ _mortar_3d_qp_mapping

const Mortar3DQuadraturePointMapping AutomaticMortarGeneration::_mortar_3d_qp_mapping
private

Method used to map 3D mortar segment quadrature points to primary and secondary faces.

Definition at line 689 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh3d(), mortar3DQpMapping(), and mortarSegmentReferencePoints().

◆ _mortar_3d_subpatch_plane

const Mortar3DSubpatchPlane AutomaticMortarGeneration::_mortar_3d_subpatch_plane
private

Method used to define the local projection planes for 3D secondary subpatches.

Definition at line 680 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh3d().

◆ _mortar_interface_coupling

std::unordered_map<dof_id_type, std::unordered_set<dof_id_type> > AutomaticMortarGeneration::_mortar_interface_coupling
private

Used by the AugmentSparsityOnInterface functor to determine whether a given Elem is coupled to any others across the gap, and to explicitly set up the dependence between interior_parent() elements on the secondary side and their lower-dimensional sides which are on the interface.

This latter type of coupling must be explicitly declared when there is no primary_elem for a given mortar segment and you are using e.g. a P^1-P^0 discretization which does not induce the coupling automatically.

Definition at line 588 of file AutomaticMortarGeneration.h.

Referenced by buildCouplingInformation(), clear(), and mortarInterfaceCoupling().

◆ _mortar_segment_mesh

std::unique_ptr<MeshBase> AutomaticMortarGeneration::_mortar_segment_mesh
private

1D Mesh of mortar segment elements which gets built by the call to build_mortar_segment_mesh().

Definition at line 560 of file AutomaticMortarGeneration.h.

Referenced by AutomaticMortarGeneration(), buildMortarSegmentMesh(), buildMortarSegmentMesh3d(), clear(), computeInactiveLMElems(), computeInactiveLMNodes(), computeIncorrectEdgeDroppingInactiveLMNodes(), mortarSegmentMesh(), and outputMortarMesh().

◆ _msm_elem_to_info

std::unordered_map<const Elem *, MortarSegmentInfo> AutomaticMortarGeneration::_msm_elem_to_info
private

Map between Elems in the mortar segment mesh and their info structs.

This gets filled in by the call to build_mortar_segment_mesh().

Definition at line 565 of file AutomaticMortarGeneration.h.

Referenced by buildCouplingInformation(), buildMortarSegmentMesh(), buildMortarSegmentMesh3d(), clear(), computeInactiveLMElems(), computeInactiveLMNodes(), computeIncorrectEdgeDroppingInactiveLMNodes(), computeMsmStatistics(), and mortarSegmentMeshElemToInfo().

◆ _msm_elem_to_reference_points

std::unordered_map<const Elem *, MortarSegmentReferencePoints> AutomaticMortarGeneration::_msm_elem_to_reference_points
private

Reference-coordinate data used only by the reference-interpolation mapping mode.

Definition at line 692 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh3d(), clear(), and mortarSegmentReferencePoints().

◆ _msm_node_id_start

std::optional<dof_id_type> AutomaticMortarGeneration::_msm_node_id_start
private

Cached per-rank starting ID for 3D MSM nodes/elements.

nullopt forces recomputation on next buildMortarSegmentMesh3d() call. Reset by meshChanged() on topology change so the allgather is skipped for displaced-mesh residual updates that only move nodes.

Definition at line 700 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh3d(), and meshChanged().

◆ _newton_tolerance

Real AutomaticMortarGeneration::_newton_tolerance = 1e-12
private

Newton solve tolerance for node projections.

Definition at line 662 of file AutomaticMortarGeneration.h.

Referenced by projectPrimaryNodesSinglePair(), and projectSecondaryNodesSinglePair().

◆ _nodes_to_primary_elem_map

std::unordered_map<dof_id_type, std::vector<const Elem *> > AutomaticMortarGeneration::_nodes_to_primary_elem_map
private

◆ _nodes_to_secondary_elem_map

std::unordered_map<dof_id_type, std::vector<const Elem *> > AutomaticMortarGeneration::_nodes_to_secondary_elem_map
private

Map from nodes to connected lower-dimensional elements on the secondary/primary subdomains.

Definition at line 527 of file AutomaticMortarGeneration.h.

Referenced by buildNodeToElemMaps(), clear(), nodesToSecondaryElem(), processAlignedNodes(), projectPrimaryNodesSinglePair(), projectSecondaryNodesSinglePair(), and secondariesToMortarSegments().

◆ _nonlocal_secondary_couplings

bool AutomaticMortarGeneration::_nonlocal_secondary_couplings = false
private

Whether buildCouplingInformation() also gathers the couplings of nonlocal secondary lower-dimensional elements.

Definition at line 659 of file AutomaticMortarGeneration.h.

Referenced by buildCouplingInformation(), and requestNonlocalSecondaryCouplings().

◆ _on_displaced

const bool AutomaticMortarGeneration::_on_displaced
private

Whether this object is on the displaced mesh.

Definition at line 649 of file AutomaticMortarGeneration.h.

Referenced by mortarInterfaceName(), onDisplaced(), and MortarNodalGeometryOutput::output().

◆ _output_params

std::unique_ptr<InputParameters> AutomaticMortarGeneration::_output_params
private

Storage for the input parameters used by the mortar nodal geometry output.

Definition at line 695 of file AutomaticMortarGeneration.h.

Referenced by initOutput().

◆ _periodic

const bool AutomaticMortarGeneration::_periodic
private

Whether this object will be generating a mortar segment mesh for periodic constraints.

Definition at line 652 of file AutomaticMortarGeneration.h.

Referenced by computeADNodalNormals(), computeNodalGeometry(), and getNormals().

◆ _primary_boundary_subdomain_ids

std::set<SubdomainID> AutomaticMortarGeneration::_primary_boundary_subdomain_ids
private

Definition at line 578 of file AutomaticMortarGeneration.h.

Referenced by AutomaticMortarGeneration(), and buildNodeToElemMaps().

◆ _primary_internal_sub_ids

std::set<SubdomainID> AutomaticMortarGeneration::_primary_internal_sub_ids
private

All the subdomain IDs of the primary interior associated with the mortar mesh (see primaryInternalSubIDs())

Definition at line 617 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh(), buildMortarSegmentMesh3d(), clear(), and primaryInternalSubIDs().

◆ _primary_node_and_elem_to_xi1_secondary_elem

std::map<std::tuple<dof_id_type, const Node *, const Elem *>, std::pair<Real, const Elem *> > AutomaticMortarGeneration::_primary_node_and_elem_to_xi1_secondary_elem
private

Same type of container, but for mapping (Primary Node ID, Primary Node, Primary Elem) -> (xi^(1), Secondary Elem) where they are inverse-projected along the nodal normal direction.

Note that the first item of the key, the primary node ID, is important for storing the key-value pairs in a consistent order across processes, e.g. this container has to be ordered!

Definition at line 556 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh(), clear(), processAlignedNodes(), and projectPrimaryNodesSinglePair().

◆ _primary_requested_boundary_ids

std::set<BoundaryID> AutomaticMortarGeneration::_primary_requested_boundary_ids
private

The boundary ids corresponding to all the primary surfaces.

Definition at line 520 of file AutomaticMortarGeneration.h.

Referenced by AutomaticMortarGeneration(), and buildNodeToElemMaps().

◆ _primary_secondary_boundary_id_pairs

std::vector<std::pair<BoundaryID, BoundaryID> > AutomaticMortarGeneration::_primary_secondary_boundary_id_pairs
private

A list of primary/secondary boundary id pairs corresponding to each side of the mortar interface.

Definition at line 524 of file AutomaticMortarGeneration.h.

Referenced by AutomaticMortarGeneration(), buildMortarSegmentMesh(), mortarInterfaceName(), and primarySecondaryBoundaryIDPair().

◆ _primary_secondary_subdomain_id_pairs

std::vector<std::pair<SubdomainID, SubdomainID> > AutomaticMortarGeneration::_primary_secondary_subdomain_id_pairs
private

A list of primary/secondary subdomain id pairs corresponding to each side of the mortar interface.

Definition at line 573 of file AutomaticMortarGeneration.h.

Referenced by AutomaticMortarGeneration(), buildMortarSegmentMesh3d(), computeInactiveLMElems(), computeInactiveLMNodes(), computeIncorrectEdgeDroppingInactiveLMNodes(), computeMsmStatistics(), projectPrimaryNodes(), and projectSecondaryNodes().

◆ _projected_secondary_nodes

std::unordered_set<dof_id_type> AutomaticMortarGeneration::_projected_secondary_nodes
private

Debugging container for printing information about fraction of successful projections for secondary nodes.

If !_debug then this should always be empty

Definition at line 704 of file AutomaticMortarGeneration.h.

Referenced by clear(), and projectSecondaryNodesSinglePair().

◆ _secondary_boundary_subdomain_ids

std::set<SubdomainID> AutomaticMortarGeneration::_secondary_boundary_subdomain_ids
private

The secondary/primary lower-dimensional boundary subdomain ids are the secondary/primary boundary ids.

Definition at line 577 of file AutomaticMortarGeneration.h.

Referenced by AutomaticMortarGeneration(), buildCouplingInformation(), buildMortarSegmentMesh(), buildNodeToElemMaps(), computeADNodalNormals(), and computeNodalGeometry().

◆ _secondary_element_to_secondary_lowerd_element

std::unordered_map<dof_id_type, const Elem *> AutomaticMortarGeneration::_secondary_element_to_secondary_lowerd_element
private

Map from full dimensional secondary element id to lower dimensional secondary element.

Definition at line 598 of file AutomaticMortarGeneration.h.

Referenced by clear(), computeNodalGeometry(), and getSecondaryLowerdElemFromSecondaryElem().

◆ _secondary_elems_to_mortar_segments

std::unordered_map<dof_id_type, std::set<Elem *, CompareDofObjectsByID> > AutomaticMortarGeneration::_secondary_elems_to_mortar_segments
private

We maintain a mapping from lower-dimensional secondary elements in the original mesh to (sets of) elements in mortar_segment_mesh.

This allows us to quickly determine which elements need to be split.

Definition at line 610 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh(), buildMortarSegmentMesh3d(), clear(), computeMsmStatistics(), secondariesToMortarSegments(), and secondariesToMortarSegments().

◆ _secondary_ip_sub_ids

std::set<SubdomainID> AutomaticMortarGeneration::_secondary_ip_sub_ids
private

All the secondary interior parent subdomain IDs associated with the mortar mesh.

Definition at line 613 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh(), buildMortarSegmentMesh3d(), clear(), and secondaryIPSubIDs().

◆ _secondary_node_and_elem_to_xi2_primary_elem

std::unordered_map<std::pair<const Node *, const Elem *>, std::pair<Real, const Elem *> > AutomaticMortarGeneration::_secondary_node_and_elem_to_xi2_primary_elem
private

Similar to the map above, but associates a (Secondary Node, Secondary Elem) pair to a (xi^(2), primary Elem) pair.

This allows a single secondary node, which is potentially connected to two elements on the secondary side, to be associated with multiple primary Elem/xi^(2) values to handle the case where the primary and secondary nodes are "matching". In this configuration:

A B o--—o--—o (secondary orientation ->) | v ---—x---— (primary orientation <-) C D

The entries in the map should be: (Elem A, Node 1) -> (Elem C, xi^(2)=-1) (Elem B, Node 0) -> (Elem D, xi^(2)=+1)

Definition at line 548 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh(), clear(), processAlignedNodes(), and projectSecondaryNodesSinglePair().

◆ _secondary_node_to_hh_nodal_tangents

std::unordered_map<const Node *, std::array<Point, 2> > AutomaticMortarGeneration::_secondary_node_to_hh_nodal_tangents
private

Container for storing the nodal tangent/binormal vectors associated with each secondary node (Householder approach).

Definition at line 595 of file AutomaticMortarGeneration.h.

Referenced by clear(), computeNodalGeometry(), getNodalTangents(), and MortarNodalGeometryOutput::output().

◆ _secondary_node_to_nodal_normal

std::unordered_map<const Node *, Point> AutomaticMortarGeneration::_secondary_node_to_nodal_normal
private

Container for storing the nodal normal vector associated with each secondary node.

Definition at line 591 of file AutomaticMortarGeneration.h.

Referenced by clear(), computeADNodalNormals(), computeNodalGeometry(), getNodalNormals(), MortarNodalGeometryOutput::output(), projectPrimaryNodesSinglePair(), and projectSecondaryNodesSinglePair().

◆ _secondary_requested_boundary_ids

std::set<BoundaryID> AutomaticMortarGeneration::_secondary_requested_boundary_ids
private

The boundary ids corresponding to all the secondary surfaces.

Definition at line 517 of file AutomaticMortarGeneration.h.

Referenced by AutomaticMortarGeneration(), and buildNodeToElemMaps().

◆ _triangulate_triangles

const bool AutomaticMortarGeneration::_triangulate_triangles
private

Whether already-triangular clipped polygons should still be centroid-subdivided.

Definition at line 686 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh3d().

◆ _triangulation_mode

const MortarSegmentTriangulationMode AutomaticMortarGeneration::_triangulation_mode
private

Triangulation mode used for clipped 3D mortar polygons.

Definition at line 683 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh3d().

◆ _xi_tolerance

Real AutomaticMortarGeneration::_xi_tolerance = 1e-6
private

Tolerance for checking projection xi values.

Usually we are checking whether we projected onto a certain element (in which case -1 <= xi <= 1) or whether we should have already projected a primary node (in which case we error if abs(xi) is sufficiently close to 1)

Definition at line 667 of file AutomaticMortarGeneration.h.

Referenced by buildMortarSegmentMesh(), projectPrimaryNodesSinglePair(), and projectSecondaryNodesSinglePair().

◆ system_name

const std::string AutomaticMortarGeneration::system_name
static

The name of the nodal normals system.

We store this in one place so it's easy to change later.

Definition at line 140 of file AutomaticMortarGeneration.h.


The documentation for this class was generated from the following files: