24 #include "libmesh/libmesh.h" 25 #include "libmesh/exodusII_io.h" 26 #include "libmesh/equation_systems.h" 27 #include "libmesh/nonlinear_implicit_system.h" 28 #include "libmesh/explicit_system.h" 29 #include "libmesh/string_to_enum.h" 30 #include "libmesh/fe_interface.h" 40 params.addClassDescription(
"Add a non-linear variable to the simulation.");
44 params.set<std::string>(
"type") =
"MooseVariableBase";
50 "family", families,
"Specifies the family of FE shape functions to use for this variable");
53 "Specifies the order of the FE shape function to use " 54 "for this variable (additional orders not listed are " 56 params.addParam<std::vector<Real>>(
"scaling",
57 "Specifies a scaling factor to apply to this variable");
58 params.addParam<std::vector<Real>>(
"initial_condition",
59 "Specifies a constant initial condition for this variable");
66 _fe_type(feType(params)),
67 _scalar_var(_fe_type.family ==
SCALAR),
76 return MooseEnum(
"LAGRANGE MONOMIAL HERMITE SCALAR HIERARCHIC CLOUGH XYZ SZABAB BERNSTEIN " 77 "L2_LAGRANGE L2_HIERARCHIC NEDELEC_ONE LAGRANGE_VEC MONOMIAL_VEC " 78 "RAVIART_THOMAS RATIONAL_BERNSTEIN SIDE_HIERARCHIC L2_HIERARCHIC_VEC " 79 "L2_LAGRANGE_VEC L2_RAVIART_THOMAS",
86 return MooseEnum(
"CONSTANT FIRST SECOND THIRD FOURTH",
"FIRST",
true);
92 return {Utility::string_to_enum<Order>(params.
get<
MooseEnum>(
"order")),
93 Utility::string_to_enum<FEFamily>(params.
get<
MooseEnum>(
"family"))};
101 mooseError(
"There must be at least one variable component, but somehow 0 has been specified");
114 mooseError(
"Both the MooseVariable* and Add*VariableAction parameters objects have had the " 115 "`family` parameter set, and they are different values: ",
119 " respectively. I don't know how you achieved this, but you need to rectify it.");
123 mooseError(
"Both the MooseVariable* and Add*VariableAction parameters objects have had the " 124 "`order` parameter set, and they are different values: ",
128 " respectively. I don't know how you achieved this, but you need to rectify it.");
131 _pars.
get<std::vector<Real>>(
"scaling") !=
133 mooseError(
"Both the MooseVariable* and Add*VariableAction parameters objects have had the " 134 "`scaling` parameter set, and they are different values. I don't know how you " 135 "achieved this, but you need to rectify it.");
140 "Two initial conditions have been provided for the variable ",
142 " using the 'initial_condition' and 'initial_from_file_var' parameters. Please " 143 "remove one of them.");
150 if (
_type ==
"MooseVariableBase")
167 std::string var_name =
name();
179 std::string var_name =
name();
181 auto value =
_pars.
get<std::vector<Real>>(
"initial_condition");
184 std::string long_name(
"");
185 long_name += var_name;
186 long_name +=
"_moose";
195 const auto fe_field_type = FEInterface::field_type(
_fe_type);
196 const bool is_vector = fe_field_type ==
TYPE_VECTOR;
199 action_params.
set<std::string>(
"type") =
"ScalarConstantIC";
203 action_params.
set<std::string>(
"type") =
"VectorConstantIC";
207 action_params.
set<std::string>(
"type") =
"FVConstantIC";
209 action_params.
set<std::string>(
"type") =
"ConstantIC";
214 action_params.
set<std::string>(
"type") =
"ArrayConstantIC";
216 mooseError(
"Size of 'initial_condition' is not consistent");
220 std::shared_ptr<MooseObjectAction> action;
239 action->getObjectParams().set<
Real>(
"x_value") =
value[0];
240 if (
value.size() > 0)
241 action->getObjectParams().set<
Real>(
"y_value") =
value[1];
242 if (
value.size() > 1)
243 action->getObjectParams().set<
Real>(
"z_value") =
value[2];
246 action->getObjectParams().set<
Real>(
"value") =
value[0];
256 "AddVariableAction::variableType() instead.");
264 return "MooseVariableFVReal";
266 const auto fe_field_type = FEInterface::field_type(fe_type);
271 ::mooseError(
"Vector finite element families do not currently have ArrayVariable support");
273 return "ArrayMooseVariable";
276 return "MooseVariableConstMonomial";
278 return "MooseVariableScalar";
280 return "VectorMooseVariable";
282 return "MooseVariable";
293 mooseError(
"Size of 'scaling' is not consistent");
309 std::set<SubdomainID>
313 std::set<SubdomainID>
blocks;
314 std::vector<SubdomainName> block_param =
316 for (
const auto & subdomain_name : block_param)
static InputParameters validParams()
std::set< SubdomainID > getSubdomainIDs()
Get the block ids from the input parameters.
bool _scalar_var
True if the variable being created is a scalar.
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
void mooseDeprecated(Args &&... args) const
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
InputParameters getValidParams(const std::string &name)
static InputParameters validParams()
Storage for action instances.
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
static InputParameters validParams()
registerMooseAction("MooseApp", AddVariableAction, "add_variable")
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual const std::string & name() const
Get the name of the class.
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters ¶meters)
static MooseEnum getNonlinearVariableFamilies()
Get the possible variable families.
libMesh::FEType _fe_type
FEType for the variable being created.
bool _fv_var
True if the variable being created is finite volume.
InputParameters & getObjectParams()
Retrieve the parameters of the object to be created by this action.
static MooseEnum getNonlinearVariableOrders()
Get the possible variable orders.
unsigned int _components
Number of components for an array variable.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
static std::string variableType(const libMesh::FEType &fe_type, const bool is_fv=false, const bool is_array=false)
Determines a variable type.
virtual void markEigenVariable(const VariableName &var_name)
Mark a variable as a variable of the eigen system.
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 ...
ActionFactory & _action_factory
Builds Actions.
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters ¶ms)
Canonical method for adding a non-linear variable.
static libMesh::FEType feType(const InputParameters ¶ms)
determine the FEType by examining family and order in the provided parameters
std::string _type
The Object type that is being created.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
InputParameters _moose_object_pars
The parameters for the object to be created.
virtual void init()
Initialize the action's member variables.
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...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
void addVariable(const std::string &var_name)
Adds a nonlinear variable to the system.
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealEigenVector
AddVariableAction(const InputParameters ¶ms)
static std::string determineType(const libMesh::FEType &fe_type, unsigned int components, bool is_fv=false)
DEPRECATED: Use variableType instead.
void createInitialConditionAction()
Create the action to generate the InitialCondition object.
std::function< void(FEProblemBase &, const std::string &, const std::string &, InputParameters &)> _problem_add_var_method