LCOV - code coverage report
Current view: top level - include/variables - MooseVariableField.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 6 6 100.0 %
Date: 2025-07-17 01:28:37 Functions: 11 11 100.0 %
Legend: Lines: hit not hit

          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 "MooseTypes.h"
      13             : #include "MooseVariableFieldBase.h"
      14             : #include "SubProblem.h"
      15             : #include "MooseMesh.h"
      16             : #include "MooseVariableData.h"
      17             : #include "MooseFunctor.h"
      18             : #include "MeshChangedInterface.h"
      19             : 
      20             : #include "libmesh/numeric_vector.h"
      21             : #include "libmesh/dof_map.h"
      22             : #include "libmesh/elem.h"
      23             : #include "libmesh/quadrature.h"
      24             : #include "libmesh/dense_vector.h"
      25             : #include "libmesh/dense_vector.h"
      26             : 
      27             : /**
      28             :  * Class for stuff related to variables
      29             :  *
      30             :  * Each variable can compute nodal or elemental (at QPs) values.
      31             :  *
      32             :  * OutputType          OutputShape           OutputData
      33             :  * ----------------------------------------------------
      34             :  * Real                Real                  Real
      35             :  * RealVectorValue     RealVectorValue       Real
      36             :  * RealEigenVector      Real                  RealEigenVector
      37             :  *
      38             :  */
      39             : template <typename OutputType>
      40             : class MooseVariableField : public MooseVariableFieldBase,
      41             :                            public Moose::FunctorBase<typename Moose::ADType<OutputType>::type>,
      42             :                            public MeshChangedInterface
      43             : {
      44             : public:
      45             :   // type for gradient, second and divergence of template class OutputType
      46             :   typedef typename libMesh::TensorTools::IncrementRank<OutputType>::type OutputGradient;
      47             :   typedef typename libMesh::TensorTools::IncrementRank<OutputGradient>::type OutputSecond;
      48             :   typedef typename libMesh::TensorTools::DecrementRank<OutputType>::type OutputDivergence;
      49             : 
      50             :   // shortcut for types storing values on quadrature points
      51             :   typedef MooseArray<OutputType> FieldVariableValue;
      52             :   typedef MooseArray<OutputGradient> FieldVariableGradient;
      53             :   typedef MooseArray<OutputSecond> FieldVariableSecond;
      54             :   typedef MooseArray<OutputType> FieldVariableCurl;
      55             :   typedef MooseArray<OutputDivergence> FieldVariableDivergence;
      56             : 
      57             :   // shape function type for the template class OutputType
      58             :   typedef typename Moose::ShapeType<OutputType>::type OutputShape;
      59             : 
      60             :   // type for gradient, second and divergence of shape functions of template class OutputType
      61             :   typedef typename libMesh::TensorTools::IncrementRank<OutputShape>::type OutputShapeGradient;
      62             :   typedef typename libMesh::TensorTools::IncrementRank<OutputShapeGradient>::type OutputShapeSecond;
      63             :   typedef typename libMesh::TensorTools::DecrementRank<OutputShape>::type OutputShapeDivergence;
      64             : 
      65             :   // shortcut for types storing shape function values on quadrature points
      66             :   typedef MooseArray<std::vector<OutputShape>> FieldVariablePhiValue;
      67             :   typedef MooseArray<std::vector<OutputShapeGradient>> FieldVariablePhiGradient;
      68             :   typedef MooseArray<std::vector<OutputShapeSecond>> FieldVariablePhiSecond;
      69             :   typedef MooseArray<std::vector<OutputShape>> FieldVariablePhiCurl;
      70             :   typedef MooseArray<std::vector<OutputShapeDivergence>> FieldVariablePhiDivergence;
      71             : 
      72             :   // shortcut for types storing test function values on quadrature points
      73             :   // Note: here we assume the types are the same as of shape functions.
      74             :   typedef MooseArray<std::vector<OutputShape>> FieldVariableTestValue;
      75             :   typedef MooseArray<std::vector<OutputShapeGradient>> FieldVariableTestGradient;
      76             :   typedef MooseArray<std::vector<OutputShapeSecond>> FieldVariableTestSecond;
      77             :   typedef MooseArray<std::vector<OutputShape>> FieldVariableTestCurl;
      78             :   typedef MooseArray<std::vector<OutputShapeDivergence>> FieldVariableTestDivergence;
      79             : 
      80             :   // DoF value type for the template class OutputType
      81             :   typedef typename Moose::DOFType<OutputType>::type OutputData;
      82             :   typedef MooseArray<OutputData> DoFValue;
      83             : 
      84             :   MooseVariableField(const InputParameters & parameters);
      85             : 
      86             :   virtual Moose::VarFieldType fieldType() const override;
      87             :   virtual bool isArray() const override;
      88             :   virtual bool isVector() const override;
      89             : 
      90             :   static InputParameters validParams();
      91             : 
      92             :   virtual void setNodalValue(const OutputType & value, unsigned int idx = 0) = 0;
      93             : 
      94             :   ///@{
      95             :   /**
      96             :    * Degree of freedom value setters
      97             :    */
      98             :   virtual void setDofValue(const OutputData & value, unsigned int index) = 0;
      99             :   ///@}
     100             : 
     101             :   /**
     102             :    * AD solution getter
     103             :    */
     104             :   virtual const ADTemplateVariableValue<OutputType> & adSln() const = 0;
     105             : 
     106             :   /**
     107             :    * AD neighbor solution getter
     108             :    */
     109             :   virtual const ADTemplateVariableValue<OutputType> & adSlnNeighbor() const = 0;
     110             : 
     111             :   /**
     112             :    * AD grad solution getter
     113             :    */
     114             :   virtual const ADTemplateVariableGradient<OutputType> & adGradSln() const = 0;
     115             : 
     116             :   /**
     117             :    * AD grad of time derivative solution getter
     118             :    */
     119             :   virtual const ADTemplateVariableGradient<OutputType> & adGradSlnDot() const = 0;
     120             : 
     121             :   /**
     122             :    * AD curl solution getter
     123             :    */
     124             :   virtual const ADTemplateVariableCurl<OutputType> & adCurlSln() const = 0;
     125             : 
     126             :   /**
     127             :    * AD grad neighbor solution getter
     128             :    */
     129             :   virtual const ADTemplateVariableGradient<OutputType> & adGradSlnNeighbor() const = 0;
     130             : 
     131             :   /**
     132             :    * AD grad of time derivative neighbor solution getter
     133             :    */
     134             :   virtual const ADTemplateVariableGradient<OutputType> & adGradSlnNeighborDot() const = 0;
     135             : 
     136             :   /**
     137             :    * AD curl neighbor solution getter
     138             :    */
     139             :   virtual const ADTemplateVariableCurl<OutputType> & adCurlSlnNeighbor() const = 0;
     140             : 
     141             :   /**
     142             :    * AD second solution getter
     143             :    */
     144             :   virtual const ADTemplateVariableSecond<OutputType> & adSecondSln() const = 0;
     145             : 
     146             :   /**
     147             :    * AD second neighbor solution getter
     148             :    */
     149             :   virtual const ADTemplateVariableSecond<OutputType> & adSecondSlnNeighbor() const = 0;
     150             : 
     151             :   /**
     152             :    * AD time derivative getter
     153             :    */
     154             :   virtual const ADTemplateVariableValue<OutputType> & adUDot() const = 0;
     155             : 
     156             :   /**
     157             :    * AD second time derivative getter
     158             :    */
     159             :   virtual const ADTemplateVariableValue<OutputType> & adUDotDot() const = 0;
     160             : 
     161             :   /**
     162             :    * AD neighbor time derivative getter
     163             :    */
     164             :   virtual const ADTemplateVariableValue<OutputType> & adUDotNeighbor() const = 0;
     165             : 
     166             :   /**
     167             :    * AD neighbor second time derivative getter
     168             :    */
     169             :   virtual const ADTemplateVariableValue<OutputType> & adUDotDotNeighbor() const = 0;
     170             : 
     171             :   /**
     172             :    * Return the AD dof values
     173             :    */
     174             :   virtual const MooseArray<ADReal> & adDofValues() const = 0;
     175             : 
     176             :   /**
     177             :    * Return the AD neighbor dof values
     178             :    */
     179             :   virtual const MooseArray<ADReal> & adDofValuesNeighbor() const = 0;
     180             : 
     181             :   /**
     182             :    * Return the AD time derivatives at dofs
     183             :    */
     184             :   virtual const MooseArray<ADReal> & adDofValuesDot() const = 0;
     185             : 
     186             :   ///@{
     187             :   /**
     188             :    * Methods for retrieving values of variables at the nodes in a MooseArray for AuxKernelBase
     189             :    */
     190             :   virtual const MooseArray<OutputType> & nodalValueArray() const = 0;
     191             :   virtual const MooseArray<OutputType> & nodalValueOldArray() const = 0;
     192             :   virtual const MooseArray<OutputType> & nodalValueOlderArray() const = 0;
     193             :   ///@}
     194             : 
     195             :   /**
     196             :    * @return the current elemental solution
     197             :    */
     198             :   virtual const FieldVariableValue & sln() const = 0;
     199             : 
     200             :   /**
     201             :    * @return the old elemental solution, e.g. that of the previous timestep
     202             :    */
     203             :   virtual const FieldVariableValue & slnOld() const = 0;
     204             : 
     205             :   /**
     206             :    * @return the current neighbor solution
     207             :    */
     208             :   virtual const FieldVariableValue & slnNeighbor() const = 0;
     209             : 
     210             :   /**
     211             :    * @return the old neighbor solution, e.g. that of the previous timestep
     212             :    */
     213             :   virtual const FieldVariableValue & slnOldNeighbor() const = 0;
     214             : 
     215             :   /**
     216             :    * @return the older elemental solution, e.g. that of two timesteps ago
     217             :    */
     218             :   virtual const FieldVariableValue & slnOlder() const = 0;
     219             : 
     220             :   /// element gradients
     221             :   virtual const FieldVariableGradient & gradSln() const = 0;
     222             :   virtual const FieldVariableGradient & gradSlnOld() const = 0;
     223             : 
     224             :   /// neighbor solution gradients
     225             :   virtual const FieldVariableGradient & gradSlnNeighbor() const = 0;
     226             :   virtual const FieldVariableGradient & gradSlnOldNeighbor() const = 0;
     227             : 
     228             :   /**
     229             :    * Whether or not this variable is computing any second derivatives.
     230             :    */
     231             :   virtual bool computingSecond() const = 0;
     232             : 
     233             :   /**
     234             :    * Whether or not this variable is computing any curl quantities
     235             :    */
     236             :   virtual bool computingCurl() const = 0;
     237             : 
     238             :   /**
     239             :    * Whether or not this variable is computing any divergence quantities
     240             :    */
     241             :   virtual bool computingDiv() const = 0;
     242             : 
     243             :   /**
     244             :    * Return the variable's elemental shape functions
     245             :    */
     246             :   virtual const FieldVariablePhiValue & phi() const = 0;
     247             : 
     248             :   /**
     249             :    * Return the gradients of the variable's elemental shape functions
     250             :    */
     251             :   virtual const FieldVariablePhiGradient & gradPhi() const = 0;
     252             : 
     253             :   /**
     254             :    * Return the rank-2 tensor of second derivatives of the variable's elemental shape functions
     255             :    */
     256             :   virtual const FieldVariablePhiSecond & secondPhi() const = 0;
     257             : 
     258             :   /**
     259             :    * Curl of the shape functions
     260             :    */
     261             :   virtual const FieldVariablePhiValue & curlPhi() const = 0;
     262             : 
     263             :   /**
     264             :    * Divergence of the shape functions
     265             :    */
     266             :   virtual const FieldVariablePhiDivergence & divPhi() const = 0;
     267             : 
     268             :   /**
     269             :    * Return the variable's shape functions on an element face
     270             :    */
     271             :   virtual const FieldVariablePhiValue & phiFace() const = 0;
     272             : 
     273             :   /**
     274             :    * Return the gradients of the variable's shape functions on an element face
     275             :    */
     276             :   virtual const FieldVariablePhiGradient & gradPhiFace() const = 0;
     277             : 
     278             :   /**
     279             :    * Return the rank-2 tensor of second derivatives of the variable's shape functions on an element
     280             :    * face
     281             :    */
     282             :   virtual const FieldVariablePhiSecond & secondPhiFace() const = 0;
     283             : 
     284             :   /**
     285             :    * Return the variable's shape functions on a neighboring element face
     286             :    */
     287             :   virtual const FieldVariablePhiValue & phiFaceNeighbor() const = 0;
     288             : 
     289             :   /**
     290             :    * Return the gradients of the variable's shape functions on a neighboring element face
     291             :    */
     292             :   virtual const FieldVariablePhiGradient & gradPhiFaceNeighbor() const = 0;
     293             : 
     294             :   /**
     295             :    * Return the rank-2 tensor of second derivatives of the variable's shape functions on a
     296             :    * neighboring element face
     297             :    */
     298             :   virtual const FieldVariablePhiSecond & secondPhiFaceNeighbor() const = 0;
     299             : 
     300             :   /**
     301             :    * Return the variable's shape functions on a neighboring element
     302             :    */
     303             :   virtual const FieldVariablePhiValue & phiNeighbor() const = 0;
     304             : 
     305             :   /**
     306             :    * Return the gradients of the variable's shape functions on a neighboring element
     307             :    */
     308             :   virtual const FieldVariablePhiGradient & gradPhiNeighbor() const = 0;
     309             : 
     310             :   /**
     311             :    * Return the rank-2 tensor of second derivatives of the variable's shape functions on a
     312             :    * neighboring element
     313             :    */
     314             :   virtual const FieldVariablePhiSecond & secondPhiNeighbor() const = 0;
     315             : 
     316             :   /**
     317             :    * Return the variable's shape functions on a lower-dimensional element
     318             :    */
     319             :   virtual const FieldVariablePhiValue & phiLower() const = 0;
     320             : 
     321             :   /**
     322             :    * Set local DOF values and evaluate the values on quadrature points
     323             :    */
     324             :   virtual void setDofValues(const DenseVector<OutputData> & values) = 0;
     325             : 
     326             :   /**
     327             :    * Set local DOF values for a lower dimensional element and evaluate the values on quadrature
     328             :    * points
     329             :    */
     330             :   virtual void setLowerDofValues(const DenseVector<OutputData> & values) = 0;
     331             : 
     332             :   /**
     333             :    * Whether or not this variable is actually using the shape function value.
     334             :    *
     335             :    * Currently hardcoded to true because we always compute the value.
     336             :    */
     337      194810 :   bool usesPhiNeighbor() const { return true; }
     338             : 
     339             :   /**
     340             :    * Whether or not this variable is actually using the shape function gradient.
     341             :    *
     342             :    * Currently hardcoded to true because we always compute the value.
     343             :    */
     344      194810 :   bool usesGradPhiNeighbor() const { return true; }
     345             : 
     346             :   /**
     347             :    * Whether or not this variable is actually using the shape function second derivatives.
     348             :    */
     349             :   virtual bool usesSecondPhiNeighbor() const = 0;
     350             : 
     351             :   ///@{
     352             :   /**
     353             :    * dof values getters
     354             :    */
     355             :   virtual const DoFValue & dofValues() const = 0;
     356             :   virtual const DoFValue & dofValuesOld() const = 0;
     357             :   virtual const DoFValue & dofValuesOlder() const = 0;
     358             :   virtual const DoFValue & dofValuesPreviousNL() const = 0;
     359             :   virtual const DoFValue & dofValuesNeighbor() const = 0;
     360             :   virtual const DoFValue & dofValuesOldNeighbor() const = 0;
     361             :   virtual const DoFValue & dofValuesOlderNeighbor() const = 0;
     362             :   virtual const DoFValue & dofValuesPreviousNLNeighbor() const = 0;
     363             :   virtual const DoFValue & dofValuesDot() const = 0;
     364             :   virtual const DoFValue & dofValuesDotNeighbor() const = 0;
     365             :   virtual const DoFValue & dofValuesDotOld() const = 0;
     366             :   virtual const DoFValue & dofValuesDotOldNeighbor() const = 0;
     367             :   virtual const DoFValue & dofValuesDotDot() const = 0;
     368             :   virtual const DoFValue & dofValuesDotDotNeighbor() const = 0;
     369             :   virtual const DoFValue & dofValuesDotDotOld() const = 0;
     370             :   virtual const DoFValue & dofValuesDotDotOldNeighbor() const = 0;
     371             :   virtual const MooseArray<libMesh::Number> & dofValuesDuDotDu() const = 0;
     372             :   virtual const MooseArray<libMesh::Number> & dofValuesDuDotDuNeighbor() const = 0;
     373             :   virtual const MooseArray<libMesh::Number> & dofValuesDuDotDotDu() const = 0;
     374             :   virtual const MooseArray<libMesh::Number> & dofValuesDuDotDotDuNeighbor() const = 0;
     375             : 
     376             :   template <bool is_ad>
     377             :   const MooseArray<GenericReal<is_ad>> & genericDofValues() const;
     378             : 
     379             :   /**
     380             :    * tag values getters
     381             :    */
     382             :   virtual const FieldVariableValue & vectorTagValue(TagID tag) const = 0;
     383             :   virtual const DoFValue & nodalVectorTagValue(TagID tag) const = 0;
     384             :   virtual const DoFValue & vectorTagDofValue(TagID tag) const = 0;
     385             :   virtual const DoFValue & nodalMatrixTagValue(TagID tag) const = 0;
     386             :   virtual const FieldVariableValue & matrixTagValue(TagID tag) const = 0;
     387             : 
     388             :   virtual void residualSetup() override;
     389             :   virtual void jacobianSetup() override;
     390             :   virtual void timestepSetup() override;
     391             : 
     392             :   using MooseVariableFieldBase::hasBlocks;
     393             :   /*
     394             :    * Returns whether a variable is defined on a block as a functor.
     395             :    * This makes the link between functor block restriction and the
     396             :    * BlockRestrictable interface.
     397             :    * @param id subdomain id we want to know whether the variable is defined on
     398             :    * @return whether the variable is defined on this domain
     399             :    */
     400   460520618 :   bool hasBlocks(const SubdomainID id) const override { return BlockRestrictable::hasBlocks(id); }
     401             : 
     402             : protected:
     403             :   /**
     404             :    * Get the solution corresponding to the provided state
     405             :    */
     406             :   const libMesh::NumericVector<libMesh::Number> & getSolution(const Moose::StateArg & state) const;
     407             : 
     408             :   /// the time integrator used for computing time derivatives
     409             :   const TimeIntegrator * const _time_integrator;
     410             : 
     411             :   /// A dummy ADReal variable
     412      172864 :   mutable ADReal _ad_real_dummy = 0;
     413             : };
     414             : 
     415             : template <>
     416             : template <>
     417             : const MooseArray<Real> & MooseVariableField<Real>::genericDofValues<false>() const;
     418             : template <>
     419             : template <>
     420             : const MooseArray<Real> & MooseVariableField<RealVectorValue>::genericDofValues<false>() const;
     421             : template <>
     422             : template <>
     423             : const MooseArray<Real> & MooseVariableField<RealEigenVector>::genericDofValues<false>() const;
     424             : 
     425             : template <typename OutputType>
     426             : template <bool is_ad>
     427             : const MooseArray<GenericReal<is_ad>> &
     428          43 : MooseVariableField<OutputType>::genericDofValues() const
     429             : {
     430          43 :   return adDofValues();
     431             : }
     432             : 
     433             : #define usingMooseVariableFieldMembers                                                             \
     434             :   usingMooseVariableFieldBaseMembers;                                                              \
     435             :   using MooseVariableField<OutputType>::_time_integrator;                                          \
     436             :   using MooseVariableField<OutputType>::_ad_real_dummy;                                            \
     437             :   using MooseVariableField<OutputType>::getSolution
     438             : 
     439             : // Prevent implicit instantiation in other translation units where these classes are used
     440             : extern template class MooseVariableField<Real>;
     441             : extern template class MooseVariableField<RealVectorValue>;
     442             : extern template class MooseVariableField<RealEigenVector>;

Generated by: LCOV version 1.14