https://mooseframework.inl.gov
NodalNormalsPreprocessor.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 // MOOSE includes
12 
13 #include "Assembly.h"
14 #include "AuxiliarySystem.h"
15 #include "MooseMesh.h"
16 #include "MooseVariableFE.h"
17 
18 #include "libmesh/numeric_vector.h"
19 #include "libmesh/quadrature.h"
20 
22 
24 
27 {
29  params.addClassDescription(
30  "An object that prepares MOOSE for computing nodal normal vectors. This object is "
31  "automatically created via the \\[NodalNormals\\] input block.");
32  params.addRequiredParam<std::vector<BoundaryName>>(
33  "surface_boundary", "The list of boundary IDs where nodal normals are computed");
34  params.addParam<BoundaryName>("corner_boundary",
35  "Node set ID which contains the nodes that are in 'corners'.");
36  params.addPrivateParam<FEFamily>("fe_family", LAGRANGE);
37  params.addPrivateParam<Order>("fe_order", FIRST);
38 
39  return params;
40 }
41 
47 bool
48 hasBoundary(const std::vector<BoundaryID> & boundary_ids1,
49  const std::vector<BoundaryID> & boundary_ids2)
50 {
51  for (auto id1 : boundary_ids1)
52  {
53  if (id1 == Moose::ANY_BOUNDARY_ID)
54  return true;
55 
56  for (auto id2 : boundary_ids2)
57  if (id1 == id2 || id2 == Moose::ANY_BOUNDARY_ID)
58  return true;
59  }
60  return false;
61 }
62 
64  : ElementUserObject(parameters),
65  _aux(_fe_problem.getAuxiliarySystem()),
66  _fe_type(getParam<Order>("fe_order"), getParam<FEFamily>("fe_family")),
67  _has_corners(isParamValid("corner_boundary")),
68  _boundaries(_mesh.getBoundaryIDs(getParam<std::vector<BoundaryName>>("surface_boundary"))),
69  _corner_boundary_id(_has_corners
70  ? _mesh.getBoundaryID(getParam<BoundaryName>("corner_boundary"))
71  : static_cast<BoundaryID>(-1)),
72  _grad_phi(_assembly.feGradPhi<Real>(_fe_type))
73 {
74 }
75 
76 void
78 {
80  _aux.system().zero_variable(sln, _aux.getVariable(_tid, "nodal_normal_x").number());
81  _aux.system().zero_variable(sln, _aux.getVariable(_tid, "nodal_normal_y").number());
82  _aux.system().zero_variable(sln, _aux.getVariable(_tid, "nodal_normal_z").number());
83  // After zero variables, we should close the solution
84  sln.close();
85 }
86 
87 void
89 {
91 
92  // Get a reference to our BoundaryInfo object for later use...
93  BoundaryInfo & boundary_info = _mesh.getMesh().get_boundary_info();
94 
95  // Container to catch IDs handed back by BoundaryInfo.
96  std::vector<BoundaryID> node_boundary_ids;
97 
98  // Loop through each node on the current element
99  for (unsigned int i = 0; i < _current_elem->n_nodes(); i++)
100  {
101  // Extract a pointer to a node
102  const Node * node = _current_elem->node_ptr(i);
103 
104  // Only continue if the node is on a boundary
105  if (_mesh.isBoundaryNode(node->id()))
106  {
107  // List of IDs for the boundary
108  boundary_info.boundary_ids(node, node_boundary_ids);
109 
110  // Perform the calculation, the node must be:
111  // (1) On a boundary to which the object is restricted
112  // (2) Not on a corner of the boundary
113  if (hasBoundary(node_boundary_ids, _boundaries) &&
114  (!_has_corners || !boundary_info.has_boundary_id(node, _corner_boundary_id)))
115  {
116  // Perform the caluation of the normal
117  if (node->n_dofs(_aux.number(),
119  .getVariable(_tid,
120  "nodal_normal_x",
123  .number()) > 0)
124  {
125  // but it is not a corner node, they will be treated differently later on
126  dof_id_type dof_x =
127  node->dof_number(_aux.number(),
129  .getVariable(_tid,
130  "nodal_normal_x",
133  .number(),
134  0);
135  dof_id_type dof_y =
136  node->dof_number(_aux.number(),
138  .getVariable(_tid,
139  "nodal_normal_y",
142  .number(),
143  0);
144  dof_id_type dof_z =
145  node->dof_number(_aux.number(),
147  .getVariable(_tid,
148  "nodal_normal_z",
151  .number(),
152  0);
153 
154  for (unsigned int qp = 0; qp < _qrule->n_points(); qp++)
155  {
156  std::scoped_lock lock(_nodal_normals_mutex);
157 
158  sln.add(dof_x, _JxW[qp] * _grad_phi[i][qp](0));
159  sln.add(dof_y, _JxW[qp] * _grad_phi[i][qp](1));
160  sln.add(dof_z, _JxW[qp] * _grad_phi[i][qp](2));
161  }
162  }
163  }
164  }
165  }
166 }
167 
168 void
170 {
171  _aux.solution().close();
172 }
std::vector< BoundaryID > _boundaries
LAGRANGE
Order
static std::mutex _nodal_normals_mutex
NumericVector< Number > & solution()
Definition: SystemBase.h:196
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
bool isBoundaryNode(dof_id_type node_id) const
Returns true if the requested node is in the list of boundary nodes, false otherwise.
Definition: MooseMesh.C:3565
unsigned int number() const
Get variable number coming from libMesh.
static InputParameters validParams()
registerMooseObject("MooseApp", NodalNormalsPreprocessor)
FIRST
An ElementUserObject that prepares MOOSE for computing nodal normals.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void finalize() override
Finalize.
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...
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const override
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
const VariablePhiGradient & _grad_phi
BoundaryID getBoundaryID(const BoundaryName &boundary_name, const MeshBase &mesh)
Gets the boundary ID associated with the given BoundaryName.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3448
void zero_variable(NumericVector< Number > &v, unsigned int var_num) const
boundary_id_type BoundaryID
std::vector< BoundaryID > getBoundaryIDs(const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown, const std::set< BoundaryID > &mesh_boundary_ids)
Gets the boundary IDs with their names.
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1149
virtual void close()=0
AuxiliarySystem & _aux
Forces object to be stored as a block object.
NodalNormalsPreprocessor(const InputParameters &parameters)
virtual void execute() override
Execute method.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
const Elem *const & _current_elem
The current element pointer (available during execute())
bool hasBoundary(const std::vector< BoundaryID > &boundary_ids1, const std::vector< BoundaryID > &boundary_ids2)
Local function to check to see if any intersection occurs between two vectors.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:211
const MooseArray< Real > & _JxW
const THREAD_ID _tid
Thread ID of this postprocessor.
Definition: UserObject.h:218
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 optional parameter and a documentation string to the InputParameters object...
virtual libMesh::System & system() override
Get the reference to the libMesh system.
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
Definition: SystemBase.C:90
FEFamily
virtual void add(const numeric_index_type i, const Number value)=0
static InputParameters validParams()
const BoundaryID ANY_BOUNDARY_ID
Definition: MooseTypes.C:21
uint8_t dof_id_type