www.mooseframework.org
BDF2.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
15 template <>
18 {
20 
21  return params;
22 }
23 
24 BDF2::BDF2(const InputParameters & parameters)
25  : TimeIntegrator(parameters), _weight(declareRestartableData<std::vector<Real>>("weight"))
26 {
27  _weight.resize(3);
28 }
29 
30 void
32 {
33  if (_t_step > 1)
34  {
35  Real sum = _dt + _dt_old;
36  _weight[0] = 1. + _dt / sum;
37  _weight[1] = -sum / _dt_old;
38  _weight[2] = _dt * _dt / _dt_old / sum;
39  }
40 }
41 
42 void
44 {
45  if (!_sys.solutionUDot())
46  mooseError("BDF2: Time derivative of solution (`u_dot`) is not stored. Please set "
47  "uDotRequested() to true in FEProblemBase befor requesting `u_dot`.");
48 
49  NumericVector<Number> & u_dot = *_sys.solutionUDot();
50  if (_t_step == 1)
51  {
52  u_dot = *_solution;
53  _du_dot_du = 1. / _dt;
54  }
55  else
56  {
57  u_dot.zero();
58  _du_dot_du = _weight[0] / _dt;
59  }
61  u_dot.close();
62 }
63 
64 void
65 BDF2::computeADTimeDerivatives(DualReal & ad_u_dot, const dof_id_type & dof) const
66 {
67  auto ad_sln = ad_u_dot;
68  if (_t_step != 1)
69  ad_u_dot = 0;
70  computeTimeDerivativeHelper(ad_u_dot, ad_sln, _solution_old(dof), _solution_older(dof));
71 }
72 
73 void
74 BDF2::postResidual(NumericVector<Number> & residual)
75 {
76  residual += _Re_time;
77  residual += _Re_non_time;
78  residual.close();
79 }
virtual NumericVector< Number > * solutionUDot()=0
void computeADTimeDerivatives(DualReal &ad_u_dot, const dof_id_type &dof) const override
method for computing local automatic differentiation time derivatives
Definition: BDF2.C:65
virtual void computeTimeDerivatives() override
Definition: BDF2.C:43
NumericVector< Number > & _Re_non_time
residual vector for non-time contributions
SystemBase & _sys
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
DualNumber< Real, NumberArray< AD_MAX_DOFS_PER_ELEM, Real > > DualReal
Definition: DualReal.h:29
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
BDF2 time integrator.
Definition: BDF2.h:23
std::vector< Real > & _weight
Definition: BDF2.h:42
virtual void preStep() override
Definition: BDF2.C:31
InputParameters validParams< TimeIntegrator >()
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:51
registerMooseObject("MooseApp", BDF2)
const NumericVector< Number > & _solution_older
BDF2(const InputParameters &parameters)
Definition: BDF2.C:24
Real & _du_dot_du
solution vector for
const NumericVector< Number > *const & _solution
solution vectors
virtual void postResidual(NumericVector< Number > &residual) override
Callback to the TimeIntegrator called immediately after the residuals are computed in NonlinearSystem...
Definition: BDF2.C:74
Base class for time integrators.
InputParameters validParams< BDF2 >()
Definition: BDF2.C:17
NumericVector< Number > & _Re_time
residual vector for time contributions
const NumericVector< Number > & _solution_old