www.mooseframework.org
BoundingBoxNodeSetGenerator.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 
11 #include "MooseMeshUtils.h"
12 #include "CastUniquePointer.h"
13 
14 #include "libmesh/node.h"
15 
17 
18 template <>
21 {
23  MooseEnum location("INSIDE OUTSIDE", "INSIDE");
24 
25  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
26  params.addClassDescription(
27  "Assigns all of the nodes either inside or outside of a bounding box to a new nodeset.");
28  params.addRequiredParam<std::vector<BoundaryName>>("new_boundary",
29  "The name of the nodeset to create");
31  "bottom_left",
32  "The bottom left point (in x,y,z with spaces in-between) of the box to select the nodes.");
34  "top_right",
35  "The bottom left point (in x,y,z with spaces in-between) of the box to select the nodes.");
36  params.addParam<MooseEnum>("location", location, "Control of where the nodeset is to be set");
37 
38  return params;
39 }
40 
42  : MeshGenerator(parameters),
43  _input(getMesh("input")),
44  _location(getParam<MooseEnum>("location")),
45  _bounding_box(getParam<RealVectorValue>("bottom_left"), getParam<RealVectorValue>("top_right"))
46 {
47 }
48 
49 std::unique_ptr<MeshBase>
51 {
52  std::unique_ptr<MeshBase> mesh = std::move(_input);
53 
54  // Get the BoundaryIDs from the mesh
55  std::vector<BoundaryName> boundary_names = getParam<std::vector<BoundaryName>>("new_boundary");
56  std::vector<BoundaryID> boundary_ids =
57  MooseMeshUtils::getBoundaryIDs(*mesh, boundary_names, true);
58  if (boundary_ids.size() != 1)
59  mooseError("Only one boundary ID can be assigned to a nodeset using a bounding box!");
60 
61  // Get a reference to our BoundaryInfo object
62  BoundaryInfo & boundary_info = mesh->get_boundary_info();
63 
64  bool found_node = false;
65  const bool inside = (_location == "INSIDE");
66 
67  // Loop over the elements and assign node set id to nodes within the bounding box
68  for (auto & node : as_range(mesh->active_nodes_begin(), mesh->active_nodes_end()))
69  if (_bounding_box.contains_point(*node) == inside)
70  {
71  boundary_info.add_node(node, boundary_ids[0]);
72  found_node = true;
73  }
74 
75  // Unless at least one processor found a node in the bounding box,
76  // the user probably specified it incorrectly.
77  this->comm().max(found_node);
78 
79  if (!found_node)
80  mooseError("No nodes found within the bounding box");
81 
82  boundary_info.nodeset_name(boundary_ids[0]) = boundary_names[0];
83 
84  return dynamic_pointer_cast<MeshBase>(mesh);
85 }
VectorValue< Real > RealVectorValue
Definition: Assembly.h:31
InputParameters validParams< BoundingBoxNodeSetGenerator >()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
Selects a set of nodes and assigns a nodeset name to them based on the bounding box specified...
BoundingBoxNodeSetGenerator(const InputParameters &parameters)
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
registerMooseObject("MooseApp", BoundingBoxNodeSetGenerator)
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...
MooseEnum _location
Select nodes on the &#39;inside&#39; or the &#39;outside&#39; of the bounding box.
std::unique_ptr< MeshBase > & _input
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
std::vector< libMesh::boundary_id_type > getBoundaryIDs(const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown)
BoundingBox _bounding_box
Bounding box for testing element centroids against. Note that.
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< MeshGenerator >()
Definition: MeshGenerator.C:16
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:30