LifeV
TimeAndExtrapolationHandlerQuadPts.hpp
Go to the documentation of this file.
1 #ifndef TIMEHANDLERQUADPTS_H
2 #define TIMEHANDLERQUADPTS_H 1
3 
4 /*
5  * author: DAVIDE FORTI, davide.forti@epfl.ch
6  * Lightweighted class to Handle the time advancing scheme (based on BDF approximation of the time derivative and for the extrapolation).
7  * It can be used for first derivatives.
8  *
9  * The formulas implemented in the methods extrapolate and rhsContribution are taken from
10  * "Algebraic fractional-step schemes with spectral methods for the incompressible Navier–Stokes equations"
11  * by Paola Gervasio, Fausto Saleri and Alessandro Veneziani. (see pag. 3 for details)
12  */
13 
14 #include <lifev/core/LifeV.hpp>
15 
16 namespace LifeV
17 {
18 
19 template <UInt DIM>
21 {
22 
24 
26 
27 public:
28 
29  // empty constructor
31 
32  // constructor taking as first input the order of the Time Advancing BDF scheme, as second the maximum order of extrapolation desired (maximum 3)
34 
35  // empty destructor
37 
38  // setup of the class taking the order of the method
39  void setBDForder(const UInt order);
40 
41  // initialize the time handler class with initial data, need a vector of M_order vectorEpetra
42  void initialize(const std::vector<vector_Type> InitialData);
43 
44  // shift - to be used when a timestep is solved
45  void shift(const vector_Type newVector);
46 
47  // getter for the state
49  {
50  return M_states;
51  }
52 
53  // set the timestep
54  void setTimeStep(const Real dt);
55 
56  // get the part from the discretization of the time derivative that goes to the right hand side
57  void rhsContribution(vector_Type& rhs_bdf);
58 
59  // get the value of alpha that should go in front of the term u_(n+1) (see the paper cited at the beginning of the doc)
60  Real alpha();
61 
62  // extrapolation
63  void extrapolate(vector_Type& extrapolation);
64 
65 private:
66 
67  // order of the BDF scheme used
69 
70  // vector with the state variable at time n, n-1, .., n-(p-1)
72 
73  // variable that contains the bigger value between M_BDForder and M_maximumExtrapolationOrder
75 
76  // timestep
78 
79 };
80 
81 template <UInt DIM>
83 M_BDForder(0),
84 M_states(),
85 M_timeStep(0.0)
86 {}
87 
88 template <UInt DIM>
90 M_BDForder(orderBDF),
91 M_states(),
92 M_timeStep()
93 {}
94 
95 template <UInt DIM>
97 {}
98 
99 template <UInt DIM>
100 void
102 {
103  M_BDForder = order;
104 }
105 
106 template <UInt DIM>
107 void
109 {
110  M_timeStep = dt;
111 }
112 
113 template <UInt DIM>
114 void
115 TimeAndExtrapolationHandlerQuadPts<DIM>::initialize(const std::vector<vector_Type> InitialData)
116 {
117  ASSERT( M_BDForder != 0, "Order of the BDF scheme has not been set, please use TimeAndExtrapolationHandler::setBDForder(const UInt order)");
118 
120 
121  ASSERT( InitialData.size() == M_sizeStencil, "Wrong initial data dimension, it has to be of size equal max(M_BDForder, M_maximumExtrapolationOrder)");
122 
123  for ( int i = 0; i < M_sizeStencil; ++i )
124  M_states.push_back(InitialData[i]);
125 }
126 
127 template <UInt DIM>
128 void
129 TimeAndExtrapolationHandlerQuadPts<DIM>::shift(const vector_Type newVector)
130 {
131  switch (M_sizeStencil) {
132  case 1: // size 1: we just replace the last entry by the new vector
133  M_states[M_sizeStencil-1] = newVector;
134  break;
135  case 2: // size 2
136  M_states[M_sizeStencil-2] = M_states[M_sizeStencil-1];
137  M_states[M_sizeStencil-1] = newVector;
138  break;
139  case 3: // size 3
140  M_states[M_sizeStencil-3] = M_states[M_sizeStencil-2];
141  M_states[M_sizeStencil-2] = M_states[M_sizeStencil-1];
142  M_states[M_sizeStencil-1] = newVector;
143  break;
144  default:
145  break;
146  }
147 }
148 
149 template <UInt DIM>
150 void
152 {
153  ASSERT( M_timeStep != 0, "Timestep has not been set, please use TimeAndExtrapolationHandler::setTimeStep(const Real dt) ");
154 
155  // nota: M_states.size() -> orderBDF
156  // M_states[0].size() -> numElements per process
157  // M_states[0][0].size() -> numQuadPts per element
158  // DIM is the size of the vector small
159 
160  switch (M_BDForder) {
161  case 1:
162  for (int i = 0 ; i < M_states[0].size() ; ++i ) // loop elements
163  {
164  for (int j = 0 ; j < M_states[0][0].size(); ++j ) // loop quadrature points
165  {
166  for (int k = 0 ; k < DIM; ++k ) // loop quadrature points
167  {
168  rhs_bdf[i][j](k) = 1/M_timeStep*M_states[M_sizeStencil-1][i][j](k); // u_rhs = 1/dt*u_n
169  }
170  }
171  }
172  break;
173  case 2:
174  for (int i = 0 ; i < M_states[0].size() ; ++i ) // loop elements
175  {
176  for (int j = 0 ; j < M_states[0][0].size(); ++j ) // loop quadrature points
177  {
178  for (int k = 0 ; k < DIM; ++k ) // loop quadrature points
179  {
180  rhs_bdf[i][j](k) = 1/M_timeStep*(2*M_states[M_sizeStencil-1][i][j](k) - (1.0/2.0)*M_states[M_sizeStencil-2][i][j](k));
181  // u_rhs = 1/dt*(2*u_n - 0.5*u_{n-1})
182  }
183  }
184  }
185  break;
186  case 3:
187  for (int i = 0 ; i < M_states[0].size() ; ++i ) // loop elements
188  {
189  for (int j = 0 ; j < M_states[0][0].size(); ++j ) // loop quadrature points
190  {
191  for (int k = 0 ; k < DIM; ++k ) // loop quadrature points
192  {
193  rhs_bdf[i][j](k) = 1/M_timeStep*(3*M_states[M_sizeStencil-1][i][j](k) - (3.0/2.0)*M_states[M_sizeStencil-2][i][j](k) +
194  (1.0/3.0)*M_states[M_sizeStencil-3][i][j](k) );
195  // u_rhs = 1/dt*(3*u_n - 3/2*u_{n-1} + 1/3*u_{n-2})
196  }
197  }
198  }
199  break;
200  default:
201  break;
202  }
203 }
204 
205 template <UInt DIM>
206 void
207 TimeAndExtrapolationHandlerQuadPts<DIM>::extrapolate(vector_Type& extrapolation)
208 {
209  ASSERT( M_timeStep != 0, "Timestep has not been set, please use TimeAndExtrapolationHandler::setTimeStep(const Real dt) ");
210 
211  switch (M_BDForder) {
212  case 1:
213  for (int i = 0 ; i < M_states[0].size() ; ++i ) // loop elements
214  {
215  for (int j = 0 ; j < M_states[0][0].size(); ++j ) // loop quadrature points
216  {
217  for (int k = 0 ; k < DIM; ++k ) // loop quadrature points
218  {
219  extrapolation[i][j](k) = M_states[M_sizeStencil-1][i][j](k); // u_star = u_n
220  }
221  }
222  }
223  break;
224  case 2:
225  for (int i = 0 ; i < M_states[0].size() ; ++i ) // loop elements
226  {
227  for (int j = 0 ; j < M_states[0][0].size(); ++j ) // loop quadrature points
228  {
229  for (int k = 0 ; k < DIM; ++k ) // loop quadrature points
230  {
231  extrapolation[i][j](k) = 2*M_states[M_sizeStencil-1][i][j](k) - M_states[M_sizeStencil-2][i][j](k);
232  // u_star = 2*u_n - u_{n-1}
233  }
234  }
235  }
236  break;
237  case 3:
238  for (int i = 0 ; i < M_states[0].size() ; ++i ) // loop elements
239  {
240  for (int j = 0 ; j < M_states[0][0].size(); ++j ) // loop quadrature points
241  {
242  for (int k = 0 ; k < DIM; ++k ) // loop quadrature points
243  {
244  extrapolation[i][j](k) = 3.0*M_states[M_sizeStencil-1][i][j](k) - 3.0*M_states[M_sizeStencil-2][i][j](k) +
245  M_states[M_sizeStencil-3][i][j](k);
246  // u_star = 3*u_n - 3*u_{n-1} + u_{n-2}
247  }
248  }
249  }
250  break;
251  default:
252  break;
253  }
254 }
255 
256 template <UInt DIM>
257 Real
259 {
260  switch (M_BDForder) {
261  case 1:
262  return 1.0;
263  break;
264  case 2:
265  return 1.5;
266  break;
267  case 3:
268  return 11.0/6.0;
269  break;
270  default:
271  break;
272  }
274 }
275 
276 } // end namespace LifeV
277 
278 #endif
#define RETURN_UNDEFINED
Definition: LifeAssert.hpp:70
std::vector< std::vector< VectorSmall< DIM > > > vector_Type
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
double Real
Generic real data.
Definition: LifeV.hpp:175
void initialize(const std::vector< vector_Type > InitialData)
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191