www.mooseframework.org
MooseMeshUtils.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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/mesh_base.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 {
29 void changeBoundaryId(MeshBase & mesh,
30  const libMesh::boundary_id_type old_id,
31  const libMesh::boundary_id_type new_id,
32  bool delete_prev);
33 
41 void
42 changeSubdomainId(MeshBase & mesh, const subdomain_id_type old_id, const subdomain_id_type new_id);
43 
53 std::vector<BoundaryID> getBoundaryIDs(const libMesh::MeshBase & mesh,
54  const std::vector<BoundaryName> & boundary_name,
55  bool generate_unknown,
56  const std::set<BoundaryID> & mesh_boundary_ids);
57 
67 std::vector<BoundaryID> getBoundaryIDs(const libMesh::MeshBase & mesh,
68  const std::vector<BoundaryName> & boundary_name,
69  bool generate_unknown);
70 
81 std::set<BoundaryID> getBoundaryIDSet(const libMesh::MeshBase & mesh,
82  const std::vector<BoundaryName> & boundary_name,
83  bool generate_unknown);
84 
91 BoundaryID getBoundaryID(const BoundaryName & boundary_name, const MeshBase & mesh);
92 
99 SubdomainID getSubdomainID(const SubdomainName & subdomain_name, const MeshBase & mesh);
100 
108 std::vector<subdomain_id_type> getSubdomainIDs(const libMesh::MeshBase & mesh,
109  const std::vector<SubdomainName> & subdomain_name);
110 
116 Point meshCentroidCalculator(const MeshBase & mesh);
117 
128 template <typename P, typename C>
129 void
130 coordTransformFactor(const P & point,
131  C & factor,
132  const Moose::CoordinateSystemType coord_type,
133  const unsigned int rz_radial_coord = libMesh::invalid_uint)
134 {
135  switch (coord_type)
136  {
137  case Moose::COORD_XYZ:
138  factor = 1.0;
139  break;
140  case Moose::COORD_RZ:
141  {
142  mooseAssert(rz_radial_coord != libMesh::invalid_uint,
143  "Must pass in a valid rz radial coordinate");
144  factor = 2 * M_PI * point(rz_radial_coord);
145  break;
146  }
148  factor = 4 * M_PI * point(0) * point(0);
149  break;
150  default:
151  mooseError("Unknown coordinate system");
152  }
153 }
154 
162 template <typename P, typename C>
163 C
164 computeDistanceToAxis(const P & point, const Point & origin, const RealVectorValue & direction)
165 {
166  return (point - origin).cross(direction).norm();
167 }
168 
177 template <typename P, typename C>
178 void
180  const std::pair<Point, RealVectorValue> & axis,
181  C & factor)
182 {
183  factor = 2 * M_PI * computeDistanceToAxis<P, C>(point, axis.first, axis.second);
184 }
185 
186 inline void
188  const Moose::CoordinateSystemType coord_type,
189  const unsigned int rz_radial_coord = libMesh::invalid_uint)
190 {
191  coordTransformFactor(fi.faceCentroid(), fi.faceCoord(), coord_type, rz_radial_coord);
192 }
193 
208 std::unordered_map<dof_id_type, dof_id_type>
209 getExtraIDUniqueCombinationMap(const MeshBase & mesh,
210  const std::set<SubdomainID> & block_ids,
211  std::vector<ExtraElementIDName> extra_ids);
212 
221 bool isCoPlanar(const std::vector<Point> vec_pts, const Point plane_nvec, const Point fixed_pt);
222 
229 bool isCoPlanar(const std::vector<Point> vec_pts, const Point plane_nvec);
230 
236 bool isCoPlanar(const std::vector<Point> vec_pts);
237 
243 SubdomainID getNextFreeSubdomainID(MeshBase & input_mesh);
244 
251 BoundaryID getNextFreeBoundaryID(MeshBase & input_mesh);
257 bool hasSubdomainID(MeshBase & input_mesh, const SubdomainID & id);
258 
264 bool hasSubdomainName(MeshBase & input_mesh, const SubdomainName & name);
265 
271 bool hasBoundaryID(const MeshBase & input_mesh, const BoundaryID id);
272 
278 bool hasBoundaryName(const MeshBase & input_mesh, const BoundaryName & name);
279 
288 void makeOrderedNodeList(std::vector<std::pair<dof_id_type, dof_id_type>> & node_assm,
289  std::vector<dof_id_type> & elem_id_list,
290  std::vector<dof_id_type> & ordered_node_list,
291  std::vector<dof_id_type> & ordered_elem_id_list);
292 }
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.
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:284
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:70
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:63
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.
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.
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition: FaceInfo.h:35
int8_t boundary_id_type
boundary_id_type BoundaryID
void computeFaceInfoFaceCoord(FaceInfo &fi, const Moose::CoordinateSystemType coord_type, const unsigned int rz_radial_coord=libMesh::invalid_uint)
bool hasSubdomainName(MeshBase &input_mesh, const SubdomainName &name)
Whether a particular subdomain name exists 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.
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...
subdomain_id_type SubdomainID
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 bas...
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.
CoordinateSystemType
Definition: MooseTypes.h:722
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.
SubdomainID getNextFreeSubdomainID(MeshBase &input_mesh)
Checks input mesh and returns max(block ID) + 1, which represents a block ID that is not currently in...
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...
bool hasSubdomainID(MeshBase &input_mesh, const SubdomainID &id)
Whether a particular subdomain ID exists in the mesh.