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 "MooseFunctor.h" 14 : #include "SystemBase.h" 15 : 16 : // libMesh forward declarations 17 : namespace libMesh 18 : { 19 : template <typename T> 20 : class NumericVector; 21 : } 22 : 23 : class Assembly; 24 : class TimeIntegrator; 25 : 26 : /** 27 : * Class for scalar variables (they are different). 28 : */ 29 : class MooseVariableScalar : public MooseVariableBase, public Moose::FunctorBase<ADReal> 30 : { 31 : public: 32 : static InputParameters validParams(); 33 : 34 : MooseVariableScalar(const InputParameters & parameters); 35 : virtual ~MooseVariableScalar(); 36 : 37 2 : bool supportsQpBasedLoops() const override { return false; } 38 2 : bool supportsGeometricInfoBasedLoops() const override { return false; } 39 : 40 : /** 41 : * Fill out the VariableValue arrays from the system solution vector 42 : * @param reinit_for_derivative_reordering A flag indicating whether we are reinitializing for the 43 : * purpose of re-ordering derivative information for ADNodalBCs 44 : */ 45 : void reinit(bool reinit_for_derivative_reordering = false); 46 : 47 51498 : const VariableValue & sln() const { return _u; } 48 : 49 : /** 50 : * Return the solution with derivative information 51 : */ 52 : const ADVariableValue & adSln() const; 53 : 54 : const VariableValue & slnOld() const; 55 : const VariableValue & slnOlder() const; 56 : const VariableValue & vectorTagSln(TagID tag) const; 57 : const VariableValue & matrixTagSln(TagID tag) const; 58 : 59 : const VariableValue & uDot() const; 60 : const VariableValue & uDotDot() const; 61 : const VariableValue & uDotOld() const; 62 : const VariableValue & uDotDotOld() const; 63 : const VariableValue & duDotDu() const; 64 : const VariableValue & duDotDotDu() const; 65 : 66 : /** 67 : * Return the first derivative of the solution with derivative information 68 : */ 69 : const ADVariableValue & adUDot() const; 70 : 71 : /** 72 : * Set the nodal value for this variable (to keep everything up to date 73 : */ 74 : void setValue(unsigned int i, Number value); 75 : 76 : /** 77 : * Set all of the values of this scalar variable to the same value 78 : */ 79 : void setValues(Number value); 80 : 81 : void insert(NumericVector<Number> & soln); 82 : 83 : /** 84 : * The oldest solution state that is requested for this variable 85 : * (0 = current, 1 = old, 2 = older, etc). 86 : */ 87 : unsigned int oldestSolutionStateRequested() const; 88 : 89 99705 : void setActiveTags(const std::set<TagID> & vtags) override { _required_vector_tags = vtags; } 90 : 91 : virtual void sizeMatrixTagData() override; 92 : 93 0 : bool supportsFaceArg() const override final { return true; } 94 0 : bool supportsElemSideQpArg() const override final { return true; } 95 : 96 : protected: 97 : /// The value of scalar variable 98 : VariableValue _u; 99 : /// The old value of scalar variable 100 : VariableValue _u_old; 101 : /// The older value of scalar variable 102 : VariableValue _u_older; 103 : /// Tagged vectors 104 : std::vector<VariableValue> _vector_tag_u; 105 : /// Only cache data when need it 106 : mutable std::vector<bool> _need_vector_tag_u; 107 : /// Tagged matrices 108 : std::vector<VariableValue> _matrix_tag_u; 109 : /// Only cache data when need it 110 : mutable std::vector<bool> _need_matrix_tag_u; 111 : 112 : VariableValue _u_dot; 113 : VariableValue _u_dotdot; 114 : VariableValue _u_dot_old; 115 : VariableValue _u_dotdot_old; 116 : VariableValue _du_dot_du; 117 : VariableValue _du_dotdot_du; 118 : 119 : mutable bool _need_u_dot; 120 : mutable bool _need_u_dotdot; 121 : mutable bool _need_u_dot_old; 122 : mutable bool _need_u_dotdot_old; 123 : mutable bool _need_du_dot_du; 124 : mutable bool _need_du_dotdot_du; 125 : 126 : /// Whether or not the old solution is needed 127 : mutable bool _need_u_old; 128 : /// Whether or not the older solution is needed 129 : mutable bool _need_u_older; 130 : 131 : /// Whether any AD calculations are needed 132 : mutable bool _need_ad; 133 : /// whether ad_u is needed 134 : mutable bool _need_ad_u; 135 : /// whether ad_u_dot is needed 136 : mutable bool _need_ad_u_dot; 137 : /// The scalar solution with derivative information 138 : ADVariableValue _ad_u; 139 : /// The first derivative of the scalar solution with derivative information 140 : ADVariableValue _ad_u_dot; 141 : 142 : private: 143 : using typename Moose::FunctorBase<ADReal>::ValueType; 144 : using typename Moose::FunctorBase<ADReal>::GradientType; 145 : using typename Moose::FunctorBase<ADReal>::DotType; 146 : 147 : using ElemArg = Moose::ElemArg; 148 : using ElemQpArg = Moose::ElemQpArg; 149 : using ElemSideQpArg = Moose::ElemSideQpArg; 150 : using FaceArg = Moose::FaceArg; 151 : using ElemPointArg = Moose::ElemPointArg; 152 : using NodeArg = Moose::NodeArg; 153 : 154 : ValueType evaluate(const ElemArg & elem, const Moose::StateArg & state) const override final; 155 : ValueType evaluate(const FaceArg & face, const Moose::StateArg & state) const override final; 156 : ValueType evaluate(const ElemQpArg & qp, const Moose::StateArg & state) const override final; 157 : ValueType evaluate(const ElemSideQpArg & elem_side_qp, 158 : const Moose::StateArg & state) const override final; 159 : ValueType evaluate(const ElemPointArg & elem_point, 160 : const Moose::StateArg & state) const override final; 161 : ValueType evaluate(const NodeArg & node, const Moose::StateArg & state) const override final; 162 : ValueType evaluate(const Moose::StateArg & state) const; 163 : 164 : GradientType evaluateGradient(const ElemArg & elem, 165 : const Moose::StateArg & state) const override final; 166 : GradientType evaluateGradient(const FaceArg & face, 167 : const Moose::StateArg & state) const override final; 168 : GradientType evaluateGradient(const ElemQpArg & qp, 169 : const Moose::StateArg & state) const override final; 170 : GradientType evaluateGradient(const ElemSideQpArg & elem_side_qp, 171 : const Moose::StateArg & state) const override final; 172 : GradientType evaluateGradient(const ElemPointArg & elem_point, 173 : const Moose::StateArg & state) const override final; 174 : GradientType evaluateGradient(const NodeArg & node, 175 : const Moose::StateArg & state) const override final; 176 : 177 : /** 178 : * Adds derivative information to the scalar variable value arrays 179 : * @param nodal_ordering Whether we are doing a nodal ordering of the derivative vector, e.g. 180 : * whether the spacing between variable groups in the derivative vector is equal to the 181 : * number of dofs per node or the number of dofs per elem 182 : */ 183 : void computeAD(bool nodal_ordering); 184 : 185 : /// The set of vector tags we need to evaluate 186 : std::set<TagID> _required_vector_tags; 187 : };