LCOV - code coverage report
Current view: top level - include/auxkernels - AuxKernel.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33187 (5aa0b2) with base d7c4bd Lines: 18 27 66.7 %
Date: 2026-06-30 12:18:20 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   113541424 :   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    76175598 :   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             :   using MooseVariableDependencyInterface::checkVariables;
      79             :   virtual std::set<MooseVariableFieldBase *>
      80             :   checkVariables(const libMesh::Node & node,
      81             :                  const std::set<MooseVariableFieldBase *> & vars_to_check) override;
      82             : 
      83             : protected:
      84             :   /**
      85             :    * Compute and return the value of the aux variable.
      86             :    */
      87             :   virtual ComputeValueType computeValue() = 0;
      88             : 
      89             :   virtual const VariableValue & coupledDot(const std::string & var_name,
      90             :                                            unsigned int comp = 0) const override;
      91             : 
      92             :   virtual const VariableValue & coupledDotDu(const std::string & var_name,
      93             :                                              unsigned int comp = 0) const override;
      94             : 
      95             :   /// This callback is used for AuxKernelTempls that need to perform a per-element calculation
      96    47141400 :   virtual void precalculateValue() {}
      97             : 
      98             :   /**
      99             :    * Retrieves the old value of the variable that this AuxKernel operates on.
     100             :    *
     101             :    * Store this as a _reference_ in the constructor.
     102             :    */
     103             :   const typename OutputTools<ComputeValueType>::VariableValue & uOld() const;
     104             : 
     105             :   /**
     106             :    * Retrieves the older value of the variable that this AuxKernel operates on.
     107             :    *
     108             :    * Store this as a _reference_ in the constructor.
     109             :    */
     110             :   const typename OutputTools<ComputeValueType>::VariableValue & uOlder() const;
     111             : 
     112             :   /// This is a regular kernel so we cast to a regular MooseVariable, hides base _var
     113             :   MooseVariableField<ComputeValueType> & _var;
     114             : 
     115             :   /// Flag indicating if the AuxKernel is nodal
     116             :   const bool _nodal;
     117             : 
     118             :   /// Holds the solution at current quadrature points
     119             :   const typename OutputTools<ComputeValueType>::VariableValue & _u;
     120             : 
     121             :   /// Holds the the test functions
     122             :   const typename OutputTools<ComputeValueType>::VariableTestValue & _test;
     123             : 
     124             :   /// Active quadrature points
     125             :   const MooseArray<Point> & _q_point;
     126             :   /// Quadrature rule being used
     127             :   const QBase * const & _qrule;
     128             :   /// Transformed Jacobian weights
     129             :   const MooseArray<Real> & _JxW;
     130             :   const MooseArray<Real> & _coord;
     131             : 
     132             :   /// Current element (valid only for elemental kernels)
     133             :   const Elem * const & _current_elem;
     134             :   /// current side of the current element
     135             :   const unsigned int & _current_side;
     136             : 
     137             :   /// Volume of the current element
     138             :   const Real & _current_elem_volume;
     139             :   /// Volume of the current side
     140             :   const Real & _current_side_volume;
     141             : 
     142             :   /// Current node (valid only for nodal kernels)
     143             :   const Node * const & _current_node;
     144             : 
     145             :   /// The current boundary ID
     146             :   const BoundaryID & _current_boundary_id;
     147             : 
     148             :   /// reference to the solution vector of auxiliary system
     149             :   NumericVector<Number> & _solution;
     150             : 
     151             :   /// The current lower dimensional element
     152             :   const Elem * const & _current_lower_d_elem;
     153             : 
     154             :   /// Quadrature point index
     155             :   unsigned int _qp;
     156             : 
     157             :   /// number of shape functions for the finite element type and current DofObject
     158             :   unsigned int _n_shapes;
     159             : 
     160             :   typedef typename Moose::DOFType<ComputeValueType>::type OutputData;
     161             : 
     162             :   /// for holding local load
     163             :   DenseVector<OutputData> _local_re;
     164             :   /// for holding local solution
     165             :   DenseVector<OutputData> _local_sol;
     166             :   /// for holding local mass matrix
     167             :   DenseMatrix<Number> _local_ke;
     168             : 
     169             :   /// Whether we are computing for a lower dimensional variable using boundary restriction, e.g. a
     170             :   /// variable whose block restriction is coincident with a higher-dimensional boundary face
     171             :   std::optional<bool> _coincident_lower_d_calc;
     172             : 
     173             :   using MooseVariableInterface<ComputeValueType>::mooseVariableBase;
     174             : 
     175             : private:
     176             :   /**
     177             :    * Currently only used when the auxiliary variable is a finite volume variable, this helps call
     178             :    * through to the variable's \p setDofValue method. This helper is necessary because \p
     179             :    * MooseVariableField::setDofValue expects a \p Real even when a variable is a vector variable, so
     180             :    * we cannot simply pass through to that method with the result of \p computeValue when \p
     181             :    * ComputeValueType is \p RealVectorValue
     182             :    */
     183             :   void setDofValueHelper(const ComputeValueType & dof_value);
     184             : };
     185             : 
     186             : template <typename ComputeValueType>
     187             : template <typename T>
     188             : const MaterialProperty<T> &
     189         215 : AuxKernelTempl<ComputeValueType>::getMaterialProperty(const std::string & name)
     190             : {
     191         215 :   if (isNodal())
     192           0 :     mooseError("Nodal AuxKernel '",
     193           0 :                AuxKernelTempl::name(),
     194             :                "' attempted to reference material property '",
     195             :                name,
     196             :                "'\nConsider using an elemental auxiliary variable for '",
     197           0 :                _var.name(),
     198             :                "'.");
     199             : 
     200         215 :   return MaterialPropertyInterface::getMaterialProperty<T>(name);
     201             : }
     202             : 
     203             : template <typename ComputeValueType>
     204             : template <typename T, bool is_ad>
     205             : const GenericMaterialProperty<T, is_ad> &
     206       34838 : AuxKernelTempl<ComputeValueType>::getGenericMaterialProperty(const std::string & name)
     207             : {
     208       34838 :   if (isNodal())
     209           3 :     mooseError("Nodal AuxKernel '",
     210           3 :                AuxKernelTempl::name(),
     211             :                "' attempted to reference material property '",
     212             :                name,
     213             :                "'\nConsider using an elemental auxiliary variable for '",
     214           3 :                _var.name(),
     215             :                "'.");
     216             : 
     217       34835 :   return MaterialPropertyInterface::getGenericMaterialProperty<T, is_ad>(name);
     218             : }
     219             : 
     220             : template <typename ComputeValueType>
     221             : template <typename T>
     222             : const MaterialProperty<T> &
     223          26 : AuxKernelTempl<ComputeValueType>::getMaterialPropertyOld(const std::string & name)
     224             : {
     225          26 :   if (isNodal())
     226           0 :     mooseError("Nodal AuxKernel '",
     227           0 :                AuxKernelTempl::name(),
     228             :                "' attempted to reference material property '",
     229             :                name,
     230             :                "'\nConsider using an elemental auxiliary variable for '",
     231           0 :                _var.name(),
     232             :                "'.");
     233             : 
     234          26 :   return MaterialPropertyInterface::getMaterialPropertyOld<T>(name);
     235             : }
     236             : 
     237             : template <typename ComputeValueType>
     238             : template <typename T>
     239             : const MaterialProperty<T> &
     240          13 : AuxKernelTempl<ComputeValueType>::getMaterialPropertyOlder(const std::string & name)
     241             : {
     242          13 :   if (isNodal())
     243           0 :     mooseError("Nodal AuxKernel '",
     244           0 :                AuxKernelTempl::name(),
     245             :                "' attempted to reference material property '",
     246             :                name,
     247             :                "'\nConsider using an elemental auxiliary variable for '",
     248           0 :                _var.name(),
     249             :                "'.");
     250             : 
     251          13 :   return MaterialPropertyInterface::getMaterialPropertyOlder<T>(name);
     252             : }
     253             : 
     254             : // Declare all the specializations, as the template specialization declaration below must know
     255             : template <>
     256             : void AuxKernelTempl<Real>::setDofValueHelper(const Real & value);
     257             : template <>
     258             : void AuxKernelTempl<RealVectorValue>::setDofValueHelper(const RealVectorValue &);
     259             : template <>
     260             : void AuxKernelTempl<RealEigenVector>::compute();
     261             : 
     262             : // Prevent implicit instantiation in other translation units where these classes are used
     263             : extern template class AuxKernelTempl<Real>;
     264             : extern template class AuxKernelTempl<RealVectorValue>;
     265             : extern template class AuxKernelTempl<RealEigenVector>;

Generated by: LCOV version 1.14