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

Referenced by MeshExtruderGenerator::changeID().

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

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

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

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

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

◆ getSubdomainIDs()

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

Definition at line 118 of file MooseMeshUtils.C.

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

119 {
120  std::vector<subdomain_id_type> ids(subdomain_name.size());
121  std::set<subdomain_id_type> mesh_subdomains;
122  mesh.subdomain_ids(mesh_subdomains);
123 
124  for (unsigned int i = 0; i < subdomain_name.size(); i++)
125  {
126  if (subdomain_name[i] == "ANY_BLOCK_ID")
127  {
128  ids.assign(mesh_subdomains.begin(), mesh_subdomains.end());
129  if (i)
130  mooseWarning("You passed \"ANY_BLOCK_ID\" in addition to other block names. This may be a "
131  "logic error.");
132  break;
133  }
134 
135  subdomain_id_type id = Moose::INVALID_BLOCK_ID;
136  std::istringstream ss(subdomain_name[i]);
137 
138  if (!(ss >> id) || !ss.eof())
139  id = mesh.get_id_by_name(subdomain_name[i]);
140 
141  ids[i] = id;
142  }
143 
144  return ids;
145 }
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:219
const SubdomainID INVALID_BLOCK_ID
Definition: MooseTypes.C:16