www.mooseframework.org
AddSideSetsFromBoundingBox.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 #include "Conversion.h"
17 #include "MooseMesh.h"
18 #include "MooseTypes.h"
19 
20 template <>
23 {
25  params.addClassDescription("Find sidesets with given boundary ids in bounding box and add new "
26  "boundary id. This can be done by finding all required boundary "
27  "and adding the new boundary id to those sidesets. Alternatively, "
28  "a number of boundary ids can be provided and all nodes within the "
29  "bounding box that have all the required boundary ids will have a new"
30  "boundary id added.");
31 
32  MooseEnum location("INSIDE OUTSIDE", "INSIDE");
33 
35  "bottom_left", "The bottom left point (in x,y,z with spaces in-between).");
37  "top_right", "The bottom left point (in x,y,z with spaces in-between).");
38  params.addRequiredParam<SubdomainID>("block_id",
39  "Subdomain id to set for inside/outside the bounding box");
40  params.addRequiredParam<std::vector<BoundaryName>>(
41  "boundary_id_old", "Boundary id on specified block within the bounding box to select");
42  params.addRequiredParam<boundary_id_type>(
43  "boundary_id_new", "Boundary id on specified block within the bounding box to assign");
44  params.addParam<bool>("boundary_id_overlap",
45  false,
46  "Set to true if boundaries need to overlap on sideset to be detected.");
47  params.addParam<MooseEnum>(
48  "location", location, "Control of where the subdomain id is to be set");
49 
50  return params;
51 }
52 
54  : MeshModifier(parameters),
55  _location(parameters.get<MooseEnum>("location")),
56  _block_id(parameters.get<SubdomainID>("block_id")),
57  _boundary_id_old(parameters.get<std::vector<BoundaryName>>("boundary_id_old")),
58  _boundary_id_new(parameters.get<boundary_id_type>("boundary_id_new")),
59  _bounding_box(parameters.get<RealVectorValue>("bottom_left"),
60  parameters.get<RealVectorValue>("top_right")),
61  _boundary_id_overlap(parameters.get<bool>("boundary_id_overlap"))
62 {
63 }
64 
65 void
67 {
68  // this modifier is not designed for working with distributed mesh
69  _mesh_ptr->errorIfDistributedMesh("BreakBoundaryOnSubdomain");
70 
71  // Check that we have access to the mesh
72  if (!_mesh_ptr)
73  mooseError("_mesh_ptr must be initialized before calling SubdomainBoundingBox::modify()");
74 
75  // Reference the the libMesh::MeshBase
76  MeshBase & mesh = _mesh_ptr->getMesh();
77 
78  // Get a reference to our BoundaryInfo object for later use
79  BoundaryInfo & boundary_info = mesh.get_boundary_info();
80 
81  bool found_element = false;
82  bool found_side_sets = false;
83 
85  {
86  // Loop over the elements
87  for (const auto & elem : mesh.active_element_ptr_range())
88  {
89  // boolean if element centroid is in bounding box
90  bool contains = _bounding_box.contains_point(elem->centroid());
91 
92  // check if active elements are found in the bounding box
93  if (contains)
94  {
95  found_element = true;
96  // loop over sides of elements within bounding box
97  for (unsigned int side = 0; side < elem->n_sides(); side++)
98  // loop over provided boundary vector to check all side sets for all boundary ids
99  for (unsigned int boundary_id_number = 0; boundary_id_number < _boundary_id_old.size();
100  boundary_id_number++)
101  // check if side has same boundary id that you are looking for
102  if (boundary_info.has_boundary_id(
103  elem, side, boundary_info.get_id_by_name(_boundary_id_old[boundary_id_number])))
104  {
105  // assign new boundary value to boundary which meets meshmodifier criteria
106  boundary_info.add_side(elem, side, _boundary_id_new);
107  found_side_sets = true;
108  }
109  }
110  }
111  if (!found_element)
112  mooseError("No elements found within the bounding box");
113 
114  if (!found_side_sets)
115  mooseError("No side sets found on active elements within the bounding box");
116  }
117 
118  else if (_boundary_id_overlap)
119  {
120  if (_boundary_id_old.size() < 2)
121  mooseError("boundary_id_old out of bounds: ",
122  _boundary_id_old.size(),
123  " Must be 2 boundary inputs or more.");
124 
125  bool found_node = false;
126  const bool inside = (_location == "INSIDE");
127 
128  // Loop over the elements and assign node set id to nodes within the bounding box
129  for (auto node = mesh.active_nodes_begin(); node != mesh.active_nodes_end(); ++node)
130  {
131  // check if nodes are inside of bounding box
132  if (_bounding_box.contains_point(**node) == inside)
133  {
134  // read out boundary ids for nodes
135  std::vector<short int> boundary_id_list = boundary_info.boundary_ids(*node);
136  std::vector<boundary_id_type> boundary_id_old_list =
138 
139  // sort boundary ids on node and sort boundary ids provided in input file
140  std::sort(boundary_id_list.begin(), boundary_id_list.end());
141  std::sort(boundary_id_old_list.begin(), boundary_id_old_list.end());
142 
143  // check if input boundary ids are all contained in the node
144  // if true, write new boundary id on respective node
145  if (std::includes(boundary_id_list.begin(),
146  boundary_id_list.end(),
147  boundary_id_old_list.begin(),
148  boundary_id_old_list.end()))
149  {
150  boundary_info.add_node(*node, _boundary_id_new);
151  found_node = true;
152  }
153  }
154  }
155 
156  if (!found_node)
157  mooseError("No nodes found within the bounding box");
158  }
159 }
VectorValue< Real > RealVectorValue
Definition: Assembly.h:40
subdomain_id_type SubdomainID
Definition: MooseTypes.h:77
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...
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:2526
BoundingBox _bounding_box
Bounding box for testing element centroids against.
AddSideSetsFromBoundingBox(const InputParameters &parameters)
Class constructor.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
MooseMesh * _mesh_ptr
Pointer to the mesh.
Definition: MeshModifier.h:74
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2408
boundary_id_type _boundary_id_new
boundary ID to assign
const bool _boundary_id_overlap
Flag to determine if the provided boundaries need to overlap.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:37
std::vector< BoundaryName > _boundary_id_old
boundary ID to select
InputParameters validParams< AddSideSetsFromBoundingBox >()
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
MooseEnum _location
ID location (inside of outside of box)
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:20