IFEM 90A354
BDF.h
Go to the documentation of this file.
1// $Id$
2//==============================================================================
12//==============================================================================
13
14#ifndef _BDF_H_
15#define _BDF_H_
16
17#include <vector>
18
19
21{
27 class BDF
28 {
29 public:
32 explicit BDF(int order = 0);
34 virtual ~BDF() {}
35
37 void setOrder(int order);
38
40 int getOrder() const;
42 int getActualOrder() const { return coefs.size() - degree; }
44 short int getDegree() const { return degree; }
45
47 bool advanceStep(double dt = 0.0, double dtn = 0.0);
48
50 virtual const std::vector<double>& getCoefs() const;
51
53 double operator[](int idx) const { return this->getCoefs()[idx]; }
54
58 template<class T> T extrapolate(const std::vector<T>& values) const
59 {
60 const T& v0 = values.front();
61 if (step > 1 && this->getActualOrder() == 2) // second order
62 return 2.0*v0 - values[1];
63 else // first order
64 return v0;
65 }
66
67 protected:
68 short int degree;
69 int step;
70 std::vector<double> coefs;
71 std::vector<double> coefs1;
72 };
73
74
79 class BDFD2 : public BDF
80 {
81 public:
85 explicit BDFD2(int order = 2, int step_ = 0);
86
88 const std::vector<double>& getCoefs() const override;
89
90 protected:
91 std::vector<double> coefs2;
92 };
93}
94
95#endif
Helper class for Backwards Difference schemes for 2nd order problems.
Definition BDF.h:80
std::vector< double > coefs2
BDF coefficients for second time step.
Definition BDF.h:91
const std::vector< double > & getCoefs() const override
Returns the BDF coefficients.
Definition BDF.C:93
Helper class for Backwards Difference Formula integration schemes.
Definition BDF.h:28
void setOrder(int order)
Initializes the coefficients for the specified order.
Definition BDF.C:24
int step
Time step counter.
Definition BDF.h:69
int getActualOrder() const
Returns the order of the scheme.
Definition BDF.h:42
double operator[](int idx) const
Indexing operator returning the idx'th coefficient.
Definition BDF.h:53
std::vector< double > coefs1
BDF coefficients for first time step.
Definition BDF.h:71
short int getDegree() const
Returns the degree of the time derivative approximation.
Definition BDF.h:44
int getOrder() const
Returns the order to be used for current time step.
Definition BDF.C:41
short int degree
Degree of the time derivative approximation.
Definition BDF.h:68
std::vector< double > coefs
The BDF coefficients.
Definition BDF.h:70
virtual ~BDF()
Empty destructor.
Definition BDF.h:34
virtual const std::vector< double > & getCoefs() const
Returns the BDF coefficients.
Definition BDF.C:66
bool advanceStep(double dt=0.0, double dtn=0.0)
Advances the time stepping scheme.
Definition BDF.C:47
T extrapolate(const std::vector< T > &values) const
Extrapolates values.
Definition BDF.h:58
Utilities for time integration.
Definition BDF.h:21