17#include "libmesh/numeric_vector.h"
18#include "libmesh/dof_map.h"
28 params.addClassDescription(
"Moose wrapper class around scalar variables");
29 params.set<
MooseEnum>(
"family") =
"SCALAR";
37 _need_u_dotdot(false),
38 _need_u_dot_old(false),
39 _need_u_dotdot_old(false),
40 _need_du_dot_du(false),
41 _need_du_dotdot_du(false),
90 if (reinit_for_derivative_reordering)
112 auto & active_coupleable_matrix_tags =
171 safe_access_tagged_vectors) ||
176 if (safe_access_tagged_matrices)
177 for (
auto tag : active_coupleable_matrix_tags)
179 for (std::size_t i = 0; i != n; ++i)
196 for (std::size_t i = 0; i != n; ++i)
199 std::vector<dof_id_type> one_dof_index(1, dof_index);
202 libmesh_assert_less(i,
_u.size());
204 current_solution.get(one_dof_index, &
_u[i]);
210 if (safe_access_tagged_vectors)
217 if (safe_access_tagged_matrices)
218 for (
auto tag : active_coupleable_matrix_tags)
223 (*u_dot).get(one_dof_index, &
_u_dot[i]);
226 (*u_dotdot).get(one_dof_index, &
_u_dotdot[i]);
229 (*u_dot_old).get(one_dof_index, &
_u_dot_old[i]);
250 for (
auto tag : active_coupleable_matrix_tags)
269 _u[i] = std::numeric_limits<Real>::quiet_NaN();
271 _u_old[i] = std::numeric_limits<Real>::quiet_NaN();
273 _u_older[i] = std::numeric_limits<Real>::quiet_NaN();
277 _vector_tag_u[tag][i] = std::numeric_limits<Real>::quiet_NaN();
279 for (
auto tag : active_coupleable_matrix_tags)
281 _matrix_tag_u[tag][i] = std::numeric_limits<Real>::quiet_NaN();
284 _u_dot[i] = std::numeric_limits<Real>::quiet_NaN();
287 _u_dotdot[i] = std::numeric_limits<Real>::quiet_NaN();
290 _u_dot_old[i] = std::numeric_limits<Real>::quiet_NaN();
308 const bool do_derivatives =
314 for (MooseIndex(n_dofs) i = 0; i < n_dofs; ++i)
325 for (MooseIndex(n_dofs) i = 0; i < n_dofs; ++i)
360 for (
unsigned int i = 0; i < n; i++)
422 mooseError(
"MooseVariableScalar: Time derivative of solution (`u_dot`) is not stored. Please "
423 "set uDotRequested() to true in FEProblemBase before requesting `u_dot`.");
435 mooseError(
"MooseVariableScalar: Time derivative of solution (`u_dot`) is not stored. Please "
436 "set uDotRequested() to true in FEProblemBase before requesting `u_dot`.");
448 mooseError(
"MooseVariableScalar: Second time derivative of solution (`u_dotdot`) is not "
449 "stored. Please set uDotDotRequested() to true in FEProblemBase before requesting "
462 mooseError(
"MooseVariableScalar: Old time derivative of solution (`u_dot_old`) is not "
463 "stored. Please set uDotOldRequested() to true in FEProblemBase before requesting "
476 mooseError(
"MooseVariableScalar: Old second time derivative of solution (`u_dotdot_old`) is "
477 "not stored. Please set uDotDotOldRequested() to true in FEProblemBase before "
478 "requesting `u_dotdot_old`.");
547 "MooseVariableScalar::evaluate may only be used for first-order scalar variables");
DualNumber< Real, DNDerivativeType, true > ADReal
OutputTools< Real >::VariableValue VariableValue
registerMooseObject("MooseApp", MooseVariableScalar)
void resize(unsigned int size)
Change the number of elements the array can store.
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...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
unsigned int _var_num
variable number (from libMesh)
SubProblem & _subproblem
Problem this variable is part of.
static InputParameters validParams()
const libMesh::NumericVector< libMesh::Number > & getSolution(const Moose::StateArg &state) const
Get the solution corresponding to the provided state.
SystemBase & sys()
Get the system this variable is part of.
const libMesh::DofMap & _dof_map
DOF map.
std::vector< dof_id_type > _dof_indices
DOF indices.
SystemBase & _sys
System this variable is part of.
unsigned int number() const
Get variable number coming from libMesh.
Class for scalar variables (they are different).
const VariableValue & uDotOld() const
ADVariableValue _ad_u_dot
The first derivative of the scalar solution with derivative information.
const VariableValue & uDot() const
bool _need_ad_u_dot
whether ad_u_dot is needed
ADVariableValue _ad_u
The scalar solution with derivative information.
std::vector< bool > _need_vector_tag_u
Only cache data when need it.
VariableValue _du_dotdot_du
MooseVariableScalar(const InputParameters ¶meters)
const VariableValue & duDotDotDu() const
static InputParameters validParams()
const VariableValue & uDotDotOld() const
const ADVariableValue & adUDot() const
Return the first derivative of the solution with derivative information.
const VariableValue & duDotDu() const
const VariableValue & uDotDot() const
const VariableValue & matrixTagSln(TagID tag) const
std::set< TagID > _required_vector_tags
The set of vector tags we need to evaluate.
VariableValue _u_older
The older value of scalar variable.
std::vector< bool > _need_matrix_tag_u
Only cache data when need it.
const VariableValue & slnOld() const
void setValue(unsigned int i, Number value)
Set the nodal value for this variable (to keep everything up to date.
std::vector< VariableValue > _matrix_tag_u
Tagged matrices.
std::vector< VariableValue > _vector_tag_u
Tagged vectors.
bool _need_u_old
Whether or not the old solution is needed.
unsigned int oldestSolutionStateRequested() const
The oldest solution state that is requested for this variable (0 = current, 1 = old,...
bool _need_ad_u
whether ad_u is needed
VariableValue _u_dotdot_old
GradientType evaluateGradient(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor gradient with a given element.
void insert(NumericVector< Number > &soln)
void reinit(bool reinit_for_derivative_reordering=false)
Fill out the VariableValue arrays from the system solution vector.
const VariableValue & slnOlder() const
virtual void sizeMatrixTagData() override
Size data structures related to matrix tagging.
bool _need_u_older
Whether or not the older solution is needed.
VariableValue _u_old
The old value of scalar variable.
void computeAD(bool nodal_ordering)
Adds derivative information to the scalar variable value arrays.
const ADVariableValue & adSln() const
Return the solution with derivative information.
VariableValue _u
The value of scalar variable.
virtual ~MooseVariableScalar()
ValueType evaluate(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor with a given element.
bool _need_ad
Whether any AD calculations are needed.
const VariableValue & vectorTagSln(TagID tag) const
void setValues(Number value)
Set all of the values of this scalar variable to the same value.
typename FunctorReturnType< ADReal, FunctorEvaluationKind::Gradient >::type GradientType
This rigmarole makes it so that a user can create functors that return containers (std::vector,...
virtual unsigned int currentNlSysNum() const =0
virtual Moose::VectorTagType vectorTagType(const TagID tag_id) const
virtual bool safeAccessTaggedMatrices() const
Is it safe to access the tagged matrices.
virtual unsigned int numMatrixTags() const
The total number of tags.
virtual unsigned int numVectorTags(const Moose::VectorTagType type=Moose::VECTOR_TAG_ANY) const
The total number of tags, which can be limited to the tag type.
const std::set< TagID > & getActiveScalarVariableCoupleableMatrixTags(const THREAD_ID tid) const
virtual bool safeAccessTaggedVectors() const
Is it safe to access the tagged vectors.
Base class for a system (of equations)
virtual const NumericVector< Number > *const & currentSolution() const =0
The solution vector that is currently being operated on.
virtual libMesh::SparseMatrix< Number > & getMatrix(TagID tag)
Get a raw SparseMatrix.
bool hasVector(const std::string &tag_name) const
Check if the named vector exists in the system.
virtual NumericVector< Number > * solutionUDot()
unsigned int number() const
Gets the number of this system.
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector by name.
NumericVector< Number > & solutionOld()
SubProblem & subproblem()
virtual NumericVector< Number > * solutionUDotOld()
virtual const Number & duDotDu(unsigned int var_num=0) const
NumericVector< Number > & solutionOlder()
virtual bool hasMatrix(TagID tag) const
Check if the tagged matrix exists in the system.
virtual NumericVector< Number > * solutionUDotDotOld()
virtual Number & duDotDotDu()
virtual NumericVector< Number > * solutionUDotDot()
dof_id_type first_dof(const processor_id_type proc) const
dof_id_type end_dof(const processor_id_type proc) const
bool all_semilocal_indices(const std::vector< dof_id_type > &dof_indices) const
void SCALAR_dof_indices(std::vector< dof_id_type > &di, const unsigned int vn, const bool old_dofs=false) const
virtual void get(const std::vector< numeric_index_type > &index, T *values) const
virtual bool closed() const=0
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
bool doDerivatives(const SubProblem &subproblem, const SystemBase &sys)
void derivInsert(SemiDynamicSparseNumberArray< Real, libMesh::dof_id_type, NWrapper< N > > &derivs, libMesh::dof_id_type index, Real value)
A structure that is used to evaluate Moose functors logically at an element/cell center.
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...
Argument for requesting functor evaluation at a quadrature point location in an element.
Argument for requesting functor evaluation at quadrature point locations on an element side.
A structure defining a "face" evaluation calling argument for Moose functors.
State argument for evaluating functors.
unsigned int state
The state.