https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
14
17{
20 "Second order backward differentiation formula time integration scheme.");
21 return params;
22}
23
24BDF2::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
32void
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
44void
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
51 NumericVector<Number> & u_dot = *_sys.solutionUDot();
52 if (_t_step == 1)
53 u_dot = *_solution;
54 else
55 u_dot.zero();
57 u_dot.close();
59}
60
61void
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
72void
73BDF2::postResidual(NumericVector<Number> & residual)
74{
75 residual += *_Re_time;
76 residual += *_Re_non_time;
77 residual.close();
78}
79
80Real
82{
83 if (_t_step == 1)
84 return 1;
85 else
86 return _weight[0];
87}
88
89Real
90BDF2::timeDerivativeRHSContribution(dof_id_type dof_id, const std::vector<Real> & factors) const
91{
92 mooseAssert(factors.size() == numStatesRequired(),
93 "Either too many or too few states are given!");
94
95 if (_t_step == 1)
96 return factors[0] * _solution_old(dof_id) / _dt;
97 else
98 return -(_weight[1] * factors[0] * _solution_old(dof_id) +
99 _weight[2] * factors[1] * _solution_older(dof_id)) /
100 _dt;
101}
102
103Real
105{
106 if (_t_step == 1)
107 return factor / _dt;
108 else
109 return factor * _weight[0] / _dt;
110}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("MooseApp", BDF2)
BDF2 time integrator.
Definition BDF2.h:19
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 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
BDF2(const InputParameters &parameters)
Definition BDF2.C:24
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.
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.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
NumericVector< Number > * _Re_non_time
residual vector for non-time contributions
NumericVector< Number > * _Re_time
residual vector for time contributions
virtual NumericVector< Number > * solutionUDot()
Definition SystemBase.h:280
Base class for time integrators.
void computeDuDotDu()
Compute _du_dot_du.
Real & _dt_old
The previous time step size.
const NumericVector< Number > *const & _solution
static InputParameters validParams()
SystemBase & _sys
Reference to the system this time integrator operates on.
Real & _dt
The current time step size.
int & _t_step
The current time step number.
const NumericVector< Number > & _solution_old
virtual void close()=0
virtual void zero()=0