www.mooseframework.org
AddExtraNodeset.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 "AddExtraNodeset.h"
16 #include "MooseApp.h"
17 #include "MooseMesh.h"
18 #include "FEProblem.h"
19 #include "ActionWarehouse.h"
20 
21 template <>
24 {
26  params.addRequiredParam<std::vector<BoundaryName>>("new_boundary",
27  "The name of the boundary to create");
28 
29  params.addParam<std::vector<unsigned int>>("nodes",
30  "The nodes you want to be in the nodeset "
31  "(Either this parameter or \"coord\" must be "
32  "supplied).");
33  params.addParam<std::vector<Real>>("coord",
34  "The nodes with coordinates you want to be in the "
35  "nodeset (Either this parameter or \"nodes\" must be "
36  "supplied).");
37  params.addParam<Real>(
38  "tolerance", TOLERANCE, "The tolerance in which two nodes are considered identical");
39 
40  return params;
41 }
42 
44 
45 void
47 {
48 
49  // make sure the input is not empty
50  bool data_valid = false;
51  if (_pars.isParamValid("nodes"))
52  if (getParam<std::vector<unsigned int>>("nodes").size() != 0)
53  data_valid = true;
54  if (_pars.isParamValid("coord"))
55  {
56  unsigned int n_coord = getParam<std::vector<Real>>("coord").size();
57  if (n_coord % _mesh_ptr->dimension() != 0)
58  mooseError("Size of node coordinates does not match the mesh dimension");
59  if (n_coord != 0)
60  data_valid = true;
61  }
62  if (!data_valid)
63  mooseError("Node set can not be empty!");
64 
65  // Get the BoundaryIDs from the mesh
66  std::vector<BoundaryName> boundary_names = getParam<std::vector<BoundaryName>>("new_boundary");
67  std::vector<BoundaryID> boundary_ids = _mesh_ptr->getBoundaryIDs(boundary_names, true);
68 
69  // Get a reference to our BoundaryInfo object
70  BoundaryInfo & boundary_info = _mesh_ptr->getMesh().get_boundary_info();
71 
72  // add nodes with their ids
73  const std::vector<unsigned int> & nodes = getParam<std::vector<unsigned int>>("nodes");
74  for (const auto & node_id : nodes)
75  for (const auto & boundary_id : boundary_ids)
76  boundary_info.add_node(node_id, boundary_id);
77 
78  // add nodes with their coordinates
79  const std::vector<Real> & coord = getParam<std::vector<Real>>("coord");
80  unsigned int dim = _mesh_ptr->dimension();
81  unsigned int n_nodes = coord.size() / dim;
82 
83  UniquePtr<PointLocatorBase> locator = _mesh_ptr->getMesh().sub_point_locator();
84  locator->enable_out_of_mesh_mode();
85 
86  for (unsigned int i = 0; i < n_nodes; ++i)
87  {
88  Point p;
89  for (unsigned int j = 0; j < dim; ++j)
90  p(j) = coord[i * dim + j];
91 
92  bool on_node = false;
93 
94  const Elem * elem = (*locator)(p);
95 
96  if (elem)
97  {
98  for (unsigned int j = 0; j < elem->n_nodes(); ++j)
99  {
100  const Node * node = elem->node_ptr(j);
101 
102  Point q;
103  for (unsigned int k = 0; k < dim; ++k)
104  q(k) = (*node)(k);
105 
106  if (p.absolute_fuzzy_equals(q, getParam<Real>("tolerance")))
107  {
108  for (const auto & boundary_id : boundary_ids)
109  boundary_info.add_node(node, boundary_id);
110 
111  on_node = true;
112  break;
113  }
114  }
115  }
116 
117  bool found_elem = elem;
118 
119  // If we are on a distributed mesh, then any particular processor
120  // may be unable to find any particular node, but *some* processor
121  // should have found it.
122  if (!_mesh_ptr->getMesh().is_replicated())
123  {
124  this->comm().max(found_elem);
125  this->comm().max(on_node);
126  }
127 
128  if (!found_elem)
129  mooseError(
130  "Unable to locate the following point within the domain, please check its coordinates:\n",
131  p);
132 
133  if (!on_node)
134  mooseError("Point can not be located!");
135  }
136 
137  for (unsigned int i = 0; i < boundary_ids.size(); ++i)
138  boundary_info.nodeset_name(boundary_ids[i]) = boundary_names[i];
139 }
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimsension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh m...
Definition: MooseMesh.C:1984
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
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
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...
AddExtraNodeset(const InputParameters &params)
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
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2408
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:122
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
Definition: MooseObject.h:111
InputParameters validParams< AddExtraNodeset >()
MPI_Comm comm
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
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:20