https://mooseframework.inl.gov
Loading...
Searching...
No Matches
AddNodalNormalsAction.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
11#include "FEProblem.h"
12#include "Factory.h"
13
14#include "libmesh/fe.h"
15#include "libmesh/string_to_enum.h"
16
17using namespace libMesh;
18
19registerMooseAction("MooseApp", AddNodalNormalsAction, "add_aux_variable");
20registerMooseAction("MooseApp", AddNodalNormalsAction, "add_postprocessor");
21registerMooseAction("MooseApp", AddNodalNormalsAction, "add_user_object");
22
25{
27 params.addClassDescription("Creates Auxiliary variables and objects for computing the outward "
28 "facing normal from a node.");
29
30 // Initialize the 'boundary' input option to default to any boundary
31 params.addParam<std::vector<BoundaryName>>(
32 "boundary",
33 {"ANY_BOUNDARY_ID"},
34 "The boundary ID or name where the normals will be computed");
35 params.addParam<BoundaryName>("corner_boundary", "boundary ID or name with nodes at 'corners'");
36 MooseEnum orders("FIRST SECOND", "FIRST");
37 params.addParam<MooseEnum>("order",
38 orders,
39 "Specifies the order of variables that hold the "
40 "nodal normals. Needs to match the order of the "
41 "mesh");
42
43 return params;
44}
45
47 : Action(parameters),
48 _boundary(getParam<std::vector<BoundaryName>>("boundary")),
49 _has_corners(isParamValid("corner_boundary")),
50 _corner_boundary(_has_corners ? getParam<BoundaryName>("corner_boundary") : BoundaryName())
51{
52}
53
54void
56{
57 // Set the order from the input
58 auto enum_order = getParam<MooseEnum>("order");
59 Order order = Utility::string_to_enum<Order>(enum_order);
60 FEFamily family = LAGRANGE;
61
62 auto var_params = _factory.getValidParams("MooseVariable");
63 var_params.set<MooseEnum>("family") = "LAGRANGE";
64 var_params.set<MooseEnum>("order") = enum_order;
65
66 // Add 3 aux variables for each component of the normal
67 if (_current_task == "add_aux_variable")
68 {
69 _problem->addAuxVariable("MooseVariable", "nodal_normal_x", var_params);
70 _problem->addAuxVariable("MooseVariable", "nodal_normal_y", var_params);
71 _problem->addAuxVariable("MooseVariable", "nodal_normal_z", var_params);
72 }
73
74 // Set the execute options
76 execute_options = {EXEC_INITIAL, EXEC_TIMESTEP_BEGIN};
77
78 // Create the NodalNormalsPreprocessor UserObject
79 if (_current_task == "add_postprocessor")
80 {
81 InputParameters pars = _factory.getValidParams("NodalNormalsPreprocessor");
82 pars.set<Order>("fe_order") = order;
83 pars.set<FEFamily>("fe_family") = family;
84 pars.set<ExecFlagEnum>("execute_on") = execute_options;
85 pars.set<std::vector<BoundaryName>>("surface_boundary") = _boundary;
86
87 if (_has_corners)
88 pars.set<BoundaryName>("corner_boundary") = _corner_boundary;
89
90 _problem->addUserObject("NodalNormalsPreprocessor", "nodal_normals_preprocessor", pars);
91 }
92
93 if (_current_task == "add_user_object")
94 {
96 if (_has_corners)
97 {
98 InputParameters pars = _factory.getValidParams("NodalNormalsCorner");
99 pars.set<ExecFlagEnum>("execute_on") = execute_options;
100 pars.set<std::vector<BoundaryName>>("boundary") = _boundary;
101 pars.set<BoundaryName>("corner_boundary") = _corner_boundary;
102 _problem->addUserObject("NodalNormalsCorner", "nodal_normals_corner", pars);
103 }
104
106 {
107 InputParameters pars = _factory.getValidParams("NodalNormalsEvaluator");
108 pars.set<ExecFlagEnum>("execute_on") = execute_options;
109 pars.set<std::vector<BoundaryName>>("boundary") = _boundary;
110 _problem->addUserObject("NodalNormalsEvaluator", "nodal_normals_evaluator", pars);
111 }
112 }
113}
registerMooseAction("MooseApp", AddNodalNormalsAction, "add_aux_variable")
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition Moose.C:37
const ExecFlagType EXEC_INITIAL
Definition Moose.C:30
Base class for actions.
Definition Action.h:38
static InputParameters validParams()
Definition Action.C:26
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition Action.h:178
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition Action.h:172
Action to setup computation of nodal normals.
bool _has_corners
Flag for testing the existance of the corner boundary input.
AddNodalNormalsAction(const InputParameters &parameters)
static InputParameters validParams()
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
std::vector< BoundaryName > _boundary
The supplied boundary name from the user.
BoundaryName _corner_boundary
The supplied boundary name for the corner boundary.
A MultiMooseEnum object to hold "execute_on" flags.
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 addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
Factory & _factory
The Factory associated with the MooseApp.
ExecFlagEnum getDefaultExecFlagEnum()
Definition MooseUtils.C:972
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...