LCOV - code coverage report
Current view: top level - include/variables - MooseVariableField.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 6 6 100.0 %
Date: 2026-05-29 20:35:17 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           DofValue
      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             :   using DofValue = typename MooseVariableDataBase<OutputType>::DofValue;
      82             :   using DofValues = typename MooseVariableDataBase<OutputType>::DofValues;
      83             :   using ADDofValue = typename MooseVariableDataBase<OutputType>::ADDofValue;
      84             :   using ADDofValues = typename MooseVariableDataBase<OutputType>::ADDofValues;
      85             : 
      86             :   MooseVariableField(const InputParameters & parameters);
      87             : 
      88             :   virtual Moose::VarFieldType fieldType() const override;
      89             :   virtual bool isArray() const override;
      90             :   virtual bool isVector() const override;
      91             : 
      92             :   static InputParameters validParams();
      93             : 
      94             :   virtual void setNodalValue(const OutputType & value, unsigned int idx = 0) = 0;
      95             : 
      96             :   ///@{
      97             :   /**
      98             :    * Degree of freedom value setters
      99             :    */
     100             :   virtual void setDofValue(const DofValue & value, unsigned int index) = 0;
     101             :   ///@}
     102             : 
     103             :   /**
     104             :    * AD solution getter
     105             :    */
     106             :   virtual const ADTemplateVariableValue<OutputType> & adSln() const = 0;
     107             : 
     108             :   /**
     109             :    * AD neighbor solution getter
     110             :    */
     111             :   virtual const ADTemplateVariableValue<OutputType> & adSlnNeighbor() const = 0;
     112             : 
     113             :   /**
     114             :    * AD grad solution getter
     115             :    */
     116             :   virtual const ADTemplateVariableGradient<OutputType> & adGradSln() const = 0;
     117             : 
     118             :   /**
     119             :    * AD grad of time derivative solution getter
     120             :    */
     121             :   virtual const ADTemplateVariableGradient<OutputType> & adGradSlnDot() const = 0;
     122             : 
     123             :   /**
     124             :    * AD curl solution getter
     125             :    */
     126             :   virtual const ADTemplateVariableCurl<OutputType> & adCurlSln() const = 0;
     127             : 
     128             :   /**
     129             :    * AD grad neighbor solution getter
     130             :    */
     131             :   virtual const ADTemplateVariableGradient<OutputType> & adGradSlnNeighbor() const = 0;
     132             : 
     133             :   /**
     134             :    * AD grad of time derivative neighbor solution getter
     135             :    */
     136             :   virtual const ADTemplateVariableGradient<OutputType> & adGradSlnNeighborDot() const = 0;
     137             : 
     138             :   /**
     139             :    * AD curl neighbor solution getter
     140             :    */
     141             :   virtual const ADTemplateVariableCurl<OutputType> & adCurlSlnNeighbor() const = 0;
     142             : 
     143             :   /**
     144             :    * AD second solution getter
     145             :    */
     146             :   virtual const ADTemplateVariableSecond<OutputType> & adSecondSln() const = 0;
     147             : 
     148             :   /**
     149             :    * AD second neighbor solution getter
     150             :    */
     151             :   virtual const ADTemplateVariableSecond<OutputType> & adSecondSlnNeighbor() const = 0;
     152             : 
     153             :   /**
     154             :    * AD time derivative getter
     155             :    */
     156             :   virtual const ADTemplateVariableValue<OutputType> & adUDot() const = 0;
     157             : 
     158             :   /**
     159             :    * AD second time derivative getter
     160             :    */
     161             :   virtual const ADTemplateVariableValue<OutputType> & adUDotDot() const = 0;
     162             : 
     163             :   /**
     164             :    * AD neighbor time derivative getter
     165             :    */
     166             :   virtual const ADTemplateVariableValue<OutputType> & adUDotNeighbor() const = 0;
     167             : 
     168             :   /**
     169             :    * AD neighbor second time derivative getter
     170             :    */
     171             :   virtual const ADTemplateVariableValue<OutputType> & adUDotDotNeighbor() const = 0;
     172             : 
     173             :   /**
     174             :    * Return the AD dof values
     175             :    */
     176             :   virtual const ADDofValues & adDofValues() const = 0;
     177             : 
     178             :   /**
     179             :    * Return the AD neighbor dof values
     180             :    */
     181             :   virtual const ADDofValues & adDofValuesNeighbor() const = 0;
     182             : 
     183             :   /**
     184             :    * Return the AD time derivatives at dofs
     185             :    */
     186             :   virtual const ADDofValues & adDofValuesDot() const = 0;
     187             : 
     188             :   ///@{
     189             :   /**
     190             :    * Methods for retrieving values of variables at the nodes in a MooseArray for AuxKernelBase
     191             :    */
     192             :   virtual const MooseArray<OutputType> & nodalValueArray() const = 0;
     193             :   virtual const MooseArray<OutputType> & nodalValueOldArray() const = 0;
     194             :   virtual const MooseArray<OutputType> & nodalValueOlderArray() const = 0;
     195             :   ///@}
     196             : 
     197             :   /**
     198             :    * @return the current elemental solution
     199             :    */
     200             :   virtual const FieldVariableValue & sln() const = 0;
     201             : 
     202             :   /**
     203             :    * @return the old elemental solution, e.g. that of the previous timestep
     204             :    */
     205             :   virtual const FieldVariableValue & slnOld() const = 0;
     206             : 
     207             :   /**
     208             :    * @return the current neighbor solution
     209             :    */
     210             :   virtual const FieldVariableValue & slnNeighbor() const = 0;
     211             : 
     212             :   /**
     213             :    * @return the old neighbor solution, e.g. that of the previous timestep
     214             :    */
     215             :   virtual const FieldVariableValue & slnOldNeighbor() const = 0;
     216             : 
     217             :   /**
     218             :    * @return the older elemental solution, e.g. that of two timesteps ago
     219             :    */
     220             :   virtual const FieldVariableValue & slnOlder() const = 0;
     221             : 
     222             :   /// element gradients
     223             :   virtual const FieldVariableGradient & gradSln() const = 0;
     224             :   virtual const FieldVariableGradient & gradSlnOld() const = 0;
     225             : 
     226             :   /// neighbor solution gradients
     227             :   virtual const FieldVariableGradient & gradSlnNeighbor() const = 0;
     228             :   virtual const FieldVariableGradient & gradSlnOldNeighbor() const = 0;
     229             : 
     230             :   /**
     231             :    * Whether or not this variable is computing any second derivatives.
     232             :    */
     233             :   virtual bool computingSecond() const = 0;
     234             : 
     235             :   /**
     236             :    * Whether or not this variable is computing any curl quantities
     237             :    */
     238             :   virtual bool computingCurl() const = 0;
     239             : 
     240             :   /**
     241             :    * Whether or not this variable is computing any divergence quantities
     242             :    */
     243             :   virtual bool computingDiv() const = 0;
     244             : 
     245             :   /**
     246             :    * Return the variable's elemental shape functions
     247             :    */
     248             :   virtual const FieldVariablePhiValue & phi() const = 0;
     249             : 
     250             :   /**
     251             :    * Return the gradients of the variable's elemental shape functions
     252             :    */
     253             :   virtual const FieldVariablePhiGradient & gradPhi() const = 0;
     254             : 
     255             :   /**
     256             :    * Return the rank-2 tensor of second derivatives of the variable's elemental shape functions
     257             :    */
     258             :   virtual const FieldVariablePhiSecond & secondPhi() const = 0;
     259             : 
     260             :   /**
     261             :    * Curl of the shape functions
     262             :    */
     263             :   virtual const FieldVariablePhiValue & curlPhi() const = 0;
     264             : 
     265             :   /**
     266             :    * Divergence of the shape functions
     267             :    */
     268             :   virtual const FieldVariablePhiDivergence & divPhi() const = 0;
     269             : 
     270             :   /**
     271             :    * Return the variable's shape functions on an element face
     272             :    */
     273             :   virtual const FieldVariablePhiValue & phiFace() const = 0;
     274             : 
     275             :   /**
     276             :    * Return the gradients of the variable's shape functions on an element face
     277             :    */
     278             :   virtual const FieldVariablePhiGradient & gradPhiFace() const = 0;
     279             : 
     280             :   /**
     281             :    * Return the rank-2 tensor of second derivatives of the variable's shape functions on an element
     282             :    * face
     283             :    */
     284             :   virtual const FieldVariablePhiSecond & secondPhiFace() const = 0;
     285             : 
     286             :   /**
     287             :    * Return the variable's shape functions on a neighboring element face
     288             :    */
     289             :   virtual const FieldVariablePhiValue & phiFaceNeighbor() const = 0;
     290             : 
     291             :   /**
     292             :    * Return the gradients of the variable's shape functions on a neighboring element face
     293             :    */
     294             :   virtual const FieldVariablePhiGradient & gradPhiFaceNeighbor() const = 0;
     295             : 
     296             :   /**
     297             :    * Return the rank-2 tensor of second derivatives of the variable's shape functions on a
     298             :    * neighboring element face
     299             :    */
     300             :   virtual const FieldVariablePhiSecond & secondPhiFaceNeighbor() const = 0;
     301             : 
     302             :   /**
     303             :    * Return the variable's shape functions on a neighboring element
     304             :    */
     305             :   virtual const FieldVariablePhiValue & phiNeighbor() const = 0;
     306             : 
     307             :   /**
     308             :    * Return the gradients of the variable's shape functions on a neighboring element
     309             :    */
     310             :   virtual const FieldVariablePhiGradient & gradPhiNeighbor() const = 0;
     311             : 
     312             :   /**
     313             :    * Return the rank-2 tensor of second derivatives of the variable's shape functions on a
     314             :    * neighboring element
     315             :    */
     316             :   virtual const FieldVariablePhiSecond & secondPhiNeighbor() const = 0;
     317             : 
     318             :   /**
     319             :    * Return the variable's shape functions on a lower-dimensional element
     320             :    */
     321             :   virtual const FieldVariablePhiValue & phiLower() const = 0;
     322             : 
     323             :   /**
     324             :    * Set local DOF values and evaluate the values on quadrature points
     325             :    */
     326             :   virtual void setDofValues(const DenseVector<DofValue> & values) = 0;
     327             : 
     328             :   /**
     329             :    * Set local DOF values for a lower dimensional element and evaluate the values on quadrature
     330             :    * points
     331             :    */
     332             :   virtual void setLowerDofValues(const DenseVector<DofValue> & values) = 0;
     333             : 
     334             :   /**
     335             :    * Whether or not this variable is actually using the shape function value.
     336             :    *
     337             :    * Currently hardcoded to true because we always compute the value.
     338             :    */
     339      188641 :   bool usesPhiNeighbor() const { return true; }
     340             : 
     341             :   /**
     342             :    * Whether or not this variable is actually using the shape function gradient.
     343             :    *
     344             :    * Currently hardcoded to true because we always compute the value.
     345             :    */
     346      188641 :   bool usesGradPhiNeighbor() const { return true; }
     347             : 
     348             :   /**
     349             :    * Whether or not this variable is actually using the shape function second derivatives.
     350             :    */
     351             :   virtual bool usesSecondPhiNeighbor() const = 0;
     352             : 
     353             :   ///@{
     354             :   /**
     355             :    * dof values getters
     356             :    */
     357             :   virtual const DofValues & dofValues() const = 0;
     358             :   virtual const DofValues & dofValuesOld() const = 0;
     359             :   virtual const DofValues & dofValuesOlder() const = 0;
     360             :   virtual const DofValues & dofValuesPreviousNL() const = 0;
     361             :   virtual const DofValues & dofValuesNeighbor() const = 0;
     362             :   virtual const DofValues & dofValuesOldNeighbor() const = 0;
     363             :   virtual const DofValues & dofValuesOlderNeighbor() const = 0;
     364             :   virtual const DofValues & dofValuesPreviousNLNeighbor() const = 0;
     365             :   virtual const DofValues & dofValuesDot() const = 0;
     366             :   virtual const DofValues & dofValuesDotNeighbor() const = 0;
     367             :   virtual const DofValues & dofValuesDotOld() const = 0;
     368             :   virtual const DofValues & dofValuesDotOldNeighbor() const = 0;
     369             :   virtual const DofValues & dofValuesDotDot() const = 0;
     370             :   virtual const DofValues & dofValuesDotDotNeighbor() const = 0;
     371             :   virtual const DofValues & dofValuesDotDotOld() const = 0;
     372             :   virtual const DofValues & dofValuesDotDotOldNeighbor() const = 0;
     373             :   virtual const MooseArray<libMesh::Number> & dofValuesDuDotDu() const = 0;
     374             :   virtual const MooseArray<libMesh::Number> & dofValuesDuDotDuNeighbor() const = 0;
     375             :   virtual const MooseArray<libMesh::Number> & dofValuesDuDotDotDu() const = 0;
     376             :   virtual const MooseArray<libMesh::Number> & dofValuesDuDotDotDuNeighbor() const = 0;
     377             : 
     378             :   template <bool is_ad>
     379             :   const MooseArray<GenericReal<is_ad>> & genericDofValues() const;
     380             : 
     381             :   /**
     382             :    * tag values getters
     383             :    */
     384             :   virtual const FieldVariableValue & vectorTagValue(TagID tag) const = 0;
     385             :   virtual const DofValues & nodalVectorTagValue(TagID tag) const = 0;
     386             :   virtual const DofValues & vectorTagDofValue(TagID tag) const = 0;
     387             :   virtual const DofValues & nodalMatrixTagValue(TagID tag) const = 0;
     388             :   virtual const FieldVariableValue & matrixTagValue(TagID tag) const = 0;
     389             : 
     390             :   virtual void residualSetup() override;
     391             :   virtual void jacobianSetup() override;
     392             :   virtual void timestepSetup() override;
     393             : 
     394             :   using MooseVariableFieldBase::hasBlocks;
     395             :   /*
     396             :    * Returns whether a variable is defined on a block as a functor.
     397             :    * This makes the link between functor block restriction and the
     398             :    * BlockRestrictable interface.
     399             :    * @param id subdomain id we want to know whether the variable is defined on
     400             :    * @return whether the variable is defined on this domain
     401             :    */
     402   553558348 :   bool hasBlocks(const SubdomainID id) const override { return BlockRestrictable::hasBlocks(id); }
     403             : 
     404             : protected:
     405             :   /// the time integrator used for computing time derivatives
     406             :   const TimeIntegrator * const _time_integrator;
     407             : 
     408             :   /// A dummy ADReal variable
     409      180720 :   mutable ADReal _ad_real_dummy = 0;
     410             : };
     411             : 
     412             : template <>
     413             : template <>
     414             : const MooseArray<Real> & MooseVariableField<Real>::genericDofValues<false>() const;
     415             : template <>
     416             : template <>
     417             : const MooseArray<Real> & MooseVariableField<RealVectorValue>::genericDofValues<false>() const;
     418             : template <>
     419             : template <>
     420             : const MooseArray<Real> & MooseVariableField<RealEigenVector>::genericDofValues<false>() const;
     421             : 
     422             : template <typename OutputType>
     423             : template <bool is_ad>
     424             : const MooseArray<GenericReal<is_ad>> &
     425          52 : MooseVariableField<OutputType>::genericDofValues() const
     426             : {
     427          52 :   return adDofValues();
     428             : }
     429             : 
     430             : #define usingMooseVariableFieldMembers                                                             \
     431             :   usingMooseVariableFieldBaseMembers;                                                              \
     432             :   using MooseVariableField<OutputType>::_time_integrator;                                          \
     433             :   using MooseVariableField<OutputType>::_ad_real_dummy;                                            \
     434             :   using MooseVariableField<OutputType>::getSolution
     435             : 
     436             : // Prevent implicit instantiation in other translation units where these classes are used
     437             : extern template class MooseVariableField<Real>;
     438             : extern template class MooseVariableField<RealVectorValue>;
     439             : extern template class MooseVariableField<RealEigenVector>;

Generated by: LCOV version 1.14