LCOV - code coverage report
Current view: top level - include/kernels - ADKernel.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 8601ad Lines: 2 4 50.0 %
Date: 2025-07-18 13:27:08 Functions: 4 8 50.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 "KernelBase.h"
      13             : #include "ADFunctorInterface.h"
      14             : #include "MooseVariableInterface.h"
      15             : 
      16             : // forward declarations
      17             : template <typename>
      18             : class ADKernelTempl;
      19             : 
      20             : using ADKernel = ADKernelTempl<Real>;
      21             : using ADVectorKernel = ADKernelTempl<RealVectorValue>;
      22             : 
      23             : template <typename T>
      24             : class ADKernelTempl : public KernelBase, public MooseVariableInterface<T>, public ADFunctorInterface
      25             : {
      26             : public:
      27             :   static InputParameters validParams();
      28             : 
      29             :   ADKernelTempl(const InputParameters & parameters);
      30             : 
      31             :   void jacobianSetup() override;
      32             : 
      33     2225481 :   const MooseVariableFE<T> & variable() const override { return _var; }
      34             : 
      35             : protected:
      36             :   void computeJacobian() override;
      37             :   void computeResidualAndJacobian() override;
      38             :   void computeOffDiagJacobian(unsigned int) override;
      39             :   void computeOffDiagJacobianScalar(unsigned int jvar) override;
      40             : 
      41             :   /**
      42             :    * Just as we allow someone deriving from this to modify the
      43             :    * \p _residuals data member in their \p computeResidualsForJacobian
      44             :    * overrides, we must also potentially allow them to modify the dof
      45             :    * indices. For example a user could have something like an \p LMKernel which sums computed
      46             :    * strong residuals into both primal and LM residuals. That user needs to be
      47             :    * able to feed dof indices from both the primal and LM variable into
      48             :    * \p Assembly::addJacobian
      49             :    */
      50     1545319 :   virtual const std::vector<dof_id_type> & dofIndices() const { return _var.dofIndices(); }
      51             : 
      52             : protected:
      53             :   // See KernelBase base for documentation of these overridden methods
      54             :   void computeResidual() override;
      55             : 
      56             :   /**
      57             :    * compute the \p _residuals member for filling the Jacobian. We want to calculate these residuals
      58             :    * up-front when doing loal derivative indexing because we can use those residuals to fill \p
      59             :    * _local_ke for every associated jvariable. We do not want to re-do these calculations for every
      60             :    * jvariable and corresponding \p _local_ke. For global indexing we will simply pass the computed
      61             :    * \p _residuals directly to \p Assembly::addJacobian
      62             :    */
      63             :   virtual void computeResidualsForJacobian();
      64             : 
      65             :   /// Compute this Kernel's contribution to the residual at the current quadrature point
      66             :   virtual ADReal computeQpResidual() = 0;
      67             : 
      68             :   /**
      69             :    * Compute this Kernel's contribution to the Jacobian at the current quadrature point
      70             :    */
      71           0 :   virtual Real computeQpJacobian() { return 0; }
      72             : 
      73             :   /**
      74             :    * This is the virtual that derived classes should override for computing an off-diagonal Jacobian
      75             :    * component.
      76             :    */
      77           0 :   virtual Real computeQpOffDiagJacobian(unsigned int /*jvar*/) { return 0; }
      78             : 
      79             :   /// This is a regular kernel so we cast to a regular MooseVariable
      80             :   MooseVariableFE<T> & _var;
      81             : 
      82             :   /// the current test function
      83             :   const ADTemplateVariableTestValue<T> & _test;
      84             : 
      85             :   /// gradient of the test function
      86             :   const ADTemplateVariableTestGradient<T> & _grad_test;
      87             : 
      88             :   // gradient of the test function without possible displacement derivatives
      89             :   const typename OutputTools<T>::VariableTestGradient & _regular_grad_test;
      90             : 
      91             :   /// Holds the solution at current quadrature points
      92             :   const ADTemplateVariableValue<T> & _u;
      93             : 
      94             :   /// Holds the solution gradient at the current quadrature points
      95             :   const ADTemplateVariableGradient<T> & _grad_u;
      96             : 
      97             :   /// The ad version of JxW
      98             :   const MooseArray<ADReal> & _ad_JxW;
      99             : 
     100             :   /// The ad version of coord
     101             :   const MooseArray<ADReal> & _ad_coord;
     102             : 
     103             :   /// The ad version of q_point
     104             :   const MooseArray<ADPoint> & _ad_q_point;
     105             : 
     106             :   /// The current shape functions
     107             :   const ADTemplateVariablePhiValue<T> & _phi;
     108             : 
     109             :   ADReal _r;
     110             :   std::vector<Real> _residuals_nonad;
     111             :   std::vector<ADReal> _residuals;
     112             : 
     113             :   /// The current gradient of the shape functions
     114             :   const ADTemplateVariablePhiGradient<T> & _grad_phi;
     115             : 
     116             :   /// The current gradient of the shape functions without possible displacement derivatives
     117             :   const typename OutputTools<T>::VariablePhiGradient & _regular_grad_phi;
     118             : 
     119             : private:
     120             :   /**
     121             :    * compute all the Jacobian entries
     122             :    */
     123             :   void computeADJacobian();
     124             : 
     125             :   const Elem * _my_elem;
     126             : };

Generated by: LCOV version 1.14