LCOV - code coverage report
Current view: top level - include/timeintegrators - CrankNicolson.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             :  * Crank-Nicolson time integrator.
      16             :  *
      17             :  * The scheme is defined as:
      18             :  *   \f$ \frac{du}{dt} = 1/2 * (F(U^{n+1}) + F(U^{n})) \f$,
      19             :  * but the form we are using it in is:
      20             :  *   \f$ 2 * \frac{du}{dt} = (F(U^{n+1}) + F(U^{n})) \f$.
      21             :  */
      22             : class CrankNicolson : public TimeIntegrator
      23             : {
      24             : public:
      25             :   static InputParameters validParams();
      26             : 
      27             :   CrankNicolson(const InputParameters & parameters);
      28             : 
      29             :   virtual void init() override;
      30           0 :   virtual int order() override { return 2; }
      31             :   virtual void computeTimeDerivatives() override;
      32             :   void computeADTimeDerivatives(ADReal & ad_u_dot,
      33             :                                 const dof_id_type & dof,
      34             :                                 ADReal & ad_u_dotdot) const override;
      35             :   virtual void postResidual(NumericVector<Number> & residual) override;
      36             :   virtual void postStep() override;
      37       18134 :   virtual bool overridesSolve() const override { return false; }
      38             : 
      39             : protected:
      40             :   /**
      41             :    * Helper function that actually does the math for computing the time derivative
      42             :    */
      43             :   template <typename T, typename T2>
      44             :   void computeTimeDerivativeHelper(T & u_dot, const T2 & u_old) const;
      45             : 
      46             :   virtual Real duDotDuCoeff() const override;
      47             : 
      48             :   NumericVector<Number> * _residual_old;
      49             : };
      50             : 
      51             : template <typename T, typename T2>
      52             : void
      53       54960 : CrankNicolson::computeTimeDerivativeHelper(T & u_dot, const T2 & u_old) const
      54             : {
      55       54960 :   u_dot -= u_old;
      56       54960 :   u_dot *= 2. / _dt;
      57       54960 : }

Generated by: LCOV version 1.14