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";
36 _need_u_dotdot(false),
37 _need_u_dot_old(false),
38 _need_u_dotdot_old(false),
39 _need_du_dot_du(false),
40 _need_du_dotdot_du(false),
89 if (reinit_for_derivative_reordering)
111 auto & active_coupleable_matrix_tags =
170 safe_access_tagged_vectors) ||
175 if (safe_access_tagged_matrices)
177 for (
auto tag : active_coupleable_matrix_tags)
179 for (std::size_t i = 0; i != n; ++i)
181 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
200 for (std::size_t i = 0; i != n; ++i)
203 std::vector<dof_id_type> one_dof_index(1, dof_index);
206 libmesh_assert_less(i,
_u.size());
208 current_solution.get(one_dof_index, &
_u[i]);
214 if (safe_access_tagged_vectors)
221 if (safe_access_tagged_matrices)
223 for (
auto tag : active_coupleable_matrix_tags)
226 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
232 (*u_dot).get(one_dof_index, &
_u_dot[i]);
235 (*u_dotdot).get(one_dof_index, &
_u_dotdot[i]);
238 (*u_dot_old).get(one_dof_index, &
_u_dot_old[i]);
245 #ifdef _GLIBCXX_DEBUG 259 for (
auto tag : active_coupleable_matrix_tags)
278 _u[i] = std::numeric_limits<Real>::quiet_NaN();
280 _u_old[i] = std::numeric_limits<Real>::quiet_NaN();
282 _u_older[i] = std::numeric_limits<Real>::quiet_NaN();
286 _vector_tag_u[tag][i] = std::numeric_limits<Real>::quiet_NaN();
288 for (
auto tag : active_coupleable_matrix_tags)
290 _matrix_tag_u[tag][i] = std::numeric_limits<Real>::quiet_NaN();
293 _u_dot[i] = std::numeric_limits<Real>::quiet_NaN();
296 _u_dotdot[i] = std::numeric_limits<Real>::quiet_NaN();
299 _u_dot_old[i] = std::numeric_limits<Real>::quiet_NaN();
317 const bool do_derivatives =
323 for (MooseIndex(n_dofs) i = 0; i < n_dofs; ++i)
334 for (MooseIndex(n_dofs) i = 0; i < n_dofs; ++i)
369 for (
unsigned int i = 0; i < n; i++)
431 mooseError(
"MooseVariableScalar: Time derivative of solution (`u_dot`) is not stored. Please " 432 "set uDotRequested() to true in FEProblemBase before requesting `u_dot`.");
444 mooseError(
"MooseVariableScalar: Time derivative of solution (`u_dot`) is not stored. Please " 445 "set uDotRequested() to true in FEProblemBase before requesting `u_dot`.");
457 mooseError(
"MooseVariableScalar: Second time derivative of solution (`u_dotdot`) is not " 458 "stored. Please set uDotDotRequested() to true in FEProblemBase before requesting " 471 mooseError(
"MooseVariableScalar: Old time derivative of solution (`u_dot_old`) is not " 472 "stored. Please set uDotOldRequested() to true in FEProblemBase before requesting " 485 mooseError(
"MooseVariableScalar: Old second time derivative of solution (`u_dotdot_old`) is " 486 "not stored. Please set uDotDotOldRequested() to true in FEProblemBase before " 487 "requesting `u_dotdot_old`.");
static InputParameters validParams()
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()
const VariableValue & uDotDotOld() const
Base class for a system (of equations)
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
std::vector< VariableValue > _vector_tag_u
Tagged vectors.
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.
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...
void setValues(Number value)
Set all of the values of this scalar variable to the same value.
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)
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
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.
VariableValue _u_old
The old value of scalar variable.