www.mooseframework.org
BoundingBoxNodeSet.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 
15 #include "BoundingBoxNodeSet.h"
16 #include "MooseMesh.h"
17 
18 template <>
21 {
22  MooseEnum location("INSIDE OUTSIDE", "INSIDE");
23 
25  params.addClassDescription(
26  "Assigns all of the nodes either inside or outside of a bounding box to a new nodeset.");
27  params.addRequiredParam<std::vector<BoundaryName>>("new_boundary",
28  "The name of the nodeset to create");
30  "bottom_left",
31  "The bottom left point (in x,y,z with spaces in-between) of the box to select the nodes.");
33  "top_right",
34  "The bottom left point (in x,y,z with spaces in-between) of the box to select the nodes.");
35  params.addParam<MooseEnum>("location", location, "Control of where the nodeset is to be set");
36 
37  return params;
38 }
39 
41  : MeshModifier(parameters),
42  _location(getParam<MooseEnum>("location")),
43  _bounding_box(getParam<RealVectorValue>("bottom_left"), getParam<RealVectorValue>("top_right"))
44 {
45 }
46 
47 void
49 {
50  // Get the BoundaryIDs from the mesh
51  std::vector<BoundaryName> boundary_names = getParam<std::vector<BoundaryName>>("new_boundary");
52  std::vector<BoundaryID> boundary_ids = _mesh_ptr->getBoundaryIDs(boundary_names, true);
53  if (boundary_ids.size() != 1)
54  mooseError("Only one boundary ID can be assigned to a nodeset using a bounding box!");
55 
56  // Get a reference to our BoundaryInfo object
57  BoundaryInfo & boundary_info = _mesh_ptr->getMesh().get_boundary_info();
58 
59  // Check that we have access to the mesh
60  if (!_mesh_ptr)
61  mooseError("_mesh_ptr must be initialized before calling BoundingBoxNodeSet::modify()");
62 
63  // Reference the the libMesh::MeshBase
64  MeshBase & mesh = _mesh_ptr->getMesh();
65 
66  bool found_node = false;
67  const bool inside = (_location == "INSIDE");
68 
69  // Loop over the elements and assign node set id to nodes within the bounding box
70  for (auto node = mesh.active_nodes_begin(); node != mesh.active_nodes_end(); ++node)
71  {
72  if (_bounding_box.contains_point(**node) == inside)
73  {
74  boundary_info.add_node(*node, boundary_ids[0]);
75  found_node = true;
76  }
77  }
78 
79  // Unless at least one processor found a node in the bounding box,
80  // the user probably specified it incorrectly.
81  this->comm().max(found_node);
82 
83  if (!found_node)
84  mooseError("No nodes found within the bounding box");
85 
86  boundary_info.nodeset_name(boundary_ids[0]) = boundary_names[0];
87 }
BoundingBoxNodeSet(const InputParameters &parameters)
VectorValue< Real > RealVectorValue
Definition: Assembly.h:40
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:1951
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 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
InputParameters validParams< BoundingBoxNodeSet >()
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2355
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:37
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
BoundingBox _bounding_box
Bounding box for testing element centroids against. Note that.
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:20
MooseEnum _location
Select nodes on the &#39;inside&#39; or the &#39;outside&#39; of the bounding box.