https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Classes | Functions
MooseMeshUtils Namespace Reference

Classes

struct  ElemSidePair
 

Functions

void mergeBoundaryIDsWithSameName (MeshBase &mesh)
 Merges the boundary IDs of boundaries that have the same names but different IDs.
 
void changeBoundaryId (MeshBase &mesh, const libMesh::boundary_id_type old_id, const libMesh::boundary_id_type new_id, bool delete_prev)
 Changes the old boundary ID to a new ID in the mesh.
 
void changeSubdomainId (MeshBase &mesh, const subdomain_id_type old_id, const subdomain_id_type new_id)
 Changes the old subdomain ID to a new ID in the mesh.
 
std::vector< BoundaryID > getBoundaryIDs (const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown, const std::set< BoundaryID > &mesh_boundary_ids)
 Gets the boundary IDs with their names.
 
std::vector< BoundaryID > getBoundaryIDs (const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown)
 Gets the boundary IDs with their names.
 
std::set< BoundaryID > getBoundaryIDSet (const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown)
 Gets the boundary IDs into a set with their names.
 
BoundaryID getBoundaryID (const BoundaryName &boundary_name, const MeshBase &mesh)
 Gets the boundary ID associated with the given BoundaryName.
 
std::set< std::pair< BoundaryName, BoundaryID > > getAllBoundaryNamesAndIDs (const libMesh::MeshBase &mesh)
 Get all boundary names and IDs from a mesh.
 
SubdomainID getSubdomainID (const SubdomainName &subdomain_name, const MeshBase &mesh)
 Gets the subdomain ID associated with the given SubdomainName.
 
std::vector< subdomain_id_type > getSubdomainIDs (const libMesh::MeshBase &mesh, const std::vector< SubdomainName > &subdomain_name)
 Get the associated subdomainIDs for the subdomain names that are passed in.
 
std::set< subdomain_id_type > getSubdomainIDs (const libMesh::MeshBase &mesh, const std::set< SubdomainName > &subdomain_name)
 
std::set< std::pair< SubdomainName, SubdomainID > > getAllSubdomainNamesAndIDs (const libMesh::MeshBase &mesh)
 Get all subdomain names and ids from a mesh.
 
Point meshCentroidCalculator (const MeshBase &mesh)
 Calculates the centroid of a MeshBase.
 
Point boundaryCentroidCalculator (const BoundaryName &boundary, MeshBase &mesh)
 Calculates the centroid of a boundary on a mesh.
 
RealVectorValue boundaryWeightedNormal (const BoundaryName &boundary, MeshBase &mesh)
 Calculates the side-volume weighted (side-vertex) average normal of a boundary on a mesh.
 
template<typename P , typename C >
void coordTransformFactor (const P &point, C &factor, const Moose::CoordinateSystemType coord_type, const unsigned int rz_radial_coord=libMesh::invalid_uint)
 Compute a coordinate transformation volume integration factor.
 
template<typename P , typename C >
C computeDistanceToAxis (const P &point, const Point &origin, const RealVectorValue &direction)
 Computes the distance to a general axis.
 
Real computeMaxDistanceToAxis (const MeshBase &mesh, const Point &origin, const RealVectorValue &direction)
 Computes the maximum distance from all nodes of a mesh to a general axis.
 
template<typename P , typename C >
void coordTransformFactorRZGeneral (const P &point, const std::pair< Point, RealVectorValue > &axis, C &factor)
 Computes a coordinate transformation factor for a general axisymmetric axis.
 
void computeFiniteVolumeCoords (FaceInfo &fi, const Moose::CoordinateSystemType coord_type, const unsigned int rz_radial_coord=libMesh::invalid_uint)
 
std::unordered_map< dof_id_type, dof_id_type > getExtraIDUniqueCombinationMap (const MeshBase &mesh, const std::set< SubdomainID > &block_ids, std::vector< ExtraElementIDName > extra_ids)
 Create a new set of element-wise IDs by finding unique combinations of existing extra ID values.
 
bool isCoPlanar (const std::vector< Point > &vec_pts, const Point plane_nvec, const Point fixed_pt)
 Decides whether all the Points of a vector of Points are in a plane that is defined by a normal vector and an inplane Point.
 
bool isCoPlanar (const std::vector< Point > &vec_pts, const Point plane_nvec)
 Decides whether all the Points of a vector of Points are in a plane with a given normal vector.
 
bool isCoPlanar (const std::vector< Point > &vec_pts)
 Decides whether all the Points of a vector of Points are coplanar.
 
SubdomainID getNextFreeSubdomainID (MeshBase &input_mesh)
 Checks input mesh and returns max(block ID) + 1, which represents a block ID that is not currently in use in the mesh.
 
std::unordered_map< subdomain_id_type, subdomain_id_type > remapSecondarySubdomainIDsForStitching (MeshBase &mesh, MeshBase &secondary_mesh, bool merge_same_name_across_ids=true)
 Renumber the subdomains of a mesh about to be stitched into another so that the subdomain names of both meshes survive the stitching.
 
std::unordered_map< boundary_id_type, boundary_id_type > remapSecondaryBoundaryIDsForStitching (MeshBase &mesh, MeshBase &secondary_mesh, const std::set< boundary_id_type > &ids_to_preserve={})
 Renumber the boundaries of a mesh about to be stitched into another so that the boundary names of both meshes survive the stitching.
 
BoundaryID getNextFreeBoundaryID (MeshBase &input_mesh)
 Checks input mesh and returns the largest boundary ID in the mesh plus one, which is a boundary ID in the mesh that is not currently in use.
 
bool hasSubdomainID (const MeshBase &input_mesh, const SubdomainID &id)
 Whether a particular subdomain ID exists in the mesh.
 
bool hasSubdomainName (const MeshBase &input_mesh, const SubdomainName &name)
 Whether a particular subdomain name exists in the mesh.
 
bool hasBoundaryID (const MeshBase &input_mesh, const BoundaryID id)
 Whether a particular boundary ID exists in the mesh.
 
bool hasBoundaryName (const MeshBase &mesh, const BoundaryName &name)
 Whether a particular boundary name exists in the mesh.
 
bool hasBoundaryNameOrID (const MeshBase &mesh, const BoundaryName &name_or_id)
 Whether a particular boundary name or ID exists in the mesh.
 
void makeOrderedNodeList (std::vector< std::pair< dof_id_type, dof_id_type > > &node_assm, std::vector< dof_id_type > &elem_id_list, std::vector< dof_id_type > &midpoint_node_list, std::vector< dof_id_type > &ordered_node_list, std::vector< dof_id_type > &ordered_elem_id_list)
 Convert a list of sides in the form of a vector of pairs of node ids into a list of ordered nodes based on connectivity.
 
void makeOrderedNodeList (std::vector< std::pair< dof_id_type, dof_id_type > > &node_assm, std::vector< dof_id_type > &elem_id_list, std::vector< dof_id_type > &ordered_node_list, std::vector< dof_id_type > &ordered_elem_id_list)
 Convert a list of sides in the form of a vector of pairs of node ids into a list of ordered nodes based on connectivity.
 
template<typename T , typename Q >
Q getIDFromName (const T &name)
 Converts a given name (BoundaryName or SubdomainName) that is known to only contain digits into a corresponding ID (BoundaryID or SubdomainID) and performs bounds checking to ensure that overflow doesn't happen.
 
void swapNodesInElem (Elem &elem, const unsigned int nd1, const unsigned int nd2)
 Swap two nodes within an element.
 
template<typename T >
void idSwapParametersProcessor (const std::string &class_name, const std::string &id_name, const std::vector< std::vector< T > > &id_swaps, std::vector< std::unordered_map< T, T > > &id_swap_pairs, const unsigned int row_index_shift=0)
 Reprocess the swap related input parameters to make pairs out of them to ease further processing.
 
void extraElemIntegerSwapParametersProcessor (const std::string &class_name, const unsigned int num_sections, const unsigned int num_integers, const std::vector< std::vector< std::vector< dof_id_type > > > &elem_integers_swaps, std::vector< std::unordered_map< dof_id_type, dof_id_type > > &elem_integers_swap_pairs)
 Reprocess the elem_integers_swaps into maps so they are easier to use.
 
std::unique_ptr< ReplicatedMesh > buildBoundaryMesh (const MeshBase &input_mesh, const boundary_id_type boundary_id)
 Build a lower-dimensional mesh from a boundary of an input mesh Note: The lower-dimensional mesh will only have one subdomain and one boundary.
 
std::unique_ptr< ReplicatedMesh > buildLoopBoundaryOf2DMesh (const MeshBase &input_mesh, const boundary_id_type boundary_id)
 Build a loop mesh of edges from the contiguous 2D boundary of 2D input mesh Note: The lower-dimensional mesh will only have one subdomain.
 
std::unordered_map< dof_id_type, std::unordered_set< dof_id_type > > buildBoundaryNodeToElemMap (const MeshBase &input_mesh, const boundary_id_type boundary_id)
 Build a map from the node ids to all element ids they are part of for the nodes on a particular nodeset.
 
std::set< dof_id_type > getBoundaryNodes (const MeshBase &mesh, const BoundaryID boundary_id)
 Get all the nodes on that particular boundary, whether a nodeset or a sideset.
 
void createSubdomainFromSidesets (MeshBase &mesh, std::vector< BoundaryName > boundary_names, const SubdomainID new_subdomain_id, const SubdomainName &new_subdomain_name)
 Create a new subdomain by generating new side elements from a list of sidesets in a given mesh.
 
void convertBlockToMesh (MeshBase &source_mesh, MeshBase &target_mesh, const std::vector< SubdomainName > &target_blocks)
 Convert a list of blocks in a given mesh to a standalone new mesh.
 
void copyIntoMesh (MeshGenerator &mg, UnstructuredMesh &destination, const UnstructuredMesh &source, const bool avoid_merging_subdomains, const bool avoid_merging_boundaries, const Parallel::Communicator &communicator, const bool skip_preparation=false)
 Helper function for copying one mesh into another.
 
void buildPolyLineMesh (MeshBase &mesh, const std::vector< Point > &points, const bool loop, const BoundaryName &start_boundary, const BoundaryName &end_boundary, const std::vector< unsigned int > &nums_edges_between_points)
 Generates meshes from edges connecting a list of points.
 
void buildPolyLineMesh (MeshBase &mesh, const std::vector< Point > &points, const std::vector< Point > &mid_points, const bool loop, const BoundaryName &start_boundary, const BoundaryName &end_boundary, const std::vector< unsigned int > &nums_edges_between_points)
 Generates meshes from edges connecting a list of points, with optional midpoints to produce Edge3 elements so as to enable quadratic meshing.
 
void buildPolyLineMesh (MeshBase &mesh, const std::vector< Point > &points, const bool loop, const BoundaryName &start_boundary, const BoundaryName &end_boundary, const Real max_elem_size)
 Generates meshes from edges connecting a list of points.
 
void addExternalBoundary (MeshBase &mesh, const BoundaryID extern_bid, bool &has_external_bid)
 Adds a sideset for the external boundary of the mesh (e.g.
 
std::vector< unsigned int > nodalQuadraturePointToNodeMap (const Elem &elem, const std::vector< Point > &q_points)
 Match the points of a nodal quadrature rule (e.g.
 
std::unique_ptr< ReplicatedMesh > stitchMeshesPairwise (std::vector< std::unique_ptr< ReplicatedMesh > > meshes, const std::function< BoundaryID(const MeshBase &)> &left_boundary_id, const std::function< BoundaryID(const MeshBase &)> &right_boundary_id, const bool clear_stitched_boundary_ids, const bool verbose)
 Stitch a list of meshes into one by repeatedly stitching neighboring pairs, so that the cost is O(N log N) in the number of meshes N instead of the O(N^2) of stitching each mesh onto one growing mesh.
 
void changeBoundaryId (MeshBase &mesh, const boundary_id_type old_id, const boundary_id_type new_id, bool delete_prev)
 
std::vector< boundary_id_type > getBoundaryIDs (const MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown)
 
std::vector< boundary_id_type > getBoundaryIDs (const MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown, const std::set< BoundaryID > &mesh_boundary_ids)
 
std::set< BoundaryID > getBoundaryIDSet (const MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown)
 
std::set< std::pair< BoundaryName, BoundaryID > > getAllBoundaryNamesAndIDs (const MeshBase &mesh)
 
std::vector< subdomain_id_type > getSubdomainIDs (const MeshBase &mesh, const std::vector< SubdomainName > &subdomain_names)
 
std::set< subdomain_id_type > getSubdomainIDs (const MeshBase &mesh, const std::set< SubdomainName > &subdomain_names)
 
std::set< std::pair< SubdomainName, SubdomainID > > getAllSubdomainNamesAndIDs (const MeshBase &mesh)
 

Function Documentation

◆ addExternalBoundary()

void MooseMeshUtils::addExternalBoundary ( MeshBase &  mesh,
const BoundaryID  extern_bid,
bool &  has_external_bid 
)

Adds a sideset for the external boundary of the mesh (e.g.

all element sides with no neighbors)

Parameters
meshthe mesh to modify
extern_bidthe ID to assign to the external boundary
has_external_bidfalse if all elements of the mesh are internal (for example a sphere shell)

Definition at line 1643 of file MooseMeshUtils.C.

1644{
1645 auto & binfo = mesh.get_boundary_info();
1646 for (const auto & elem : mesh.active_element_ptr_range())
1647 for (const auto & i_side : elem->side_index_range())
1648 if (elem->neighbor_ptr(i_side) == nullptr)
1649 {
1650 has_external_bid = true;
1651 binfo.add_side(elem, i_side, extern_bid);
1652 }
1653}
for(PetscInt i=0;i< nvars;++i)
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
MeshBase & mesh

Referenced by SurfaceSubdomainsDelaunayRemesher::generate(), XYDelaunayGenerator::generate(), and XYTriangleBoundaryLayerGenerator::generate().

◆ boundaryCentroidCalculator()

Point MooseMeshUtils::boundaryCentroidCalculator ( const BoundaryName &  boundary,
MeshBase &  mesh 
)

Calculates the centroid of a boundary on a mesh.

Parameters
boundaryboundary to compute the centroid of
meshinput mesh holding the boundary whose centroid needs to be calculated
Returns
a Point corresponding to the boundary centroid

Definition at line 330 of file MooseMeshUtils.C.

331{
332 // Need boundaries to be synchronized
333 if (!mesh.preparation().has_boundary_id_sets)
334 mesh.get_boundary_info().synchronize_global_id_set();
335 BoundaryInfo & mesh_boundary_info = mesh.get_boundary_info();
336 boundary_id_type boundary_id = mesh_boundary_info.get_id_by_name(boundary);
337 const auto side_list = mesh_boundary_info.build_side_list();
338
339 // Initialize sums
340 Real volume_sum = 0;
341 Point volume_weighted_centroid_sum(0, 0, 0);
342
343 for (const auto & [eid, side_i, bid] : side_list)
344 {
345 if (bid != boundary_id)
346 continue;
347
348 // Get the side
349 const auto elem = mesh.elem_ptr(eid);
350 const auto side = elem->side_ptr(side_i);
351
352 volume_sum += side->volume();
353 volume_weighted_centroid_sum += side->volume() * side->true_centroid();
354 }
355 // Sum across processes
356 mesh.comm().sum(volume_weighted_centroid_sum);
357 mesh.comm().sum(volume_sum);
358
359 if (volume_sum == 0)
360 {
361 mooseWarning("Boundary centroid was requested but boundary '" + boundary + "' is empty.");
362 return Point(0.);
363 }
364 return volume_weighted_centroid_sum / volume_sum;
365}
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345

Referenced by BSplineCurveGenerator::endPoint(), and BSplineCurveGenerator::startPoint().

◆ boundaryWeightedNormal()

RealVectorValue MooseMeshUtils::boundaryWeightedNormal ( const BoundaryName &  boundary,
MeshBase &  mesh 
)

Calculates the side-volume weighted (side-vertex) average normal of a boundary on a mesh.

Parameters
boundaryboundary to compute the weighted normal of
meshinput mesh holding the boundary whose averaged normal needs to be calculated
Returns
a Point corresponding to the boundary weighted normal

Definition at line 368 of file MooseMeshUtils.C.

369{
370 // Need boundaries to be synchronized
371 if (!mesh.preparation().has_boundary_id_sets)
372 mesh.get_boundary_info().synchronize_global_id_set();
373 BoundaryInfo & mesh_boundary_info = mesh.get_boundary_info();
374 boundary_id_type boundary_id = mesh_boundary_info.get_id_by_name(boundary);
375 const auto side_list = mesh_boundary_info.build_side_list();
376
377 // Initialize sums
378 Real volume_sum = 0;
379 RealVectorValue volume_weighted_normal_sum(0, 0, 0);
380
381 for (const auto & [eid, side_i, bid] : side_list)
382 {
383 if (bid != boundary_id)
384 continue;
385
386 // Get the side
387 const auto elem = mesh.elem_ptr(eid);
388 const auto side = elem->side_ptr(side_i);
389
390 volume_sum += side->volume();
391 volume_weighted_normal_sum += side->volume() * elem->side_vertex_average_normal(side_i);
392 }
393 // Sum across processes
394 mesh.comm().sum(volume_weighted_normal_sum);
395 mesh.comm().sum(volume_sum);
396
397 return volume_weighted_normal_sum / volume_sum;
398}

Referenced by BSplineCurveGenerator::endDirection(), and BSplineCurveGenerator::startDirection().

◆ buildBoundaryMesh()

std::unique_ptr< ReplicatedMesh > MooseMeshUtils::buildBoundaryMesh ( const MeshBase &  input_mesh,
const boundary_id_type  boundary_id 
)

Build a lower-dimensional mesh from a boundary of an input mesh Note: The lower-dimensional mesh will only have one subdomain and one boundary.

Error will be thrown if the mesh does not have the boundary. This function works only with replicated mesh, for similar functionality with distributed meshes, please refer to LowerDBlockFromSidesetGenerator generator.

Parameters
input_meshThe input mesh
boundary_idThe boundary id

Definition at line 832 of file MooseMeshUtils.C.

833{
834 if (!input_mesh.is_serial())
835 ::mooseError("Input mesh should be serialized for extracting the boundary mesh.\nInput mesh:" +
836 input_mesh.get_info());
837 auto poly_mesh = std::make_unique<ReplicatedMesh>(input_mesh.comm());
838
839 auto side_list = input_mesh.get_boundary_info().build_side_list();
840
841 std::unordered_map<dof_id_type, dof_id_type> old_new_node_map;
842 for (const auto & [eid, side_i, bid] : side_list)
843 {
844 if (bid != boundary_id)
845 continue;
846
847 // Get the side
848 const auto elem = input_mesh.elem_ptr(eid);
849 const auto side = elem->side_ptr(side_i);
850 auto side_elem = elem->build_side_ptr(side_i);
851 auto copy = side_elem->build(side_elem->type());
852
853 for (const auto i : side_elem->node_index_range())
854 {
855 auto & n = side_elem->node_ref(i);
856
857 if (old_new_node_map.count(n.id()))
858 copy->set_node(i, poly_mesh->node_ptr(old_new_node_map[n.id()]));
859 else
860 {
861 Node * node = poly_mesh->add_point(side_elem->point(i));
862 copy->set_node(i, node);
863 old_new_node_map[n.id()] = node->id();
864 }
865 }
866 poly_mesh->add_elem(copy.release());
867 }
868 poly_mesh->skip_partitioning(true);
869 poly_mesh->prepare_for_use();
870 if (poly_mesh->n_elem() == 0)
871 mooseError("The input mesh to extract the boundary from does not have a boundary with id ",
872 boundary_id,
873 ".\n",
874 input_mesh);
875
876 return poly_mesh;
877}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311

◆ buildBoundaryNodeToElemMap()

std::unordered_map< dof_id_type, std::unordered_set< dof_id_type > > MooseMeshUtils::buildBoundaryNodeToElemMap ( const MeshBase &  input_mesh,
const boundary_id_type  boundary_id 
)

Build a map from the node ids to all element ids they are part of for the nodes on a particular nodeset.

Parameters
input_meshThe input mesh to get the map for
boundary_idThe boundary id of interest

Definition at line 1095 of file MooseMeshUtils.C.

1096{
1097 if (!input_mesh.is_serial())
1099 "Input 2D mesh should be serialized for extracting the loop boundary mesh.\nInput mesh:" +
1100 input_mesh.get_info());
1101
1102 // Get all nodes on that boundary
1103 // Boundary ID might be a sideset or a nodeset, get nodes regardless
1104 const auto particular_node_ids = getBoundaryNodes(input_mesh, boundary_id);
1105
1106 std::unordered_map<dof_id_type, std::unordered_set<dof_id_type>> nid_to_eids_map;
1107 // Fill the map from looping over elements
1108 for (const auto & elem :
1109 as_range(input_mesh.active_elements_begin(), input_mesh.active_elements_end()))
1110 {
1111 for (const auto & nd : elem->node_ref_range())
1112 {
1113 // Only add the element id if the node is on the boundary
1114 if (!particular_node_ids.count(nd.id()))
1115 continue;
1116
1117 auto & elem_ids = nid_to_eids_map[nd.id()];
1118 elem_ids.insert(elem->id());
1119 }
1120 }
1121 return nid_to_eids_map;
1122}
std::set< dof_id_type > getBoundaryNodes(const MeshBase &mesh, const BoundaryID boundary_id)
Get all the nodes on that particular boundary, whether a nodeset or a sideset.

Referenced by buildLoopBoundaryOf2DMesh().

◆ buildLoopBoundaryOf2DMesh()

std::unique_ptr< ReplicatedMesh > MooseMeshUtils::buildLoopBoundaryOf2DMesh ( const MeshBase &  input_mesh,
const boundary_id_type  boundary_id 
)

Build a loop mesh of edges from the contiguous 2D boundary of 2D input mesh Note: The lower-dimensional mesh will only have one subdomain.

An error will be thrown if the mesh does not have the boundary. Note: currently, the boundary_id must be a nodeset!

Parameters
input_meshThe input mesh
boundary_idThe boundary id

Definition at line 880 of file MooseMeshUtils.C.

881{
882 if (!input_mesh.is_serial())
884 "Input 2D mesh should be serialized for extracting the loop boundary mesh.\nInput mesh:" +
885 input_mesh.get_info());
886 auto edge_mesh = std::make_unique<ReplicatedMesh>(input_mesh.comm());
887 auto side_list = input_mesh.get_boundary_info().build_side_list();
888 std::set<BoundaryInfo::BCTuple> visited;
889 bool already_seen_this_side_tuple = false;
890 BoundaryInfo::BCTuple first_side_visited = {libMesh::invalid_uint, 0, 0};
891
892 // Helps move elem to elem at a given node
893 const auto node_to_elem_map = buildBoundaryNodeToElemMap(input_mesh, boundary_id);
894 // Helps check if a node is part of a boundary
895 const auto & node_to_bids = input_mesh.get_boundary_info().get_nodeset_map();
896
897 // Traverse from the first side (edge) in the side_list that matches the boundary_id
898 for (const auto & bside : side_list)
899 {
900 if (std::get<2>(bside) != boundary_id)
901 continue;
902
903 // Check that we are not starting 'another' loop
904 if (bside != first_side_visited)
905 {
906 if (visited.size() && !visited.count(bside))
908 "Boundary " + std::to_string(boundary_id) +
909 " is not a (contiguous) loop. Boundary side: (" + Moose::stringify(bside) +
910 ") was not visited after a single pass around the boundary. Boundary sides visited: " +
911 Moose::stringify(visited));
912 else if (visited.empty())
913 first_side_visited = bside;
914 else
915 continue;
916 }
917
918 // Form the element to be able to find the side
919 // These three variables will be updated while traversing the loop boundary
920 const Elem * elem = input_mesh.elem_ptr(std::get<0>(bside));
921 auto current_side = std::get<1>(bside);
922 auto side_elem = elem->build_side_ptr(current_side);
923
924 // 3D elements should not be part of this boundary
925 if (elem->dim() != 2)
927 "Finding the loop boundary of a 2D mesh cannot be done with non-2D elements such as ",
928 *elem);
929
930 // Start from node 0 of the side (on the boundary), set the next node as the other node
931 // one that side, and keep going from tht next node
932 bool looped_back = false;
933 const Node * starting_node = side_elem->node_ptr(0);
934 const auto new_mesh_starting_node = edge_mesh->add_point(side_elem->point(0));
935 Node * new_first_node = new_mesh_starting_node;
936 [[maybe_unused]] dof_id_type first_node_index = starting_node->id();
937 dof_id_type second_node_index = input_mesh.node_ptr(side_elem->node_id(1))->id();
938
939 while (!looped_back && !already_seen_this_side_tuple)
940 {
941 if (MooseUtils::absoluteFuzzyEqual(input_mesh.point(second_node_index),
942 Point(*starting_node)))
943 looped_back = true;
944
945 // Get the opposite node (the next node) and add it to the edge mesh
946 Node * new_second_node = looped_back
947 ? new_mesh_starting_node
948 : edge_mesh->add_point(input_mesh.point(second_node_index));
949
950 // Add a copy of the edge side element to the mesh
951 side_elem = elem->build_side_ptr(current_side);
952 auto copy = side_elem->build(side_elem->type());
953 copy->set_node(0, new_first_node);
954 copy->set_node(1, new_second_node);
955 edge_mesh->add_elem(copy.release());
956
957 // Make this side as 'visited'
958 std::tuple<dof_id_type, unsigned short int, boundary_id_type> bc_tuple = {
959 elem->id(), current_side, boundary_id};
960 const auto & visit_iter = visited.insert(bc_tuple);
961 if (!looped_back && !visit_iter.second)
962 already_seen_this_side_tuple = true;
963
964 // Find the next element and side_elem
965 auto & connected_elems = libmesh_map_find(node_to_elem_map, second_node_index);
966 bool found_match = false;
967 const auto current_eid = elem->id();
968
969 for (const auto eid : connected_elems)
970 {
971 mooseAssert(!found_match,
972 "We should only find one node on a connected element on this boundary");
973 if (eid != current_eid)
974 {
975 // Update the element (on the input mesh)
976 elem = input_mesh.elem_ptr(eid);
977
978 // Find the side and the opposite node index in that side
979 for (const auto si : elem->side_index_range())
980 {
981 // Check that second node is on the side
982 const auto local_second_node_index =
983 elem->get_node_index(input_mesh.node_ptr(second_node_index));
984 // 2 sides should match this
985 if (elem->is_node_on_side(local_second_node_index, si))
986 {
987 // Only one side should be on the same boundary (node is connected to two elements)
988 // Form a bc_tuple and check the list of boundary sides
989 std::tuple<dof_id_type, unsigned short int, boundary_id_type> side_bc_tuple = {
990 elem->id(), si, boundary_id};
991
992 if (std::find(side_list.begin(), side_list.end(), side_bc_tuple) == side_list.end())
993 continue;
994
995 // We are on the right boundary, just need to get the other node
996 for (const auto local_side_node_id : elem->nodes_on_side(si))
997 {
998 const auto side_node_id = elem->node_id(local_side_node_id);
999
1000 // Skip current node (use global index to compare)
1001 if (side_node_id == second_node_index)
1002 continue;
1003 mooseAssert(side_node_id != first_node_index,
1004 "Somehow looped back in a single element");
1005
1006 current_side = si;
1007 second_node_index = side_node_id;
1008 found_match = true;
1009 break;
1010 }
1011 }
1012 // No need to examine more sides
1013 if (found_match)
1014 break;
1015 }
1016
1017 // No need to examine more elements
1018 if (found_match)
1019 break;
1020 }
1021 // next node could be on the same element, just moving on to the next side
1022 else if (connected_elems.size() == 1)
1023 {
1024 elem = input_mesh.elem_ptr(eid);
1025 const auto local_second_node_index =
1026 elem->get_node_index(input_mesh.node_ptr(second_node_index));
1027
1028 // Move on to the next side
1029 for (const auto si : elem->side_index_range())
1030 if (si != current_side && elem->is_node_on_side(local_second_node_index, si))
1031 {
1032 // Check all nodes on that next side
1033 for (const auto local_side_node_id : elem->nodes_on_side(si))
1034 {
1035 const auto side_node_id = elem->node_id(local_side_node_id);
1036 // Skip current node
1037 if (side_node_id == second_node_index)
1038 continue;
1039 mooseAssert((side_node_id != first_node_index) ||
1040 (side_list.size() == elem->n_sides()),
1041 "Somehow looped back in a single element");
1042
1043 // Check all the boundaries the other node (on the edge side) is part of
1044 const auto bids_range = node_to_bids.equal_range(input_mesh.node_ptr(side_node_id));
1045
1046 for (auto iter = bids_range.first; iter != bids_range.second; iter++)
1047 if (iter->second == boundary_id)
1048 {
1049 current_side = si;
1050 second_node_index = side_node_id;
1051 found_match = true;
1052 }
1053 }
1054
1055 // no need to examine other sides
1056 if (found_match)
1057 break;
1058 }
1059 }
1060 }
1061
1062 // Set current node to opposite node of new element
1063 // NOTE: do not use new_first_node or new_second_node to search in the input mesh!
1064 new_first_node = new_second_node;
1065 first_node_index = second_node_index;
1066
1067 // Handle loop ending criterion
1068 if (!found_match)
1069 {
1070 mooseWarning("Search for next element in loop boundary failed. Is boundary '" +
1071 std::to_string(boundary_id) + "' of mesh ",
1072 input_mesh,
1073 " a loop boundary?");
1074 break;
1075 }
1076 }
1077 }
1078
1079 if (already_seen_this_side_tuple)
1080 mooseWarning("Boundary " + std::to_string(boundary_id) +
1081 " seems to have cycles. A single-cycle loop should be used");
1082
1083 edge_mesh->skip_partitioning(true);
1084 edge_mesh->prepare_for_use();
1085 if (edge_mesh->n_elem() == 0)
1086 mooseError("The input mesh to extract the boundary from does not have a boundary with id ",
1087 boundary_id,
1088 "\n",
1089 input_mesh);
1090
1091 return edge_mesh;
1092}
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:65
const unsigned int invalid_uint
uint8_t dof_id_type

Referenced by SurfaceSubdomainsDelaunayRemesher::General2DDelaunay().

◆ buildPolyLineMesh() [1/3]

void MooseMeshUtils::buildPolyLineMesh ( MeshBase &  mesh,
const std::vector< Point > &  points,
const bool  loop,
const BoundaryName &  start_boundary,
const BoundaryName &  end_boundary,
const Real  max_elem_size 
)

Generates meshes from edges connecting a list of points.

Note that we do not support max_elem_size and quadratic mid points at the same time as we cannot pre-determine the number of mid points needed for quadratic elements when max_elem_size is specified.

Parameters
meshThe mesh to be built
pointsThe list of points defining the polyline
loopWhether the polyline is a closed loop
start_boundaryThe boundary name to assign to the start of the polyline (if not a loop)
end_boundaryThe boundary name to assign to the end of the polyline (if not a loop)
max_elem_sizeThe maximum element size for the mesh

Definition at line 1617 of file MooseMeshUtils.C.

1623{
1624 std::vector<unsigned int> nums_edges_between_points;
1625 const auto n_points = points.size();
1626 for (auto i : make_range(n_points))
1627 {
1628 if (!loop && (i + 1) == n_points)
1629 break;
1630
1631 const auto ip1 = (i + 1) % n_points;
1632 const Real length = (points[ip1] - points[i]).norm();
1633 const unsigned int n_elems = std::max(
1634 static_cast<unsigned int>(std::ceil(length / max_elem_size)), static_cast<unsigned int>(1));
1635 nums_edges_between_points.push_back(n_elems);
1636 }
1637
1638 buildPolyLineMesh(
1639 mesh, points, {}, loop, start_boundary, end_boundary, nums_edges_between_points);
1640}

◆ buildPolyLineMesh() [2/3]

void MooseMeshUtils::buildPolyLineMesh ( MeshBase &  mesh,
const std::vector< Point > &  points,
const bool  loop,
const BoundaryName &  start_boundary,
const BoundaryName &  end_boundary,
const std::vector< unsigned int > &  nums_edges_between_points 
)

Generates meshes from edges connecting a list of points.

Parameters
meshThe mesh to be built
pointsThe list of points defining the polyline
loopWhether the polyline is a closed loop
start_boundaryThe boundary name to assign to the start of the polyline (if not a loop)
end_boundaryThe boundary name to assign to the end of the polyline (if not a loop)
nums_edges_between_pointsThe numbers of edges to create between each pair of points (if only one number is given, it is used for all point pairs)

Definition at line 1605 of file MooseMeshUtils.C.

1611{
1613 mesh, points, {}, loop, start_boundary, end_boundary, nums_edges_between_points);
1614}
void buildPolyLineMesh(MeshBase &mesh, const std::vector< Point > &points, const bool loop, const BoundaryName &start_boundary, const BoundaryName &end_boundary, const std::vector< unsigned int > &nums_edges_between_points)
Generates meshes from edges connecting a list of points.

Referenced by BoundaryLayerUtils::buildBoundaryLayerRing(), buildPolyLineMesh(), buildPolyLineMesh(), SurfaceSubdomainsDelaunayRemesher::General2DDelaunay(), and PolyLineMeshGenerator::generate().

◆ buildPolyLineMesh() [3/3]

void MooseMeshUtils::buildPolyLineMesh ( MeshBase &  mesh,
const std::vector< Point > &  points,
const std::vector< Point > &  mid_points,
const bool  loop,
const BoundaryName &  start_boundary,
const BoundaryName &  end_boundary,
const std::vector< unsigned int > &  nums_edges_between_points 
)

Generates meshes from edges connecting a list of points, with optional midpoints to produce Edge3 elements so as to enable quadratic meshing.

If mid_points is empty, Edge2 elements are produced.

Parameters
meshThe mesh to be built
pointsThe list of points defining the polyline
mid_pointsThe optional list of midpoints corresponding to the segments for quadratic elements. if provided, it must contains exactly one midpoint per segment and nums_edges_between_points must be unity for every segment.
loopWhether the polyline is a closed loop
start_boundaryThe boundary name to assign to the start of the polyline (if not a loop)
end_boundaryThe boundary name to assign to the end of the polyline (if not a loop)
nums_edges_between_pointsThe numbers of edges to create between each pair of points (if only one number is given, it is used for all point pairs)

Definition at line 1497 of file MooseMeshUtils.C.

1504{
1505 mooseAssert(nums_edges_between_points.size() == 1 ||
1506 nums_edges_between_points.size() == points.size() - 1 + loop,
1507 "nums_edges_between_points must be either a single value or have the same number of "
1508 "entries as segments defined by the points.");
1509 mooseAssert(
1510 mid_points.size() == 0 || mid_points.size() == points.size() - (loop ? 0 : 1),
1511 "mid_points must be either empty or have the consistent number of entries as points.");
1512 mooseAssert(
1513 mid_points.size() == 0 ||
1514 (nums_edges_between_points.size() == 1 && nums_edges_between_points.front() == 1) ||
1515 (nums_edges_between_points.size() == points.size() - 1 + loop &&
1516 std::all_of(nums_edges_between_points.begin(),
1517 nums_edges_between_points.end(),
1518 [](unsigned int n) { return n == 1; })),
1519 "mid_points can only be provided if each segment has exactly one edge.");
1520
1521 const auto n_points = points.size();
1522 for (auto i : make_range(n_points))
1523 {
1524 const auto & num_edges_between_points =
1525 (nums_edges_between_points.size() == 1)
1526 ? nums_edges_between_points[0]
1527 : (i == nums_edges_between_points.size() ? 0 : nums_edges_between_points[i]);
1528
1529 Point p = points[i];
1530 const auto pt_counter = (nums_edges_between_points.size() == 1)
1531 ? i
1532 : std::accumulate(nums_edges_between_points.begin(),
1533 nums_edges_between_points.begin() + i,
1534 0);
1535 mesh.add_point(
1536 p, nums_edges_between_points.size() == 1 ? (i * num_edges_between_points) : pt_counter);
1537
1538 if (num_edges_between_points > 1)
1539 {
1540 if (!loop && (i + 1) == n_points)
1541 break;
1542
1543 const auto ip1 = (i + 1) % n_points;
1544 const Point pvec = (points[ip1] - p) / num_edges_between_points;
1545
1546 for (auto j : make_range(1u, num_edges_between_points))
1547 {
1548 p += pvec;
1549 mesh.add_point(
1550 p,
1551 (nums_edges_between_points.size() == 1 ? (i * num_edges_between_points) : pt_counter) +
1552 j);
1553 }
1554 }
1555 }
1556 // Add mid points if applicable. When mid points are provided, each segment has exactly one edge,
1557 // so the midpoint node ids follow the vertex node ids.
1558 for (const auto & i : make_range(mid_points.size()))
1559 mesh.add_point(mid_points[i], n_points + i);
1560
1561 const auto n_segments = loop ? n_points : (n_points - 1);
1562 const auto n_elem =
1563 nums_edges_between_points.size() == 1
1564 ? n_segments * nums_edges_between_points[0]
1565 : std::accumulate(nums_edges_between_points.begin(), nums_edges_between_points.end(), 0);
1566 const auto max_nodes =
1567 (nums_edges_between_points.size() == 1 ? n_segments * nums_edges_between_points[0]
1568 : std::accumulate(nums_edges_between_points.begin(),
1569 nums_edges_between_points.end(),
1570 0)) +
1571 (loop ? 0 : 1);
1572 for (auto i : make_range(n_elem))
1573 {
1574 std::unique_ptr<Elem> elem;
1575 if (mid_points.size())
1576 {
1577 elem = std::make_unique<Edge3>();
1578 elem->set_node(2, mesh.node_ptr(n_points + i));
1579 }
1580 else
1581 elem = Elem::build(EDGE2);
1582 const auto ip1 = (i + 1) % max_nodes;
1583 elem->set_node(0, mesh.node_ptr(i));
1584 elem->set_node(1, mesh.node_ptr(ip1));
1585 elem->set_id() = i;
1586 mesh.add_elem(std::move(elem));
1587 }
1588
1589 if (!loop)
1590 {
1591 BoundaryInfo & bi = mesh.get_boundary_info();
1592 std::vector<BoundaryName> bdy_names{start_boundary, end_boundary};
1593 std::vector<boundary_id_type> ids = MooseMeshUtils::getBoundaryIDs(mesh, bdy_names, true);
1594 bi.add_side(mesh.elem_ptr(0), 0, ids[0]);
1595 bi.add_side(mesh.elem_ptr(n_elem - 1), 1, ids[1]);
1596 }
1597 else
1598 mooseAssert(start_boundary.empty() && end_boundary.empty(),
1599 "Cannot assign start/end boundaries on a looped polyline.");
1600
1601 mesh.prepare_for_use();
1602}
std::vector< BoundaryID > getBoundaryIDs(const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown, const std::set< BoundaryID > &mesh_boundary_ids)
Gets the boundary IDs with their names.
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
IntRange< T > make_range(T beg, T end)

◆ changeBoundaryId() [1/2]

void MooseMeshUtils::changeBoundaryId ( MeshBase &  mesh,
const boundary_id_type  old_id,
const boundary_id_type  new_id,
bool  delete_prev 
)

Definition at line 63 of file MooseMeshUtils.C.

67{
68 // Get a reference to our BoundaryInfo object, we will use it several times below...
69 BoundaryInfo & boundary_info = mesh.get_boundary_info();
70
71 // Container to catch ids passed back from BoundaryInfo
72 std::vector<boundary_id_type> old_ids;
73
74 // Only level-0 elements store BCs. Loop over them.
75 for (auto & elem : as_range(mesh.level_elements_begin(0), mesh.level_elements_end(0)))
76 {
77 unsigned int n_sides = elem->n_sides();
78 for (const auto s : make_range(n_sides))
79 {
80 boundary_info.boundary_ids(elem, s, old_ids);
81 if (std::find(old_ids.begin(), old_ids.end(), old_id) != old_ids.end())
82 {
83 std::vector<boundary_id_type> new_ids(old_ids);
84 std::replace(new_ids.begin(), new_ids.end(), old_id, new_id);
85 if (delete_prev)
86 {
87 boundary_info.remove_side(elem, s);
88 boundary_info.add_side(elem, s, new_ids);
89 }
90 else
91 boundary_info.add_side(elem, s, new_ids);
92 }
93 }
94 }
95
96 // Remove any remaining references to the old ID from the
97 // BoundaryInfo object. This prevents things like empty sidesets
98 // from showing up when printing information, etc.
99 if (delete_prev)
100 boundary_info.remove_id(old_id);
101
102 // global information may now be out of sync
103 mesh.unset_is_prepared();
104}

◆ changeBoundaryId() [2/2]

void MooseMeshUtils::changeBoundaryId ( MeshBase &  mesh,
const libMesh::boundary_id_type  old_id,
const libMesh::boundary_id_type  new_id,
bool  delete_prev 
)

Changes the old boundary ID to a new ID in the mesh.

Parameters
meshthe mesh
old_idthe old boundary id
new_idthe new boundary id
delete_prevwhether to delete the previous boundary id from the mesh

Referenced by MeshExtruderGenerator::changeID(), MeshTriangulationUtils::finalizeTriangulation(), FillBetweenSidesetsGenerator::generate(), XYDelaunayGenerator::generate(), and MooseMeshElementConversionUtils::transitionLayerGenerator().

◆ changeSubdomainId()

void MooseMeshUtils::changeSubdomainId ( MeshBase &  mesh,
const subdomain_id_type  old_id,
const subdomain_id_type  new_id 
)

Changes the old subdomain ID to a new ID in the mesh.

Parameters
meshthe mesh
old_idthe old subdomain id
new_idthe new subdomain id

Definition at line 298 of file MooseMeshUtils.C.

299{
300 for (const auto & elem : mesh.element_ptr_range())
301 if (elem->subdomain_id() == old_id)
302 elem->subdomain_id() = new_id;
303
304 // global cached information may now be out of sync
305 mesh.unset_is_prepared();
306}

◆ computeDistanceToAxis()

template<typename P , typename C >
C MooseMeshUtils::computeDistanceToAxis ( const P &  point,
const Point &  origin,
const RealVectorValue &  direction 
)

Computes the distance to a general axis.

Parameters
[in]pointPoint for which to compute distance from axis
[in]originAxis starting point
[in]directionAxis direction

Definition at line 236 of file MooseMeshUtils.h.

237{
238 return (point - origin).cross(direction).norm();
239}

◆ computeFiniteVolumeCoords()

void MooseMeshUtils::computeFiniteVolumeCoords ( FaceInfo &  fi,
const Moose::CoordinateSystemType  coord_type,
const unsigned int  rz_radial_coord = libMesh::invalid_uint 
)
inline

Definition at line 270 of file MooseMeshUtils.h.

273{
274 coordTransformFactor(fi.faceCentroid(), fi.faceCoord(), coord_type, rz_radial_coord);
275}
void coordTransformFactor(const SubProblem &s, SubdomainID sub_id, const P &point, C &factor, SubdomainID neighbor_sub_id=libMesh::Elem::invalid_subdomain_id)
Computes a conversion multiplier for use when computing integraals for the current coordinate system ...
Definition Assembly.C:41
Real & faceCoord()
Sets/gets the coordinate transformation factor (for e.g.
Definition FaceInfo.h:68
const Point & faceCentroid() const
Returns the coordinates of the face centroid.
Definition FaceInfo.h:75

◆ computeMaxDistanceToAxis()

Real MooseMeshUtils::computeMaxDistanceToAxis ( const MeshBase &  mesh,
const Point &  origin,
const RealVectorValue &  direction 
)

Computes the maximum distance from all nodes of a mesh to a general axis.

Parameters
[in]meshmesh to get the distance from
[in]originAxis starting point
[in]directionAxis direction

Definition at line 401 of file MooseMeshUtils.C.

404{
405 Real distance = 0;
406 mooseAssert(MooseUtils::absoluteFuzzyEqual(direction.norm_sq(), 1),
407 "Direction should be normalized");
408 for (const auto & node : mesh.node_ptr_range())
409 if (const auto dist_node = (*node - origin).cross(direction).norm(); dist_node > distance)
410 distance = dist_node;
411 mesh.comm().max(distance);
412 return distance;
413}
Real distance(const Point &p)

Referenced by AdvancedExtruderGenerator::generate().

◆ convertBlockToMesh()

void MooseMeshUtils::convertBlockToMesh ( MeshBase &  source_mesh,
MeshBase &  target_mesh,
const std::vector< SubdomainName > &  target_blocks 
)

Convert a list of blocks in a given mesh to a standalone new mesh.

Parameters
source_meshThe source mesh from which the blocks will be converted
target_meshThe target mesh to which the blocks will be converted
target_blocksThe names of the blocks to be converted to the target mesh

Definition at line 1252 of file MooseMeshUtils.C.

1255{
1256 if (!source_mesh.is_replicated())
1257 mooseError("This generator does not support distributed meshes.");
1258
1259 const auto target_block_ids = MooseMeshUtils::getSubdomainIDs(source_mesh, target_blocks);
1260
1261 // Our source is non-const, so we can fix any missing caches
1262 if (!source_mesh.preparation().has_cached_elem_data)
1263 source_mesh.cache_elem_data();
1264
1265 // Check that the block ids/names exist in the mesh
1266 std::set<SubdomainID> mesh_blocks;
1267 source_mesh.subdomain_ids(mesh_blocks);
1268
1269 for (const auto i : index_range(target_block_ids))
1270 if (target_block_ids[i] == Moose::INVALID_BLOCK_ID || !mesh_blocks.count(target_block_ids[i]))
1271 {
1272 mooseException("The target_block '", target_blocks[i], "' was not found within the mesh.");
1273 }
1274
1275 // know which nodes have already been inserted, by tracking the old mesh's node's ids'
1276 std::unordered_map<dof_id_type, dof_id_type> old_new_node_map;
1277
1278 for (const auto target_block_id : target_block_ids)
1279 {
1280
1281 for (auto elem : source_mesh.active_subdomain_elements_ptr_range(target_block_id))
1282 {
1283 if (elem->level() != 0)
1284 mooseError("Refined blocks are not supported by this generator. "
1285 "Can you re-organize mesh generators to refine after converting the block?");
1286
1287 // make a deep copy so that mutiple meshes' destructors don't segfault at program termination
1288 auto copy = elem->build(elem->type());
1289
1290 // Keep the subdomain id
1291 copy->subdomain_id() = elem->subdomain_id();
1292
1293 // index of node in the copy element must be managed manually as there is no intelligent
1294 // insert method
1295 dof_id_type copy_n_index = 0;
1296
1297 // correctly assign new copies of nodes, loop over nodes
1298 for (dof_id_type i : elem->node_index_range())
1299 {
1300 auto & n = elem->node_ref(i);
1301
1302 if (old_new_node_map.count(n.id()))
1303 {
1304 // case where we have already inserted this particular point before
1305 // then we need to find the already-inserted one and hook it up right
1306 // to it's respective element
1307 copy->set_node(copy_n_index++, target_mesh.node_ptr(old_new_node_map[n.id()]));
1308 }
1309 else
1310 {
1311 // case where we've NEVER inserted this particular point before
1312 // add them both to the element and the mesh
1313
1314 // Nodes' IDs are their indexes in the nodes' respective mesh
1315 // If we set them as invalid they are automatically assigned
1316 // Add to mesh, auto-assigning a new id.
1317 Node * node = target_mesh.add_point(elem->point(i));
1318
1319 // Add to element copy (manually)
1320 copy->set_node(copy_n_index++, node);
1321
1322 // remember the (old) ID
1323 old_new_node_map[n.id()] = node->id();
1324 }
1325 }
1326
1327 // it is ok to release the copy element into the mesh because derived meshes class
1328 // (ReplicatedMesh, DistributedMesh) manage their own elements, will delete them
1329 target_mesh.add_elem(copy.release());
1330 }
1331 }
1332
1333 // Move subdomain names
1334 for (const auto sbd_id : target_block_ids)
1335 target_mesh.set_subdomain_name(sbd_id, source_mesh.subdomain_name(sbd_id));
1336}
unsigned int count
Definition MortarUtils.C:53
std::vector< subdomain_id_type > getSubdomainIDs(const libMesh::MeshBase &mesh, const std::vector< SubdomainName > &subdomain_name)
Get the associated subdomainIDs for the subdomain names that are passed in.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...

Referenced by Boundary2DDelaunayGenerator::General2DDelaunay(), SurfaceSubdomainsDelaunayRemesher::General2DDelaunay(), BlockToMeshConverterGenerator::generate(), Boundary2DDelaunayGenerator::generate(), SubdomainsFromPartitionerGenerator::generate(), and SurfaceSubdomainsDelaunayRemesher::generate().

◆ coordTransformFactor()

template<typename P , typename C >
void MooseMeshUtils::coordTransformFactor ( const P &  point,
C &  factor,
const Moose::CoordinateSystemType  coord_type,
const unsigned int  rz_radial_coord = libMesh::invalid_uint 
)

Compute a coordinate transformation volume integration factor.

Parameters
pointThe libMesh Point in space where we are evaluating the factor
factorThe output of this function. Would be 1 for cartesian coordinate systems, 2*pi*r for cylindrical coordinate systems, and 4*pi*r^2 for spherical coordinate systems
coord_typeThe coordinate system type, e.g. cartesian (COORD_XYZ), cylindrical (COORD_RZ), or spherical (COORD_RSPHERICAL)
rz_radial_coordThe index at which to index point for the radial coordinate when in a cylindrical coordinate system

Definition at line 202 of file MooseMeshUtils.h.

206{
207 switch (coord_type)
208 {
209 case Moose::COORD_XYZ:
210 factor = 1.0;
211 break;
212 case Moose::COORD_RZ:
213 {
214 mooseAssert(rz_radial_coord != libMesh::invalid_uint,
215 "Must pass in a valid rz radial coordinate");
216 factor = 2 * M_PI * point(rz_radial_coord);
217 break;
218 }
220 factor = 4 * M_PI * point(0) * point(0);
221 break;
222 default:
223 mooseError("Unknown coordinate system");
224 }
225}
@ COORD_RZ
Definition MooseTypes.h:871
@ COORD_RSPHERICAL
Definition MooseTypes.h:872
@ COORD_XYZ
Definition MooseTypes.h:870

Referenced by computeFiniteVolumeCoords(), coordTransformFactor(), Moose::FV::greenGaussGradient(), and Moose::FV::loopOverElemFaceInfo().

◆ coordTransformFactorRZGeneral()

template<typename P , typename C >
void MooseMeshUtils::coordTransformFactorRZGeneral ( const P &  point,
const std::pair< Point, RealVectorValue > &  axis,
C &  factor 
)

Computes a coordinate transformation factor for a general axisymmetric axis.

Parameters
[in]pointThe libMesh Point in space where we are evaluating the factor
[in]axisThe pair of values defining the general axisymmetric axis. Respectively, the values are the axis starting point and direction.
[out]factorThe coordinate transformation factor

Definition at line 262 of file MooseMeshUtils.h.

265{
266 factor = 2 * M_PI * computeDistanceToAxis<P, C>(point, axis.first, axis.second);
267}

Referenced by coordTransformFactor().

◆ copyIntoMesh()

void MooseMeshUtils::copyIntoMesh ( MeshGenerator &  mg,
UnstructuredMesh &  destination,
const UnstructuredMesh &  source,
const bool  avoid_merging_subdomains,
const bool  avoid_merging_boundaries,
const Parallel::Communicator &  communicator,
const bool  skip_preparation = false 
)

Helper function for copying one mesh into another.

Parameters
mgThe mesh generator calling this function
destinationThe mesh to copy into
sourceThe mesh to copy from
avoid_merging_subdomainsIf true, subdomain IDs in the source mesh will be offset to avoid merging with subdomain IDs in the destination mesh
avoid_merging_boundariesIf true, boundary IDs in the source mesh will be offset to avoid merging with boundary IDs in the destination mesh
communicatorThe communicator for parallel operations
skip_preparationIf true, the destination mesh is not prepared after the copy. A caller that copies many meshes in a row should set this and prepare the destination once at the end, since preparing it after every copy makes the total cost quadratic in the number of copies.

Definition at line 1339 of file MooseMeshUtils.C.

1346{
1347 dof_id_type node_delta = destination.max_node_id();
1348 dof_id_type elem_delta = destination.max_elem_id();
1349
1350 unique_id_type unique_delta =
1351#ifdef LIBMESH_ENABLE_UNIQUE_ID
1352 destination.parallel_max_unique_id();
1353#else
1354 0;
1355#endif
1356
1357 // Prevent overlaps by offsetting the subdomains in
1358 std::unordered_map<subdomain_id_type, subdomain_id_type> id_remapping;
1359 unsigned int block_offset = 0;
1360 if (avoid_merging_subdomains)
1361 {
1362 // Note: if performance becomes an issue, this is overkill for just getting the max node id
1363 std::set<subdomain_id_type> source_ids;
1364 std::set<subdomain_id_type> dest_ids;
1365
1366 // We need source subdomain ids already cached; libMesh will
1367 // scream otherwise
1368 source.subdomain_ids(source_ids, true);
1369
1370 // Our destination is non-const, so we can fix any missing caches
1371 if (!destination.preparation().has_cached_elem_data)
1372 destination.cache_elem_data();
1373
1374 destination.subdomain_ids(dest_ids, true);
1375
1376 mooseAssert(source_ids.size(), "Should have a subdomain");
1377 mooseAssert(dest_ids.size(), "Should have a subdomain");
1378 unsigned int max_dest_bid = *dest_ids.rbegin();
1379 unsigned int min_source_bid = *source_ids.begin();
1380 communicator.max(max_dest_bid);
1381 communicator.min(min_source_bid);
1382 block_offset = 1 + max_dest_bid - min_source_bid;
1383 for (const auto bid : source_ids)
1384 id_remapping[bid] = block_offset + bid;
1385 }
1386
1387 // Copy mesh data over from the other mesh
1388 destination.copy_nodes_and_elements(source,
1389 // Skipping this should cause the neighbors
1390 // to simply be copied from the other mesh
1391 // (which makes sense and is way faster)
1392 /*skip_find_neighbors = */ true,
1393 elem_delta,
1394 node_delta,
1395 unique_delta,
1396 avoid_merging_subdomains ? &id_remapping : nullptr,
1397 skip_preparation);
1398
1399 // Get an offset to prevent overlaps / wild merging between boundaries
1400 BoundaryInfo & boundary = destination.get_boundary_info();
1401 const BoundaryInfo & other_boundary = source.get_boundary_info();
1402
1403 unsigned int bid_offset = 0;
1404 if (avoid_merging_boundaries)
1405 {
1406 const auto boundary_ids = boundary.get_boundary_ids();
1407 const auto other_boundary_ids = other_boundary.get_boundary_ids();
1408 unsigned int max_dest_bid = boundary_ids.size() ? *boundary_ids.rbegin() : 0;
1409 unsigned int min_source_bid = other_boundary_ids.size() ? *other_boundary_ids.begin() : 0;
1410 communicator.max(max_dest_bid);
1411 communicator.min(min_source_bid);
1412 bid_offset = 1 + max_dest_bid - min_source_bid;
1413 }
1414
1415 // Note: the code below originally came from ReplicatedMesh::stitch_mesh_helper()
1416 // in libMesh replicated_mesh.C around line 1203
1417
1418 // Copy BoundaryInfo from other_mesh too. We do this via the
1419 // list APIs rather than element-by-element for speed.
1420 for (const auto & t : other_boundary.build_node_list())
1421 boundary.add_node(std::get<0>(t) + node_delta, bid_offset + std::get<1>(t));
1422
1423 for (const auto & t : other_boundary.build_side_list())
1424 boundary.add_side(std::get<0>(t) + elem_delta, std::get<1>(t), bid_offset + std::get<2>(t));
1425
1426 for (const auto & t : other_boundary.build_edge_list())
1427 boundary.add_edge(std::get<0>(t) + elem_delta, std::get<1>(t), bid_offset + std::get<2>(t));
1428
1429 for (const auto & t : other_boundary.build_shellface_list())
1430 boundary.add_shellface(
1431 std::get<0>(t) + elem_delta, std::get<1>(t), bid_offset + std::get<2>(t));
1432
1433 // Check for the case with two block ids sharing the same name
1434 if (avoid_merging_subdomains)
1435 {
1436 mooseAssert(mg.parameters().isParamDefined("avoid_merging_subdomains"),
1437 "Missing parameter in the mesh generator calling this function: "
1438 "avoid_merging_subdomains. Considering setting avoid_merging_subdomains to true.");
1439 for (const auto & [block_id, block_name] : destination.get_subdomain_name_map())
1440 for (const auto & [source_id, source_name] : source.get_subdomain_name_map())
1441 if (block_name == source_name)
1442 mg.paramWarning(
1443 "avoid_merging_subdomains",
1444 "Not merging subdomains is creating two subdomains with the same name '" +
1445 block_name + "' but different ids: " + std::to_string(source_id) + " & " +
1446 std::to_string(block_id + block_offset) +
1447 ".\n We recommend using a RenameBlockGenerator to prevent this as you "
1448 "will get errors reading the Exodus output later.");
1449 }
1450
1451 for (const auto & [block_id, block_name] : source.get_subdomain_name_map())
1452 destination.set_subdomain_name_map().insert(
1453 std::make_pair<SubdomainID, SubdomainName>(block_id + block_offset, block_name));
1454
1455 // Check for the case with two boundary ids sharing the same name
1456 if (avoid_merging_boundaries)
1457 {
1458 mooseAssert(mg.parameters().isParamDefined("avoid_merging_boundaries"),
1459 "Missing parameter in the mesh generator calling this function: "
1460 "avoid_merging_boundaries. Considering setting avoid_merging_boundaries to true.");
1461 for (const auto & [b_id, b_name] : other_boundary.get_sideset_name_map())
1462 for (const auto & [source_id, source_name] : boundary.get_sideset_name_map())
1463 if (b_name == source_name)
1464 mg.paramWarning(
1465 "avoid_merging_boundaries",
1466 "Not merging boundaries is creating two sidesets with the same name '" + b_name +
1467 "' but different ids: " + std::to_string(source_id) + " & " +
1468 std::to_string(b_id + bid_offset) +
1469 ".\n We recommend using a RenameBoundaryGenerator to prevent this as you "
1470 "will get errors reading the Exodus output later.");
1471 for (const auto & [b_id, b_name] : other_boundary.get_nodeset_name_map())
1472 for (const auto & [source_id, source_name] : boundary.get_nodeset_name_map())
1473 if (b_name == source_name)
1474 mg.paramWarning(
1475 "avoid_merging_boundaries",
1476 "Not merging boundaries is creating two nodesets with the same name '" + b_name +
1477 "' but different ids: " + std::to_string(source_id) + " & " +
1478 std::to_string(b_id + bid_offset) +
1479 ".\n We recommend using a RenameBoundaryGenerator to prevent this as you "
1480 "will get errors reading the Exodus output later.");
1481 }
1482
1483 for (const auto & [nodeset_id, nodeset_name] : other_boundary.get_nodeset_name_map())
1484 boundary.set_nodeset_name_map().insert(
1485 std::make_pair<BoundaryID, BoundaryName>(nodeset_id + bid_offset, nodeset_name));
1486
1487 for (const auto & [sideset_id, sideset_name] : other_boundary.get_sideset_name_map())
1488 boundary.set_sideset_name_map().insert(
1489 std::make_pair<BoundaryID, BoundaryName>(sideset_id + bid_offset, sideset_name));
1490
1491 for (const auto & [edgeset_id, edgeset_name] : other_boundary.get_edgeset_name_map())
1492 boundary.set_edgeset_name_map().insert(
1493 std::make_pair<BoundaryID, BoundaryName>(edgeset_id + bid_offset, edgeset_name));
1494}
boundary_id_type BoundaryID
subdomain_id_type SubdomainID
bool isParamDefined(const std::string &name) const
Method returns true if the parameter is defined for any type.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const Elem & get(const ElemType type_in)

Referenced by CombinerGenerator::generate(), and XYZDelaunayGenerator::generate().

◆ createSubdomainFromSidesets()

void MooseMeshUtils::createSubdomainFromSidesets ( MeshBase &  mesh,
std::vector< BoundaryName >  boundary_names,
const SubdomainID  new_subdomain_id,
const SubdomainName &  new_subdomain_name 
)

Create a new subdomain by generating new side elements from a list of sidesets in a given mesh.

Parameters
meshThe mesh to work on
boundary_namesThe names of the sidesets to be used to create the new subdomain
new_subdomain_idThe ID of the new subdomain to be created based on the sidesets
new_subdomain_nameThe name of the new subdomain to be created based on the sidesets
type_nameThe type of the mesh generator that is calling this method, used for error messages and debugging purposes.

Definition at line 1153 of file MooseMeshUtils.C.

1157{
1158 // Generate a new block id if one isn't supplied.
1159 SubdomainID new_block_id = new_subdomain_id;
1160
1161 // Make sure our boundary info and parallel counts are setup
1162 if (!mesh.is_prepared())
1163 {
1164 const bool allow_remote_element_removal = mesh.allow_remote_element_removal();
1165 // We want all of our boundary elements available, so avoid removing them if they haven't
1166 // already been so
1167 mesh.allow_remote_element_removal(false);
1168 mesh.complete_preparation();
1169 mesh.allow_remote_element_removal(allow_remote_element_removal);
1170 }
1171
1172 // Check that the sidesets are present in the mesh
1173 for (const auto & sideset : boundary_names)
1174 if (!MooseMeshUtils::hasBoundaryNameOrID(mesh, sideset))
1175 mooseException("The sideset '", sideset, "' was not found within the mesh");
1176
1177 auto sideset_ids = MooseMeshUtils::getBoundaryIDs(mesh, boundary_names, true);
1178 std::set<boundary_id_type> sidesets(sideset_ids.begin(), sideset_ids.end());
1179 auto side_list = mesh.get_boundary_info().build_side_list();
1180 if (!mesh.is_serial() && mesh.comm().size() > 1)
1181 {
1182 std::vector<Elem *> elements_to_send;
1183 unsigned short i_need_boundary_elems = 0;
1184 for (const auto & [elem_id, side, bc_id] : side_list)
1185 {
1186 libmesh_ignore(side);
1187 if (sidesets.count(bc_id))
1188 {
1189 // Whether we have this boundary information through our locally owned element or a ghosted
1190 // element, we'll need the boundary elements for parallel consistent addition
1191 i_need_boundary_elems = 1;
1192 auto * elem = mesh.elem_ptr(elem_id);
1193 if (elem->processor_id() == mesh.processor_id())
1194 elements_to_send.push_back(elem);
1195 }
1196 }
1197
1198 std::set<const Elem *, libMesh::CompareElemIdsByLevel> connected_elements(
1199 elements_to_send.begin(), elements_to_send.end());
1200 std::set<const Node *> connected_nodes;
1201 reconnect_nodes(connected_elements, connected_nodes);
1202 std::set<dof_id_type> connected_node_ids;
1203 for (auto * nd : connected_nodes)
1204 connected_node_ids.insert(nd->id());
1205
1206 std::vector<unsigned short> need_boundary_elems(mesh.comm().size());
1207 mesh.comm().allgather(i_need_boundary_elems, need_boundary_elems);
1208 std::unordered_map<processor_id_type, decltype(elements_to_send)> push_element_data;
1209 std::unordered_map<processor_id_type, decltype(connected_nodes)> push_node_data;
1210
1211 for (const auto pid : index_range(mesh.comm()))
1212 // Don't need to send to self
1213 if (pid != mesh.processor_id() && need_boundary_elems[pid])
1214 {
1215 if (elements_to_send.size())
1216 push_element_data[pid] = elements_to_send;
1217 if (connected_nodes.size())
1218 push_node_data[pid] = connected_nodes;
1219 }
1220
1221 auto node_action_functor = [](processor_id_type, const auto &)
1222 {
1223 // Node packing specialization already has unpacked node into mesh, so nothing to do
1224 };
1225 Parallel::push_parallel_packed_range(mesh.comm(), push_node_data, &mesh, node_action_functor);
1226 auto elem_action_functor = [](processor_id_type, const auto &)
1227 {
1228 // Elem packing specialization already has unpacked elem into mesh, so nothing to do
1229 };
1230 TIMPI::push_parallel_packed_range(mesh.comm(), push_element_data, &mesh, elem_action_functor);
1231
1232 // now that we've gathered everything, we need to rebuild the side list
1233 side_list = mesh.get_boundary_info().build_side_list();
1234 }
1235
1236 // Use libmesh's BoundaryInfo::add_elements to create lower-d elements with interior_parent
1237 // pointers and subdomain IDs set in one pass.
1238 auto & unstr_mesh = libMesh::cast_ref<UnstructuredMesh &>(mesh);
1239 unstr_mesh.get_boundary_info().add_elements(sidesets, unstr_mesh, false, {new_block_id});
1240
1241 // Assign block name, if provided
1242 if (new_subdomain_name.size())
1243 mesh.set_subdomain_name(new_block_id, new_subdomain_name);
1244
1245 const bool skip_partitioning_old = mesh.skip_partitioning();
1246 mesh.skip_partitioning(true);
1247 mesh.prepare_for_use();
1248 mesh.skip_partitioning(skip_partitioning_old);
1249}
std::set< std::string > sideset
uint8_t processor_id_type
void push_parallel_packed_range(const Communicator &comm, MapToContainers &&data, Context *context, const ActionFunctor &act_on_data)
void reconnect_nodes(connected_elem_set_type &connected_elements, connected_node_set_type &connected_nodes)
auto index_range(const T &sizable)

Referenced by Boundary2DDelaunayGenerator::General2DDelaunay(), SurfaceSubdomainsDelaunayRemesher::General2DDelaunay(), Boundary2DDelaunayGenerator::generate(), and LowerDBlockFromSidesetGenerator::generate().

◆ extraElemIntegerSwapParametersProcessor()

void MooseMeshUtils::extraElemIntegerSwapParametersProcessor ( const std::string &  class_name,
const unsigned int  num_sections,
const unsigned int  num_integers,
const std::vector< std::vector< std::vector< dof_id_type > > > &  elem_integers_swaps,
std::vector< std::unordered_map< dof_id_type, dof_id_type > > &  elem_integers_swap_pairs 
)

Reprocess the elem_integers_swaps into maps so they are easier to use.

Parameters
class_namename of the mesh generator class used for exception messages
num_sectionsnumber of sections in the mesh
num_integersnumber of extra element integers in the mesh
elem_integers_swapsvector of vectors of vectors of extra element ids to be swapped
elem_integers_swap_pairsvector of maps of the swapped pairs

Definition at line 800 of file MooseMeshUtils.C.

806{
807 elem_integers_swap_pairs.reserve(num_sections * num_integers);
808 for (const auto i : make_range(num_integers))
809 {
810 const auto & elem_integer_swaps = elem_integers_swaps[i];
811 std::vector<std::unordered_map<dof_id_type, dof_id_type>> elem_integer_swap_pairs;
812 try
813 {
815 "elem_integers_swaps",
816 elem_integer_swaps,
817 elem_integer_swap_pairs,
818 i * num_sections);
819 }
820 catch (const MooseException & e)
821 {
822 throw MooseException(e.what());
823 }
824
825 elem_integers_swap_pairs.insert(elem_integers_swap_pairs.end(),
826 elem_integer_swap_pairs.begin(),
827 elem_integer_swap_pairs.end());
828 }
829}
Provides a way for users to bail out of the current solve.
virtual const char * what() const
Get out the error message.
void idSwapParametersProcessor(const std::string &class_name, const std::string &id_name, const std::vector< std::vector< T > > &id_swaps, std::vector< std::unordered_map< T, T > > &id_swap_pairs, const unsigned int row_index_shift=0)
Reprocess the swap related input parameters to make pairs out of them to ease further processing.

Referenced by AdvancedExtruderGenerator::AdvancedExtruderGenerator().

◆ getAllBoundaryNamesAndIDs() [1/2]

std::set< std::pair< BoundaryName, BoundaryID > > MooseMeshUtils::getAllBoundaryNamesAndIDs ( const libMesh::MeshBase &  mesh)

Get all boundary names and IDs from a mesh.

Parameters
meshthe mesh of interest
Returns
a set of pairs of boundary names and ids

Referenced by AdvancedExtruderGenerator::generate(), and LowerDBlockFromSidesetGenerator::generate().

◆ getAllBoundaryNamesAndIDs() [2/2]

std::set< std::pair< BoundaryName, BoundaryID > > MooseMeshUtils::getAllBoundaryNamesAndIDs ( const MeshBase &  mesh)

Definition at line 200 of file MooseMeshUtils.C.

201{
202 std::set<std::pair<BoundaryName, BoundaryID>> boundaries;
203 const auto & binfo = mesh.get_boundary_info();
204 const auto & boundary_ids = binfo.get_boundary_ids();
205 for (const auto id : boundary_ids)
206 {
207 // if neither a sideset or nodeset, then empty
208 if (binfo.get_sideset_name(id).size())
209 boundaries.insert(std::make_pair(binfo.get_sideset_name(id), id));
210 else
211 boundaries.insert(std::make_pair(binfo.get_nodeset_name(id), id));
212 }
213 return boundaries;
214}

◆ getAllSubdomainNamesAndIDs() [1/2]

std::set< std::pair< SubdomainName, SubdomainID > > MooseMeshUtils::getAllSubdomainNamesAndIDs ( const libMesh::MeshBase &  mesh)

Get all subdomain names and ids from a mesh.

Parameters
meshthe mesh of interest
Returns
a set of pairs of subdomain names and ids

Referenced by AdvancedExtruderGenerator::generate(), and remapSecondarySubdomainIDsForStitching().

◆ getAllSubdomainNamesAndIDs() [2/2]

std::set< std::pair< SubdomainName, SubdomainID > > MooseMeshUtils::getAllSubdomainNamesAndIDs ( const MeshBase &  mesh)

Definition at line 254 of file MooseMeshUtils.C.

255{
256 std::set<std::pair<SubdomainName, SubdomainID>> subdomains;
257 std::set<subdomain_id_type> subdomain_ids;
258 mesh.subdomain_ids(subdomain_ids, /*global*/ true);
259 for (const auto id : subdomain_ids)
260 subdomains.insert(std::make_pair(mesh.subdomain_name(id), id));
261 return subdomains;
262}

◆ getBoundaryID()

BoundaryID MooseMeshUtils::getBoundaryID ( const BoundaryName &  boundary_name,
const MeshBase &  mesh 
)

Gets the boundary ID associated with the given BoundaryName.

This is needed because the BoundaryName can be either an ID or a name. If it is a name, the mesh is queried for the ID associated with said name.

Definition at line 265 of file MooseMeshUtils.C.

266{
268 if (boundary_name.empty())
269 return id;
270
271 if (!MooseUtils::isDigits(boundary_name))
272 id = mesh.get_boundary_info().get_id_by_name(boundary_name);
273 else
274 id = getIDFromName<BoundaryName, BoundaryID>(boundary_name);
275
276 return id;
277}
const BoundaryID INVALID_BOUNDARY_ID
Definition MooseTypes.C:22

Referenced by BoundaryDeletionGenerator::generate(), CutMeshByLevelSetGeneratorBase::generate(), MoveBoundaryNodesToCurveGenerator::generate(), PolyLineMeshFollowingNodeSetGenerator::generate(), RenameBoundaryGenerator::generate(), MooseMesh::getBoundaryID(), hasBoundaryNameOrID(), MeshTriangulationUtils::outerBoundaryIds(), Moose::PeriodicBCHelper::setupManualPeriodicBoundaries(), and MooseMeshElementConversionUtils::transitionLayerGenerator().

◆ getBoundaryIDs() [1/4]

std::vector< BoundaryID > MooseMeshUtils::getBoundaryIDs ( const libMesh::MeshBase &  mesh,
const std::vector< BoundaryName > &  boundary_name,
bool  generate_unknown 
)

Gets the boundary IDs with their names.

The ordering of the returned boundary ID vector matches the vector of the boundary names in boundary_name.

When a boundary name is not available in the mesh, if generate_unknown is true a non-existant boundary ID will be returned, otherwise a BoundaryInfo::invalid_id will be returned.

If generate_unknown is true and !mesh.preparation().has_boundary_id_sets, this must be called across all ranks for synchronization.

◆ getBoundaryIDs() [2/4]

std::vector< BoundaryID > MooseMeshUtils::getBoundaryIDs ( const libMesh::MeshBase &  mesh,
const std::vector< BoundaryName > &  boundary_name,
bool  generate_unknown,
const std::set< BoundaryID > &  mesh_boundary_ids 
)

Gets the boundary IDs with their names.

The ordering of the returned boundary ID vector matches the vector of the boundary names in boundary_name.

When a boundary name is not available in the mesh, if generate_unknown is true a non-existant boundary ID will be returned, otherwise a BoundaryInfo::invalid_id will be returned.

If generate_unknown is true and !mesh.preparation().has_boundary_id_sets, this must be called across all ranks for synchronization.

Referenced by BoundaryPreservedMarker::BoundaryPreservedMarker(), BoundaryLayerUtils::buildBoundaryLayerRing(), buildPolyLineMesh(), MeshExtruderGenerator::changeID(), createSubdomainFromSidesets(), MeshTriangulationUtils::finalizeTriangulation(), FunctorNodalCorrector::FunctorNodalCorrector(), Boundary2DDelaunayGenerator::General2DDelaunay(), AdvancedExtruderGenerator::generate(), BoundaryLayerSubdomainGenerator::generate(), BoundingBoxNodeSetGenerator::generate(), BreakBoundaryOnSubdomainGenerator::generate(), CircularBoundaryCorrectionGenerator::generate(), CoarsenSurfaceMeshAlongSidesetGenerator::generate(), ElementDeletionGeneratorBase::generate(), ExtraNodesetGenerator::generate(), FillBetweenSidesetsGenerator::generate(), MeshDiagnosticsGenerator::generate(), ParsedGenerateNodeset::generate(), ParsedGenerateSideset::generate(), PolyLineMeshFollowingNodeSetGenerator::generate(), RefineSidesetGenerator::generate(), SideSetsAroundSubdomainGenerator::generate(), SideSetsBetweenSubdomainsGenerator::generate(), SideSetsFromBoundingBoxGenerator::generate(), SideSetsFromNormalsGenerator::generate(), SideSetsFromPointsGenerator::generate(), StackGenerator::generate(), XYDelaunayGenerator::generate(), XYTriangleBoundaryLayerGenerator::generate(), PatternedMeshGenerator::generate(), getBoundaryIDs(), MooseMesh::getBoundaryIDs(), getBoundaryIDSet(), NodeSetsGeneratorBase::setup(), and SideSetsGeneratorBase::setup().

◆ getBoundaryIDs() [3/4]

std::vector< boundary_id_type > MooseMeshUtils::getBoundaryIDs ( const MeshBase &  mesh,
const std::vector< BoundaryName > &  boundary_name,
bool  generate_unknown 
)

Definition at line 107 of file MooseMeshUtils.C.

110{
111 return getBoundaryIDs(
112 mesh, boundary_name, generate_unknown, mesh.get_boundary_info().get_boundary_ids());
113}

◆ getBoundaryIDs() [4/4]

std::vector< boundary_id_type > MooseMeshUtils::getBoundaryIDs ( const MeshBase &  mesh,
const std::vector< BoundaryName > &  boundary_name,
bool  generate_unknown,
const std::set< BoundaryID > &  mesh_boundary_ids 
)

If the conversion from a name to a number fails, that means that this must be a named boundary. We will look in the complete map for this sideset and create a new name/ID pair if requested.

Definition at line 116 of file MooseMeshUtils.C.

120{
121 const BoundaryInfo & boundary_info = mesh.get_boundary_info();
122 const std::map<BoundaryID, std::string> & sideset_map = boundary_info.get_sideset_name_map();
123 const std::map<BoundaryID, std::string> & nodeset_map = boundary_info.get_nodeset_name_map();
124
125 /* It is required to generate a new ID for a given name. It is used often in mesh modifiers such
126 * as SideSetsBetweenSubdomains. Then we need to check the current boundary ids since they are
127 * changing during "mesh modify()", and figure out the right max boundary ID. Most of mesh
128 * modifiers are running in serial, and we won't involve a global communication.
129 */
130 BoundaryID max_boundary_id = 0;
131 if (generate_unknown)
132 {
133 bool has_boundary_id_sets = mesh.preparation().has_boundary_id_sets;
134
135 // Ideally, this requirement should be able to be enforced earlier when we
136 // get the name maps. However, that preparedness check on sideset and
137 // nodeset maps doesn't exist yet.
138 if (!has_boundary_id_sets)
139 libmesh_parallel_only(mesh.comm());
140
141 const auto & bids = has_boundary_id_sets ? boundary_info.get_global_boundary_ids()
142 : boundary_info.get_boundary_ids();
143 if (bids.size())
144 max_boundary_id = *(bids.rbegin());
145 if (!has_boundary_id_sets)
146 mesh.comm().max(max_boundary_id);
147 }
148
149 std::vector<BoundaryID> ids(boundary_name.size());
150 for (const auto i : index_range(boundary_name))
151 {
152 if (boundary_name[i] == "ANY_BOUNDARY_ID")
153 {
154 ids.assign(mesh_boundary_ids.begin(), mesh_boundary_ids.end());
155 if (i)
156 mooseWarning("You passed \"ANY_BOUNDARY_ID\" in addition to other boundary_names. This "
157 "may be a logic error.");
158 break;
159 }
160
161 if (boundary_name[i].empty() && !generate_unknown)
162 mooseError("Incoming boundary name is empty and we are not generating unknown boundary IDs. "
163 "This is invalid.");
164
165 BoundaryID id;
166
167 if (boundary_name[i].empty() || !MooseUtils::isDigits(boundary_name[i]))
168 {
174 if (generate_unknown &&
175 !MooseUtils::doesMapContainValue(sideset_map, std::string(boundary_name[i])) &&
176 !MooseUtils::doesMapContainValue(nodeset_map, std::string(boundary_name[i])))
177 id = ++max_boundary_id;
178 else
179 id = boundary_info.get_id_by_name(boundary_name[i]);
180 }
181 else
182 id = getIDFromName<BoundaryName, BoundaryID>(boundary_name[i]);
183
184 ids[i] = id;
185 }
186
187 return ids;
188}

◆ getBoundaryIDSet() [1/2]

std::set< BoundaryID > MooseMeshUtils::getBoundaryIDSet ( const libMesh::MeshBase &  mesh,
const std::vector< BoundaryName > &  boundary_name,
bool  generate_unknown 
)

Gets the boundary IDs into a set with their names.

Because libMesh allows the same boundary to have multiple different boundary names, the size of the returned boundary ID set may be smaller than the size of the boundary name vector.

When a boundary name is not available in the mesh, if generate_unknown is true a non-existant boundary ID will be returned, otherwise a BoundaryInfo::invalid_id will be returned.

If generate_unknown is true and !mesh.preparation().has_boundary_id_sets, this must be called across all ranks for synchronization.

Referenced by DomainUserObject::DomainUserObject().

◆ getBoundaryIDSet() [2/2]

std::set< BoundaryID > MooseMeshUtils::getBoundaryIDSet ( const MeshBase &  mesh,
const std::vector< BoundaryName > &  boundary_name,
bool  generate_unknown 
)

Definition at line 191 of file MooseMeshUtils.C.

194{
195 auto boundaries = getBoundaryIDs(mesh, boundary_name, generate_unknown);
196 return std::set<BoundaryID>(boundaries.begin(), boundaries.end());
197}

◆ getBoundaryNodes()

std::set< dof_id_type > MooseMeshUtils::getBoundaryNodes ( const MeshBase &  mesh,
const BoundaryID  boundary_id 
)

Get all the nodes on that particular boundary, whether a nodeset or a sideset.

Note: if the mesh has both a nodeset and a sideset with the same ID, they will both be considered If this is undesirable, renumber one of them prior to calling this routine

Parameters
input_meshThe input mesh to get the map for
boundary_idThe boundary id of interest

Definition at line 1125 of file MooseMeshUtils.C.

1126{
1127 std::set<dof_id_type> boundary_node_ids;
1128 const BoundaryInfo & boundary_info = mesh.get_boundary_info();
1129
1130 // Get all nodes from the sideset with ID of boundary_id
1131 const auto & bc_sides =
1132 boundary_info.build_side_list(libMesh::BoundaryInfo::BCTupleSortBy::BOUNDARY_ID);
1133 for (const auto & [elem_id, side, bc_id] : bc_sides)
1134 {
1135 if (bc_id == boundary_id)
1136 {
1137 const auto elem = mesh.elem_ptr(elem_id);
1138 for (const auto ni : elem->nodes_on_side(side))
1139 boundary_node_ids.insert(elem->node_id(ni));
1140 }
1141 }
1142
1143 // Get all nodes from nodeset with ID of boundary_id
1144 const auto & bc_nodes = boundary_info.build_node_list();
1145 for (const auto & [n_id, bc_id] : bc_nodes)
1146 if (bc_id == boundary_id)
1147 boundary_node_ids.insert(n_id);
1148
1149 return boundary_node_ids;
1150}

Referenced by buildBoundaryNodeToElemMap().

◆ getExtraIDUniqueCombinationMap()

std::unordered_map< dof_id_type, dof_id_type > MooseMeshUtils::getExtraIDUniqueCombinationMap ( const MeshBase &  mesh,
const std::set< SubdomainID > &  block_ids,
std::vector< ExtraElementIDName >  extra_ids 
)

Create a new set of element-wise IDs by finding unique combinations of existing extra ID values.

This function finds the unique combinations by recursively calling itself for extra ID inputs. In the recursive calling, the new unique combinations is determined by combining the extra ID value of current level and the unique combination determined in the previous level in recursion. In the lowest level of recursion, the base combination is set by the unique ID values of the corresponding extra ID.

Parameters
meshinput mesh
block_idsblock ids
extra_idsextra ids
Returns
map of element id to new extra id

Definition at line 416 of file MooseMeshUtils.C.

419{
420 // check block restriction
421 const bool block_restricted = !block_ids.empty();
422 // get element id name of interest in recursive parsing algorithm
423 ExtraElementIDName id_name = extra_ids.back();
424 extra_ids.pop_back();
425 const auto id_index = mesh.get_elem_integer_index(id_name);
426
427 // create base parsed id set
428 if (extra_ids.empty())
429 {
430 // get set of extra id values;
431 std::vector<dof_id_type> ids;
432 {
433 std::set<dof_id_type> ids_set;
434 for (const auto & elem : mesh.active_element_ptr_range())
435 {
436 if (block_restricted && block_ids.find(elem->subdomain_id()) == block_ids.end())
437 continue;
438 const auto id = elem->get_extra_integer(id_index);
439 ids_set.insert(id);
440 }
441 mesh.comm().set_union(ids_set);
442 ids.assign(ids_set.begin(), ids_set.end());
443 }
444
445 // determine new extra id values;
446 std::unordered_map<dof_id_type, dof_id_type> parsed_ids;
447 for (auto & elem : mesh.active_element_ptr_range())
448 {
449 if (block_restricted && block_ids.find(elem->subdomain_id()) == block_ids.end())
450 continue;
451 parsed_ids[elem->id()] = std::distance(
452 ids.begin(), std::lower_bound(ids.begin(), ids.end(), elem->get_extra_integer(id_index)));
453 }
454 return parsed_ids;
455 }
456
457 // if extra_ids is not empty, recursively call getExtraIDUniqueCombinationMap
458 const auto base_parsed_ids =
459 MooseMeshUtils::getExtraIDUniqueCombinationMap(mesh, block_ids, extra_ids);
460 // parsing extra ids based on ref_parsed_ids
461 std::vector<std::pair<dof_id_type, dof_id_type>> unique_ids;
462 {
463 std::set<std::pair<dof_id_type, dof_id_type>> unique_ids_set;
464 for (const auto & elem : mesh.active_element_ptr_range())
465 {
466 if (block_restricted && block_ids.find(elem->subdomain_id()) == block_ids.end())
467 continue;
468 const dof_id_type id1 = libmesh_map_find(base_parsed_ids, elem->id());
469 const dof_id_type id2 = elem->get_extra_integer(id_index);
470 const std::pair<dof_id_type, dof_id_type> ids = std::make_pair(id1, id2);
471 unique_ids_set.insert(ids);
472 }
473 mesh.comm().set_union(unique_ids_set);
474 unique_ids.assign(unique_ids_set.begin(), unique_ids_set.end());
475 }
476
477 std::unordered_map<dof_id_type, dof_id_type> parsed_ids;
478
479 for (const auto & elem : mesh.active_element_ptr_range())
480 {
481 if (block_restricted && block_ids.find(elem->subdomain_id()) == block_ids.end())
482 continue;
483 const dof_id_type id1 = libmesh_map_find(base_parsed_ids, elem->id());
484 const dof_id_type id2 = elem->get_extra_integer(id_index);
485 const dof_id_type new_id = std::distance(
486 unique_ids.begin(),
487 std::lower_bound(unique_ids.begin(), unique_ids.end(), std::make_pair(id1, id2)));
488 parsed_ids[elem->id()] = new_id;
489 }
490
491 return parsed_ids;
492}
std::unordered_map< dof_id_type, dof_id_type > getExtraIDUniqueCombinationMap(const MeshBase &mesh, const std::set< SubdomainID > &block_ids, std::vector< ExtraElementIDName > extra_ids)
Create a new set of element-wise IDs by finding unique combinations of existing extra ID values.

Referenced by ExtraIDIntegralVectorPostprocessor::ExtraIDIntegralVectorPostprocessor(), UniqueExtraIDMeshGenerator::generate(), and getExtraIDUniqueCombinationMap().

◆ getIDFromName()

template<typename T , typename Q >
Q MooseMeshUtils::getIDFromName ( const T &  name)

Converts a given name (BoundaryName or SubdomainName) that is known to only contain digits into a corresponding ID (BoundaryID or SubdomainID) and performs bounds checking to ensure that overflow doesn't happen.

Parameters
nameName that is to be converted into an ID.
Returns
ID type corresponding to the type of name.

Definition at line 446 of file MooseMeshUtils.h.

447{
448 if (!MooseUtils::isDigits(name))
450 "'name' ", name, " should only contain digits that can be converted to a numerical type.");
451 long long id = std::stoll(name);
452 Q id_Q = Q(id);
453 if (id < std::numeric_limits<Q>::min() || id > std::numeric_limits<Q>::max())
454 mooseError(MooseUtils::prettyCppType<T>(&name),
455 " ",
456 name,
457 " is not within the numeric limits of the expected ID type ",
458 MooseUtils::prettyCppType<Q>(&id_Q),
459 ".");
460
461 return id_Q;
462}

◆ getNextFreeBoundaryID()

BoundaryID MooseMeshUtils::getNextFreeBoundaryID ( MeshBase &  input_mesh)

Checks input mesh and returns the largest boundary ID in the mesh plus one, which is a boundary ID in the mesh that is not currently in use.

Parameters
inputmesh over which to compute the next free boundary ID

Definition at line 646 of file MooseMeshUtils.C.

647{
648 if (!input_mesh.preparation().has_boundary_id_sets)
649 input_mesh.get_boundary_info().regenerate_id_sets();
650
651 auto boundary_ids = input_mesh.get_boundary_info().get_boundary_ids();
652 if (boundary_ids.empty())
653 return 0;
654 return (*boundary_ids.rbegin() + 1);
655}

Referenced by MeshTriangulationUtils::finalizeTriangulation(), Boundary2DDelaunayGenerator::General2DDelaunay(), SurfaceSubdomainsDelaunayRemesher::General2DDelaunay(), CutMeshByLevelSetGeneratorBase::generate(), SurfaceSubdomainsDelaunayRemesher::generate(), XYDelaunayGenerator::generate(), XYMeshLineCutter::generate(), XYZDelaunayGenerator::generate(), remapSecondaryBoundaryIDsForStitching(), and MooseMeshElementConversionUtils::transitionLayerGenerator().

◆ getNextFreeSubdomainID()

SubdomainID MooseMeshUtils::getNextFreeSubdomainID ( MeshBase &  input_mesh)

Checks input mesh and returns max(block ID) + 1, which represents a block ID that is not currently in use in the mesh.

Parameters
inputmesh over which to compute the next free block id

Definition at line 537 of file MooseMeshUtils.C.

538{
539 // Call this to get most up to date block id information
540 input_mesh.cache_elem_data();
541
542 std::set<SubdomainID> preexisting_subdomain_ids;
543 input_mesh.subdomain_ids(preexisting_subdomain_ids);
544 if (preexisting_subdomain_ids.empty())
545 return 0;
546 else
547 {
548 const auto highest_subdomain_id =
549 *std::max_element(preexisting_subdomain_ids.begin(), preexisting_subdomain_ids.end());
550 mooseAssert(highest_subdomain_id < std::numeric_limits<SubdomainID>::max(),
551 "A SubdomainID with max possible value was found");
552 return highest_subdomain_id + 1;
553 }
554}

Referenced by MeshTriangulationUtils::finalizeTriangulation(), Boundary2DDelaunayGenerator::General2DDelaunay(), SurfaceSubdomainsDelaunayRemesher::General2DDelaunay(), AdvancedExtruderGenerator::generate(), Boundary2DDelaunayGenerator::generate(), BoundaryLayerSubdomainGenerator::generate(), CutMeshByLevelSetGeneratorBase::generate(), LowerDBlockFromSidesetGenerator::generate(), ProjectSideSetOntoLevelSetGenerator::generate(), SurfaceSubdomainsFromAllNormalsGenerator::generate(), XYZDelaunayGenerator::generate(), TriToQuadConverter::recombine(), remapSecondarySubdomainIDsForStitching(), MeshRepairGenerator::separateSubdomainsByElementType(), TriToQuadConverter::subdivide(), and MooseMeshElementConversionUtils::transitionLayerGenerator().

◆ getSubdomainID()

SubdomainID MooseMeshUtils::getSubdomainID ( const SubdomainName &  subdomain_name,
const MeshBase &  mesh 
)

Gets the subdomain ID associated with the given SubdomainName.

This is needed because the SubdomainName can be either an ID or a name. If it is a name, the mesh is queried for the ID associated with said name.

Definition at line 280 of file MooseMeshUtils.C.

281{
282 if (subdomain_name == "ANY_BLOCK_ID")
283 mooseError("getSubdomainID() does not work with \"ANY_BLOCK_ID\"");
284
286 if (subdomain_name.empty())
287 return id;
288
289 if (!MooseUtils::isDigits(subdomain_name))
290 id = mesh.get_id_by_name(subdomain_name);
291 else
292 id = getIDFromName<SubdomainName, SubdomainID>(subdomain_name);
293
294 return id;
295}
const SubdomainID INVALID_BLOCK_ID
Definition MooseTypes.C:20

Referenced by MeshTriangulationUtils::finalizeTriangulation(), AdvancedExtruderGenerator::generate(), ManifoldSubdomainGenerator::generate(), ParsedExtraElementIDGenerator::generate(), RenameBlockGenerator::generate(), RenumberBySubdomainGenerator::generate(), SubdomainBoundingBoxGenerator::generate(), SubdomainsFromPartitionerGenerator::generate(), UniqueExtraIDMeshGenerator::generate(), XYZDelaunayGenerator::generate(), MooseMesh::getSubdomainID(), getSubdomainIDs(), hasSubdomainName(), TriToQuadConverter::moveSurvivingTriangles(), MooseMeshXYCuttingUtils::quadToTriOnLine(), MooseMeshXYCuttingUtils::quasiTriElementsFixer(), and remapSecondarySubdomainIDsForStitching().

◆ getSubdomainIDs() [1/4]

std::set< subdomain_id_type > MooseMeshUtils::getSubdomainIDs ( const libMesh::MeshBase &  mesh,
const std::set< SubdomainName > &  subdomain_name 
)

◆ getSubdomainIDs() [2/4]

std::vector< subdomain_id_type > MooseMeshUtils::getSubdomainIDs ( const libMesh::MeshBase &  mesh,
const std::vector< SubdomainName > &  subdomain_name 
)

◆ getSubdomainIDs() [3/4]

std::set< subdomain_id_type > MooseMeshUtils::getSubdomainIDs ( const MeshBase &  mesh,
const std::set< SubdomainName > &  subdomain_names 
)

Definition at line 246 of file MooseMeshUtils.C.

247{
248 const auto blk_ids = getSubdomainIDs(
249 mesh, std::vector<SubdomainName>(subdomain_names.begin(), subdomain_names.end()));
250 return {blk_ids.begin(), blk_ids.end()};
251}

◆ getSubdomainIDs() [4/4]

std::vector< subdomain_id_type > MooseMeshUtils::getSubdomainIDs ( const MeshBase &  mesh,
const std::vector< SubdomainName > &  subdomain_names 
)

Definition at line 217 of file MooseMeshUtils.C.

218{
219 std::vector<subdomain_id_type> ids;
220
221 // shortcut for "ANY_BLOCK_ID"
222 if (subdomain_names.size() == 1 && subdomain_names[0] == "ANY_BLOCK_ID")
223 {
224 // since get_mesh_subdomains() requires a prepared mesh, we need to check that here
225 mooseAssert(mesh.is_prepared(),
226 "getSubdomainIDs() should only be called on a prepared mesh if ANY_BLOCK_ID is "
227 "used to query all block IDs");
228 ids.assign(mesh.get_mesh_subdomains().begin(), mesh.get_mesh_subdomains().end());
229 return ids;
230 }
231
232 // loop through subdomain names and get IDs (this preserves the order of subdomain_names)
233 ids.resize(subdomain_names.size());
234 for (auto i : index_range(subdomain_names))
235 {
236 if (subdomain_names[i] == "ANY_BLOCK_ID")
237 mooseError("getSubdomainIDs() accepts \"ANY_BLOCK_ID\" if and only if it is the only "
238 "subdomain name being queried.");
239 ids[i] = MooseMeshUtils::getSubdomainID(subdomain_names[i], mesh);
240 }
241
242 return ids;
243}
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
Gets the subdomain ID associated with the given SubdomainName.

◆ hasBoundaryID()

bool MooseMeshUtils::hasBoundaryID ( const MeshBase &  input_mesh,
const BoundaryID  id 
)

Whether a particular boundary ID exists in the mesh.

Parameters
inputmesh over which to determine boundary IDs
boundaryID

Definition at line 679 of file MooseMeshUtils.C.

680{
681 const BoundaryInfo & boundary_info = input_mesh.get_boundary_info();
682 std::set<boundary_id_type> boundary_ids = boundary_info.get_boundary_ids();
683
684 // On a distributed mesh we may have boundary IDs that only exist on
685 // other processors
686 if (!input_mesh.is_replicated())
687 input_mesh.comm().set_union(boundary_ids);
688
689 return boundary_ids.count(id) && (id != Moose::INVALID_BOUNDARY_ID);
690}

Referenced by MooseMeshXYCuttingUtils::boundaryTriElemImprover(), AdvancedExtruderGenerator::generate(), XYMeshLineCutter::generate(), and hasBoundaryNameOrID().

◆ hasBoundaryName()

bool MooseMeshUtils::hasBoundaryName ( const MeshBase &  mesh,
const BoundaryName &  name 
)

Whether a particular boundary name exists in the mesh.

This returns true if name is non-empty and is a name (not ID) that exists.

Parameters
meshmesh over which to determine boundary names
nameboundary name

Definition at line 693 of file MooseMeshUtils.C.

694{
695 const BoundaryInfo & boundary_info = mesh.get_boundary_info();
696 const BoundaryID id = boundary_info.get_id_by_name(name);
697 return id != Moose::INVALID_BOUNDARY_ID;
698}

Referenced by DomainUserObject::DomainUserObject().

◆ hasBoundaryNameOrID()

bool MooseMeshUtils::hasBoundaryNameOrID ( const MeshBase &  mesh,
const BoundaryName &  name_or_id 
)

Whether a particular boundary name or ID exists in the mesh.

This returns true if name_or_id is non-empty and either a name or ID that exists.

Parameters
meshmesh over which to determine boundary names
name_or_idboundary name or ID

Definition at line 701 of file MooseMeshUtils.C.

702{
703 const auto id = getBoundaryID(name_or_id, mesh);
704 return hasBoundaryID(mesh, id);
705}
bool hasBoundaryID(const MeshBase &input_mesh, const BoundaryID id)
Whether a particular boundary ID exists in the mesh.
BoundaryID getBoundaryID(const BoundaryName &boundary_name, const MeshBase &mesh)
Gets the boundary ID associated with the given BoundaryName.

Referenced by createSubdomainFromSidesets(), MultiAppNearestNodeTransfer::execute(), MultiAppUserObjectTransfer::execute(), BreakBoundaryOnSubdomainGenerator::generate(), CircularBoundaryCorrectionGenerator::generate(), CutMeshByLevelSetGeneratorBase::generate(), MeshDiagnosticsGenerator::generate(), MoveBoundaryNodesToCurveGenerator::generate(), MultiAppNearestNodeTransfer::getLocalEntitiesAndComponents(), MultiAppNearestNodeTransfer::getTargetLocalNodes(), MultiAppGeneralFieldTransfer::initialSetup(), and MooseMeshElementConversionUtils::transitionLayerGenerator().

◆ hasSubdomainID()

bool MooseMeshUtils::hasSubdomainID ( const MeshBase &  input_mesh,
const SubdomainID &  id 
)

Whether a particular subdomain ID exists in the mesh.

Parameters
inputmesh over which to determine subdomain IDs
subdomainID

Definition at line 658 of file MooseMeshUtils.C.

659{
660 std::set<SubdomainID> mesh_blocks;
661 input_mesh.subdomain_ids(mesh_blocks);
662
663 // On a distributed mesh we may have sideset IDs that only exist on
664 // other processors
665 if (!input_mesh.is_replicated())
666 input_mesh.comm().set_union(mesh_blocks);
667
668 return mesh_blocks.count(id) && (id != Moose::INVALID_BLOCK_ID);
669}

Referenced by MooseMeshElementConversionUtils::assignConvertedElementsSubdomainNameSuffix(), AdvancedExtruderGenerator::generate(), BlockDeletionGenerator::generate(), BreakMeshByElementGenerator::generate(), CoarsenBlockGenerator::generate(), ManifoldSubdomainGenerator::generate(), MeshExtruderGenerator::generate(), RefineBlockGenerator::generate(), hasSubdomainName(), and remapSecondarySubdomainIDsForStitching().

◆ hasSubdomainName()

bool MooseMeshUtils::hasSubdomainName ( const MeshBase &  input_mesh,
const SubdomainName &  name 
)

◆ idSwapParametersProcessor()

template<typename T >
void MooseMeshUtils::idSwapParametersProcessor ( const std::string &  class_name,
const std::string &  id_name,
const std::vector< std::vector< T > > &  id_swaps,
std::vector< std::unordered_map< T, T > > &  id_swap_pairs,
const unsigned int  row_index_shift = 0 
)

Reprocess the swap related input parameters to make pairs out of them to ease further processing.

Parameters
class_namename of the mesh generator class used for exception messages
id_namename of the parameter to be swapped used for exception messages
id_swapsvector of vectors of the ids to be swapped
id_swap_pairsvector of maps of the swapped pairs
row_index_shiftshift to be applied to the row index in the exception messages (useful when this method is utilized to process a fraction of a long vector)

Definition at line 483 of file MooseMeshUtils.h.

488{
489 id_swap_pairs.resize(id_swaps.size());
490 for (const auto i : index_range(id_swaps))
491 {
492 const auto & swaps = id_swaps[i];
493 auto & swap_pairs = id_swap_pairs[i];
494
495 if (swaps.size() % 2)
496 throw MooseException("Row ",
497 row_index_shift + i + 1,
498 " of ",
499 id_name,
500 " in ",
501 class_name,
502 " does not contain an even number of entries! Num entries: ",
503 swaps.size());
504
505 swap_pairs.reserve(swaps.size() / 2);
506 for (unsigned int j = 0; j < swaps.size(); j += 2)
507 swap_pairs[swaps[j]] = swaps[j + 1];
508 }
509}

Referenced by AdvancedExtruderGenerator::AdvancedExtruderGenerator(), extraElemIntegerSwapParametersProcessor(), and AdvancedExtruderGenerator::generate().

◆ isCoPlanar() [1/3]

bool MooseMeshUtils::isCoPlanar ( const std::vector< Point > &  vec_pts)

Decides whether all the Points of a vector of Points are coplanar.

Parameters
vec_ptsvector of points to be examined
Returns
whether all the Points are in a same plane

Definition at line 510 of file MooseMeshUtils.C.

511{
512 // Assuming that overlapped Points are allowed, the Points that are overlapped with vec_pts[0] are
513 // removed before further calculation.
514 std::vector<Point> vec_pts_nonzero{vec_pts[0]};
515 for (const auto i : index_range(vec_pts))
516 if (!MooseUtils::absoluteFuzzyEqual((vec_pts[i] - vec_pts[0]).norm(), 0.0))
517 vec_pts_nonzero.push_back(vec_pts[i]);
518 // 3 or fewer points are always coplanar
519 if (vec_pts_nonzero.size() <= 3)
520 return true;
521 else
522 {
523 for (const auto i : make_range(vec_pts_nonzero.size() - 1))
524 {
525 const Point tmp_pt = (vec_pts_nonzero[i] - vec_pts_nonzero[0])
526 .cross(vec_pts_nonzero[i + 1] - vec_pts_nonzero[0]);
527 // if the three points are not collinear, use cross product as the normal vector of the plane
528 if (!MooseUtils::absoluteFuzzyEqual(tmp_pt.norm(), 0.0))
529 return isCoPlanar(vec_pts_nonzero, tmp_pt.unit());
530 }
531 }
532 // If all the points are collinear, they are also coplanar
533 return true;
534}

◆ isCoPlanar() [2/3]

bool MooseMeshUtils::isCoPlanar ( const std::vector< Point > &  vec_pts,
const Point  plane_nvec 
)

Decides whether all the Points of a vector of Points are in a plane with a given normal vector.

Parameters
vec_ptsvector of points to be examined
plane_nvecnormal vector of the plane
Returns
whether all the Points are in the same plane with the given normal vector

Definition at line 504 of file MooseMeshUtils.C.

505{
506 return isCoPlanar(vec_pts, plane_nvec, vec_pts.front());
507}
bool isCoPlanar(const std::vector< Point > &vec_pts, const Point plane_nvec, const Point fixed_pt)
Decides whether all the Points of a vector of Points are in a plane that is defined by a normal vecto...

◆ isCoPlanar() [3/3]

bool MooseMeshUtils::isCoPlanar ( const std::vector< Point > &  vec_pts,
const Point  plane_nvec,
const Point  fixed_pt 
)

Decides whether all the Points of a vector of Points are in a plane that is defined by a normal vector and an inplane Point.

Parameters
vec_ptsvector of points to be examined
plane_nvecnormal vector of the plane
fixed_pta Point in the plane
Returns
whether all the Points are in the given plane

Definition at line 495 of file MooseMeshUtils.C.

496{
497 for (const auto & pt : vec_pts)
498 if (!MooseUtils::absoluteFuzzyEqual((pt - fixed_pt) * plane_nvec, 0.0))
499 return false;
500 return true;
501}

Referenced by Positions::arePositionsCoplanar(), FillBetweenPointVectorsTools::fillBetweenPointVectorsGenerator(), SurfaceMeshGeneratorBase::get2DElemNormal(), isCoPlanar(), and isCoPlanar().

◆ makeOrderedNodeList() [1/2]

void MooseMeshUtils::makeOrderedNodeList ( std::vector< std::pair< dof_id_type, dof_id_type > > &  node_assm,
std::vector< dof_id_type > &  elem_id_list,
std::vector< dof_id_type > &  midpoint_node_list,
std::vector< dof_id_type > &  ordered_node_list,
std::vector< dof_id_type > &  ordered_elem_id_list 
)

Convert a list of sides in the form of a vector of pairs of node ids into a list of ordered nodes based on connectivity.

Parameters
node_assmvector of pairs of node ids that represent the sides
elem_id_listvector of element ids that represent the elements that contain the sides
midpoint_node_listvector of node ids that represent the midpoints of the sides for quadratic sides
ordered_node_listvector of node ids that represent the ordered nodes
ordered_elem_id_listvector of element corresponding to the ordered nodes

Definition at line 708 of file MooseMeshUtils.C.

713{
714 // a flag to indicate if the ordered_node_list has been reversed
715 bool is_flipped = false;
716 // Start from the first element, try to find a chain of nodes
717 mooseAssert(node_assm.size(), "Node list must not be empty");
718 ordered_node_list.push_back(node_assm.front().first);
719 if (midpoint_node_list.front() != DofObject::invalid_id)
720 ordered_node_list.push_back(midpoint_node_list.front());
721 ordered_node_list.push_back(node_assm.front().second);
722 ordered_elem_id_list.push_back(elem_id_list.front());
723 // Remove the element that has just been added to ordered_node_list
724 node_assm.erase(node_assm.begin());
725 midpoint_node_list.erase(midpoint_node_list.begin());
726 elem_id_list.erase(elem_id_list.begin());
727 const unsigned int node_assm_size_0 = node_assm.size();
728 for (unsigned int i = 0; i < node_assm_size_0; i++)
729 {
730 // Find nodes to expand the chain
731 dof_id_type end_node_id = ordered_node_list.back();
732 auto isMatch1 = [end_node_id](std::pair<dof_id_type, dof_id_type> old_id_pair)
733 { return old_id_pair.first == end_node_id; };
734 auto isMatch2 = [end_node_id](std::pair<dof_id_type, dof_id_type> old_id_pair)
735 { return old_id_pair.second == end_node_id; };
736 auto result = std::find_if(node_assm.begin(), node_assm.end(), isMatch1);
737 bool match_first;
738 if (result == node_assm.end())
739 {
740 match_first = false;
741 result = std::find_if(node_assm.begin(), node_assm.end(), isMatch2);
742 }
743 else
744 {
745 match_first = true;
746 }
747 // If found, add the node to boundary_ordered_node_list
748 if (result != node_assm.end())
749 {
750 const auto elem_index = std::distance(node_assm.begin(), result);
751 if (midpoint_node_list[elem_index] != DofObject::invalid_id)
752 ordered_node_list.push_back(midpoint_node_list[elem_index]);
753 ordered_node_list.push_back(match_first ? (*result).second : (*result).first);
754 node_assm.erase(result);
755 midpoint_node_list.erase(midpoint_node_list.begin() + elem_index);
756 ordered_elem_id_list.push_back(elem_id_list[elem_index]);
757 elem_id_list.erase(elem_id_list.begin() + elem_index);
758 }
759 // If there are still elements in node_assm and result ==
760 // node_assm.end(), this means the curve is not a loop, the
761 // ordered_node_list is flipped and try the other direction that has not
762 // been examined yet.
763 else
764 {
765 if (is_flipped)
766 // Flipped twice; this means the node list has at least two segments.
767 throw MooseException("The node list provided has more than one segments.");
768
769 // mark the first flip event.
770 is_flipped = true;
771 std::reverse(ordered_node_list.begin(), ordered_node_list.end());
772 std::reverse(midpoint_node_list.begin(), midpoint_node_list.end());
773 std::reverse(ordered_elem_id_list.begin(), ordered_elem_id_list.end());
774 // As this iteration is wasted, set the iterator backward
775 i--;
776 }
777 }
778}

Referenced by MooseMeshXYCuttingUtils::boundaryTriElemImprover(), FillBetweenPointVectorsTools::isClosedLoop(), and makeOrderedNodeList().

◆ makeOrderedNodeList() [2/2]

void MooseMeshUtils::makeOrderedNodeList ( std::vector< std::pair< dof_id_type, dof_id_type > > &  node_assm,
std::vector< dof_id_type > &  elem_id_list,
std::vector< dof_id_type > &  ordered_node_list,
std::vector< dof_id_type > &  ordered_elem_id_list 
)

Convert a list of sides in the form of a vector of pairs of node ids into a list of ordered nodes based on connectivity.

Parameters
node_assmvector of pairs of node ids that represent the sides
elem_id_listvector of element ids that represent the elements that contain the sides
ordered_node_listvector of node ids that represent the ordered nodes
ordered_elem_id_listvector of element corresponding to the ordered nodes

Definition at line 781 of file MooseMeshUtils.C.

785{
786 std::vector<dof_id_type> dummy_midpoint_node_list(node_assm.size(), DofObject::invalid_id);
788 node_assm, elem_id_list, dummy_midpoint_node_list, ordered_node_list, ordered_elem_id_list);
789}
void makeOrderedNodeList(std::vector< std::pair< dof_id_type, dof_id_type > > &node_assm, std::vector< dof_id_type > &elem_id_list, std::vector< dof_id_type > &midpoint_node_list, std::vector< dof_id_type > &ordered_node_list, std::vector< dof_id_type > &ordered_elem_id_list)
Convert a list of sides in the form of a vector of pairs of node ids into a list of ordered nodes bas...

◆ mergeBoundaryIDsWithSameName()

void MooseMeshUtils::mergeBoundaryIDsWithSameName ( MeshBase &  mesh)

Merges the boundary IDs of boundaries that have the same names but different IDs.

Parameters
meshThe input mesh whose boundaries we will modify

Definition at line 36 of file MooseMeshUtils.C.

37{
38 // We check if we have the same boundary name with different IDs. If we do, we assign the
39 // first ID to every occurrence.
40 const auto & side_bd_name_map = mesh.get_boundary_info().get_sideset_name_map();
41 const auto & node_bd_name_map = mesh.get_boundary_info().get_nodeset_name_map();
42 std::map<boundary_id_type, boundary_id_type> same_name_ids;
43
44 auto populate_map = [](const std::map<boundary_id_type, std::string> & map,
45 std::map<boundary_id_type, boundary_id_type> & same_ids)
46 {
47 for (const auto & pair_outer : map)
48 for (const auto & pair_inner : map)
49 // The last condition is needed to make sure we only store one combination
50 if (pair_outer.second == pair_inner.second && pair_outer.first != pair_inner.first &&
51 same_ids.find(pair_inner.first) == same_ids.end())
52 same_ids[pair_outer.first] = pair_inner.first;
53 };
54
55 populate_map(side_bd_name_map, same_name_ids);
56 populate_map(node_bd_name_map, same_name_ids);
57
58 for (const auto & [id1, id2] : same_name_ids)
59 mesh.get_boundary_info().renumber_id(id2, id1);
60}

Referenced by MeshRepairGenerator::generate(), and StitchMeshGenerator::generate().

◆ meshCentroidCalculator()

Point MooseMeshUtils::meshCentroidCalculator ( const MeshBase &  mesh)

Calculates the centroid of a MeshBase.

Parameters
meshinput mesh whose centroid needs to be calculated. It must be partitioned, as the centroid is summed over the local elements
Returns
a Point corresponding to the mesh centroid

Definition at line 309 of file MooseMeshUtils.C.

310{
311 // The is_partitioned flag is not checked, as unset_is_prepared() clears it even when every
312 // element keeps a valid processor id
313 mooseAssert(!mesh.n_unpartitioned_elem(),
314 "Mesh must be partitioned: the centroid is summed over local elements");
315 Point centroid_pt = Point(0.0, 0.0, 0.0);
316 Real vol_tmp = 0.0;
317 for (const auto & elem : mesh.active_local_element_ptr_range())
318 {
319 Real elem_vol = elem->volume();
320 centroid_pt += (elem->true_centroid()) * elem_vol;
321 vol_tmp += elem_vol;
322 }
323 mesh.comm().sum(centroid_pt);
324 mesh.comm().sum(vol_tmp);
325 centroid_pt /= vol_tmp;
326 return centroid_pt;
327}

Referenced by Boundary2DDelaunayGenerator::General2DDelaunay(), SurfaceSubdomainsDelaunayRemesher::General2DDelaunay(), AdvancedExtruderGenerator::generate(), FillBetweenSidesetsGenerator::generate(), and MultiAppPositions::initialize().

◆ nodalQuadraturePointToNodeMap()

std::vector< unsigned int > MooseMeshUtils::nodalQuadraturePointToNodeMap ( const Elem &  elem,
const std::vector< Point > &  q_points 
)

Match the points of a nodal quadrature rule (e.g.

QNodal on a side of a parent element) to the nodes of an element at the same physical locations. The quadrature ordering is not guaranteed to match the node ordering of the element, especially for higher-order faces, so the association is built geometrically so each quadrature value is attached to the node at the same physical point.

Parameters
elemthe element whose nodes are matched
q_pointsthe physical locations of the nodal quadrature points
Returns
a map from each quadrature point index to the local index of the matching node

Definition at line 1656 of file MooseMeshUtils.C.

1657{
1658 const auto n_nodes = elem.n_nodes();
1659 if (q_points.size() != n_nodes)
1660 mooseError("Nodal quadrature produced ",
1661 q_points.size(),
1662 " points for element ",
1663 elem.id(),
1664 " of type ",
1665 libMesh::Utility::enum_to_string<ElemType>(elem.type()),
1666 ", but the element has ",
1667 n_nodes,
1668 " nodes.");
1669
1670 const auto invalid_node = std::numeric_limits<unsigned int>::max();
1671 std::vector<unsigned int> qpoint_to_node(n_nodes, invalid_node);
1672 std::vector<bool> node_used(n_nodes, false);
1673
1674 const Real element_size = elem.hmax();
1675 mooseAssert(
1676 element_size > 0,
1677 "Element " << elem.id() << " of type "
1678 << libMesh::Utility::enum_to_string<ElemType>(elem.type())
1679 << " has a non-positive hmax and cannot be used for nodal quadrature point "
1680 "matching.");
1681
1682 // The nodal quadrature locations and the generated nodes are two floating-point
1683 // reconstructions of the same physical points. Scale the tolerance by element size so the
1684 // matching is insensitive to coordinate magnitude; the 100*TOLERANCE factor allows roundoff
1685 // from FE reinitialization and mesh generation while remaining far below a valid node spacing.
1686 const Real matching_tol = 100 * TOLERANCE * element_size;
1687 const Real matching_tol_sq = matching_tol * matching_tol;
1688
1689 // Each nodal quadrature point should coincide with exactly one still-unused
1690 // node. The unused-node search makes the mapping one-to-one and
1691 // avoids silently assigning two quadrature entries to the same node.
1692 for (const auto qp : make_range(q_points.size()))
1693 {
1694 unsigned int closest_node = invalid_node;
1695 Real closest_dist_sq = std::numeric_limits<Real>::max();
1696 Real second_closest_dist_sq = std::numeric_limits<Real>::max();
1697
1698 for (const auto n : make_range(n_nodes))
1699 {
1700 if (node_used[n])
1701 continue;
1702
1703 const Real dist_sq = (q_points[qp] - elem.point(n)).norm_sq();
1704 if (dist_sq < closest_dist_sq)
1705 {
1706 second_closest_dist_sq = closest_dist_sq;
1707 closest_dist_sq = dist_sq;
1708 closest_node = n;
1709 }
1710 else if (dist_sq < second_closest_dist_sq)
1711 second_closest_dist_sq = dist_sq;
1712 }
1713
1714 if (closest_node == invalid_node || closest_dist_sq > matching_tol_sq)
1715 mooseError("Could not match nodal quadrature point ",
1716 qp,
1717 " at ",
1718 q_points[qp],
1719 " to a node on element ",
1720 elem.id(),
1721 " of type ",
1722 libMesh::Utility::enum_to_string<ElemType>(elem.type()),
1723 ". The nearest unmatched node distance is ",
1724 std::sqrt(closest_dist_sq),
1725 ", which exceeds the tolerance ",
1726 matching_tol,
1727 ".");
1728
1729 if (second_closest_dist_sq <= matching_tol_sq)
1730 mooseError("Nodal quadrature point ",
1731 qp,
1732 " at ",
1733 q_points[qp],
1734 " does not map uniquely to element ",
1735 elem.id(),
1736 " of type ",
1737 libMesh::Utility::enum_to_string<ElemType>(elem.type()),
1738 ". Two unmatched nodes are within the matching tolerance ",
1739 matching_tol,
1740 ".");
1741
1742 qpoint_to_node[qp] = closest_node;
1743 node_used[closest_node] = true;
1744 }
1745
1746#ifdef DEBUG
1747 // In optimized builds the mapping above skips already matched nodes for speed. In debug builds,
1748 // audit the full candidate set to catch ambiguous geometry or accidental many-to-one matches.
1749 std::vector<unsigned int> node_to_qpoint(n_nodes, invalid_node);
1750 for (const auto qp : make_range(q_points.size()))
1751 {
1752 const auto mapped_node = qpoint_to_node[qp];
1753 mooseAssert(mapped_node != invalid_node && mapped_node < n_nodes,
1754 "Invalid node mapping for nodal quadrature point " << qp << ".");
1755 mooseAssert(node_to_qpoint[mapped_node] == invalid_node,
1756 "Node " << mapped_node << " on element " << elem.id()
1757 << " was matched to both nodal quadrature point "
1758 << node_to_qpoint[mapped_node] << " and " << qp << ".");
1759 node_to_qpoint[mapped_node] = qp;
1760
1761 // Check the qp -> node direction without excluding nodes already matched by previous qps.
1762 unsigned int candidate_count = 0;
1763 unsigned int candidate_node = invalid_node;
1764 for (const auto n : make_range(n_nodes))
1765 if ((q_points[qp] - elem.point(n)).norm_sq() <= matching_tol_sq)
1766 {
1767 ++candidate_count;
1768 candidate_node = n;
1769 }
1770
1771 mooseAssert(candidate_count == 1,
1772 "Nodal quadrature point " << qp << " on element " << elem.id() << " has "
1773 << candidate_count << " node candidates within tolerance "
1774 << matching_tol << ".");
1775 mooseAssert(candidate_node == mapped_node,
1776 "Nodal quadrature point "
1777 << qp << " on element " << elem.id() << " was matched to node " << mapped_node
1778 << ", but the full candidate search found node " << candidate_node << ".");
1779 }
1780
1781 for (const auto n : make_range(n_nodes))
1782 {
1783 mooseAssert(node_to_qpoint[n] != invalid_node,
1784 "Node " << n << " on element " << elem.id()
1785 << " was not matched to a nodal quadrature point.");
1786
1787 // Check the node -> qp direction so every node is also uniquely represented.
1788 unsigned int candidate_count = 0;
1789 unsigned int candidate_qp = invalid_node;
1790 for (const auto qp : make_range(q_points.size()))
1791 if ((q_points[qp] - elem.point(n)).norm_sq() <= matching_tol_sq)
1792 {
1793 ++candidate_count;
1794 candidate_qp = qp;
1795 }
1796
1797 mooseAssert(candidate_count == 1,
1798 "Node " << n << " on element " << elem.id() << " has " << candidate_count
1799 << " nodal quadrature point candidates within tolerance " << matching_tol
1800 << ".");
1801 mooseAssert(candidate_qp == node_to_qpoint[n],
1802 "Node " << n << " on element " << elem.id()
1803 << " was matched to nodal quadrature point " << node_to_qpoint[n]
1804 << ", but the full candidate search found point " << candidate_qp << ".");
1805 }
1806#endif
1807
1808 return qpoint_to_node;
1809}
LIBMESH_DEVICE_INLINE auto norm_sq(const T &a)
const dof_id_type n_nodes

Referenced by AutomaticMortarGeneration::computeADNodalNormals(), AutomaticMortarGeneration::computeNodalGeometry(), and AdvancedExtruderGenerator::computeNodeNormals().

◆ remapSecondaryBoundaryIDsForStitching()

std::unordered_map< boundary_id_type, boundary_id_type > MooseMeshUtils::remapSecondaryBoundaryIDsForStitching ( MeshBase &  mesh,
MeshBase &  secondary_mesh,
const std::set< boundary_id_type > &  ids_to_preserve = {} 
)

Renumber the boundaries of a mesh about to be stitched into another so that the boundary names of both meshes survive the stitching.

A boundary whose ID is already used for a different name in the primary mesh is moved to a free ID; boundaries sharing a name keep their ID so that they still merge. Only the secondary mesh is modified.

Parameters
meshthe primary mesh, which the secondary mesh will be stitched into
secondary_meshthe mesh to be stitched in, whose boundaries are renumbered
ids_to_preserveboundary IDs to leave alone, such as the temporary IDs identifying the surfaces being stitched together
Returns
the remapping applied to the secondary mesh, from old to new boundary ID

Definition at line 603 of file MooseMeshUtils.C.

606{
607 // We compare the ids of both meshes, so they need to be synchronized
608 if (!mesh.preparation().has_boundary_id_sets)
609 mesh.get_boundary_info().synchronize_global_id_set();
610 if (!secondary_mesh.preparation().has_boundary_id_sets)
611 secondary_mesh.get_boundary_info().synchronize_global_id_set();
612
613 auto & secondary_boundary_info = secondary_mesh.get_boundary_info();
614 const auto & boundary_info = mesh.get_boundary_info();
615 const auto & mesh_bids = boundary_info.get_global_boundary_ids();
616 const auto secondary_bids = secondary_boundary_info.get_global_boundary_ids();
617
618 auto next_free_id = std::max(getNextFreeBoundaryID(mesh), getNextFreeBoundaryID(secondary_mesh));
619
620 // Only move a boundary that would otherwise inherit another boundary's name. Boundaries that
621 // share a name are left alone so that stitching still merges them
622 std::unordered_map<boundary_id_type, boundary_id_type> id_remapping;
623 for (const auto bid : secondary_bids)
624 if (!ids_to_preserve.count(bid) && mesh_bids.count(bid) &&
625 boundary_info.get_sideset_name(bid) != secondary_boundary_info.get_sideset_name(bid))
626 id_remapping[bid] = next_free_id++;
627
628 for (const auto & [old_id, new_id] : id_remapping)
629 {
630 const auto name = secondary_boundary_info.get_sideset_name(old_id);
631 const auto nodeset_name = secondary_boundary_info.get_nodeset_name(old_id);
632 secondary_boundary_info.renumber_id(old_id, new_id);
633 // renumber_id() does not carry the names over to the new ID
634 secondary_boundary_info.sideset_name(new_id) = name;
635 secondary_boundary_info.nodeset_name(new_id) = nodeset_name;
636 }
637
638 // renumber_id() only operates locally, so the global ids must be synchronized again
639 if (!id_remapping.empty())
640 secondary_boundary_info.synchronize_global_id_set();
641
642 return id_remapping;
643}
BoundaryID getNextFreeBoundaryID(MeshBase &input_mesh)
Checks input mesh and returns the largest boundary ID in the mesh plus one, which is a boundary ID in...

Referenced by XYZDelaunayGenerator::generate().

◆ remapSecondarySubdomainIDsForStitching()

std::unordered_map< subdomain_id_type, subdomain_id_type > MooseMeshUtils::remapSecondarySubdomainIDsForStitching ( MeshBase &  mesh,
MeshBase &  secondary_mesh,
bool  merge_same_name_across_ids = true 
)

Renumber the subdomains of a mesh about to be stitched into another so that the subdomain names of both meshes survive the stitching.

Subdomains sharing a name are merged onto the primary mesh's ID, while a subdomain whose ID is already used for a different name in the primary mesh is moved to a free ID. Both meshes are modified: the secondary mesh's elements are renumbered, and the names of the moved subdomains are added to the primary mesh.

Parameters
meshthe primary mesh, which the secondary mesh will be stitched into
secondary_meshthe mesh to be stitched in, whose subdomains are renumbered
merge_same_name_across_idswhether to merge subdomains that share a name but not an ID. If false, such a pair is left for the caller to handle, which lets a caller that considers it an error keep reporting one
Returns
the remapping applied to the secondary mesh, from old to new subdomain ID

Definition at line 557 of file MooseMeshUtils.C.

560{
561 const auto secondary_subdomains = getAllSubdomainNamesAndIDs(secondary_mesh);
562 // the free id must be present in neither mesh
563 auto next_free_id =
564 std::max(getNextFreeSubdomainID(mesh), getNextFreeSubdomainID(secondary_mesh));
565
566 // Check subdomains in the secondary mesh for the remapping criteria. The remapping is
567 // gathered first then applied in a single pass, so that swapped IDs are not remapped twice
568 std::unordered_map<subdomain_id_type, subdomain_id_type> id_remapping;
569 for (const auto & [bl_name, bl_id] : secondary_subdomains)
570 {
571 subdomain_id_type new_id = bl_id;
572 // If first mesh has the same-name subdomain, we'll use its subdomainID to merge
573 if (merge_same_name_across_ids && !bl_name.empty() && hasSubdomainName(mesh, bl_name))
574 new_id = getSubdomainID(bl_name, mesh);
575 // If first mesh has the same ID BUT different name, change the subdomainID to avoid merging.
576 // A subdomain sharing both its name and ID needs no remapping: it merges as it is
577 else if (hasSubdomainID(mesh, bl_id) && std::as_const(mesh).subdomain_name(bl_id) != bl_name)
578 {
579 new_id = next_free_id++;
580 // the name is pre-positioned, the ID will be added to mesh after stitching
581 mesh.set_subdomain_name(new_id, bl_name, true);
582 }
583
584 if (new_id != bl_id)
585 id_remapping[bl_id] = new_id;
586 }
587
588 if (!id_remapping.empty())
589 {
590 for (auto * const elem : secondary_mesh.element_ptr_range())
591 if (const auto it = id_remapping.find(elem->subdomain_id()); it != id_remapping.end())
592 elem->subdomain_id() = it->second;
593 // The names of the remapped subdomains are already in the first mesh, under the new IDs
594 auto & secondary_name_map = secondary_mesh.set_subdomain_name_map();
595 for (const auto & [old_id, _] : id_remapping)
596 secondary_name_map.erase(old_id);
597 }
598
599 return id_remapping;
600}
bool hasSubdomainName(const MeshBase &input_mesh, const SubdomainName &name)
Whether a particular subdomain name exists in the mesh.
std::set< std::pair< SubdomainName, SubdomainID > > getAllSubdomainNamesAndIDs(const libMesh::MeshBase &mesh)
Get all subdomain names and ids from a mesh.
SubdomainID getNextFreeSubdomainID(MeshBase &input_mesh)
Checks input mesh and returns max(block ID) + 1, which represents a block ID that is not currently in...
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

Referenced by MeshTriangulationUtils::finalizeTriangulation(), StitchMeshGenerator::generate(), and XYZDelaunayGenerator::generate().

◆ stitchMeshesPairwise()

std::unique_ptr< ReplicatedMesh > MooseMeshUtils::stitchMeshesPairwise ( std::vector< std::unique_ptr< ReplicatedMesh > >  meshes,
const std::function< BoundaryID(const MeshBase &)> &  left_boundary_id,
const std::function< BoundaryID(const MeshBase &)> &  right_boundary_id,
const bool  clear_stitched_boundary_ids,
const bool  verbose 
)

Stitch a list of meshes into one by repeatedly stitching neighboring pairs, so that the cost is O(N log N) in the number of meshes N instead of the O(N^2) of stitching each mesh onto one growing mesh.

The left mesh of each pair absorbs the right one, and a stitch appends the elements of the right mesh after those of the left, so the elements of the result are those of meshes[0], then meshes[1], and so on. A node shared by several meshes keeps the copy of the lowest-index mesh. The element and node order is therefore the same as stitching the list one mesh after another onto meshes[0]; reporting id assignment depends on this order.

Parameters
meshesmeshes to stitch, in the order their elements must appear; must not be empty
left_boundary_idreturns the id of the boundary of a given mesh that is stitched to the mesh on its right
right_boundary_idreturns the id of the boundary of a given mesh that is stitched to the mesh on its left
clear_stitched_boundary_idswhether to clear the stitched boundary ids
verbosewhether libMesh prints stitching information
Returns
the stitched mesh

Definition at line 1812 of file MooseMeshUtils.C.

1817{
1818 mooseAssert(!meshes.empty(), "No meshes to stitch");
1819 while (meshes.size() > 1)
1820 {
1821 const auto n = meshes.size();
1822 for (const auto k : make_range(n / 2))
1823 {
1824 auto & left = meshes[2 * k];
1825 auto & right = meshes[2 * k + 1];
1826 left->stitch_meshes(*right,
1827 left_boundary_id(*left),
1828 right_boundary_id(*right),
1829 TOLERANCE,
1830 clear_stitched_boundary_ids,
1831 verbose);
1832 // Free the absorbed mesh now and compact the list in place; k <= 2k, so this never
1833 // overwrites a mesh that is still needed
1834 right.reset();
1835 meshes[k] = std::move(left);
1836 }
1837 if (n % 2)
1838 meshes[n / 2] = std::move(meshes[n - 1]);
1839 meshes.resize((n + 1) / 2);
1840 }
1841 return std::move(meshes.front());
1842}

Referenced by PatternedMeshGenerator::generate().

◆ swapNodesInElem()

void MooseMeshUtils::swapNodesInElem ( Elem &  elem,
const unsigned int  nd1,
const unsigned int  nd2 
)

Swap two nodes within an element.

Parameters
elemelement whose nodes need to be swapped
nd1index of the first node to be swapped
nd2index of the second node to be swapped

Definition at line 792 of file MooseMeshUtils.C.

793{
794 Node * n_temp = elem.node_ptr(nd1);
795 elem.set_node(nd1, elem.node_ptr(nd2));
796 elem.set_node(nd2, n_temp);
797}

Referenced by AdvancedExtruderGenerator::generate().