https://mooseframework.inl.gov
Functions
MooseMeshUtils Namespace Reference

Functions

void mergeBoundaryIDsWithSameName (MeshBase &mesh)
 Merges the boundary IDs of boundaries that have the same names but different IDs. More...
 
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. More...
 
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. More...
 
std::vector< BoundaryIDgetBoundaryIDs (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. More...
 
std::vector< BoundaryIDgetBoundaryIDs (const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown)
 Gets the boundary IDs with their names. More...
 
std::set< BoundaryIDgetBoundaryIDSet (const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown)
 Gets the boundary IDs into a set with their names. More...
 
BoundaryID getBoundaryID (const BoundaryName &boundary_name, const MeshBase &mesh)
 Gets the boundary ID associated with the given BoundaryName. More...
 
SubdomainID getSubdomainID (const SubdomainName &subdomain_name, const MeshBase &mesh)
 Gets the subdomain ID associated with the given SubdomainName. More...
 
std::vector< subdomain_id_typegetSubdomainIDs (const libMesh::MeshBase &mesh, const std::vector< SubdomainName > &subdomain_name)
 Get the associated subdomainIDs for the subdomain names that are passed in. More...
 
std::set< subdomain_id_typegetSubdomainIDs (const libMesh::MeshBase &mesh, const std::set< SubdomainName > &subdomain_name)
 
Point meshCentroidCalculator (const MeshBase &mesh)
 Calculates the centroid of a MeshBase. More...
 
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 factor More...
 
template<typename P , typename C >
computeDistanceToAxis (const P &point, const Point &origin, const RealVectorValue &direction)
 Computes the distance to a general axis. More...
 
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. More...
 
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_typegetExtraIDUniqueCombinationMap (const MeshBase &mesh, const std::set< SubdomainID > &block_ids, std::vector< ExtraElementIDName > extra_ids)
 Crate a new set of element-wise IDs by finding unique combinations of existing extra ID values. More...
 
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. More...
 
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. More...
 
bool isCoPlanar (const std::vector< Point > vec_pts)
 Decides whether all the Points of a vector of Points are coplanar. More...
 
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. More...
 
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. More...
 
bool hasSubdomainID (const MeshBase &input_mesh, const SubdomainID &id)
 Whether a particular subdomain ID exists in the mesh. More...
 
bool hasSubdomainName (const MeshBase &input_mesh, const SubdomainName &name)
 Whether a particular subdomain name exists in the mesh. More...
 
bool hasBoundaryID (const MeshBase &input_mesh, const BoundaryID id)
 Whether a particular boundary ID exists in the mesh. More...
 
bool hasBoundaryName (const MeshBase &input_mesh, const BoundaryName &name)
 Whether a particular boundary name exists in the mesh. More...
 
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. More...
 
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. More...
 
template<typename T , typename 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. More...
 
void swapNodesInElem (Elem &elem, const unsigned int nd1, const unsigned int nd2)
 Swap two nodes within an element. More...
 
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. More...
 
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. More...
 
std::unique_ptr< ReplicatedMesh > buildBoundaryMesh (const ReplicatedMesh &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. More...
 
void mergeBoundaryIDsWithSameName (MeshBase &mesh)
 
void changeBoundaryId (MeshBase &mesh, const boundary_id_type old_id, const boundary_id_type new_id, bool delete_prev)
 
BoundaryID getBoundaryID (const BoundaryName &boundary_name, const MeshBase &mesh)
 
SubdomainID getSubdomainID (const SubdomainName &subdomain_name, const MeshBase &mesh)
 
void changeSubdomainId (MeshBase &mesh, const subdomain_id_type old_id, const subdomain_id_type new_id)
 
Point meshCentroidCalculator (const MeshBase &mesh)
 
std::unordered_map< dof_id_type, dof_id_typegetExtraIDUniqueCombinationMap (const MeshBase &mesh, const std::set< SubdomainID > &block_ids, std::vector< ExtraElementIDName > extra_ids)
 
bool isCoPlanar (const std::vector< Point > vec_pts, const Point plane_nvec, const Point fixed_pt)
 
bool isCoPlanar (const std::vector< Point > vec_pts, const Point plane_nvec)
 
bool isCoPlanar (const std::vector< Point > vec_pts)
 
SubdomainID getNextFreeSubdomainID (MeshBase &input_mesh)
 
BoundaryID getNextFreeBoundaryID (MeshBase &input_mesh)
 
bool hasSubdomainID (const MeshBase &input_mesh, const SubdomainID &id)
 
bool hasSubdomainName (const MeshBase &input_mesh, const SubdomainName &name)
 
bool hasBoundaryID (const MeshBase &input_mesh, const BoundaryID id)
 
bool hasBoundaryName (const MeshBase &input_mesh, const BoundaryName &name)
 
void swapNodesInElem (Elem &elem, const unsigned int nd1, const unsigned int nd2)
 
std::unique_ptr< ReplicatedMeshbuildBoundaryMesh (const ReplicatedMesh &input_mesh, const boundary_id_type boundary_id)
 

Function Documentation

◆ buildBoundaryMesh() [1/2]

std::unique_ptr<ReplicatedMesh> MooseMeshUtils::buildBoundaryMesh ( const ReplicatedMesh &  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

◆ buildBoundaryMesh() [2/2]

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

Definition at line 603 of file MooseMeshUtils.C.

604 {
605  auto poly_mesh = std::make_unique<ReplicatedMesh>(input_mesh.comm());
606 
607  auto side_list = input_mesh.get_boundary_info().build_side_list();
608 
609  std::unordered_map<dof_id_type, dof_id_type> old_new_node_map;
610  for (const auto & bside : side_list)
611  {
612  if (std::get<2>(bside) != boundary_id)
613  continue;
614 
615  const Elem * elem = input_mesh.elem_ptr(std::get<0>(bside));
616  const auto side = std::get<1>(bside);
617  auto side_elem = elem->build_side_ptr(side);
618  auto copy = side_elem->build(side_elem->type());
619 
620  for (const auto i : side_elem->node_index_range())
621  {
622  auto & n = side_elem->node_ref(i);
623 
624  if (old_new_node_map.count(n.id()))
625  copy->set_node(i, poly_mesh->node_ptr(old_new_node_map[n.id()]));
626  else
627  {
628  Node * node = poly_mesh->add_point(side_elem->point(i));
629  copy->set_node(i, node);
630  old_new_node_map[n.id()] = node->id();
631  }
632  }
633  poly_mesh->add_elem(copy.release());
634  }
635  poly_mesh->skip_partitioning(true);
636  poly_mesh->prepare_for_use();
637  if (poly_mesh->n_elem() == 0)
638  mooseError("The input mesh does not have a boundary with id ", boundary_id);
639 
640  return poly_mesh;
641 }
virtual std::unique_ptr< Elem > build_side_ptr(const unsigned int i)=0
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
const Parallel::Communicator & comm() const
const BoundaryInfo & get_boundary_info() const
void build_side_list(std::vector< dof_id_type > &element_id_list, std::vector< unsigned short int > &side_list, std::vector< boundary_id_type > &bc_id_list) const
virtual const Elem * elem_ptr(const dof_id_type i) const override final
dof_id_type id() const

◆ changeBoundaryId() [1/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(), and FillBetweenSidesetsGenerator::generate().

◆ changeBoundaryId() [2/2]

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

Definition at line 54 of file MooseMeshUtils.C.

58 {
59  // Get a reference to our BoundaryInfo object, we will use it several times below...
60  BoundaryInfo & boundary_info = mesh.get_boundary_info();
61 
62  // Container to catch ids passed back from BoundaryInfo
63  std::vector<boundary_id_type> old_ids;
64 
65  // Only level-0 elements store BCs. Loop over them.
66  for (auto & elem : as_range(mesh.level_elements_begin(0), mesh.level_elements_end(0)))
67  {
68  unsigned int n_sides = elem->n_sides();
69  for (const auto s : make_range(n_sides))
70  {
71  boundary_info.boundary_ids(elem, s, old_ids);
72  if (std::find(old_ids.begin(), old_ids.end(), old_id) != old_ids.end())
73  {
74  std::vector<boundary_id_type> new_ids(old_ids);
75  std::replace(new_ids.begin(), new_ids.end(), old_id, new_id);
76  if (delete_prev)
77  {
78  boundary_info.remove_side(elem, s);
79  boundary_info.add_side(elem, s, new_ids);
80  }
81  else
82  boundary_info.add_side(elem, s, new_ids);
83  }
84  }
85  }
86 
87  // Remove any remaining references to the old ID from the
88  // BoundaryInfo object. This prevents things like empty sidesets
89  // from showing up when printing information, etc.
90  if (delete_prev)
91  boundary_info.remove_id(old_id);
92 
93  // global information may now be out of sync
95 }
void remove_id(boundary_id_type id, bool global=false)
void set_isnt_prepared()
MeshBase & mesh
void boundary_ids(const Node *node, std::vector< boundary_id_type > &vec_to_fill) const
const BoundaryInfo & get_boundary_info() const
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
void remove_side(const Elem *elem, const unsigned short int side)
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
IntRange< T > make_range(T beg, T end)

◆ changeSubdomainId() [1/2]

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

◆ changeSubdomainId() [2/2]

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

Definition at line 258 of file MooseMeshUtils.C.

259 {
260  for (const auto & elem : mesh.element_ptr_range())
261  if (elem->subdomain_id() == old_id)
262  elem->subdomain_id() = new_id;
263 
264  // global cached information may now be out of sync
266 }
void set_isnt_prepared()
MeshBase & mesh

◆ 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 174 of file MooseMeshUtils.h.

175 {
176  return (point - origin).cross(direction).norm();
177 }

◆ computeFiniteVolumeCoords()

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

Definition at line 197 of file MooseMeshUtils.h.

200 {
201  coordTransformFactor(fi.faceCentroid(), fi.faceCoord(), coord_type, rz_radial_coord);
202 }
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 factor
const Point & faceCentroid() const
Returns the coordinates of the face centroid.
Definition: FaceInfo.h:71
Real & faceCoord()
Sets/gets the coordinate transformation factor (for e.g.
Definition: FaceInfo.h:64

◆ 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 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 140 of file MooseMeshUtils.h.

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

144 {
145  switch (coord_type)
146  {
147  case Moose::COORD_XYZ:
148  factor = 1.0;
149  break;
150  case Moose::COORD_RZ:
151  {
152  mooseAssert(rz_radial_coord != libMesh::invalid_uint,
153  "Must pass in a valid rz radial coordinate");
154  factor = 2 * M_PI * point(rz_radial_coord);
155  break;
156  }
158  factor = 4 * M_PI * point(0) * point(0);
159  break;
160  default:
161  mooseError("Unknown coordinate system");
162  }
163 }
const unsigned int invalid_uint
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302

◆ 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 189 of file MooseMeshUtils.h.

Referenced by coordTransformFactor().

192 {
193  factor = 2 * M_PI * computeDistanceToAxis<P, C>(point, axis.first, axis.second);
194 }

◆ 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 571 of file MooseMeshUtils.C.

Referenced by AdvancedExtruderGenerator::AdvancedExtruderGenerator().

577 {
578  elem_integers_swap_pairs.reserve(num_sections * num_integers);
579  for (const auto i : make_range(num_integers))
580  {
581  const auto & elem_integer_swaps = elem_integers_swaps[i];
582  std::vector<std::unordered_map<dof_id_type, dof_id_type>> elem_integer_swap_pairs;
583  try
584  {
586  "elem_integers_swaps",
587  elem_integer_swaps,
588  elem_integer_swap_pairs,
589  i * num_sections);
590  }
591  catch (const MooseException & e)
592  {
593  throw MooseException(e.what());
594  }
595 
596  elem_integers_swap_pairs.insert(elem_integers_swap_pairs.end(),
597  elem_integer_swap_pairs.begin(),
598  elem_integer_swap_pairs.end());
599  }
600 }
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...
Provides a way for users to bail out of the current solve.
IntRange< T > make_range(T beg, T end)

◆ getBoundaryID() [1/2]

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.

Referenced by MultiAppNearestNodeTransfer::execute(), BoundaryDeletionGenerator::generate(), RenameBoundaryGenerator::generate(), SideSetsFromBoundingBoxGenerator::generate(), XYDelaunayGenerator::generate(), CutMeshByLevelSetGeneratorBase::generate(), and MooseMesh::getBoundaryID().

◆ getBoundaryID() [2/2]

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

Definition at line 225 of file MooseMeshUtils.C.

Referenced by hasBoundaryName().

226 {
228  if (boundary_name.empty())
229  return id;
230 
231  if (!MooseUtils::isDigits(boundary_name))
232  id = mesh.get_boundary_info().get_id_by_name(boundary_name);
233  else
234  id = getIDFromName<BoundaryName, BoundaryID>(boundary_name);
235 
236  return id;
237 }
const BoundaryID INVALID_BOUNDARY_ID
Definition: MooseTypes.C:22
MeshBase & mesh
const BoundaryInfo & get_boundary_info() const
boundary_id_type get_id_by_name(std::string_view name) const
boundary_id_type BoundaryID
bool isDigits(const std::string &str)
Courtesy https://stackoverflow.com/a/8889045 and https://en.cppreference.com/w/cpp/string/byte/isdigi...
Definition: MooseUtils.h:1208

◆ getBoundaryIDs() [1/2]

std::vector< boundary_id_type > 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 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.

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 107 of file MooseMeshUtils.C.

Referenced by BoundaryPreservedMarker::BoundaryPreservedMarker(), MeshExtruderGenerator::changeID(), SubProblem::checkBoundaryMatProps(), BoundaryLayerSubdomainGenerator::generate(), ExtraNodesetGenerator::generate(), FillBetweenSidesetsGenerator::generate(), LowerDBlockFromSidesetGenerator::generate(), SideSetsFromNormalsGenerator::generate(), BreakBoundaryOnSubdomainGenerator::generate(), PolyLineMeshGenerator::generate(), RefineSidesetGenerator::generate(), SideSetsBetweenSubdomainsGenerator::generate(), SideSetsFromPointsGenerator::generate(), MeshDiagnosticsGenerator::generate(), StackGenerator::generate(), ParsedGenerateNodeset::generate(), AdvancedExtruderGenerator::generate(), CircularBoundaryCorrectionGenerator::generate(), XYDelaunayGenerator::generate(), ElementDeletionGeneratorBase::generate(), ParsedGenerateSideset::generate(), SideSetsAroundSubdomainGenerator::generate(), PatternedMeshGenerator::generate(), BoundingBoxNodeSetGenerator::generate(), getBoundaryIDs(), MooseMesh::getBoundaryIDs(), getBoundaryIDSet(), NodeSetsGeneratorBase::setup(), and SideSetsGeneratorBase::setup().

111 {
112  const BoundaryInfo & boundary_info = mesh.get_boundary_info();
113  const std::map<BoundaryID, std::string> & sideset_map = boundary_info.get_sideset_name_map();
114  const std::map<BoundaryID, std::string> & nodeset_map = boundary_info.get_nodeset_name_map();
115 
116  BoundaryID max_boundary_local_id = 0;
117  /* It is required to generate a new ID for a given name. It is used often in mesh modifiers such
118  * as SideSetsBetweenSubdomains. Then we need to check the current boundary ids since they are
119  * changing during "mesh modify()", and figure out the right max boundary ID. Most of mesh
120  * modifiers are running in serial, and we won't involve a global communication.
121  */
122  if (generate_unknown)
123  {
126  max_boundary_local_id = bids.empty() ? 0 : *(bids.rbegin());
127  /* We should not hit this often */
128  if (!mesh.is_prepared() && !mesh.is_serial())
129  mesh.comm().max(max_boundary_local_id);
130  }
131 
132  BoundaryID max_boundary_id = mesh_boundary_ids.empty() ? 0 : *(mesh_boundary_ids.rbegin());
133 
134  max_boundary_id =
135  max_boundary_id > max_boundary_local_id ? max_boundary_id : max_boundary_local_id;
136 
137  std::vector<BoundaryID> ids(boundary_name.size());
138  for (const auto i : index_range(boundary_name))
139  {
140  if (boundary_name[i] == "ANY_BOUNDARY_ID")
141  {
142  ids.assign(mesh_boundary_ids.begin(), mesh_boundary_ids.end());
143  if (i)
144  mooseWarning("You passed \"ANY_BOUNDARY_ID\" in addition to other boundary_names. This "
145  "may be a logic error.");
146  break;
147  }
148 
149  if (boundary_name[i].empty() && !generate_unknown)
150  mooseError("Incoming boundary name is empty and we are not generating unknown boundary IDs. "
151  "This is invalid.");
152 
153  BoundaryID id;
154 
155  if (boundary_name[i].empty() || !MooseUtils::isDigits(boundary_name[i]))
156  {
162  if (generate_unknown &&
163  !MooseUtils::doesMapContainValue(sideset_map, std::string(boundary_name[i])) &&
164  !MooseUtils::doesMapContainValue(nodeset_map, std::string(boundary_name[i])))
165  id = ++max_boundary_id;
166  else
167  id = boundary_info.get_id_by_name(boundary_name[i]);
168  }
169  else
170  id = getIDFromName<BoundaryName, BoundaryID>(boundary_name[i]);
171 
172  ids[i] = id;
173  }
174 
175  return ids;
176 }
bool is_prepared() const
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:336
bool doesMapContainValue(const std::map< T1, T2 > &the_map, const T2 &value)
This routine is a simple helper function for searching a map by values instead of keys...
Definition: MooseUtils.h:356
const std::map< boundary_id_type, std::string > & get_sideset_name_map() const
MeshBase & mesh
const Parallel::Communicator & comm() const
const BoundaryInfo & get_boundary_info() const
boundary_id_type get_id_by_name(std::string_view name) const
virtual bool is_serial() const
const std::map< boundary_id_type, std::string > & get_nodeset_name_map() const
boundary_id_type BoundaryID
const std::set< boundary_id_type > & get_boundary_ids() const
void max(const T &r, T &o, Request &req) const
const std::set< boundary_id_type > & get_global_boundary_ids() const
bool isDigits(const std::string &str)
Courtesy https://stackoverflow.com/a/8889045 and https://en.cppreference.com/w/cpp/string/byte/isdigi...
Definition: MooseUtils.h:1208
auto index_range(const T &sizable)

◆ getBoundaryIDs() [2/2]

std::vector< boundary_id_type > 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.

Definition at line 98 of file MooseMeshUtils.C.

101 {
102  return getBoundaryIDs(
103  mesh, boundary_name, generate_unknown, mesh.get_boundary_info().get_boundary_ids());
104 }
MeshBase & mesh
const BoundaryInfo & get_boundary_info() const
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.
const std::set< boundary_id_type > & get_boundary_ids() const

◆ getBoundaryIDSet()

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 bounndary 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.

Definition at line 179 of file MooseMeshUtils.C.

Referenced by DomainUserObject::DomainUserObject().

182 {
183  auto boundaries = getBoundaryIDs(mesh, boundary_name, generate_unknown);
184  return std::set<BoundaryID>(boundaries.begin(), boundaries.end());
185 }
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.

◆ getExtraIDUniqueCombinationMap() [1/2]

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 
)

Crate 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

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

◆ getExtraIDUniqueCombinationMap() [2/2]

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 
)

Definition at line 287 of file MooseMeshUtils.C.

290 {
291  // check block restriction
292  const bool block_restricted = !block_ids.empty();
293  // get element id name of interest in recursive parsing algorithm
294  ExtraElementIDName id_name = extra_ids.back();
295  extra_ids.pop_back();
296  const auto id_index = mesh.get_elem_integer_index(id_name);
297 
298  // create base parsed id set
299  if (extra_ids.empty())
300  {
301  // get set of extra id values;
302  std::vector<dof_id_type> ids;
303  {
304  std::set<dof_id_type> ids_set;
305  for (const auto & elem : mesh.active_element_ptr_range())
306  {
307  if (block_restricted && block_ids.find(elem->subdomain_id()) == block_ids.end())
308  continue;
309  const auto id = elem->get_extra_integer(id_index);
310  ids_set.insert(id);
311  }
312  mesh.comm().set_union(ids_set);
313  ids.assign(ids_set.begin(), ids_set.end());
314  }
315 
316  // determine new extra id values;
317  std::unordered_map<dof_id_type, dof_id_type> parsed_ids;
318  for (auto & elem : mesh.active_element_ptr_range())
319  {
320  if (block_restricted && block_ids.find(elem->subdomain_id()) == block_ids.end())
321  continue;
322  parsed_ids[elem->id()] = std::distance(
323  ids.begin(), std::lower_bound(ids.begin(), ids.end(), elem->get_extra_integer(id_index)));
324  }
325  return parsed_ids;
326  }
327 
328  // if extra_ids is not empty, recursively call getExtraIDUniqueCombinationMap
329  const auto base_parsed_ids =
330  MooseMeshUtils::getExtraIDUniqueCombinationMap(mesh, block_ids, extra_ids);
331  // parsing extra ids based on ref_parsed_ids
332  std::vector<std::pair<dof_id_type, dof_id_type>> unique_ids;
333  {
334  std::set<std::pair<dof_id_type, dof_id_type>> unique_ids_set;
335  for (const auto & elem : mesh.active_element_ptr_range())
336  {
337  if (block_restricted && block_ids.find(elem->subdomain_id()) == block_ids.end())
338  continue;
339  const dof_id_type id1 = libmesh_map_find(base_parsed_ids, elem->id());
340  const dof_id_type id2 = elem->get_extra_integer(id_index);
341  const std::pair<dof_id_type, dof_id_type> ids = std::make_pair(id1, id2);
342  unique_ids_set.insert(ids);
343  }
344  mesh.comm().set_union(unique_ids_set);
345  unique_ids.assign(unique_ids_set.begin(), unique_ids_set.end());
346  }
347 
348  std::unordered_map<dof_id_type, dof_id_type> parsed_ids;
349 
350  for (const auto & elem : mesh.active_element_ptr_range())
351  {
352  if (block_restricted && block_ids.find(elem->subdomain_id()) == block_ids.end())
353  continue;
354  const dof_id_type id1 = libmesh_map_find(base_parsed_ids, elem->id());
355  const dof_id_type id2 = elem->get_extra_integer(id_index);
356  const dof_id_type new_id = std::distance(
357  unique_ids.begin(),
358  std::lower_bound(unique_ids.begin(), unique_ids.end(), std::make_pair(id1, id2)));
359  parsed_ids[elem->id()] = new_id;
360  }
361 
362  return parsed_ids;
363 }
std::unordered_map< dof_id_type, dof_id_type > getExtraIDUniqueCombinationMap(const MeshBase &mesh, const std::set< SubdomainID > &block_ids, std::vector< ExtraElementIDName > extra_ids)
Crate a new set of element-wise IDs by finding unique combinations of existing extra ID values...
MeshBase & mesh
const Parallel::Communicator & comm() const
unsigned int get_elem_integer_index(std::string_view name) const
uint8_t dof_id_type
void set_union(T &data, const unsigned int root_id) const

◆ 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 328 of file MooseMeshUtils.h.

329 {
330  if (!MooseUtils::isDigits(name))
331  mooseError(
332  "'name' ", name, " should only contain digits that can be converted to a numerical type.");
333  long long id = std::stoll(name);
334  Q id_Q = Q(id);
336  mooseError(MooseUtils::prettyCppType<T>(&name),
337  " ",
338  name,
339  " is not within the numeric limits of the expected ID type ",
340  MooseUtils::prettyCppType<Q>(&id_Q),
341  ".");
342 
343  return id_Q;
344 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
auto max(const L &left, const R &right)
bool isDigits(const std::string &str)
Courtesy https://stackoverflow.com/a/8889045 and https://en.cppreference.com/w/cpp/string/byte/isdigi...
Definition: MooseUtils.h:1208
auto min(const L &left, const R &right)

◆ getNextFreeBoundaryID() [1/2]

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

Referenced by SideSetsFromBoundingBoxGenerator::generate(), XYZDelaunayGenerator::generate(), XYMeshLineCutter::generate(), XYDelaunayGenerator::generate(), and CutMeshByLevelSetGeneratorBase::generate().

◆ getNextFreeBoundaryID() [2/2]

BoundaryID MooseMeshUtils::getNextFreeBoundaryID ( MeshBase input_mesh)

Definition at line 428 of file MooseMeshUtils.C.

429 {
430  auto boundary_ids = input_mesh.get_boundary_info().get_boundary_ids();
431  if (boundary_ids.empty())
432  return 0;
433  return (*boundary_ids.rbegin() + 1);
434 }
const BoundaryInfo & get_boundary_info() const
const std::set< boundary_id_type > & get_boundary_ids() const

◆ getNextFreeSubdomainID() [1/2]

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

Referenced by BoundaryLayerSubdomainGenerator::generate(), LowerDBlockFromSidesetGenerator::generate(), XYZDelaunayGenerator::generate(), XYDelaunayGenerator::generate(), and MeshRepairGenerator::separateSubdomainsByElementType().

◆ getNextFreeSubdomainID() [2/2]

SubdomainID MooseMeshUtils::getNextFreeSubdomainID ( MeshBase input_mesh)

Definition at line 408 of file MooseMeshUtils.C.

409 {
410  // Call this to get most up to date block id information
411  input_mesh.cache_elem_data();
412 
413  std::set<SubdomainID> preexisting_subdomain_ids;
414  input_mesh.subdomain_ids(preexisting_subdomain_ids);
415  if (preexisting_subdomain_ids.empty())
416  return 0;
417  else
418  {
419  const auto highest_subdomain_id =
420  *std::max_element(preexisting_subdomain_ids.begin(), preexisting_subdomain_ids.end());
421  mooseAssert(highest_subdomain_id < std::numeric_limits<SubdomainID>::max(),
422  "A SubdomainID with max possible value was found");
423  return highest_subdomain_id + 1;
424  }
425 }
auto max(const L &left, const R &right)
void subdomain_ids(std::set< subdomain_id_type > &ids, const bool global=true) const

◆ getSubdomainID() [1/2]

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.

Referenced by UniqueExtraIDMeshGenerator::generate(), RenameBlockGenerator::generate(), ParsedExtraElementIDGenerator::generate(), XYZDelaunayGenerator::generate(), XYDelaunayGenerator::generate(), SubdomainBoundingBoxGenerator::generate(), MooseMesh::getSubdomainID(), getSubdomainIDs(), MooseMeshXYCuttingUtils::quadToTriOnLine(), and MooseMeshXYCuttingUtils::quasiTriElementsFixer().

◆ getSubdomainID() [2/2]

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

Definition at line 240 of file MooseMeshUtils.C.

Referenced by hasSubdomainName().

241 {
242  if (subdomain_name == "ANY_BLOCK_ID")
243  mooseError("getSubdomainID() does not work with \"ANY_BLOCK_ID\"");
244 
246  if (subdomain_name.empty())
247  return id;
248 
249  if (!MooseUtils::isDigits(subdomain_name))
250  id = mesh.get_id_by_name(subdomain_name);
251  else
252  id = getIDFromName<SubdomainName, SubdomainID>(subdomain_name);
253 
254  return id;
255 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
MeshBase & mesh
subdomain_id_type get_id_by_name(std::string_view name) const
const SubdomainID INVALID_BLOCK_ID
Definition: MooseTypes.C:20
bool isDigits(const std::string &str)
Courtesy https://stackoverflow.com/a/8889045 and https://en.cppreference.com/w/cpp/string/byte/isdigi...
Definition: MooseUtils.h:1208

◆ getSubdomainIDs() [1/2]

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

Get the associated subdomainIDs for the subdomain names that are passed in.

Parameters
meshThe mesh
subdomain_nameThe names of the subdomains
Returns
The subdomain ids from the passed subdomain names.

Definition at line 188 of file MooseMeshUtils.C.

Referenced by FEProblemBase::checkProblemIntegrity(), BlockToMeshConverterGenerator::generate(), BreakMeshByBlockGenerator::generate(), RefineBlockGenerator::generate(), CoarsenBlockGenerator::generate(), BlockDeletionGenerator::generate(), ParsedSubdomainGeneratorBase::generate(), XYDelaunayGenerator::generate(), getSubdomainIDs(), MooseMesh::getSubdomainIDs(), BlockWeightedPartitioner::initialize(), LibmeshPartitioner::prepareBlocksForSubdomainPartitioner(), NodeSetsGeneratorBase::setup(), SideSetsGeneratorBase::setup(), and SidesetAroundSubdomainUpdater::SidesetAroundSubdomainUpdater().

189 {
190  std::vector<subdomain_id_type> ids;
191 
192  // shortcut for "ANY_BLOCK_ID"
193  if (subdomain_names.size() == 1 && subdomain_names[0] == "ANY_BLOCK_ID")
194  {
195  // since get_mesh_subdomains() requires a prepared mesh, we need to check that here
196  mooseAssert(mesh.is_prepared(),
197  "getSubdomainIDs() should only be called on a prepared mesh if ANY_BLOCK_ID is "
198  "used to query all block IDs");
199  ids.assign(mesh.get_mesh_subdomains().begin(), mesh.get_mesh_subdomains().end());
200  return ids;
201  }
202 
203  // loop through subdomain names and get IDs (this preserves the order of subdomain_names)
204  ids.resize(subdomain_names.size());
205  for (auto i : index_range(subdomain_names))
206  {
207  if (subdomain_names[i] == "ANY_BLOCK_ID")
208  mooseError("getSubdomainIDs() accepts \"ANY_BLOCK_ID\" if and only if it is the only "
209  "subdomain name being queried.");
210  ids[i] = MooseMeshUtils::getSubdomainID(subdomain_names[i], mesh);
211  }
212 
213  return ids;
214 }
bool is_prepared() const
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
MeshBase & mesh
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
Gets the subdomain ID associated with the given SubdomainName.
const std::set< subdomain_id_type > & get_mesh_subdomains() const
auto index_range(const T &sizable)

◆ getSubdomainIDs() [2/2]

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

Definition at line 217 of file MooseMeshUtils.C.

218 {
219  const auto blk_ids = getSubdomainIDs(
220  mesh, std::vector<SubdomainName>(subdomain_names.begin(), subdomain_names.end()));
221  return {blk_ids.begin(), blk_ids.end()};
222 }
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.

◆ hasBoundaryID() [1/2]

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

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

◆ hasBoundaryID() [2/2]

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

Definition at line 458 of file MooseMeshUtils.C.

Referenced by hasBoundaryName().

459 {
460  const BoundaryInfo & boundary_info = input_mesh.get_boundary_info();
461  std::set<boundary_id_type> boundary_ids = boundary_info.get_boundary_ids();
462 
463  // On a distributed mesh we may have boundary IDs that only exist on
464  // other processors
465  if (!input_mesh.is_replicated())
466  input_mesh.comm().set_union(boundary_ids);
467 
468  return boundary_ids.count(id) && (id != Moose::INVALID_BOUNDARY_ID);
469 }
const BoundaryID INVALID_BOUNDARY_ID
Definition: MooseTypes.C:22
const Parallel::Communicator & comm() const
const BoundaryInfo & get_boundary_info() const
const std::set< boundary_id_type > & get_boundary_ids() const
virtual bool is_replicated() const
void set_union(T &data, const unsigned int root_id) const

◆ hasBoundaryName() [1/2]

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

◆ hasBoundaryName() [2/2]

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

Definition at line 472 of file MooseMeshUtils.C.

473 {
474  const auto id = getBoundaryID(name, input_mesh);
475  return hasBoundaryID(input_mesh, id);
476 }
bool hasBoundaryID(const MeshBase &input_mesh, const BoundaryID id)
BoundaryID getBoundaryID(const BoundaryName &boundary_name, const MeshBase &mesh)

◆ hasSubdomainID() [1/2]

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

Referenced by BlockDeletionGenerator::generate(), CoarsenBlockGenerator::generate(), RefineBlockGenerator::generate(), AdvancedExtruderGenerator::generate(), MeshExtruderGenerator::generate(), and BreakMeshByElementGenerator::generate().

◆ hasSubdomainID() [2/2]

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

Definition at line 437 of file MooseMeshUtils.C.

Referenced by hasSubdomainName().

438 {
439  std::set<SubdomainID> mesh_blocks;
440  input_mesh.subdomain_ids(mesh_blocks);
441 
442  // On a distributed mesh we may have sideset IDs that only exist on
443  // other processors
444  if (!input_mesh.is_replicated())
445  input_mesh.comm().set_union(mesh_blocks);
446 
447  return mesh_blocks.count(id) && (id != Moose::INVALID_BLOCK_ID);
448 }
const Parallel::Communicator & comm() const
const SubdomainID INVALID_BLOCK_ID
Definition: MooseTypes.C:20
void subdomain_ids(std::set< subdomain_id_type > &ids, const bool global=true) const
virtual bool is_replicated() const
void set_union(T &data, const unsigned int root_id) const

◆ hasSubdomainName() [1/2]

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

◆ hasSubdomainName() [2/2]

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

Definition at line 451 of file MooseMeshUtils.C.

452 {
453  const auto id = getSubdomainID(name, input_mesh);
454  return hasSubdomainID(input_mesh, id);
455 }
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
bool hasSubdomainID(const MeshBase &input_mesh, const SubdomainID &id)

◆ 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 365 of file MooseMeshUtils.h.

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

370 {
371  id_swap_pairs.resize(id_swaps.size());
372  for (const auto i : index_range(id_swaps))
373  {
374  const auto & swaps = id_swaps[i];
375  auto & swap_pairs = id_swap_pairs[i];
376 
377  if (swaps.size() % 2)
378  throw MooseException("Row ",
379  row_index_shift + i + 1,
380  " of ",
381  id_name,
382  " in ",
383  class_name,
384  " does not contain an even number of entries! Num entries: ",
385  swaps.size());
386 
387  swap_pairs.reserve(swaps.size() / 2);
388  for (unsigned int j = 0; j < swaps.size(); j += 2)
389  swap_pairs[swaps[j]] = swaps[j + 1];
390  }
391 }
Provides a way for users to bail out of the current solve.
auto index_range(const T &sizable)

◆ isCoPlanar() [1/6]

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

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

◆ isCoPlanar() [2/6]

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

◆ isCoPlanar() [3/6]

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

◆ isCoPlanar() [4/6]

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

Definition at line 366 of file MooseMeshUtils.C.

367 {
368  for (const auto & pt : vec_pts)
369  if (!MooseUtils::absoluteFuzzyEqual((pt - fixed_pt) * plane_nvec, 0.0))
370  return false;
371  return true;
372 }
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
Definition: MooseUtils.h:380

◆ isCoPlanar() [5/6]

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

Definition at line 375 of file MooseMeshUtils.C.

376 {
377  return isCoPlanar(vec_pts, plane_nvec, vec_pts.front());
378 }
bool isCoPlanar(const std::vector< Point > vec_pts)

◆ isCoPlanar() [6/6]

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

Definition at line 381 of file MooseMeshUtils.C.

Referenced by isCoPlanar().

382 {
383  // Assuming that overlapped Points are allowed, the Points that are overlapped with vec_pts[0] are
384  // removed before further calculation.
385  std::vector<Point> vec_pts_nonzero{vec_pts[0]};
386  for (const auto i : index_range(vec_pts))
387  if (!MooseUtils::absoluteFuzzyEqual((vec_pts[i] - vec_pts[0]).norm(), 0.0))
388  vec_pts_nonzero.push_back(vec_pts[i]);
389  // 3 or fewer points are always coplanar
390  if (vec_pts_nonzero.size() <= 3)
391  return true;
392  else
393  {
394  for (const auto i : make_range(vec_pts_nonzero.size() - 1))
395  {
396  const Point tmp_pt = (vec_pts_nonzero[i] - vec_pts_nonzero[0])
397  .cross(vec_pts_nonzero[i + 1] - vec_pts_nonzero[0]);
398  // if the three points are not collinear, use cross product as the normal vector of the plane
399  if (!MooseUtils::absoluteFuzzyEqual(tmp_pt.norm(), 0.0))
400  return isCoPlanar(vec_pts_nonzero, tmp_pt.unit());
401  }
402  }
403  // If all the points are collinear, they are also coplanar
404  return true;
405 }
auto norm() const -> decltype(std::norm(Real()))
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
Definition: MooseUtils.h:380
TypeVector< Real > unit() const
auto norm(const T &a) -> decltype(std::abs(a))
bool isCoPlanar(const std::vector< Point > vec_pts)
IntRange< T > make_range(T beg, T end)
auto index_range(const T &sizable)

◆ 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 479 of file MooseMeshUtils.C.

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

484 {
485  // a flag to indicate if the ordered_node_list has been reversed
486  bool is_flipped = false;
487  // Start from the first element, try to find a chain of nodes
488  mooseAssert(node_assm.size(), "Node list must not be empty");
489  ordered_node_list.push_back(node_assm.front().first);
490  if (midpoint_node_list.front() != DofObject::invalid_id)
491  ordered_node_list.push_back(midpoint_node_list.front());
492  ordered_node_list.push_back(node_assm.front().second);
493  ordered_elem_id_list.push_back(elem_id_list.front());
494  // Remove the element that has just been added to ordered_node_list
495  node_assm.erase(node_assm.begin());
496  midpoint_node_list.erase(midpoint_node_list.begin());
497  elem_id_list.erase(elem_id_list.begin());
498  const unsigned int node_assm_size_0 = node_assm.size();
499  for (unsigned int i = 0; i < node_assm_size_0; i++)
500  {
501  // Find nodes to expand the chain
502  dof_id_type end_node_id = ordered_node_list.back();
503  auto isMatch1 = [end_node_id](std::pair<dof_id_type, dof_id_type> old_id_pair)
504  { return old_id_pair.first == end_node_id; };
505  auto isMatch2 = [end_node_id](std::pair<dof_id_type, dof_id_type> old_id_pair)
506  { return old_id_pair.second == end_node_id; };
507  auto result = std::find_if(node_assm.begin(), node_assm.end(), isMatch1);
508  bool match_first;
509  if (result == node_assm.end())
510  {
511  match_first = false;
512  result = std::find_if(node_assm.begin(), node_assm.end(), isMatch2);
513  }
514  else
515  {
516  match_first = true;
517  }
518  // If found, add the node to boundary_ordered_node_list
519  if (result != node_assm.end())
520  {
521  const auto elem_index = std::distance(node_assm.begin(), result);
522  if (midpoint_node_list[elem_index] != DofObject::invalid_id)
523  ordered_node_list.push_back(midpoint_node_list[elem_index]);
524  ordered_node_list.push_back(match_first ? (*result).second : (*result).first);
525  node_assm.erase(result);
526  midpoint_node_list.erase(midpoint_node_list.begin() + elem_index);
527  ordered_elem_id_list.push_back(elem_id_list[elem_index]);
528  elem_id_list.erase(elem_id_list.begin() + elem_index);
529  }
530  // If there are still elements in node_assm and result ==
531  // node_assm.end(), this means the curve is not a loop, the
532  // ordered_node_list is flipped and try the other direction that has not
533  // been examined yet.
534  else
535  {
536  if (is_flipped)
537  // Flipped twice; this means the node list has at least two segments.
538  throw MooseException("The node list provided has more than one segments.");
539 
540  // mark the first flip event.
541  is_flipped = true;
542  std::reverse(ordered_node_list.begin(), ordered_node_list.end());
543  std::reverse(midpoint_node_list.begin(), midpoint_node_list.end());
544  std::reverse(ordered_elem_id_list.begin(), ordered_elem_id_list.end());
545  // As this iteration is wasted, set the iterator backward
546  i--;
547  }
548  }
549 }
Provides a way for users to bail out of the current solve.
uint8_t dof_id_type

◆ 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 552 of file MooseMeshUtils.C.

556 {
557  std::vector<dof_id_type> dummy_midpoint_node_list(node_assm.size(), DofObject::invalid_id);
559  node_assm, elem_id_list, dummy_midpoint_node_list, ordered_node_list, ordered_elem_id_list);
560 }
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() [1/2]

void MooseMeshUtils::mergeBoundaryIDsWithSameName ( MeshBase mesh)

Definition at line 27 of file MooseMeshUtils.C.

28 {
29  // We check if we have the same boundary name with different IDs. If we do, we assign the
30  // first ID to every occurrence.
31  const auto & side_bd_name_map = mesh.get_boundary_info().get_sideset_name_map();
32  const auto & node_bd_name_map = mesh.get_boundary_info().get_nodeset_name_map();
33  std::map<boundary_id_type, boundary_id_type> same_name_ids;
34 
35  auto populate_map = [](const std::map<boundary_id_type, std::string> & map,
36  std::map<boundary_id_type, boundary_id_type> & same_ids)
37  {
38  for (const auto & pair_outer : map)
39  for (const auto & pair_inner : map)
40  // The last condition is needed to make sure we only store one combination
41  if (pair_outer.second == pair_inner.second && pair_outer.first != pair_inner.first &&
42  same_ids.find(pair_inner.first) == same_ids.end())
43  same_ids[pair_outer.first] = pair_inner.first;
44  };
45 
46  populate_map(side_bd_name_map, same_name_ids);
47  populate_map(node_bd_name_map, same_name_ids);
48 
49  for (const auto & [id1, id2] : same_name_ids)
51 }
const std::map< boundary_id_type, std::string > & get_sideset_name_map() const
MeshBase & mesh
const BoundaryInfo & get_boundary_info() const
void renumber_id(boundary_id_type old_id, boundary_id_type new_id)
const std::map< boundary_id_type, std::string > & get_nodeset_name_map() const

◆ mergeBoundaryIDsWithSameName() [2/2]

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

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

◆ meshCentroidCalculator() [1/2]

Point MooseMeshUtils::meshCentroidCalculator ( const MeshBase &  mesh)

Calculates the centroid of a MeshBase.

Parameters
meshinput mesh whose centroid needs to be calculated
Returns
a Point data containing the mesh centroid

Referenced by FillBetweenSidesetsGenerator::generate(), and MultiAppPositions::initialize().

◆ meshCentroidCalculator() [2/2]

Point MooseMeshUtils::meshCentroidCalculator ( const MeshBase mesh)

Definition at line 269 of file MooseMeshUtils.C.

270 {
271  Point centroid_pt = Point(0.0, 0.0, 0.0);
272  Real vol_tmp = 0.0;
273  for (const auto & elem :
274  as_range(mesh.active_local_elements_begin(), mesh.active_local_elements_end()))
275  {
276  Real elem_vol = elem->volume();
277  centroid_pt += (elem->true_centroid()) * elem_vol;
278  vol_tmp += elem_vol;
279  }
280  mesh.comm().sum(centroid_pt);
281  mesh.comm().sum(vol_tmp);
282  centroid_pt /= vol_tmp;
283  return centroid_pt;
284 }
MeshBase & mesh
const Parallel::Communicator & comm() const
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ swapNodesInElem() [1/2]

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

Referenced by AdvancedExtruderGenerator::generate().

◆ swapNodesInElem() [2/2]

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

Definition at line 563 of file MooseMeshUtils.C.

564 {
565  Node * n_temp = elem.node_ptr(nd1);
566  elem.set_node(nd1, elem.node_ptr(nd2));
567  elem.set_node(nd2, n_temp);
568 }
virtual Node *& set_node(const unsigned int i)
const Node * node_ptr(const unsigned int i) const