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)
178 for (
auto tag : active_coupleable_matrix_tags)
180 for (std::size_t i = 0; i != n; ++i)
182 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
201 for (std::size_t i = 0; i != n; ++i)
204 std::vector<dof_id_type> one_dof_index(1, dof_index);
207 libmesh_assert_less(i,
_u.size());
209 current_solution.get(one_dof_index, &
_u[i]);
215 if (safe_access_tagged_vectors)
222 if (safe_access_tagged_matrices)
224 for (
auto tag : active_coupleable_matrix_tags)
227 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
233 (*u_dot).get(one_dof_index, &
_u_dot[i]);
236 (*u_dotdot).get(one_dof_index, &
_u_dotdot[i]);
239 (*u_dot_old).get(one_dof_index, &
_u_dot_old[i]);
246 #ifdef _GLIBCXX_DEBUG 260 for (
auto tag : active_coupleable_matrix_tags)
279 _u[i] = std::numeric_limits<Real>::quiet_NaN();
281 _u_old[i] = std::numeric_limits<Real>::quiet_NaN();
283 _u_older[i] = std::numeric_limits<Real>::quiet_NaN();
287 _vector_tag_u[tag][i] = std::numeric_limits<Real>::quiet_NaN();
289 for (
auto tag : active_coupleable_matrix_tags)
291 _matrix_tag_u[tag][i] = std::numeric_limits<Real>::quiet_NaN();
294 _u_dot[i] = std::numeric_limits<Real>::quiet_NaN();
297 _u_dotdot[i] = std::numeric_limits<Real>::quiet_NaN();
300 _u_dot_old[i] = std::numeric_limits<Real>::quiet_NaN();
318 const bool do_derivatives =
324 for (MooseIndex(n_dofs) i = 0; i < n_dofs; ++i)
335 for (MooseIndex(n_dofs) i = 0; i < n_dofs; ++i)
370 for (
unsigned int i = 0; i < n; i++)
432 mooseError(
"MooseVariableScalar: Time derivative of solution (`u_dot`) is not stored. Please " 433 "set uDotRequested() to true in FEProblemBase before requesting `u_dot`.");
445 mooseError(
"MooseVariableScalar: Time derivative of solution (`u_dot`) is not stored. Please " 446 "set uDotRequested() to true in FEProblemBase before requesting `u_dot`.");
458 mooseError(
"MooseVariableScalar: Second time derivative of solution (`u_dotdot`) is not " 459 "stored. Please set uDotDotRequested() to true in FEProblemBase before requesting " 472 mooseError(
"MooseVariableScalar: Old time derivative of solution (`u_dot_old`) is not " 473 "stored. Please set uDotOldRequested() to true in FEProblemBase before requesting " 486 mooseError(
"MooseVariableScalar: Old second time derivative of solution (`u_dotdot_old`) is " 487 "not stored. Please set uDotDotOldRequested() to true in FEProblemBase before " 488 "requesting `u_dotdot_old`.");
557 "MooseVariableScalar::evaluate may only be used for first-order scalar variables");
static InputParameters validParams()
std::string name(const ElemQuality q)
const libMesh::NumericVector< libMesh::Number > & getSolution(const Moose::StateArg &state) const
Get the solution corresponding to the provided state.
std::set< TagID > _required_vector_tags
The set of vector tags we need to evaluate.
virtual void insert(const Number *v, const std::vector< numeric_index_type > &dof_indices)
const VariableValue & uDotOld() const
virtual const NumericVector< Number > *const & currentSolution() const =0
The solution vector that is currently being operated on.
dof_id_type end_dof(const processor_id_type proc) const
const VariableValue & uDotDot() const
const ADVariableValue & adUDot() const
Return the first derivative of the solution with derivative information.
bool hasVector(const std::string &tag_name) const
Check if the named vector exists in the system.
void computeAD(bool nodal_ordering)
Adds derivative information to the scalar variable value arrays.
ADVariableValue _ad_u_dot
The first derivative of the scalar solution with derivative information.
virtual void get(const std::vector< numeric_index_type > &index, Number *values) const
void reinit(bool reinit_for_derivative_reordering=false)
Fill out the VariableValue arrays from the system solution vector.
unsigned int number() const
Get variable number coming from libMesh.
virtual unsigned int currentNlSysNum() const =0
bool _need_u_older
Whether or not the older solution is needed.
virtual bool safeAccessTaggedVectors() const
Is it safe to access the tagged vectors.
VariableValue _u
The value of scalar variable.
MooseVariableScalar(const InputParameters ¶meters)
VariableValue _du_dotdot_du
const VariableValue & slnOlder() const
bool _need_ad_u
whether ad_u is needed
ADVariableValue _ad_u
The scalar solution with derivative information.
virtual void sizeMatrixTagData() override
Size data structures related to matrix tagging.
const VariableValue & duDotDotDu() const
virtual bool hasMatrix(TagID tag) const
Check if the tagged matrix exists in the system.
VariableValue _u_older
The older value of scalar variable.
virtual NumericVector< Number > * solutionUDotDotOld()
VariableValue _u_dotdot_old
NumericVector< Number > & solutionOlder()
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...
const VariableValue & uDotDotOld() const
Base class for a system (of equations)
DualNumber< Real, DNDerivativeType, true > ADReal
typename FunctorReturnType< ADReal, FunctorEvaluationKind::Gradient >::type GradientType
This rigmarole makes it so that a user can create functors that return containers (std::vector...
void SCALAR_dof_indices(std::vector< dof_id_type > &di, const unsigned int vn, const bool old_dofs=false) const
std::vector< dof_id_type > _dof_indices
DOF indices.
const std::set< TagID > & getActiveScalarVariableCoupleableMatrixTags(const THREAD_ID tid) const
bool doDerivatives(const SubProblem &subproblem, const SystemBase &sys)
std::vector< VariableValue > _vector_tag_u
Tagged vectors.
GradientType evaluateGradient(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor gradient with a given element.
const VariableValue & slnOld() const
std::vector< bool > _need_vector_tag_u
Only cache data when need it.
registerMooseObject("MooseApp", MooseVariableScalar)
const VariableValue & uDot() const
const VariableValue & vectorTagSln(TagID tag) const
bool _need_ad
Whether any AD calculations are needed.
const libMesh::DofMap & _dof_map
DOF map.
virtual Number & duDotDotDu()
virtual const Number & duDotDu(unsigned int var_num=0) const
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
SubProblem & _subproblem
Problem this variable is part of.
A structure defining a "face" evaluation calling argument for Moose functors.
unsigned int oldestSolutionStateRequested() const
The oldest solution state that is requested for this variable (0 = current, 1 = old, 2 = older, etc).
virtual ~MooseVariableScalar()
SystemBase & _sys
System this variable is part of.
virtual NumericVector< Number > * solutionUDot()
static InputParameters validParams()
SubProblem & subproblem()
virtual NumericVector< Number > * solutionUDotOld()
virtual Moose::VectorTagType vectorTagType(const TagID tag_id) const
void setValue(unsigned int i, Number value)
Set the nodal value for this variable (to keep everything up to date.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
A structure that is used to evaluate Moose functors logically at an element/cell center.
void setValues(Number value)
Set all of the values of this scalar variable to the same value.
Argument for requesting functor evaluation at a quadrature point location in an element.
unsigned int number() const
Gets the number of this system.
std::vector< bool > _need_matrix_tag_u
Only cache data when need it.
const VariableValue & matrixTagSln(TagID tag) const
virtual bool closed() const=0
std::vector< VariableValue > _matrix_tag_u
Tagged matrices.
OutputTools< Real >::VariableValue VariableValue
virtual unsigned int numMatrixTags() const
The total number of tags.
bool _need_ad_u_dot
whether ad_u_dot is needed
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual libMesh::SparseMatrix< Number > & getMatrix(TagID tag)
Get a raw SparseMatrix.
const VariableValue & duDotDu() const
unsigned int _var_num
variable number (from libMesh)
bool _need_u_old
Whether or not the old solution is needed.
Class for scalar variables (they are different).
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...
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.
void insert(NumericVector< Number > &soln)
State argument for evaluating functors.
void derivInsert(SemiDynamicSparseNumberArray< Real, libMesh::dof_id_type, NWrapper< N >> &derivs, libMesh::dof_id_type index, Real value)
const ADVariableValue & adSln() const
Return the solution with derivative information.
bool all_semilocal_indices(const std::vector< dof_id_type > &dof_indices) const
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
dof_id_type first_dof(const processor_id_type proc) const
virtual bool safeAccessTaggedMatrices() const
Is it safe to access the tagged matrices.
virtual NumericVector< Number > * solutionUDotDot()
NumericVector< Number > & solutionOld()
SystemBase & sys()
Get the system this variable is part of.
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector by name.
Argument for requesting functor evaluation at quadrature point locations on an element side...
unsigned int state
The state.
ValueType evaluate(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor with a given element.
VariableValue _u_old
The old value of scalar variable.