www.mooseframework.org
NodalNormalsPreprocessor.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 // MOOSE includes
17 
18 #include "Assembly.h"
19 #include "AuxiliarySystem.h"
20 #include "MooseMesh.h"
21 #include "MooseVariable.h"
22 
23 #include "libmesh/numeric_vector.h"
24 #include "libmesh/quadrature.h"
25 
27 
28 template <>
31 {
33  params.addRequiredParam<std::vector<BoundaryName>>(
34  "surface_boundary", "The list of boundary IDs where nodal normals are computed");
35  params.addParam<BoundaryName>("corner_boundary",
36  "Node set ID which contains the nodes that are in 'corners'.");
37  params.addPrivateParam<FEFamily>("fe_family", LAGRANGE);
38  params.addPrivateParam<Order>("fe_order", FIRST);
39 
40  return params;
41 }
42 
48 bool
49 hasBoundary(const std::vector<BoundaryID> & boundary_ids1,
50  const std::vector<BoundaryID> & boundary_ids2)
51 {
52  for (auto id1 : boundary_ids1)
53  {
54  if (id1 == Moose::ANY_BOUNDARY_ID)
55  return true;
56 
57  for (auto id2 : boundary_ids2)
58  if (id1 == id2 || id2 == Moose::ANY_BOUNDARY_ID)
59  return true;
60  }
61  return false;
62 }
63 
65  : ElementUserObject(parameters),
66  _aux(_fe_problem.getAuxiliarySystem()),
67  _fe_type(getParam<Order>("fe_order"), getParam<FEFamily>("fe_family")),
68  _has_corners(isParamValid("corner_boundary")),
69  _boundaries(_mesh.getBoundaryIDs(getParam<std::vector<BoundaryName>>("surface_boundary"))),
70  _corner_boundary_id(_has_corners
71  ? _mesh.getBoundaryID(getParam<BoundaryName>("corner_boundary"))
72  : static_cast<BoundaryID>(-1)),
73  _grad_phi(_assembly.feGradPhi(_fe_type))
74 {
75 }
76 
77 void
79 {
80  NumericVector<Number> & sln = _aux.solution();
81  _aux.system().zero_variable(sln, _aux.getVariable(_tid, "nodal_normal_x").number());
82  _aux.system().zero_variable(sln, _aux.getVariable(_tid, "nodal_normal_y").number());
83  _aux.system().zero_variable(sln, _aux.getVariable(_tid, "nodal_normal_z").number());
84  // After zero variables, we should close the solution
85  sln.close();
86 }
87 
88 void
90 {
91  NumericVector<Number> & sln = _aux.solution();
92 
93  // Get a reference to our BoundaryInfo object for later use...
94  BoundaryInfo & boundary_info = _mesh.getMesh().get_boundary_info();
95 
96  // Container to catch IDs handed back by BoundaryInfo.
97  std::vector<BoundaryID> node_boundary_ids;
98 
99  // Loop through each node on the current element
100  for (unsigned int i = 0; i < _current_elem->n_nodes(); i++)
101  {
102  // Extract a pointer to a node
103  const Node * node = _current_elem->node_ptr(i);
104 
105  // Only continue if the node is on a boundary
106  if (_mesh.isBoundaryNode(node->id()))
107  {
108  // List of IDs for the boundary
109  boundary_info.boundary_ids(node, node_boundary_ids);
110 
111  // Perform the calculation, the node must be:
112  // (1) On a boundary to which the object is restricted
113  // (2) Not on a corner of the boundary
114  if (hasBoundary(node_boundary_ids, _boundaries) &&
115  (!_has_corners || !boundary_info.has_boundary_id(node, _corner_boundary_id)))
116  {
117  // Perform the caluation of the normal
118  if (node->n_dofs(_aux.number(), _fe_problem.getVariable(_tid, "nodal_normal_x").number()) >
119  0)
120  {
121  // but it is not a corner node, they will be treated differently later on
122  dof_id_type dof_x = node->dof_number(
123  _aux.number(), _fe_problem.getVariable(_tid, "nodal_normal_x").number(), 0);
124  dof_id_type dof_y = node->dof_number(
125  _aux.number(), _fe_problem.getVariable(_tid, "nodal_normal_y").number(), 0);
126  dof_id_type dof_z = node->dof_number(
127  _aux.number(), _fe_problem.getVariable(_tid, "nodal_normal_z").number(), 0);
128 
129  for (unsigned int qp = 0; qp < _qrule->n_points(); qp++)
130  {
131  Threads::spin_mutex::scoped_lock lock(nodal_normals_preprocessor_mutex);
132 
133  sln.add(dof_x, _JxW[qp] * _grad_phi[i][qp](0));
134  sln.add(dof_y, _JxW[qp] * _grad_phi[i][qp](1));
135  sln.add(dof_z, _JxW[qp] * _grad_phi[i][qp](2));
136  }
137  }
138  }
139  }
140  }
141 }
142 
143 void
145 {
146  _aux.solution().close();
147 }
148 
149 void
151 {
152 }
std::vector< BoundaryID > _boundaries
InputParameters validParams< ElementUserObject >()
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...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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:2474
virtual void finalize() override
Finalize.
THREAD_ID _tid
Thread ID of this postprocessor.
Definition: UserObject.h:152
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 void initialize() override
Called before execute() is ever called so that data can be cleared.
const VariablePhiGradient & _grad_phi
Threads::spin_mutex nodal_normals_preprocessor_mutex
virtual MooseVariable & getVariable(THREAD_ID tid, const std::string &var_name)
Gets a reference to a variable of with specified name.
Definition: SystemBase.C:103
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2408
const Elem *& _current_elem
The current element pointer (available during execute())
virtual NumericVector< Number > & solution() override
AuxiliarySystem & _aux
Forces object to be stored as a block object.
NodalNormalsPreprocessor(const InputParameters &parameters)
virtual unsigned int number()
Gets the number of this system.
Definition: SystemBase.C:604
unsigned int number() const
Get variable number coming from libMesh.
virtual void execute() override
Execute method.
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:149
virtual System & system() override
Get the reference to the libMesh system.
const MooseArray< Real > & _JxW
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< NodalNormalsPreprocessor >()
virtual void threadJoin(const UserObject &uo) override
Must override.
virtual MooseVariable & getVariable(THREAD_ID tid, const std::string &var_name) override
Returns the variable reference for requested variable which may be in any system. ...
Base class for user-specific data.
Definition: UserObject.h:42
const BoundaryID ANY_BOUNDARY_ID
Definition: MooseTypes.h:119
boundary_id_type BoundaryID
Definition: MooseTypes.h:75