LCOV - code coverage report
Current view: top level - include/auxkernels - AuxKernel.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 18 27 66.7 %
Date: 2026-05-29 20:35:17 Functions: 34 34 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 "AuxKernelBase.h"
      13             : #include "MooseVariableInterface.h"
      14             : 
      15             : // forward declarations
      16             : template <typename ComputeValueType>
      17             : class AuxKernelTempl;
      18             : 
      19             : typedef AuxKernelTempl<Real> AuxKernel;
      20             : typedef AuxKernelTempl<RealVectorValue> VectorAuxKernel;
      21             : typedef AuxKernelTempl<RealEigenVector> ArrayAuxKernel;
      22             : 
      23             : /**
      24             :  * Base class for creating new auxiliary kernels and auxiliary boundary conditions.
      25             :  */
      26             : template <typename ComputeValueType>
      27             : class AuxKernelTempl : public AuxKernelBase, public MooseVariableInterface<ComputeValueType>
      28             : {
      29             : public:
      30             :   static InputParameters validParams();
      31             : 
      32             :   AuxKernelTempl(const InputParameters & parameters);
      33             : 
      34             :   /**
      35             :    * Computes the value and stores it in the solution vector
      36             :    */
      37             :   virtual void compute() override;
      38             : 
      39             :   /**
      40             :    * Nodal or elemental kernel?
      41             :    * @return true if this is a nodal kernel, otherwise false
      42             :    */
      43   113509676 :   bool isNodal() const { return _nodal; }
      44             : 
      45             :   /**
      46             :    * @return whether this is a mortar auxiliary kernel
      47             :    */
      48             :   bool isMortar();
      49             : 
      50             :   /**
      51             :    * Get a reference to a variable this kernel is action on
      52             :    * @return reference to a variable this kernel is action on
      53             :    */
      54    76160157 :   MooseVariableField<ComputeValueType> & variable() { return _var; }
      55             : 
      56             :   /**
      57             :    * Override functions from MaterialPropertyInterface for error checking
      58             :    */
      59             :   template <typename T>
      60             :   const MaterialProperty<T> & getMaterialProperty(const std::string & name);
      61             :   template <typename T, bool is_ad>
      62             :   const GenericMaterialProperty<T, is_ad> & getGenericMaterialProperty(const std::string & name);
      63             :   template <typename T>
      64             :   const MaterialProperty<T> & getMaterialPropertyOld(const std::string & name);
      65             :   template <typename T>
      66             :   const MaterialProperty<T> & getMaterialPropertyOlder(const std::string & name);
      67             : 
      68             :   /**
      69             :    * Insert the just computed values into the auxiliary solution vector
      70             :    */
      71             :   void insert();
      72             : 
      73             :   /**
      74             :    * Determines whether we're a coincident lower-d calculation
      75             :    */
      76             :   void determineWhetherCoincidentLowerDCalc();
      77             : 
      78             : protected:
      79             :   /**
      80             :    * Compute and return the value of the aux variable.
      81             :    */
      82             :   virtual ComputeValueType computeValue() = 0;
      83             : 
      84             :   virtual const VariableValue & coupledDot(const std::string & var_name,
      85             :                                            unsigned int comp = 0) const override;
      86             : 
      87             :   virtual const VariableValue & coupledDotDu(const std::string & var_name,
      88             :                                              unsigned int comp = 0) const override;
      89             : 
      90             :   /// This callback is used for AuxKernelTempls that need to perform a per-element calculation
      91    47128074 :   virtual void precalculateValue() {}
      92             : 
      93             :   /**
      94             :    * Retrieves the old value of the variable that this AuxKernel operates on.
      95             :    *
      96             :    * Store this as a _reference_ in the constructor.
      97             :    */
      98             :   const typename OutputTools<ComputeValueType>::VariableValue & uOld() const;
      99             : 
     100             :   /**
     101             :    * Retrieves the older value of the variable that this AuxKernel operates on.
     102             :    *
     103             :    * Store this as a _reference_ in the constructor.
     104             :    */
     105             :   const typename OutputTools<ComputeValueType>::VariableValue & uOlder() const;
     106             : 
     107             :   /// This is a regular kernel so we cast to a regular MooseVariable, hides base _var
     108             :   MooseVariableField<ComputeValueType> & _var;
     109             : 
     110             :   /// Flag indicating if the AuxKernel is nodal
     111             :   const bool _nodal;
     112             : 
     113             :   /// Holds the solution at current quadrature points
     114             :   const typename OutputTools<ComputeValueType>::VariableValue & _u;
     115             : 
     116             :   /// Holds the the test functions
     117             :   const typename OutputTools<ComputeValueType>::VariableTestValue & _test;
     118             : 
     119             :   /// Active quadrature points
     120             :   const MooseArray<Point> & _q_point;
     121             :   /// Quadrature rule being used
     122             :   const QBase * const & _qrule;
     123             :   /// Transformed Jacobian weights
     124             :   const MooseArray<Real> & _JxW;
     125             :   const MooseArray<Real> & _coord;
     126             : 
     127             :   /// Current element (valid only for elemental kernels)
     128             :   const Elem * const & _current_elem;
     129             :   /// current side of the current element
     130             :   const unsigned int & _current_side;
     131             : 
     132             :   /// Volume of the current element
     133             :   const Real & _current_elem_volume;
     134             :   /// Volume of the current side
     135             :   const Real & _current_side_volume;
     136             : 
     137             :   /// Current node (valid only for nodal kernels)
     138             :   const Node * const & _current_node;
     139             : 
     140             :   /// The current boundary ID
     141             :   const BoundaryID & _current_boundary_id;
     142             : 
     143             :   /// reference to the solution vector of auxiliary system
     144             :   NumericVector<Number> & _solution;
     145             : 
     146             :   /// The current lower dimensional element
     147             :   const Elem * const & _current_lower_d_elem;
     148             : 
     149             :   /// Quadrature point index
     150             :   unsigned int _qp;
     151             : 
     152             :   /// number of shape functions for the finite element type and current DofObject
     153             :   unsigned int _n_shapes;
     154             : 
     155             :   typedef typename Moose::DOFType<ComputeValueType>::type OutputData;
     156             : 
     157             :   /// for holding local load
     158             :   DenseVector<OutputData> _local_re;
     159             :   /// for holding local solution
     160             :   DenseVector<OutputData> _local_sol;
     161             :   /// for holding local mass matrix
     162             :   DenseMatrix<Number> _local_ke;
     163             : 
     164             :   /// Whether we are computing for a lower dimensional variable using boundary restriction, e.g. a
     165             :   /// variable whose block restriction is coincident with a higher-dimensional boundary face
     166             :   std::optional<bool> _coincident_lower_d_calc;
     167             : 
     168             :   using MooseVariableInterface<ComputeValueType>::mooseVariableBase;
     169             : 
     170             : private:
     171             :   /**
     172             :    * Currently only used when the auxiliary variable is a finite volume variable, this helps call
     173             :    * through to the variable's \p setDofValue method. This helper is necessary because \p
     174             :    * MooseVariableField::setDofValue expects a \p Real even when a variable is a vector variable, so
     175             :    * we cannot simply pass through to that method with the result of \p computeValue when \p
     176             :    * ComputeValueType is \p RealVectorValue
     177             :    */
     178             :   void setDofValueHelper(const ComputeValueType & dof_value);
     179             : };
     180             : 
     181             : template <typename ComputeValueType>
     182             : template <typename T>
     183             : const MaterialProperty<T> &
     184         215 : AuxKernelTempl<ComputeValueType>::getMaterialProperty(const std::string & name)
     185             : {
     186         215 :   if (isNodal())
     187           0 :     mooseError("Nodal AuxKernel '",
     188           0 :                AuxKernelTempl::name(),
     189             :                "' attempted to reference material property '",
     190             :                name,
     191             :                "'\nConsider using an elemental auxiliary variable for '",
     192           0 :                _var.name(),
     193             :                "'.");
     194             : 
     195         215 :   return MaterialPropertyInterface::getMaterialProperty<T>(name);
     196             : }
     197             : 
     198             : template <typename ComputeValueType>
     199             : template <typename T, bool is_ad>
     200             : const GenericMaterialProperty<T, is_ad> &
     201       34789 : AuxKernelTempl<ComputeValueType>::getGenericMaterialProperty(const std::string & name)
     202             : {
     203       34789 :   if (isNodal())
     204           3 :     mooseError("Nodal AuxKernel '",
     205           3 :                AuxKernelTempl::name(),
     206             :                "' attempted to reference material property '",
     207             :                name,
     208             :                "'\nConsider using an elemental auxiliary variable for '",
     209           3 :                _var.name(),
     210             :                "'.");
     211             : 
     212       34786 :   return MaterialPropertyInterface::getGenericMaterialProperty<T, is_ad>(name);
     213             : }
     214             : 
     215             : template <typename ComputeValueType>
     216             : template <typename T>
     217             : const MaterialProperty<T> &
     218          26 : AuxKernelTempl<ComputeValueType>::getMaterialPropertyOld(const std::string & name)
     219             : {
     220          26 :   if (isNodal())
     221           0 :     mooseError("Nodal AuxKernel '",
     222           0 :                AuxKernelTempl::name(),
     223             :                "' attempted to reference material property '",
     224             :                name,
     225             :                "'\nConsider using an elemental auxiliary variable for '",
     226           0 :                _var.name(),
     227             :                "'.");
     228             : 
     229          26 :   return MaterialPropertyInterface::getMaterialPropertyOld<T>(name);
     230             : }
     231             : 
     232             : template <typename ComputeValueType>
     233             : template <typename T>
     234             : const MaterialProperty<T> &
     235          13 : AuxKernelTempl<ComputeValueType>::getMaterialPropertyOlder(const std::string & name)
     236             : {
     237          13 :   if (isNodal())
     238           0 :     mooseError("Nodal AuxKernel '",
     239           0 :                AuxKernelTempl::name(),
     240             :                "' attempted to reference material property '",
     241             :                name,
     242             :                "'\nConsider using an elemental auxiliary variable for '",
     243           0 :                _var.name(),
     244             :                "'.");
     245             : 
     246          13 :   return MaterialPropertyInterface::getMaterialPropertyOlder<T>(name);
     247             : }
     248             : 
     249             : // Declare all the specializations, as the template specialization declaration below must know
     250             : template <>
     251             : void AuxKernelTempl<Real>::setDofValueHelper(const Real & value);
     252             : template <>
     253             : void AuxKernelTempl<RealVectorValue>::setDofValueHelper(const RealVectorValue &);
     254             : template <>
     255             : void AuxKernelTempl<RealEigenVector>::compute();
     256             : 
     257             : // Prevent implicit instantiation in other translation units where these classes are used
     258             : extern template class AuxKernelTempl<Real>;
     259             : extern template class AuxKernelTempl<RealVectorValue>;
     260             : extern template class AuxKernelTempl<RealEigenVector>;

Generated by: LCOV version 1.14