www.mooseframework.org
BoundingBoxNodeSet.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "BoundingBoxNodeSet.h"
11 #include "MooseMesh.h"
12 
13 #include "libmesh/node.h"
14 
16 
17 template <>
20 {
21  MooseEnum location("INSIDE OUTSIDE", "INSIDE");
22 
24  params.addClassDescription(
25  "Assigns all of the nodes either inside or outside of a bounding box to a new nodeset.");
26  params.addRequiredParam<std::vector<BoundaryName>>("new_boundary",
27  "The name of the nodeset to create");
29  "bottom_left",
30  "The bottom left point (in x,y,z with spaces in-between) of the box to select the nodes.");
32  "top_right",
33  "The bottom left point (in x,y,z with spaces in-between) of the box to select the nodes.");
34  params.addParam<MooseEnum>("location", location, "Control of where the nodeset is to be set");
35 
36  return params;
37 }
38 
40  : MeshModifier(parameters),
41  _location(getParam<MooseEnum>("location")),
42  _bounding_box(getParam<RealVectorValue>("bottom_left"), getParam<RealVectorValue>("top_right"))
43 {
44 }
45 
46 void
48 {
49  // Get the BoundaryIDs from the mesh
50  std::vector<BoundaryName> boundary_names = getParam<std::vector<BoundaryName>>("new_boundary");
51  std::vector<BoundaryID> boundary_ids = _mesh_ptr->getBoundaryIDs(boundary_names, true);
52  if (boundary_ids.size() != 1)
53  mooseError("Only one boundary ID can be assigned to a nodeset using a bounding box!");
54 
55  // Get a reference to our BoundaryInfo object
56  BoundaryInfo & boundary_info = _mesh_ptr->getMesh().get_boundary_info();
57 
58  // Check that we have access to the mesh
59  if (!_mesh_ptr)
60  mooseError("_mesh_ptr must be initialized before calling BoundingBoxNodeSet::modify()");
61 
62  // Reference the the libMesh::MeshBase
63  MeshBase & mesh = _mesh_ptr->getMesh();
64 
65  bool found_node = false;
66  const bool inside = (_location == "INSIDE");
67 
68  // Loop over the elements and assign node set id to nodes within the bounding box
69  for (auto & node : as_range(mesh.active_nodes_begin(), mesh.active_nodes_end()))
70  if (_bounding_box.contains_point(*node) == inside)
71  {
72  boundary_info.add_node(node, boundary_ids[0]);
73  found_node = true;
74  }
75 
76  // Unless at least one processor found a node in the bounding box,
77  // the user probably specified it incorrectly.
78  this->comm().max(found_node);
79 
80  if (!found_node)
81  mooseError("No nodes found within the bounding box");
82 
83  boundary_info.nodeset_name(boundary_ids[0]) = boundary_names[0];
84 }
BoundingBoxNodeSet(const InputParameters &parameters)
VectorValue< Real > RealVectorValue
Definition: Assembly.h:31
MeshModifiers are objects that can modify or add to an existing mesh.
Definition: MeshModifier.h:25
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
registerMooseObject("MooseApp", BoundingBoxNodeSet)
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:68
InputParameters validParams< BoundingBoxNodeSet >()
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
Selects a set of nodes and assigns a nodeset name to them based on the bounding box specified...
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...
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:2153
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...
BoundingBox _bounding_box
Bounding box for testing element centroids against. Note that.
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:15
MooseEnum _location
Select nodes on the &#39;inside&#39; or the &#39;outside&#39; of the bounding box.