21#include "libmesh/string_to_enum.h"
22#include "libmesh/fe_interface.h"
30 params.addClassDescription(
"Add a non-linear variable to the simulation.");
34 params.set<std::string>(
"type") =
"MooseVariableBase";
39 "Specifies the family of FE shape functions to use for this variable");
42 "Specifies the order of the FE shape function to use for this "
43 "variable (additional orders not listed are allowed)");
44 params.addParam<std::vector<Real>>(
"scaling",
45 "Specifies a scaling factor to apply to this variable");
46 params.addParam<
bool>(
48 "Whether this variable's finite element basis should use element p-levels when the mesh is "
49 "p-refined. If this is not specified, MOOSE sets the default based on the finite element "
51 params.addDeprecatedParam<
bool>(
"disable_p_refinement",
52 "True to disable p-refinement for this variable.",
53 "Use 'p_refinement = false' instead.");
54 params.addParam<std::vector<Real>>(
"initial_condition",
55 "Specifies a constant initial condition for this variable");
62 _fe_type(feType(params)),
63 _scalar_var(_fe_type.family == SCALAR),
72 return MooseEnum(
"LAGRANGE MONOMIAL HERMITE SCALAR HIERARCHIC CLOUGH XYZ SZABAB BERNSTEIN "
73 "L2_LAGRANGE L2_HIERARCHIC NEDELEC_ONE LAGRANGE_VEC MONOMIAL_VEC "
74 "RAVIART_THOMAS RATIONAL_BERNSTEIN SIDE_HIERARCHIC L2_HIERARCHIC_VEC "
75 "L2_LAGRANGE_VEC L2_RAVIART_THOMAS",
83 "CONSTANT FIRST SECOND THIRD FOURTH FIFTH SIXTH SEVENTH EIGHTH NINTH TENTH ELEVENTH TWELFTH "
84 "THIRTEENTH FOURTEENTH FIFTEENTH SIXTEENTH SEVENTEENTH EIGHTTEENTH NINETEENTH TWENTIETH "
85 "TWENTYFIRST TWENTYSECOND TWENTYTHIRD TWENTYFOURTH TWENTYFIFTH TWENTYSIXTH TWENTYSEVENTH "
86 "TWENTYEIGHTH TWENTYNINTH THIRTIETH THIRTYFIRST THIRTYSECOND THIRTYTHIRD THIRTYFOURTH "
87 "THIRTYFIFTH THIRTYSIXTH THIRTYSEVENTH THIRTYEIGHTH THIRTYNINTH FORTIETH FORTYFIRST "
88 "FORTYSECOND FORTYTHIRD",
104 mooseError(
"There must be at least one variable component, but somehow 0 has been specified");
117 mooseError(
"Both the MooseVariable* and Add*VariableAction parameters objects have had the "
118 "`family` parameter set, and they are different values: ",
121 getParam<MooseEnum>(
"family"),
122 " respectively. I don't know how you achieved this, but you need to rectify it.");
126 mooseError(
"Both the MooseVariable* and Add*VariableAction parameters objects have had the "
127 "`order` parameter set, and they are different values: ",
130 getParam<MooseEnum>(
"order"),
131 " respectively. I don't know how you achieved this, but you need to rectify it.");
134 getParam<std::vector<Real>>(
"scaling") !=
136 mooseError(
"Both the MooseVariable* and Add*VariableAction parameters objects have had the "
137 "`scaling` parameter set, and they are different values. I don't know how you "
138 "achieved this, but you need to rectify it.");
142 "Two initial conditions have been provided for the variable ",
144 " using the 'initial_condition' and 'initial_from_file_var' parameters. Please "
145 "remove one of them.");
148 _pars, {
"order",
"family",
"scaling",
"p_refinement",
"disable_p_refinement"});
156 if (
_type ==
"MooseVariableBase")
173 const auto var_name =
varName();
179 const auto & value = getParam<std::vector<Real>>(
"initial_condition");
188 const auto var_name =
varName();
191 std::string long_name(
"");
192 long_name += var_name;
193 long_name +=
"_moose";
202 const auto fe_field_type = FEInterface::field_type(
_fe_type);
207 action_params.
set<std::string>(
"type") =
"ScalarConstantIC";
211 action_params.
set<std::string>(
"type") =
"VectorConstantIC";
215 action_params.
set<std::string>(
"type") =
"FVConstantIC";
217 action_params.
set<std::string>(
"type") =
"ConstantIC";
222 action_params.
set<std::string>(
"type") =
"ArrayConstantIC";
224 mooseError(
"Size of 'initial_condition' is not consistent");
228 std::shared_ptr<MooseObjectAction> action;
230 action = std::static_pointer_cast<MooseObjectAction>(
233 action = std::static_pointer_cast<MooseObjectAction>(
237 action->getObjectParams().set<VariableName>(
"variable") = var_name;
243 action->getObjectParams().set<RealEigenVector>(
"value") = v;
247 action->getObjectParams().set<Real>(
"x_value") = value[0];
248 if (value.size() > 0)
249 action->getObjectParams().set<Real>(
"y_value") = value[1];
250 if (value.size() > 1)
251 action->getObjectParams().set<Real>(
"z_value") = value[2];
254 action->getObjectParams().set<Real>(
"value") = value[0];
264 "AddVariableAction::variableType() instead.");
272 return "MooseVariableFVReal";
274 const auto fe_field_type = FEInterface::field_type(fe_type);
279 ::mooseError(
"Vector finite element families do not currently have ArrayVariable support");
281 return "ArrayMooseVariable";
283 else if (fe_type.order == CONSTANT && fe_type.family == MONOMIAL && !fe_type.p_refinement)
284 return "MooseVariableConstMonomial";
285 else if (fe_type.family == SCALAR)
286 return "MooseVariableScalar";
288 return "VectorMooseVariable";
290 return "MooseVariable";
301 mooseError(
"Size of 'scaling' is not consistent");
321 std::set<SubdomainID>
blocks;
322 std::vector<SubdomainName> block_param =
324 for (
const auto & subdomain_name : block_param)
registerMooseAction("MooseApp", AddVariableAction, "add_variable")
subdomain_id_type SubdomainID
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters ¶meters)
InputParameters getValidParams(const std::string &name)
Storage for action instances.
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
void associateWithParameter(const std::string ¶m_name, InputParameters ¶ms) const
Associates the object's parameters params with the input location from this Action's parameter with t...
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
void createInitialConditionAction(const std::vector< Real > &value)
Create the action to generate the InitialCondition object.
static MooseEnum getNonlinearVariableFamilies()
Get the possible variable families.
std::function< void(FEProblemBase &, const std::string &, const std::string &, InputParameters &)> _problem_add_var_method
libMesh::FEType _fe_type
FEType for the variable being created.
static libMesh::FEType feType(const InputParameters ¶ms)
determine the FEType by examining family and order in the provided parameters
static MooseEnum getNonlinearVariableOrders()
Get the possible variable orders.
AddVariableAction(const InputParameters ¶ms)
static std::string determineType(const libMesh::FEType &fe_type, unsigned int components, bool is_fv=false)
DEPRECATED: Use variableType instead.
static std::string variableType(const libMesh::FEType &fe_type, const bool is_fv=false, const bool is_array=false)
Determines a variable type.
unsigned int _components
Number of components for an array variable.
virtual std::string varName() const
Return the name of the nonlinear variable to be created.
std::set< SubdomainID > getSubdomainIDs()
Get the block ids from the input parameters.
bool _fv_var
True if the variable being created is finite volume.
static InputParameters validParams()
bool _scalar_var
True if the variable being created is a scalar.
virtual void init()
Initialize the action's member variables.
void addVariable(const std::string &var_name)
Adds a nonlinear variable to the system.
static InputParameters validParams()
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters ¶ms)
Canonical method for adding a non-linear variable.
const std::string & name() const
Get the name of the class.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
bool isParamSetByUser(const std::string &name) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
const InputParameters & _pars
The object's parameters.
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
virtual void markEigenVariable(const VariableName &var_name)
Mark a variable as a variable of the eigen system.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
InputParameters _moose_object_pars
The parameters for the object to be created.
static InputParameters validParams()
std::string _type
The Object type that is being created.
ActionFactory & _action_factory
Builds Actions.
void mooseDeprecated(Args &&... args) const
libMesh::FEType variableFEType(const InputParameters ¶ms)