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 
141  LUE virtual std::string GetName() const
142  {
143  return std::string("AdamsBashforth");
144  }
145 
147  {
148  return 1.0;
149  }
150 
152  int order)
153  {
154  // clang-format off
155  const NekDouble coefficients[5][4] =
156  { { 0., 0., 0., 0. },
157  // 1st Order
158  { 1., 0., 0., 0. },
159  // 2nd Order
160  { 3./ 2., -1./ 2., 0., 0. },
161  // 3rd Order
162  { 23./12., -16./12., 5./12., 0. },
163  // 4th Order
164  { 55./24., -59./24., 37./24., -9./24.} };
165  // clang-format on
166 
167  phase->m_schemeType = eExplicit;
168  phase->m_order = order;
169  phase->m_name =
170  std::string("AdamsBashforthOrder" + std::to_string(phase->m_order));
171 
172  phase->m_numsteps = phase->m_order;
173  phase->m_numstages = 1;
174 
175  phase->m_A = Array<OneD, Array<TwoD, NekDouble>>(1);
176  phase->m_B = Array<OneD, Array<TwoD, NekDouble>>(1);
177 
178  phase->m_A[0] =
179  Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numstages, 0.0);
180  phase->m_B[0] =
181  Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numstages, 0.0);
182  phase->m_U =
183  Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numsteps, 0.0);
184  phase->m_V =
185  Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numsteps, 0.0);
186 
187  // Coefficients
188 
189  // When multiple steps are taken B[0][0] and V[0][1...s] must be
190  // weighted so the time contribution is correct.
191 
192  // B Coefficient for first row first column
193  phase->m_B[0][0][0] = coefficients[phase->m_order][0];
194 
195  // B evaluation value shuffling second row first column
196  if (phase->m_order > 1)
197  {
198  phase->m_B[0][1][0] = 1.0; // constant 1
199  }
200 
201  // U Curent time step evaluation first row first column
202  phase->m_U[0][0] = 1.0;
203  phase->m_V[0][0] = 1.0;
204 
205  // V Coefficients for first row additional columns
206  for (int n = 1; n < phase->m_order; ++n)
207  {
208  phase->m_V[0][n] = coefficients[phase->m_order][n];
209  }
210 
211  // V evaluation value shuffling row n column n-1
212  for (int n = 2; n < phase->m_order; ++n)
213  {
214  phase->m_V[n][n - 1] = 1.0;
215  }
216 
217  phase->m_numMultiStepValues = 1;
218  phase->m_numMultiStepDerivs = phase->m_order - 1;
219  phase->m_timeLevelOffset = Array<OneD, unsigned int>(phase->m_numsteps);
220  phase->m_timeLevelOffset[0] = 0;
221 
222  // For order > 1 derivatives are needed.
223  for (int n = 1; n < phase->m_order; ++n)
224  {
225  phase->m_timeLevelOffset[n] = n;
226  }
227 
228  phase->CheckAndVerify();
229  }
230 
231 }; // end class AdamsBashforthTimeIntegrationScheme
232 
233 ////////////////////////////////////////////////////////////////////////////////
234 // Backwards compatibility
237 {
238 public:
240  unsigned int order,
241  std::vector<NekDouble> freeParams)
242  : AdamsBashforthTimeIntegrationScheme("", 1, freeParams)
243  {
244  boost::ignore_unused(variant);
245  boost::ignore_unused(order);
246  }
247 
249  std::string variant, unsigned int order,
250  std::vector<NekDouble> freeParams)
251  {
252  boost::ignore_unused(variant);
253  boost::ignore_unused(order);
254 
256  AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 1,
257  freeParams);
258  return p;
259  }
260 
261  static std::string className;
262 
263 }; // end class AdamsBashforthOrder1TimeIntegrationScheme
264 
267 {
268 public:
270  unsigned int order,
271  std::vector<NekDouble> freeParams)
272  : AdamsBashforthTimeIntegrationScheme("", 2, freeParams)
273  {
274  boost::ignore_unused(variant);
275  boost::ignore_unused(order);
276  }
277 
279  std::string variant, unsigned int order,
280  std::vector<NekDouble> freeParams)
281  {
282  boost::ignore_unused(variant);
283  boost::ignore_unused(order);
284 
286  AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 2,
287  freeParams);
288  return p;
289  }
290 
291  static std::string className;
292 
293 }; // end class AdamsBashforthOrder2TimeIntegrationScheme
294 
297 {
298 public:
300  unsigned int order,
301  std::vector<NekDouble> freeParams)
302  : AdamsBashforthTimeIntegrationScheme("", 3, freeParams)
303  {
304  boost::ignore_unused(variant);
305  boost::ignore_unused(order);
306  }
307 
309  std::string variant, unsigned int order,
310  std::vector<NekDouble> freeParams)
311  {
312  boost::ignore_unused(variant);
313  boost::ignore_unused(order);
314 
316  AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 3,
317  freeParams);
318  return p;
319  }
320 
321  static std::string className;
322 
323 }; // end class AdamsBashforthOrder3TimeIntegrationScheme
324 
327 {
328 public:
330  unsigned int order,
331  std::vector<NekDouble> freeParams)
332  : AdamsBashforthTimeIntegrationScheme("", 4, freeParams)
333  {
334  boost::ignore_unused(variant);
335  boost::ignore_unused(order);
336  }
337 
339  std::string variant, unsigned int order,
340  std::vector<NekDouble> freeParams)
341  {
342  boost::ignore_unused(variant);
343  boost::ignore_unused(order);
344 
346  AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 4,
347  freeParams);
348  return p;
349  }
350 
351  static std::string className;
352 
353 }; // end class AdamsBashforthOrder4TimeIntegrationScheme
354 
355 } // end namespace LibUtilities
356 } // end namespace Nektar
357 
358 #endif
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:250
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:1
double NekDouble