www.mooseframework.org
Functions
MooseMeshUtils Namespace Reference

Functions

void changeBoundaryId (MeshBase &mesh, const libMesh::boundary_id_type old_id, const libMesh::boundary_id_type new_id, bool delete_prev)
 
std::vector< libMesh::boundary_id_type > getBoundaryIDs (const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown)
 
std::vector< subdomain_id_type > getSubdomainIDs (const libMesh::MeshBase &mesh, const std::vector< SubdomainName > &subdomain_name)
 

Function Documentation

◆ changeBoundaryId()

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

Definition at line 22 of file MooseMeshUtils.C.

26 {
27  // Get a reference to our BoundaryInfo object, we will use it several times below...
28  libMesh::BoundaryInfo & boundary_info = mesh.get_boundary_info();
29 
30  // Container to catch ids passed back from BoundaryInfo
31  std::vector<libMesh::boundary_id_type> old_ids;
32 
33  // Only level-0 elements store BCs. Loop over them.
34  for (auto & elem : as_range(mesh.level_elements_begin(0), mesh.level_elements_end(0)))
35  {
36  unsigned int n_sides = elem->n_sides();
37  for (unsigned int s = 0; s != n_sides; ++s)
38  {
39  boundary_info.boundary_ids(elem, s, old_ids);
40  if (std::find(old_ids.begin(), old_ids.end(), old_id) != old_ids.end())
41  {
42  std::vector<libMesh::boundary_id_type> new_ids(old_ids);
43  std::replace(new_ids.begin(), new_ids.end(), old_id, new_id);
44  if (delete_prev)
45  {
46  boundary_info.remove_side(elem, s);
47  boundary_info.add_side(elem, s, new_ids);
48  }
49  else
50  boundary_info.add_side(elem, s, new_ids);
51  }
52  }
53  }
54 
55  // Remove any remaining references to the old ID from the
56  // BoundaryInfo object. This prevents things like empty sidesets
57  // from showing up when printing information, etc.
58  if (delete_prev)
59  boundary_info.remove_id(old_id);
60 }

Referenced by MeshExtruderGenerator::changeID().

◆ getBoundaryIDs()

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

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

66 {
67  const libMesh::BoundaryInfo & boundary_info = mesh.get_boundary_info();
68  const std::map<libMesh::boundary_id_type, std::string> & sideset_map =
69  boundary_info.get_sideset_name_map();
70  const std::map<libMesh::boundary_id_type, std::string> & nodeset_map =
71  boundary_info.get_nodeset_name_map();
72 
73  std::set<libMesh::boundary_id_type> boundary_ids = boundary_info.get_boundary_ids();
74 
75  // On a distributed mesh we may have boundary ids that only exist on
76  // other processors.
77  if (!mesh.is_replicated())
78  mesh.comm().set_union(boundary_ids);
79 
80  libMesh::boundary_id_type max_boundary_id = boundary_ids.empty() ? 0 : *(boundary_ids.rbegin());
81 
82  std::vector<libMesh::boundary_id_type> ids(boundary_name.size());
83  for (unsigned int i = 0; i < boundary_name.size(); i++)
84  {
85  if (boundary_name[i] == "ANY_BOUNDARY_ID")
86  {
87  ids.assign(boundary_ids.begin(), boundary_ids.end());
88  if (i)
89  mooseWarning("You passed \"ANY_BOUNDARY_ID\" in addition to other boundary_names. This "
90  "may be a logic error.");
91  break;
92  }
93 
94  libMesh::boundary_id_type id;
95  std::istringstream ss(boundary_name[i]);
96 
97  if (!(ss >> id) || !ss.eof())
98  {
104  if (generate_unknown &&
105  !MooseUtils::doesMapContainValue(sideset_map, std::string(boundary_name[i])) &&
106  !MooseUtils::doesMapContainValue(nodeset_map, std::string(boundary_name[i])))
107  id = ++max_boundary_id;
108  else
109  id = boundary_info.get_id_by_name(boundary_name[i]);
110  }
111 
112  ids[i] = id;
113  }
114 
115  return ids;
116 }

Referenced by MeshExtruderGenerator::changeID(), SubProblem::checkBoundaryMatProps(), ExtraNodesetGenerator::generate(), BreakBoundaryOnSubdomainGenerator::generate(), LowerDBlockFromSidesetGenerator::generate(), SideSetsBetweenSubdomainsGenerator::generate(), SideSetsFromNormalsGenerator::generate(), SideSetsFromPointsGenerator::generate(), SideSetsFromBoundingBoxGenerator::generate(), StackGenerator::generate(), ElementDeletionGeneratorBase::generate(), ParsedGenerateSideset::generate(), SideSetsAroundSubdomainGenerator::generate(), PatternedMeshGenerator::generate(), and BoundingBoxNodeSetGenerator::generate().

◆ getSubdomainIDs()

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

Definition at line 119 of file MooseMeshUtils.C.

120 {
121  std::vector<subdomain_id_type> ids(subdomain_name.size());
122  std::set<subdomain_id_type> mesh_subdomains;
123  mesh.subdomain_ids(mesh_subdomains);
124 
125  for (unsigned int i = 0; i < subdomain_name.size(); i++)
126  {
127  if (subdomain_name[i] == "ANY_BLOCK_ID")
128  {
129  ids.assign(mesh_subdomains.begin(), mesh_subdomains.end());
130  if (i)
131  mooseWarning("You passed \"ANY_BLOCK_ID\" in addition to other block names. This may be a "
132  "logic error.");
133  break;
134  }
135 
136  subdomain_id_type id = Moose::INVALID_BLOCK_ID;
137  std::istringstream ss(subdomain_name[i]);
138 
139  if (!(ss >> id) || !ss.eof())
140  id = mesh.get_id_by_name(subdomain_name[i]);
141 
142  ids[i] = id;
143  }
144 
145  return ids;
146 }

Referenced by SideSetsBetweenSubdomainsGenerator::generate(), and SideSetsAroundSubdomainGenerator::generate().

mooseWarning
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:222
Moose::INVALID_BLOCK_ID
const SubdomainID INVALID_BLOCK_ID
Definition: MooseTypes.C:18
MooseUtils::doesMapContainValue
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:211