www.mooseframework.org
NodalNormalsEvaluator.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 "NodalNormalsEvaluator.h"
16 
17 // MOOSE includes
18 #include "AuxiliarySystem.h"
19 #include "MooseVariable.h"
20 
21 Threads::spin_mutex nodal_normals_evaluator_mutex;
22 
23 template <>
26 {
28  params.set<bool>("_dual_restrictable") = true;
29  params.set<std::vector<SubdomainName>>("block") = {"ANY_BLOCK_ID"};
30  return params;
31 }
32 
34  : NodalUserObject(parameters), _aux(_fe_problem.getAuxiliarySystem())
35 {
36 }
37 
38 void
40 {
41 
42  if (_current_node->processor_id() == processor_id())
43  {
44  if (_current_node->n_dofs(_aux.number(),
45  _fe_problem.getVariable(_tid, "nodal_normal_x").number()) > 0)
46  {
47  Threads::spin_mutex::scoped_lock lock(nodal_normals_evaluator_mutex);
48 
49  dof_id_type dof_x = _current_node->dof_number(
50  _aux.number(), _fe_problem.getVariable(_tid, "nodal_normal_x").number(), 0);
51  dof_id_type dof_y = _current_node->dof_number(
52  _aux.number(), _fe_problem.getVariable(_tid, "nodal_normal_y").number(), 0);
53  dof_id_type dof_z = _current_node->dof_number(
54  _aux.number(), _fe_problem.getVariable(_tid, "nodal_normal_z").number(), 0);
55 
56  NumericVector<Number> & sln = _aux.solution();
57  Real nx = sln(dof_x);
58  Real ny = sln(dof_y);
59  Real nz = sln(dof_z);
60 
61  Real n = std::sqrt((nx * nx) + (ny * ny) + (nz * nz));
62  if (std::abs(n) >= 1e-13)
63  {
64  // divide by n only if it is not close to zero to avoid NaNs
65  sln.set(dof_x, nx / n);
66  sln.set(dof_y, ny / n);
67  sln.set(dof_z, nz / n);
68  }
69  }
70  }
71 }
72 
73 void
75 {
76  _aux.solution().close();
77 }
78 
79 void
81 {
82  _aux.solution().close();
83 }
84 
85 void
87 {
88 }
InputParameters validParams< NodalNormalsEvaluator >()
const Node *& _current_node
Reference to current node pointer.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
THREAD_ID _tid
Thread ID of this postprocessor.
Definition: UserObject.h:152
A user object that runs over all the nodes and does an aggregation step to compute a single value...
NodalNormalsEvaluator(const InputParameters &parameters)
virtual void finalize() override
Finalize.
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
Threads::spin_mutex nodal_normals_evaluator_mutex
virtual void threadJoin(const UserObject &uo) override
Must override.
virtual NumericVector< Number > & solution() override
virtual unsigned int number()
Gets the number of this system.
Definition: SystemBase.C:604
unsigned int number() const
Get variable number coming from libMesh.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:149
PetscInt n
InputParameters validParams< NodalUserObject >()
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
virtual void execute() override
Execute method.