LCOV - code coverage report
Current view: top level - include/timeintegrators - BDF2.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 10 11 90.9 %
Date: 2025-07-17 01:28:37 Functions: 4 5 80.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             : #include "MathUtils.h"
      14             : 
      15             : /**
      16             :  * BDF2 time integrator
      17             :  */
      18             : class BDF2 : public TimeIntegrator
      19             : {
      20             : public:
      21             :   static InputParameters validParams();
      22             : 
      23             :   BDF2(const InputParameters & parameters);
      24             : 
      25           0 :   virtual int order() override { return 2; }
      26             :   virtual void preStep() override;
      27             :   virtual void computeTimeDerivatives() override;
      28             :   void computeADTimeDerivatives(ADReal & ad_u_dot,
      29             :                                 const dof_id_type & dof,
      30             :                                 ADReal & ad_u_dotdot) const override;
      31             :   virtual void postResidual(NumericVector<Number> & residual) override;
      32        4138 :   virtual bool overridesSolve() const override { return false; }
      33             : 
      34             : protected:
      35             :   /**
      36             :    * Helper function that actually does the math for computing the time derivative
      37             :    */
      38             :   template <typename T, typename T2, typename T3, typename T4>
      39             :   void
      40             :   computeTimeDerivativeHelper(T & u_dot, const T2 & u, const T3 & u_old, const T4 & u_older) const;
      41             : 
      42             :   virtual Real duDotDuCoeff() const override;
      43             : 
      44             :   std::vector<Real> & _weight;
      45             : 
      46             :   /// The older solution
      47             :   const NumericVector<Number> & _solution_older;
      48             : };
      49             : 
      50             : namespace BDF2Helper
      51             : {
      52             : }
      53             : 
      54             : template <typename T, typename T2, typename T3, typename T4>
      55             : void
      56      788961 : BDF2::computeTimeDerivativeHelper(T & u_dot,
      57             :                                   const T2 & u,
      58             :                                   const T3 & u_old,
      59             :                                   const T4 & u_older) const
      60             : {
      61      788961 :   if (_t_step == 1)
      62             :   {
      63       80096 :     u_dot -= u_old;
      64       80096 :     u_dot *= 1 / _dt;
      65             :   }
      66             :   else
      67             :   {
      68      708865 :     MathUtils::addScaled(_weight[0], u, u_dot);
      69      708865 :     MathUtils::addScaled(_weight[1], u_old, u_dot);
      70      708865 :     MathUtils::addScaled(_weight[2], u_older, u_dot);
      71      708865 :     u_dot *= 1. / _dt;
      72             :   }
      73      788961 : }

Generated by: LCOV version 1.14