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
17registerMooseAction("MooseApp", AddNodalNormalsAction, "add_aux_variable");
18registerMooseAction("MooseApp", AddNodalNormalsAction, "add_postprocessor");
19registerMooseAction("MooseApp", AddNodalNormalsAction, "add_user_object");
20
23{
25 params.addClassDescription("Creates Auxiliary variables and objects for computing the outward "
26 "facing normal from a node.");
27
28 // Initialize the 'boundary' input option to default to any boundary
29 params.addParam<std::vector<BoundaryName>>(
30 "boundary",
31 {"ANY_BOUNDARY_ID"},
32 "The boundary ID or name where the normals will be computed");
33 params.addParam<BoundaryName>("corner_boundary", "boundary ID or name with nodes at 'corners'");
34 MooseEnum orders("FIRST SECOND", "FIRST");
35 params.addParam<MooseEnum>("order",
36 orders,
37 "Specifies the order of variables that hold the "
38 "nodal normals. Needs to match the order of the "
39 "mesh");
40
41 return params;
42}
43
45 : Action(parameters),
46 _boundary(getParam<std::vector<BoundaryName>>("boundary")),
47 _has_corners(isParamValid("corner_boundary")),
48 _corner_boundary(_has_corners ? getParam<BoundaryName>("corner_boundary") : BoundaryName())
49{
50}
51
52void
54{
55 // Set the order from the input
56 auto enum_order = getParam<MooseEnum>("order");
57 Order order = Utility::string_to_enum<Order>(enum_order);
58 FEFamily family = LAGRANGE;
59
60 auto var_params = _factory.getValidParams("MooseVariable");
61 var_params.set<MooseEnum>("family") = "LAGRANGE";
62 var_params.set<MooseEnum>("order") = enum_order;
63
64 // Add 3 aux variables for each component of the normal
65 if (_current_task == "add_aux_variable")
66 {
67 _problem->addAuxVariable("MooseVariable", "nodal_normal_x", var_params);
68 _problem->addAuxVariable("MooseVariable", "nodal_normal_y", var_params);
69 _problem->addAuxVariable("MooseVariable", "nodal_normal_z", var_params);
70 }
71
72 // Set the execute options
74 execute_options = {EXEC_INITIAL, EXEC_TIMESTEP_BEGIN};
75
76 // Create the NodalNormalsPreprocessor UserObject
77 if (_current_task == "add_postprocessor")
78 {
79 InputParameters pars = _factory.getValidParams("NodalNormalsPreprocessor");
80 pars.set<Order>("fe_order") = order;
81 pars.set<FEFamily>("fe_family") = family;
82 pars.set<ExecFlagEnum>("execute_on") = execute_options;
83 pars.set<std::vector<BoundaryName>>("surface_boundary") = _boundary;
84
85 if (_has_corners)
86 pars.set<BoundaryName>("corner_boundary") = _corner_boundary;
87
88 _problem->addUserObject("NodalNormalsPreprocessor", "nodal_normals_preprocessor", pars);
89 }
90
91 if (_current_task == "add_user_object")
92 {
94 if (_has_corners)
95 {
96 InputParameters pars = _factory.getValidParams("NodalNormalsCorner");
97 pars.set<ExecFlagEnum>("execute_on") = execute_options;
98 pars.set<std::vector<BoundaryName>>("boundary") = _boundary;
99 pars.set<BoundaryName>("corner_boundary") = _corner_boundary;
100 _problem->addUserObject("NodalNormalsCorner", "nodal_normals_corner", pars);
101 }
102
104 {
105 InputParameters pars = _factory.getValidParams("NodalNormalsEvaluator");
106 pars.set<ExecFlagEnum>("execute_on") = execute_options;
107 pars.set<std::vector<BoundaryName>>("boundary") = _boundary;
108 _problem->addUserObject("NodalNormalsEvaluator", "nodal_normals_evaluator", pars);
109 }
110 }
111}
registerMooseAction("MooseApp", AddNodalNormalsAction, "add_aux_variable")
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition Moose.C:38
const ExecFlagType EXEC_INITIAL
Definition Moose.C:31
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.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
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