Nektar++
AdamsBashforthTimeIntegrationSchemes.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: AdamsBashforthTimeIntegrationSchemes.h
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2018 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Combined header file for all Adams Bashforth based time
33 // integration schemes.
34 //
35 ///////////////////////////////////////////////////////////////////////////////
36 
37 // Note : If adding a new integrator be sure to register the
38 // integrator with the Time Integration Scheme Facatory in
39 // SchemeInitializor.cpp.
40 
41 #ifndef NEKTAR_LIB_UTILITIES_TIME_INTEGRATION_AB_TIME_INTEGRATION_SCHEME
42 #define NEKTAR_LIB_UTILITIES_TIME_INTEGRATION_AB_TIME_INTEGRATION_SCHEME
43 
44 #define LUE LIB_UTILITIES_EXPORT
45 
48 
50 
51 namespace Nektar
52 {
53 namespace LibUtilities
54 {
55 
56 ///////////////////////////////////////////////////////////////////////////////
57 // Adams Bashforth Order N
58 
60 {
61 public:
62  AdamsBashforthTimeIntegrationScheme(std::string variant, unsigned int order,
63  std::vector<NekDouble> freeParams)
64  : TimeIntegrationSchemeGLM(variant, order, freeParams)
65  {
66  // Currently up to 4th order is implemented.
67  ASSERTL1(1 <= order && order <= 4,
68  "AdamsBashforth Time integration scheme bad order (1-4): " +
69  std::to_string(order));
70 
72 
73  for (unsigned int n = 0; n < order; ++n)
74  {
76  new TimeIntegrationAlgorithmGLM(this));
77  }
78 
79  // Next to last phase
80  if (order > 1)
82  m_integration_phases[order - 2], order - 1);
83 
84  // Last phase
86  m_integration_phases[order - 1], order);
87 
88  // Initial phases
89  switch (order)
90  {
91  case 1:
92  // No intial phases.
93  break;
94 
95  case 2:
96  // Done above.
97  break;
98 
99  case 3:
100  // Order 2
102  m_integration_phases[0], "", 2, std::vector<NekDouble>());
103  break;
104 
105  case 4:
106  // SSP Order 3
108  m_integration_phases[0], "SSP", 3,
109  std::vector<NekDouble>());
110  // SSP Order 3
112  m_integration_phases[1], "SSP", 3,
113  std::vector<NekDouble>());
114  break;
115 
116  default:
117  ASSERTL1(false,
118  "AdamsBashforth Time integration scheme bad order: " +
119  std::to_string(order));
120  }
121  }
122 
124  {
125  }
126 
128  std::string variant, unsigned int order,
129  std::vector<NekDouble> freeParams)
130  {
132  AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr(variant,
133  order,
134  freeParams);
135 
136  return p;
137  }
138 
139  static std::string className;
140 
142  int order)
143  {
144  // clang-format off
145  const NekDouble coefficients[5][4] =
146  { { 0., 0., 0., 0. },
147  // 1st Order
148  { 1., 0., 0., 0. },
149  // 2nd Order
150  { 3./ 2., -1./ 2., 0., 0. },
151  // 3rd Order
152  { 23./12., -16./12., 5./12., 0. },
153  // 4th Order
154  { 55./24., -59./24., 37./24., -9./24.} };
155  // clang-format on
156 
157  phase->m_schemeType = eExplicit;
158  phase->m_order = order;
159  phase->m_name =
160  std::string("AdamsBashforthOrder" + std::to_string(phase->m_order));
161 
162  phase->m_numsteps = phase->m_order;
163  phase->m_numstages = 1;
164 
165  phase->m_A = Array<OneD, Array<TwoD, NekDouble>>(1);
166  phase->m_B = Array<OneD, Array<TwoD, NekDouble>>(1);
167 
168  phase->m_A[0] =
169  Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numstages, 0.0);
170  phase->m_B[0] =
171  Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numstages, 0.0);
172  phase->m_U =
173  Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numsteps, 0.0);
174  phase->m_V =
175  Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numsteps, 0.0);
176 
177  // Coefficients
178 
179  // When multiple steps are taken B[0][0] and V[0][1...s] must be
180  // weighted so the time contribution is correct.
181 
182  // B Coefficient for first row first column
183  phase->m_B[0][0][0] = coefficients[phase->m_order][0];
184 
185  // B evaluation value shuffling second row first column
186  if (phase->m_order > 1)
187  {
188  phase->m_B[0][1][0] = 1.0; // constant 1
189  }
190 
191  // U Curent time step evaluation first row first column
192  phase->m_U[0][0] = 1.0;
193  phase->m_V[0][0] = 1.0;
194 
195  // V Coefficients for first row additional columns
196  for (int n = 1; n < phase->m_order; ++n)
197  {
198  phase->m_V[0][n] = coefficients[phase->m_order][n];
199  }
200 
201  // V evaluation value shuffling row n column n-1
202  for (int n = 2; n < phase->m_order; ++n)
203  {
204  phase->m_V[n][n - 1] = 1.0;
205  }
206 
207  phase->m_numMultiStepValues = 1;
208  phase->m_numMultiStepImplicitDerivs = 0;
209  phase->m_numMultiStepDerivs = phase->m_order - 1;
210  phase->m_timeLevelOffset = Array<OneD, unsigned int>(phase->m_numsteps);
211  phase->m_timeLevelOffset[0] = 0;
212 
213  // For order > 1 derivatives are needed.
214  for (int n = 1; n < phase->m_order; ++n)
215  {
216  phase->m_timeLevelOffset[n] = n;
217  }
218 
219  phase->CheckAndVerify();
220  }
221 
222 protected:
223  LUE virtual std::string v_GetName() const override
224  {
225  return std::string("AdamsBashforth");
226  }
227 
228  LUE virtual NekDouble v_GetTimeStability() const override
229  {
230  return 1.0;
231  }
232 
233 }; // end class AdamsBashforthTimeIntegrationScheme
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 // Backwards compatibility
239 {
240 public:
242  unsigned int order,
243  std::vector<NekDouble> freeParams)
244  : AdamsBashforthTimeIntegrationScheme("", 1, freeParams)
245  {
246  boost::ignore_unused(variant);
247  boost::ignore_unused(order);
248  }
249 
251  std::string variant, unsigned int order,
252  std::vector<NekDouble> freeParams)
253  {
254  boost::ignore_unused(variant);
255  boost::ignore_unused(order);
256 
258  AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 1,
259  freeParams);
260  return p;
261  }
262 
263  static std::string className;
264 
265 }; // end class AdamsBashforthOrder1TimeIntegrationScheme
266 
269 {
270 public:
272  unsigned int order,
273  std::vector<NekDouble> freeParams)
274  : AdamsBashforthTimeIntegrationScheme("", 2, freeParams)
275  {
276  boost::ignore_unused(variant);
277  boost::ignore_unused(order);
278  }
279 
281  std::string variant, unsigned int order,
282  std::vector<NekDouble> freeParams)
283  {
284  boost::ignore_unused(variant);
285  boost::ignore_unused(order);
286 
288  AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 2,
289  freeParams);
290  return p;
291  }
292 
293  static std::string className;
294 
295 }; // end class AdamsBashforthOrder2TimeIntegrationScheme
296 
299 {
300 public:
302  unsigned int order,
303  std::vector<NekDouble> freeParams)
304  : AdamsBashforthTimeIntegrationScheme("", 3, freeParams)
305  {
306  boost::ignore_unused(variant);
307  boost::ignore_unused(order);
308  }
309 
311  std::string variant, unsigned int order,
312  std::vector<NekDouble> freeParams)
313  {
314  boost::ignore_unused(variant);
315  boost::ignore_unused(order);
316 
318  AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 3,
319  freeParams);
320  return p;
321  }
322 
323  static std::string className;
324 
325 }; // end class AdamsBashforthOrder3TimeIntegrationScheme
326 
329 {
330 public:
332  unsigned int order,
333  std::vector<NekDouble> freeParams)
334  : AdamsBashforthTimeIntegrationScheme("", 4, freeParams)
335  {
336  boost::ignore_unused(variant);
337  boost::ignore_unused(order);
338  }
339 
341  std::string variant, unsigned int order,
342  std::vector<NekDouble> freeParams)
343  {
344  boost::ignore_unused(variant);
345  boost::ignore_unused(order);
346 
348  AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 4,
349  freeParams);
350  return p;
351  }
352 
353  static std::string className;
354 
355 }; // end class AdamsBashforthOrder4TimeIntegrationScheme
356 
357 } // end namespace LibUtilities
358 } // end namespace Nektar
359 
360 #endif
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:249
AdamsBashforthOrder1TimeIntegrationScheme(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
static TimeIntegrationSchemeSharedPtr create(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
AdamsBashforthOrder2TimeIntegrationScheme(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
static TimeIntegrationSchemeSharedPtr create(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
AdamsBashforthOrder3TimeIntegrationScheme(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
static TimeIntegrationSchemeSharedPtr create(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
static TimeIntegrationSchemeSharedPtr create(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
AdamsBashforthOrder4TimeIntegrationScheme(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
static LUE void SetupSchemeData(TimeIntegrationAlgorithmGLMSharedPtr &phase, int order)
AdamsBashforthTimeIntegrationScheme(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
static TimeIntegrationSchemeSharedPtr create(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
static LUE void SetupSchemeData(TimeIntegrationAlgorithmGLMSharedPtr &phase, std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
Base class for GLM time integration schemes.
TimeIntegrationAlgorithmGLMVector m_integration_phases
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::shared_ptr< TimeIntegrationAlgorithmGLM > TimeIntegrationAlgorithmGLMSharedPtr
@ eExplicit
Formally explicit scheme.
std::vector< TimeIntegrationAlgorithmGLMSharedPtr > TimeIntegrationAlgorithmGLMVector
std::shared_ptr< TimeIntegrationScheme > TimeIntegrationSchemeSharedPtr
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble