https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
18class BDF2 : public TimeIntegrator
19{
20public:
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 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 virtual unsigned int numStatesRequired() const override { return 2; }
37
38protected:
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
51 const NumericVector<Number> & _solution_older;
52};
53
54namespace BDF2Helper
55{
56}
57
58template <typename T, typename T2, typename T3, typename T4>
59void
61 const T2 & u,
62 const T3 & u_old,
63 const T4 & u_older) const
64{
65 if (_t_step == 1)
66 {
67 u_dot -= u_old;
68 u_dot *= 1 / _dt;
69 }
70 else
71 {
72 MathUtils::addScaled(_weight[0], u, u_dot);
73 MathUtils::addScaled(_weight[1], u_old, u_dot);
74 MathUtils::addScaled(_weight[2], u_older, u_dot);
75 u_dot *= 1. / _dt;
76 }
77}
DualNumber< Real, DNDerivativeType, true > ADReal
BDF2 time integrator.
Definition BDF2.h:19
virtual bool overridesSolve() const override
Definition BDF2.h:32
virtual Real duDotDuCoeff() const override
Definition BDF2.C:81
virtual void postResidual(NumericVector< Number > &residual) override
Callback to the NonLinearTimeIntegratorInterface called immediately after the residuals are computed ...
Definition BDF2.C:73
virtual int order() override
Definition BDF2.h:25
virtual Real timeDerivativeRHSContribution(const dof_id_type dof_id, const std::vector< Real > &factors) const override
The time derivative's contribution to the right hand side of a linear system.
Definition BDF2.C:90
std::vector< Real > & _weight
Definition BDF2.h:48
virtual unsigned int numStatesRequired() const override
Return the number of states this requires in a linear system setting.
Definition BDF2.h:36
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
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:60
virtual void computeTimeDerivatives() override
Computes the time derivative and the Jacobian of the time derivative.
Definition BDF2.C:45
virtual Real timeDerivativeMatrixContribution(const Real factor) const override
The time derivative's contribution to the right hand side of a linear system.
Definition BDF2.C:104
virtual void preStep() override
Definition BDF2.C:33
static InputParameters validParams()
Definition BDF2.C:16
const NumericVector< Number > & _solution_older
The older solution.
Definition BDF2.h:51
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
Base class for time integrators.
Real & _dt
The current time step size.
int & _t_step
The current time step number.
void addScaled(const T &a, const T2 &b, T3 &result)
Definition MathUtils.h:175