https://mooseframework.inl.gov
MooseMeshUtils.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "libmesh/replicated_mesh.h"
13 #include "libmesh/boundary_info.h"
14 
15 #include "MooseUtils.h"
16 #include "MooseTypes.h"
17 #include "FaceInfo.h"
18 
19 namespace MooseMeshUtils
20 {
21 
27 void mergeBoundaryIDsWithSameName(MeshBase & mesh);
28 
37 void changeBoundaryId(MeshBase & mesh,
38  const libMesh::boundary_id_type old_id,
39  const libMesh::boundary_id_type new_id,
40  bool delete_prev);
41 
49 void
50 changeSubdomainId(MeshBase & mesh, const subdomain_id_type old_id, const subdomain_id_type new_id);
51 
61 std::vector<BoundaryID> getBoundaryIDs(const libMesh::MeshBase & mesh,
62  const std::vector<BoundaryName> & boundary_name,
63  bool generate_unknown,
64  const std::set<BoundaryID> & mesh_boundary_ids);
65 
75 std::vector<BoundaryID> getBoundaryIDs(const libMesh::MeshBase & mesh,
76  const std::vector<BoundaryName> & boundary_name,
77  bool generate_unknown);
78 
89 std::set<BoundaryID> getBoundaryIDSet(const libMesh::MeshBase & mesh,
90  const std::vector<BoundaryName> & boundary_name,
91  bool generate_unknown);
92 
99 BoundaryID getBoundaryID(const BoundaryName & boundary_name, const MeshBase & mesh);
100 
107 SubdomainID getSubdomainID(const SubdomainName & subdomain_name, const MeshBase & mesh);
108 
116 std::vector<subdomain_id_type> getSubdomainIDs(const libMesh::MeshBase & mesh,
117  const std::vector<SubdomainName> & subdomain_name);
118 std::set<subdomain_id_type> getSubdomainIDs(const libMesh::MeshBase & mesh,
119  const std::set<SubdomainName> & subdomain_name);
120 
126 Point meshCentroidCalculator(const MeshBase & mesh);
127 
138 template <typename P, typename C>
139 void
140 coordTransformFactor(const P & point,
141  C & factor,
142  const Moose::CoordinateSystemType coord_type,
143  const unsigned int rz_radial_coord = libMesh::invalid_uint)
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 }
164 
172 template <typename P, typename C>
173 C
174 computeDistanceToAxis(const P & point, const Point & origin, const RealVectorValue & direction)
175 {
176  return (point - origin).cross(direction).norm();
177 }
178 
187 template <typename P, typename C>
188 void
190  const std::pair<Point, RealVectorValue> & axis,
191  C & factor)
192 {
193  factor = 2 * M_PI * computeDistanceToAxis<P, C>(point, axis.first, axis.second);
194 }
195 
196 inline void
198  const Moose::CoordinateSystemType coord_type,
199  const unsigned int rz_radial_coord = libMesh::invalid_uint)
200 {
201  coordTransformFactor(fi.faceCentroid(), fi.faceCoord(), coord_type, rz_radial_coord);
202 }
203 
218 std::unordered_map<dof_id_type, dof_id_type>
219 getExtraIDUniqueCombinationMap(const MeshBase & mesh,
220  const std::set<SubdomainID> & block_ids,
221  std::vector<ExtraElementIDName> extra_ids);
222 
231 bool isCoPlanar(const std::vector<Point> vec_pts, const Point plane_nvec, const Point fixed_pt);
232 
239 bool isCoPlanar(const std::vector<Point> vec_pts, const Point plane_nvec);
240 
246 bool isCoPlanar(const std::vector<Point> vec_pts);
247 
253 SubdomainID getNextFreeSubdomainID(MeshBase & input_mesh);
254 
261 BoundaryID getNextFreeBoundaryID(MeshBase & input_mesh);
267 bool hasSubdomainID(const MeshBase & input_mesh, const SubdomainID & id);
268 
274 bool hasSubdomainName(const MeshBase & input_mesh, const SubdomainName & name);
275 
281 bool hasBoundaryID(const MeshBase & input_mesh, const BoundaryID id);
282 
288 bool hasBoundaryName(const MeshBase & input_mesh, const BoundaryName & name);
289 
300 void makeOrderedNodeList(std::vector<std::pair<dof_id_type, dof_id_type>> & node_assm,
301  std::vector<dof_id_type> & elem_id_list,
302  std::vector<dof_id_type> & midpoint_node_list,
303  std::vector<dof_id_type> & ordered_node_list,
304  std::vector<dof_id_type> & ordered_elem_id_list);
305 
314 void makeOrderedNodeList(std::vector<std::pair<dof_id_type, dof_id_type>> & node_assm,
315  std::vector<dof_id_type> & elem_id_list,
316  std::vector<dof_id_type> & ordered_node_list,
317  std::vector<dof_id_type> & ordered_elem_id_list);
318 
326 template <typename T, typename Q>
327 Q
328 getIDFromName(const T & name)
329 {
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 }
345 
352 void swapNodesInElem(Elem & elem, const unsigned int nd1, const unsigned int nd2);
353 
363 template <typename T>
364 void
365 idSwapParametersProcessor(const std::string & class_name,
366  const std::string & id_name,
367  const std::vector<std::vector<T>> & id_swaps,
368  std::vector<std::unordered_map<T, T>> & id_swap_pairs,
369  const unsigned int row_index_shift = 0)
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 }
392 
402  const std::string & class_name,
403  const unsigned int num_sections,
404  const unsigned int num_integers,
405  const std::vector<std::vector<std::vector<dof_id_type>>> & elem_integers_swaps,
406  std::vector<std::unordered_map<dof_id_type, dof_id_type>> & elem_integers_swap_pairs);
407 
417 std::unique_ptr<ReplicatedMesh> buildBoundaryMesh(const ReplicatedMesh & input_mesh,
418  const boundary_id_type boundary_id);
419 }
void swapNodesInElem(Elem &elem, const unsigned int nd1, const unsigned int nd2)
Swap two nodes within an element.
std::string name(const ElemQuality q)
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...
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...
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.
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...
const unsigned int invalid_uint
bool hasBoundaryName(const MeshBase &input_mesh, const BoundaryName &name)
Whether a particular boundary name exists in the mesh.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
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
MeshBase & mesh
void coordTransformFactorRZGeneral(const P &point, const std::pair< Point, RealVectorValue > &axis, C &factor)
Computes a coordinate transformation factor for a general axisymmetric axis.
bool hasBoundaryID(const MeshBase &input_mesh, const BoundaryID id)
Whether a particular boundary ID exists in the mesh.
Real & faceCoord()
Sets/gets the coordinate transformation factor (for e.g.
Definition: FaceInfo.h:64
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.
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
Gets the subdomain ID associated with the given SubdomainName.
auto max(const L &left, const R &right)
bool hasSubdomainID(const MeshBase &input_mesh, const SubdomainID &id)
Whether a particular subdomain ID exists in the mesh.
C computeDistanceToAxis(const P &point, const Point &origin, const RealVectorValue &direction)
Computes the distance to a general axis.
BoundaryID getBoundaryID(const BoundaryName &boundary_name, const MeshBase &mesh)
Gets the boundary ID associated with the given BoundaryName.
void computeFiniteVolumeCoords(FaceInfo &fi, const Moose::CoordinateSystemType coord_type, const unsigned int rz_radial_coord=libMesh::invalid_uint)
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition: FaceInfo.h:36
int8_t boundary_id_type
boundary_id_type BoundaryID
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...
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.
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...
bool hasSubdomainName(const MeshBase &input_mesh, const SubdomainName &name)
Whether a particular subdomain name exists 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.
Provides a way for users to bail out of the current solve.
CoordinateSystemType
Definition: MooseTypes.h:809
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.
Point meshCentroidCalculator(const MeshBase &mesh)
Calculates the centroid of a MeshBase.
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 mergeBoundaryIDsWithSameName(MeshBase &mesh)
Merges the boundary IDs of boundaries that have the same names but different IDs. ...
Q getIDFromName(const T &name)
Converts a given name (BoundaryName or SubdomainName) that is known to only contain digits into a cor...
SubdomainID getNextFreeSubdomainID(MeshBase &input_mesh)
Checks input mesh and returns max(block ID) + 1, which represents a block ID that is not currently in...
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
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...
auto min(const L &left, const R &right)
auto index_range(const T &sizable)