LCOV - code coverage report
Current view: top level - include/timeintegrators - BDF2.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 11 12 91.7 %
Date: 2026-05-29 20:35:17 Functions: 5 6 83.3 %
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        4562 :   virtual bool overridesSolve() const override { return false; }
      33             :   virtual Real timeDerivativeRHSContribution(const dof_id_type dof_id,
      34             :                                              const std::vector<Real> & factors) const override;
      35             :   virtual Real timeDerivativeMatrixContribution(const Real factor) const override;
      36          18 :   virtual unsigned int numStatesRequired() const override { return 2; }
      37             : 
      38             : protected:
      39             :   /**
      40             :    * Helper function that actually does the math for computing the time derivative
      41             :    */
      42             :   template <typename T, typename T2, typename T3, typename T4>
      43             :   void
      44             :   computeTimeDerivativeHelper(T & u_dot, const T2 & u, const T3 & u_old, const T4 & u_older) const;
      45             : 
      46             :   virtual Real duDotDuCoeff() const override;
      47             : 
      48             :   std::vector<Real> & _weight;
      49             : 
      50             :   /// The older solution
      51             :   const NumericVector<Number> & _solution_older;
      52             : };
      53             : 
      54             : namespace BDF2Helper
      55             : {
      56             : }
      57             : 
      58             : template <typename T, typename T2, typename T3, typename T4>
      59             : void
      60     1042638 : BDF2::computeTimeDerivativeHelper(T & u_dot,
      61             :                                   const T2 & u,
      62             :                                   const T3 & u_old,
      63             :                                   const T4 & u_older) const
      64             : {
      65     1042638 :   if (_t_step == 1)
      66             :   {
      67      129890 :     u_dot -= u_old;
      68      129890 :     u_dot *= 1 / _dt;
      69             :   }
      70             :   else
      71             :   {
      72      912748 :     MathUtils::addScaled(_weight[0], u, u_dot);
      73      912748 :     MathUtils::addScaled(_weight[1], u_old, u_dot);
      74      912748 :     MathUtils::addScaled(_weight[2], u_older, u_dot);
      75      912748 :     u_dot *= 1. / _dt;
      76             :   }
      77     1042638 : }

Generated by: LCOV version 1.14