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