www.mooseframework.org
AddNavierStokesVariablesAction.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
8 
9 // MOOSE includes
10 #include "AddVariableAction.h"
11 #include "FEProblem.h"
12 #include "MooseMesh.h"
13 
14 #include "libmesh/fe.h"
15 #include "libmesh/string_to_enum.h"
16 
17 template <>
18 InputParameters
20 {
21  InputParameters params = validParams<NSAction>();
22 
23  MooseEnum families(AddVariableAction::getNonlinearVariableFamilies(), "LAGRANGE");
24  MooseEnum orders(AddVariableAction::getNonlinearVariableOrders(), "FIRST");
25  params.addClassDescription("This class allows us to have a section of the input file like the "
26  "following which automatically adds all the required nonlinear "
27  "variables with the appropriate scaling.");
28  params.addParam<std::vector<SubdomainName>>(
29  "block", "The list of block ids (SubdomainID) on which this action will be applied");
30  params.addParam<MooseEnum>(
31  "family", families, "Specifies the family of FE shape functions to use for this variable");
32  params.addParam<MooseEnum>("order",
33  orders,
34  "Specifies the order of the FE shape function to use "
35  "for this variable (additional orders not listed are "
36  "allowed)");
37  params.addRequiredParam<std::vector<Real>>(
38  "scaling", "Specifies a scaling factor to apply to this variable");
39 
40  return params;
41 }
42 
44  : NSAction(parameters),
45  _scaling(getParam<std::vector<Real>>("scaling")),
46  _blocks(getParam<std::vector<SubdomainName>>("block"))
47 {
48 }
49 
51 
52 void
54 {
55  // Call the base class's act() function to initialize the _vars and _auxs names.
56  NSAction::act();
57 
58  // Make sure the number of scaling parameters matches the number of variables
59  if (_scaling.size() != _vars.size())
60  mooseError("Must provide a scaling parameter for each variable.");
61 
62  // All variables have the same type
63  FEType fe_type(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
64  Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family")));
65 
66  std::set<SubdomainID> _block_ids;
67  for (const auto & subdomain_name : _blocks)
68  {
69  SubdomainID id = _mesh->getSubdomainID(subdomain_name);
70  _block_ids.insert(id);
71  }
72 
73  if (_block_ids.size() == 0)
74  {
75  // Add the variables to the FEProblemBase
76  for (unsigned int i = 0; i < _vars.size(); ++i)
77  _problem->addVariable(_vars[i], fe_type, _scaling[i]);
78 
79  // Add Aux variables. These are all required in order for the code
80  // to run, so they should not be independently selectable by the
81  // user.
82  for (const auto & aux_name : _auxs)
83  _problem->addAuxVariable(aux_name, fe_type);
84  }
85  else
86  {
87  // Add the variables to the FEProblemBase
88  for (unsigned int i = 0; i < _vars.size(); ++i)
89  _problem->addVariable(_vars[i], fe_type, _scaling[i], &_block_ids);
90 
91  // Add Aux variables. These are all required in order for the code
92  // to run, so they should not be independently selectable by the
93  // user.
94  for (const auto & aux_name : _auxs)
95  _problem->addAuxVariable(aux_name, fe_type, &_block_ids);
96  }
97 }
std::vector< std::string > _auxs
Definition: NSAction.h:33
InputParameters validParams< NSAction >()
Definition: NSAction.C:17
AddNavierStokesVariablesAction(InputParameters parameters)
std::vector< std::string > _vars
Definition: NSAction.h:32
virtual void act()
Definition: NSAction.C:33
InputParameters validParams< AddNavierStokesVariablesAction >()
This is a base Action class for the Navier-Stokes module which is responsible for building lists of n...
Definition: NSAction.h:23