https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
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
47bool
48hasBoundary(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
76void
78{
79 NumericVector<Number> & sln = _aux.solution();
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
87void
89{
90 NumericVector<Number> & sln = _aux.solution();
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(),
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(),
130 "nodal_normal_x",
133 .number(),
134 0);
135 dof_id_type dof_y =
136 node->dof_number(_aux.number(),
139 "nodal_normal_y",
142 .number(),
143 0);
144 dof_id_type dof_z =
145 node->dof_number(_aux.number(),
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
168void
boundary_id_type BoundaryID
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.
registerMooseObject("MooseApp", NodalNormalsPreprocessor)
virtual libMesh::System & system() override
Get the reference to the libMesh system.
static InputParameters validParams()
const QBase *const & _qrule
const Elem *const & _current_elem
The current element pointer (available during execute())
const MooseArray< Real > & _JxW
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...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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...
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...
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.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3549
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:3666
unsigned int number() const
Get variable number coming from libMesh.
An ElementUserObject that prepares MOOSE for computing nodal normals.
NodalNormalsPreprocessor(const InputParameters &parameters)
virtual void execute() override
Execute method.
AuxiliarySystem & _aux
Forces object to be stored as a block object.
static InputParameters validParams()
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
virtual void finalize() override
Finalize.
const VariablePhiGradient & _grad_phi
std::vector< BoundaryID > _boundaries
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
Definition SystemBase.C:91
unsigned int number() const
Gets the number of this system.
NumericVector< Number > & solution()
Definition SystemBase.h:203
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
const THREAD_ID _tid
Thread ID of this postprocessor.
virtual void close()=0
void zero_variable(NumericVector< Number > &v, unsigned int var_num) const
@ VAR_FIELD_STANDARD
Definition MooseTypes.h:777
@ VAR_AUXILIARY
Definition MooseTypes.h:771
const BoundaryID ANY_BOUNDARY_ID
Definition MooseTypes.C:21