www.mooseframework.org
AddNodalNormalsAction.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 #include "AddNodalNormalsAction.h"
11 #include "FEProblem.h"
12 #include "Factory.h"
13 
14 #include "libmesh/fe.h"
15 #include "libmesh/string_to_enum.h"
16 
17 registerMooseAction("MooseApp", AddNodalNormalsAction, "add_aux_variable");
18 
19 registerMooseAction("MooseApp", AddNodalNormalsAction, "add_postprocessor");
20 
21 registerMooseAction("MooseApp", AddNodalNormalsAction, "add_user_object");
22 
23 template <>
26 {
28 
29  // Initialize the 'boundary' input option to default to any boundary
30  std::vector<BoundaryName> everywhere(1, "ANY_BOUNDARY_ID");
31  params.addParam<std::vector<BoundaryName>>(
32  "boundary", everywhere, "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 
52 void
54 {
55  // Set the order from the input
56  Order order = Utility::string_to_enum<Order>(getParam<MooseEnum>("order"));
57  FEFamily family = LAGRANGE;
58  FEType fe_type(order, family);
59 
60  // Add 3 aux variables for each component of the normal
61  if (_current_task == "add_aux_variable")
62  {
63  _problem->addAuxVariable("nodal_normal_x", fe_type);
64  _problem->addAuxVariable("nodal_normal_y", fe_type);
65  _problem->addAuxVariable("nodal_normal_z", fe_type);
66  }
67 
68  // Set the execute options
70  execute_options = {EXEC_INITIAL, EXEC_TIMESTEP_BEGIN};
71 
72  // Create the NodalNormalsPreprocessor UserObject
73  if (_current_task == "add_postprocessor")
74  {
75  InputParameters pars = _factory.getValidParams("NodalNormalsPreprocessor");
76  pars.set<Order>("fe_order") = order;
77  pars.set<FEFamily>("fe_family") = family;
78  pars.set<ExecFlagEnum>("execute_on") = execute_options;
79  pars.set<std::vector<BoundaryName>>("surface_boundary") = _boundary;
80 
81  if (_has_corners)
82  pars.set<BoundaryName>("corner_boundary") = _corner_boundary;
83 
84  _problem->addUserObject("NodalNormalsPreprocessor", "nodal_normals_preprocessor", pars);
85  }
86 
87  if (_current_task == "add_user_object")
88  {
90  if (_has_corners)
91  {
92  InputParameters pars = _factory.getValidParams("NodalNormalsCorner");
93  pars.set<ExecFlagEnum>("execute_on") = execute_options;
94  pars.set<std::vector<BoundaryName>>("boundary") = _boundary;
95  pars.set<BoundaryName>("corner_boundary") = _corner_boundary;
96  _problem->addUserObject("NodalNormalsCorner", "nodal_normals_corner", pars);
97  }
98 
100  {
101  InputParameters pars = _factory.getValidParams("NodalNormalsEvaluator");
102  pars.set<ExecFlagEnum>("execute_on") = execute_options;
103  pars.set<std::vector<BoundaryName>>("boundary") = _boundary;
104  _problem->addUserObject("NodalNormalsEvaluator", "nodal_normals_evaluator", pars);
105  }
106  }
107 }
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:24
std::vector< BoundaryName > _boundary
The supplied boundary name from the user.
bool _has_corners
Flag for testing the existance of the corner boundary input.
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: Factory.C:67
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...
Factory & _factory
The Factory associated with the MooseApp.
Definition: Action.h:186
Action to setup computation of nodal normals.
Base class for actions.
Definition: Action.h:35
registerMooseAction("MooseApp", AddNodalNormalsAction, "add_aux_variable")
ExecFlagEnum getDefaultExecFlagEnum()
Return the default ExecFlagEnum for MOOSE.
Definition: MooseUtils.C:715
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
const ExecFlagType EXEC_TIMESTEP_BEGIN
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
const std::string & _current_task
The current action (even though we have seperate instances for each action)
Definition: Action.h:210
InputParameters validParams< AddNodalNormalsAction >()
AddNodalNormalsAction(InputParameters parameters)
BoundaryName _corner_boundary
The supplied boundary name for the corner boundary.
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:216
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< Action >()
Definition: Action.C:22
const ExecFlagType EXEC_INITIAL