https://mooseframework.inl.gov
BDF2.h
Go to the documentation of this file.
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 
18 class BDF2 : public TimeIntegrator
19 {
20 public:
22 
24 
25  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  virtual bool overridesSolve() const override { return false; }
33 
34 protected:
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 
48 };
49 
50 namespace BDF2Helper
51 {
52 }
53 
54 template <typename T, typename T2, typename T3, typename T4>
55 void
57  const T2 & u,
58  const T3 & u_old,
59  const T4 & u_older) const
60 {
61  if (_t_step == 1)
62  {
63  u_dot -= u_old;
64  u_dot *= 1 / _dt;
65  }
66  else
67  {
68  MathUtils::addScaled(_weight[0], u, u_dot);
69  MathUtils::addScaled(_weight[1], u_old, u_dot);
70  MathUtils::addScaled(_weight[2], u_older, u_dot);
71  u_dot *= 1. / _dt;
72  }
73 }
void addScaled(const T &a, const T2 &b, T3 &result)
Definition: MathUtils.h:170
virtual int order() override
Definition: BDF2.h:25
virtual void computeTimeDerivatives() override
Computes the time derivative and the Jacobian of the time derivative.
Definition: BDF2.C:45
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:47
Real & _dt
The current time step size.
BDF2 time integrator.
Definition: BDF2.h:18
const NumericVector< Number > & _solution_older
The older solution.
Definition: BDF2.h:47
std::vector< Real > & _weight
Definition: BDF2.h:44
virtual void preStep() override
Definition: BDF2.C:33
void computeTimeDerivativeHelper(T &u_dot, const T2 &u, const T3 &u_old, const T4 &u_older) const
Helper function that actually does the math for computing the time derivative.
Definition: BDF2.h:56
void computeADTimeDerivatives(ADReal &ad_u_dot, const dof_id_type &dof, ADReal &ad_u_dotdot) const override
method for computing local automatic differentiation time derivatives
Definition: BDF2.C:62
BDF2(const InputParameters &parameters)
Definition: BDF2.C:24
static InputParameters validParams()
Definition: BDF2.C:16
virtual void postResidual(NumericVector< Number > &residual) override
Callback to the NonLinearTimeIntegratorInterface called immediately after the residuals are computed ...
Definition: BDF2.C:73
virtual bool overridesSolve() const override
Definition: BDF2.h:32
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Base class for time integrators.
virtual Real duDotDuCoeff() const override
Definition: BDF2.C:81
const InputParameters & parameters() const
Get the parameters of the object.
int & _t_step
The current time step number.
uint8_t dof_id_type