20#include "libmesh/variable.h"
21#include "libmesh/dof_map.h"
22#include "libmesh/system.h"
23#include "libmesh/fe_type.h"
24#include "libmesh/string_to_enum.h"
43 "components", 1,
"components>0",
"Number of components for an array variable");
47 params.
addParam<
bool>(
"eigen",
false,
"True to make this variable an eigen variable");
48 params.
addParam<
bool>(
"fv",
false,
"True to make this variable a finite volume variable");
51 "True to make this variable a array variable regardless of number of "
52 "components. If 'components' > 1, this will automatically be set to true.");
54 params.
addParam<std::vector<std::string>>(
55 "array_var_component_names",
56 "Only for use with array variables, allows setting custom names for each array variable "
57 "component. If this not set, the default name for each array variable componenet is "
58 "`base_name`+'_'+component number. If used, a name must be provided for each component and "
59 "the values are used to name the components as `base_name`+'_'+ "
60 "`array_var_component_names[component]`.");
62 params.
addParam<SolverSystemName>(
"solver_sys",
64 "If this variable is a solver variable, this is the "
65 "solver system to which it should be added.");
67 "disable_p_refinement",
68 "True to disable p-refinement for this variable. Note that because this happens on the "
69 "family basis, users need to have this flag consistently set for all variables in the same "
70 "family. Currently MOOSE disables p-refinement for variables in the following families by "
71 "default: LAGRANGE NEDELEC_ONE RAVIART_THOMAS LAGRANGE_VEC CLOUGH BERNSTEIN and "
72 "RATIONAL_BERNSTEIN.");
76 params.
addParam<
bool>(
"use_dual",
false,
"True to use dual basis for Lagrange multipliers");
89 "Base class for Moose variables. This should never be the terminal object type");
101 _var_num(getParam<unsigned
int>(
"_var_num")),
102 _is_eigen(getParam<bool>(
"eigen")),
103 _var_kind(getParam<
Moose::VarKindType>(
"_var_kind")),
104 _subproblem(_sys.subproblem()),
105 _variable(_sys.system().variable(_var_num)),
106 _assembly(_subproblem.assembly(getParam<
THREAD_ID>(
"_tid"),
107 (_var_kind ==
Moose::VAR_SOLVER) ? _sys.number() : 0)),
108 _dof_map(_sys.dofMap()),
109 _mesh(_subproblem.
mesh()),
111 _count(getParam<unsigned
int>(
"components")),
112 _scaling_factor(_count, 1.0),
113 _use_dual(getParam<bool>(
"use_dual"))
116 : std::vector<Real>(
_count, 1.));
117 if (getParam<bool>(
"fv") && getParam<bool>(
"eigen"))
118 paramError(
"eigen",
"finite volume (fv=true) variables do not have eigen support");
120 paramError(
"family",
"finite volume (fv=true) variables must be have MONOMIAL family");
122 paramError(
"order",
"finite volume (fv=true) variables currently support CONST order only");
127 std::size_t found = name0.find_last_of(
"_");
128 if (found == std::string::npos)
129 mooseError(
"Error creating ArrayMooseVariable name with base name ", name0);
130 const auto name_base = name0.substr(0, found);
131 const auto & name_endings = getParam<std::vector<std::string>>(
"array_var_component_names");
132 for (
const auto &
name : name_endings)
136 mooseError(
"Component size of normal variable (_count) must be one; equals " +
137 std::to_string(
_count) +
"");
142 "An inconsistent numer of names or no names were provided for array variable components");
144 mooseAssert(
isArray(),
"Must be true with component > 1");
152 "Requested array variable component number is greater than the number of component names.");
156const std::vector<dof_id_type> &
163 mooseError(
"VariableAllDoFMap not prepared for ",
165 " . Check nonlocal coupling requirement for the variable.");
174std::vector<dof_id_type>
176 unsigned int component)
const
178 mooseAssert(dof_indices.size() % this->count() == 0,
179 "The dof indices container must be a multiple of count");
180 std::vector<dof_id_type> new_dof_indices(dof_indices.size() / this->count());
182 new_dof_indices[i] = dof_indices[component * new_dof_indices.size() + i];
183 return new_dof_indices;
189 mooseAssert(factor.size() ==
_count,
"Inconsistent scaling factor size");
202 [](
const Real element)
203 { return !MooseUtils::absoluteFuzzyEqual(element, 1.); }) !=
224 "Base class should not assume anything regarding this. In an ideal world this would "
225 "be pure virtual but we can't do that because we register MooseVariableBase as an "
226 "available variable type for the user");
234 "Base class should not assume anything regarding this. In an ideal world this would "
235 "be pure virtual but we can't do that because we register MooseVariableBase as an "
236 "available variable type for the user");
registerMooseObject("MooseApp", MooseVariableBase)
void ErrorVector unsigned int
static InputParameters validParams()
An interface that restricts an object to subdomains via the 'blocks' input parameter.
static InputParameters validParams()
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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 ...
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 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.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Every object that can be built by the factory should be derived from this class.
static InputParameters validParams()
Moose::VarKindType _var_kind
Variable type (see MooseTypes.h)
virtual bool supportsGeometricInfoBasedLoops() const
Whether this variable supports geometric-info-based loops, such as ElemInfo/FaceInfo loops.
unsigned int _var_num
variable number (from libMesh)
std::vector< dof_id_type > componentDofIndices(const std::vector< dof_id_type > &dof_indices, unsigned int component) const
Obtain DoF indices of a component with the indices of the 0th component.
std::vector< std::string > _array_var_component_names
Array variable names when the variable is an array variable.
Real scalingFactor() const
Get the scaling factor for this variable.
virtual bool isArray() const
SubProblem & _subproblem
Problem this variable is part of.
libMesh::FEType _fe_type
The FEType associated with this variable.
static InputParameters validParams()
MooseVariableBase(const InputParameters ¶meters)
void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
const libMesh::NumericVector< libMesh::Number > & getSolution(const Moose::StateArg &state) const
Get the solution corresponding to the provided state.
const std::string & arrayVariableComponent(const unsigned int i) const
Returns the variable name of a component of an array variable.
const std::vector< dof_id_type > & allDofIndices() const
Get all global dofindices for the variable.
std::vector< Real > _scaling_factor
scaling factor for this variable
const unsigned int _count
Number of variables in the array.
libMesh::Order order() const
Get the order of this variable Note: Order enum can be implicitly converted to unsigned int.
SystemBase & _sys
System this variable is part of.
virtual bool supportsQpBasedLoops() const
Whether this variable supports QP-indexed loops.
A class to provide an common interface to objects requiring "outputs" option.
static InputParameters validParams()
std::map< std::string, std::vector< dof_id_type > > _var_dof_map
virtual void haveADObjects(bool have_ad_objects)
Method for setting whether we have any ad objects.
virtual void automaticScaling(bool automatic_scaling)
Automatic scaling setter.
Base class for a system (of equations)
virtual const NumericVector< Number > *const & currentSolution() const =0
The solution vector that is currently being operated on.
SubProblem & subproblem()
void addScalingVector()
Add the scaling factor vector to the system.
virtual NumericVector< Number > & solutionState(const unsigned int state, Moose::SolutionIterationType iteration_type=Moose::SolutionIterationType::Time)
Get a state of the solution (0 = current, 1 = old, 2 = older, etc).
virtual libMesh::System & system()=0
Get the reference to the libMesh system.
const Variable & variable(unsigned int var) const
const std::string & name() const
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
VarKindType
Framework-wide stuff.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
auto index_range(const T &sizable)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
State argument for evaluating functors.
SolutionIterationType iteration_type
The solution iteration type, e.g. time or nonlinear.
unsigned int state
The state.