LCOV - code coverage report
Current view: top level - include/timeintegrators - LStableDirk2.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 5 6 83.3 %
Date: 2025-07-17 01:28:37 Functions: 2 5 40.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 "TimeIntegrator.h"
      13             : 
      14             : /**
      15             :  * Second order diagonally implicit Runge Kutta method (Dirk) with two stages.
      16             :  *
      17             :  * The Butcher tableau for this method is:
      18             :  * alpha | alpha
      19             :  * 1     | 1-alpha alpha
      20             :  * ---------------------
      21             :  *       | 1-alpha alpha
      22             :  *
      23             :  * where alpha = 1 - sqrt(2)/2 ~ .29289
      24             :  *
      25             :  * The stability function for this method is:
      26             :  * R(z) = 4*(-z*(-sqrt(2) + 2) + z + 1) / (z**2*(-sqrt(2) + 2)**2 - 4*z*(-sqrt(2) + 2) + 4)
      27             :  *
      28             :  * The method is L-stable:
      29             :  * lim R(z), z->oo = 0
      30             :  *
      31             :  * Notes: This method is derived in detail in: R. Alexander,
      32             :  * "Diagonally implicit Runge-Kutta Methods for Stiff ODEs", SIAM
      33             :  * J. Numer. Anal., 14(6), Dec. 1977, pg. 1006-1021.  This method is
      34             :  * more expensive than Crank-Nicolson, but has the advantage of being
      35             :  * L-stable (the same type of stability as the implicit Euler method)
      36             :  * so may be more suitable for "stiff" problems.
      37             :  */
      38             : class LStableDirk2 : public TimeIntegrator
      39             : {
      40             : public:
      41             :   static InputParameters validParams();
      42             : 
      43             :   LStableDirk2(const InputParameters & parameters);
      44             : 
      45           0 :   virtual int order() override { return 2; }
      46             :   virtual void computeTimeDerivatives() override;
      47             :   void computeADTimeDerivatives(ADReal & ad_u_dot,
      48             :                                 const dof_id_type & dof,
      49             :                                 ADReal & ad_u_dotdot) const override;
      50             :   virtual void solve() override;
      51             :   virtual void postResidual(NumericVector<Number> & residual) override;
      52         462 :   virtual bool overridesSolve() const override { return true; }
      53             : 
      54             : protected:
      55             :   /**
      56             :    * Helper function that actually does the math for computing the time derivative
      57             :    */
      58             :   template <typename T, typename T2>
      59             :   void computeTimeDerivativeHelper(T & u_dot, const T2 & u_old) const;
      60             : 
      61             :   //! Indicates the current stage (1 or 2).
      62             :   unsigned int _stage;
      63             : 
      64             :   //! Buffer to store non-time residual from first stage solve.
      65             :   NumericVector<Number> * _residual_stage1;
      66             : 
      67             :   //! Buffer to store non-time residual from second stage solve
      68             :   NumericVector<Number> * _residual_stage2;
      69             : 
      70             :   // The parameter of the method, set at construction time and cannot be changed.
      71             :   const Real _alpha;
      72             : };
      73             : 
      74             : template <typename T, typename T2>
      75             : void
      76        7327 : LStableDirk2::computeTimeDerivativeHelper(T & u_dot, const T2 & u_old) const
      77             : {
      78        7327 :   u_dot -= u_old;
      79        7327 :   u_dot *= 1. / _dt;
      80        7327 : }

Generated by: LCOV version 1.14