https://mooseframework.inl.gov
BDF2.C
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 #include "BDF2.h"
11 #include "NonlinearSystem.h"
12 
13 registerMooseObject("MooseApp", BDF2);
14 
17 {
19  params.addClassDescription(
20  "Second order backward differentiation formula time integration scheme.");
21  return params;
22 }
23 
24 BDF2::BDF2(const InputParameters & parameters)
25  : TimeIntegrator(parameters),
26  _weight(declareRestartableData<std::vector<Real>>("weight")),
27  _solution_older(_sys.solutionState(2))
28 {
29  _weight.resize(3);
30 }
31 
32 void
34 {
35  if (_t_step > 1)
36  {
37  Real sum = _dt + _dt_old;
38  _weight[0] = 1. + _dt / sum;
39  _weight[1] = -sum / _dt_old;
40  _weight[2] = _dt * _dt / _dt_old / sum;
41  }
42 }
43 
44 void
46 {
47  if (!_sys.solutionUDot())
48  mooseError("BDF2: Time derivative of solution (`u_dot`) is not stored. Please set "
49  "uDotRequested() to true in FEProblemBase befor requesting `u_dot`.");
50 
52  if (_t_step == 1)
53  u_dot = *_solution;
54  else
55  u_dot.zero();
57  u_dot.close();
59 }
60 
61 void
63  const dof_id_type & dof,
64  ADReal & /*ad_u_dotdot*/) const
65 {
66  auto ad_sln = ad_u_dot;
67  if (_t_step != 1)
68  ad_u_dot = 0;
69  computeTimeDerivativeHelper(ad_u_dot, ad_sln, _solution_old(dof), _solution_older(dof));
70 }
71 
72 void
74 {
75  residual += *_Re_time;
76  residual += *_Re_non_time;
77  residual.close();
78 }
79 
80 Real
82 {
83  if (_t_step == 1)
84  return 1;
85  else
86  return _weight[0];
87 }
virtual void computeTimeDerivatives() override
Computes the time derivative and the Jacobian of the time derivative.
Definition: BDF2.C:45
SystemBase & _sys
Reference to the system this time integrator operates on.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:46
Real & _dt
The current time step size.
Real & _dt_old
The previous time step size.
NumericVector< Number > * _Re_time
residual vector for time contributions
virtual void zero()=0
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 NumericVector< Number > * solutionUDot()
Definition: SystemBase.h:252
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
registerMooseObject("MooseApp", BDF2)
virtual void close()=0
BDF2(const InputParameters &parameters)
Definition: BDF2.C:24
static InputParameters validParams()
Definition: BDF2.C:16
const NumericVector< Number > *const & _solution
virtual void postResidual(NumericVector< Number > &residual) override
Callback to the NonLinearTimeIntegratorInterface called immediately after the residuals are computed ...
Definition: BDF2.C:73
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
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
const NumericVector< Number > & _solution_old
NumericVector< Number > * _Re_non_time
residual vector for non-time contributions
int & _t_step
The current time step number.
static InputParameters validParams()
uint8_t dof_id_type
void computeDuDotDu()
Compute _du_dot_du.