www.mooseframework.org
BreakBoundaryOnSubdomain.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
16 
17 #include "MooseMesh.h"
18 #include "MooseUtils.h"
19 
20 template <>
23 {
25  params.addClassDescription("Break boundaries based on the subdomains to which their sides are "
26  "attached. Naming convention for the new boundaries will be the old "
27  "boundary name plus \"_to_\" plus the subdomain name");
28  params.addParam<std::vector<BoundaryName>>(
29  "boundaries", "Boundaries to be broken. Default means to break all boundaries");
30  return params;
31 }
32 
34  : MeshModifier(parameters)
35 {
36 }
37 
38 void
40 {
41  // get the mesh and boundary info
42  auto & mesh = _mesh_ptr->getMesh();
43  auto & boundary_info = mesh.get_boundary_info();
44 
45  // get IDs of all boundaries to be broken
46  std::set<BoundaryID> breaking_boundary_ids;
47  if (isParamValid("boundaries"))
48  {
49  auto & boundary_names = getParam<std::vector<BoundaryName>>("boundaries");
50  for (auto & boundary_name : boundary_names)
51  breaking_boundary_ids.insert(_mesh_ptr->getBoundaryID(boundary_name));
52  }
53  else
54  {
55  breaking_boundary_ids = boundary_info.get_boundary_ids();
56 
57  // We might be on a distributed mesh with remote boundary ids
58  if (!mesh.is_replicated())
59  this->comm().set_union(breaking_boundary_ids);
60  }
61 
62  // create a list of new boundary names
63  std::set<std::string> new_boundary_name_set;
64  for (const auto & elem : mesh.active_element_ptr_range())
65  {
66  auto subdomain_id = elem->subdomain_id();
67  auto subdomain_name = mesh.subdomain_name(subdomain_id);
68  if (subdomain_name == "")
69  subdomain_name = std::to_string(subdomain_id);
70  for (unsigned int side = 0; side < elem->n_sides(); ++side)
71  {
72  auto side_boundary_ids = boundary_info.boundary_ids(elem, side);
73  for (auto i = beginIndex(side_boundary_ids); i < side_boundary_ids.size(); ++i)
74  if (breaking_boundary_ids.count(side_boundary_ids[i]) > 0)
75  new_boundary_name_set.emplace(boundary_info.sideset_name(side_boundary_ids[i]) + "_to_" +
76  subdomain_name);
77  }
78  }
79 
80  // We might be on a distributed mesh with remote elements that had
81  // new boundary ids added
82  if (!mesh.is_replicated())
83  this->comm().set_union(new_boundary_name_set);
84 
85  // assign boundary IDs to the boundaries to be added
86  std::vector<BoundaryName> new_boundary_names(new_boundary_name_set.begin(),
87  new_boundary_name_set.end());
88  auto new_boundary_ids = _mesh_ptr->getBoundaryIDs(new_boundary_names, true);
89 
90  // assign boundary names to the new boundaries
91  mooseAssert(new_boundary_ids.size() == new_boundary_names.size(),
92  "sizes of boundary names and boundary IDs mismatch");
93  for (auto i = beginIndex(new_boundary_ids); i < new_boundary_ids.size(); ++i)
94  {
95  boundary_info.sideset_name(new_boundary_ids[i]) = new_boundary_names[i];
96  boundary_info.nodeset_name(new_boundary_ids[i]) = new_boundary_names[i];
97  }
98 
99  // add sides into the side sets
100  for (const auto & elem : mesh.active_element_ptr_range())
101  {
102  auto subdomain_id = elem->subdomain_id();
103  auto subdomain_name = mesh.subdomain_name(subdomain_id);
104  if (subdomain_name == "")
105  subdomain_name = std::to_string(subdomain_id);
106  for (unsigned int side = 0; side < elem->n_sides(); ++side)
107  {
108  auto side_boundary_ids = boundary_info.boundary_ids(elem, side);
109  for (auto i = beginIndex(side_boundary_ids); i < side_boundary_ids.size(); ++i)
110  {
111  if (breaking_boundary_ids.count(side_boundary_ids[i]) > 0)
112  {
113  BoundaryName bname =
114  boundary_info.sideset_name(side_boundary_ids[i]) + "_to_" + subdomain_name;
115  auto bid = boundary_info.get_id_by_name(bname);
116  boundary_info.add_side(elem, side, bid);
117  }
118  }
119  }
120  }
121 }
InputParameters validParams< BreakBoundaryOnSubdomain >()
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
Returns a vector of boundary IDs for the requested element on the requested side. ...
Definition: MooseMesh.C:1990
MeshModifiers are objects that can modify or add to an existing mesh.
Definition: MeshModifier.h:31
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
BreakBoundaryOnSubdomain(const InputParameters &parameters)
MooseMesh * _mesh_ptr
Pointer to the mesh.
Definition: MeshModifier.h:74
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition: MooseMesh.C:968
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2408
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:67
MPI_Comm comm
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:20
virtual void modify()
Pure virtual modify function MUST be overridden by children classes.