Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : #include "MooseVariableBase.h" 13 : #include "SystemBase.h" 14 : 15 : // libMesh forward declarations 16 : namespace libMesh 17 : { 18 : template <typename T> 19 : class NumericVector; 20 : } 21 : 22 : class Assembly; 23 : class TimeIntegrator; 24 : 25 : /** 26 : * Class for scalar variables (they are different). 27 : */ 28 : class MooseVariableScalar : public MooseVariableBase 29 : { 30 : public: 31 : static InputParameters validParams(); 32 : 33 : MooseVariableScalar(const InputParameters & parameters); 34 : virtual ~MooseVariableScalar(); 35 : 36 : /** 37 : * Fill out the VariableValue arrays from the system solution vector 38 : * @param reinit_for_derivative_reordering A flag indicating whether we are reinitializing for the 39 : * purpose of re-ordering derivative information for ADNodalBCs 40 : */ 41 : void reinit(bool reinit_for_derivative_reordering = false); 42 : 43 63640 : const VariableValue & sln() const { return _u; } 44 : 45 : /** 46 : * Return the solution with derivative information 47 : */ 48 : const ADVariableValue & adSln() const; 49 : 50 : const VariableValue & slnOld() const; 51 : const VariableValue & slnOlder() const; 52 : const VariableValue & vectorTagSln(TagID tag) const; 53 : const VariableValue & matrixTagSln(TagID tag) const; 54 : 55 : const VariableValue & uDot() const; 56 : const VariableValue & uDotDot() const; 57 : const VariableValue & uDotOld() const; 58 : const VariableValue & uDotDotOld() const; 59 : const VariableValue & duDotDu() const; 60 : const VariableValue & duDotDotDu() const; 61 : 62 : /** 63 : * Return the first derivative of the solution with derivative information 64 : */ 65 : const ADVariableValue & adUDot() const; 66 : 67 : /** 68 : * Set the nodal value for this variable (to keep everything up to date 69 : */ 70 : void setValue(unsigned int i, Number value); 71 : 72 : /** 73 : * Set all of the values of this scalar variable to the same value 74 : */ 75 : void setValues(Number value); 76 : 77 : void insert(NumericVector<Number> & soln); 78 : 79 : /** 80 : * The oldest solution state that is requested for this variable 81 : * (0 = current, 1 = old, 2 = older, etc). 82 : */ 83 : unsigned int oldestSolutionStateRequested() const; 84 : 85 109838 : void setActiveTags(const std::set<TagID> & vtags) override { _required_vector_tags = vtags; } 86 : 87 : protected: 88 : /// The value of scalar variable 89 : VariableValue _u; 90 : /// The old value of scalar variable 91 : VariableValue _u_old; 92 : /// The older value of scalar variable 93 : VariableValue _u_older; 94 : /// Tagged vectors 95 : std::vector<VariableValue> _vector_tag_u; 96 : /// Only cache data when need it 97 : mutable std::vector<bool> _need_vector_tag_u; 98 : /// Tagged matrices 99 : std::vector<VariableValue> _matrix_tag_u; 100 : /// Only cache data when need it 101 : mutable std::vector<bool> _need_matrix_tag_u; 102 : 103 : VariableValue _u_dot; 104 : VariableValue _u_dotdot; 105 : VariableValue _u_dot_old; 106 : VariableValue _u_dotdot_old; 107 : VariableValue _du_dot_du; 108 : VariableValue _du_dotdot_du; 109 : 110 : mutable bool _need_u_dot; 111 : mutable bool _need_u_dotdot; 112 : mutable bool _need_u_dot_old; 113 : mutable bool _need_u_dotdot_old; 114 : mutable bool _need_du_dot_du; 115 : mutable bool _need_du_dotdot_du; 116 : 117 : /// Whether or not the old solution is needed 118 : mutable bool _need_u_old; 119 : /// Whether or not the older solution is needed 120 : mutable bool _need_u_older; 121 : 122 : /// Whether any AD calculations are needed 123 : mutable bool _need_ad; 124 : /// whether ad_u is needed 125 : mutable bool _need_ad_u; 126 : /// whether ad_u_dot is needed 127 : mutable bool _need_ad_u_dot; 128 : /// The scalar solution with derivative information 129 : ADVariableValue _ad_u; 130 : /// The first derivative of the scalar solution with derivative information 131 : ADVariableValue _ad_u_dot; 132 : 133 : private: 134 : /** 135 : * Adds derivative information to the scalar variable value arrays 136 : * @param nodal_ordering Whether we are doing a nodal ordering of the derivative vector, e.g. 137 : * whether the spacing between variable groups in the derivative vector is equal to the 138 : * number of dofs per node or the number of dofs per elem 139 : */ 140 : void computeAD(bool nodal_ordering); 141 : 142 : /// The set of vector tags we need to evaluate 143 : std::set<TagID> _required_vector_tags; 144 : };