Nektar++
AdamsMoultonTimeIntegrationSchemes.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: AdamsMoultonTimeIntegrationSchemes.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 Moulton 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_AM_TIME_INTEGRATION_SCHEME
42 #define NEKTAR_LIB_UTILITIES_TIME_INTEGRATION_AM_TIME_INTEGRATION_SCHEME
43 
44 #define LUE LIB_UTILITIES_EXPORT
45 
48 
51 
52 namespace Nektar
53 {
54 namespace LibUtilities
55 {
56 
57 ///////////////////////////////////////////////////////////////////////////////
58 // Adams Moulton Order N
59 
61 {
62 public:
63  AdamsMoultonTimeIntegrationScheme(std::string variant, unsigned int order,
64  std::vector<NekDouble> freeParams)
65  : TimeIntegrationSchemeGLM(variant, order, freeParams)
66  {
67  // Currently up to 4th order is implemented.
68  ASSERTL1(1 <= order && order <= 4,
69  "AdamsMoulton Time integration scheme bad order (1-4): " +
70  std::to_string(order));
71 
73 
74  for (unsigned int n = 0; n < order; ++n)
75  {
77  new TimeIntegrationAlgorithmGLM(this));
78  }
79 
80  // Next to last phase
81  if (order > 1)
83  m_integration_phases[order - 2], order - 1);
84 
85  // Last phase
87  m_integration_phases[order - 1], order);
88 
89  // Initial phases
90  switch (order)
91  {
92  case 1:
93  // No intial phases.
94  break;
95 
96  case 2:
97  // Why forward euler and not backward euler???
99  m_integration_phases[0], "Forward");
100  break;
101 
102  case 3:
103  // The first and second phases needed to be set correctly
105  m_integration_phases[0], "Forward");
107  m_integration_phases[1], 3, std::vector<NekDouble>{3, 4});
108  break;
109 
110  case 4:
111  // The first and second phases needed to be set correctly
113  m_integration_phases[0], 3, std::vector<NekDouble>{2, 3});
115  m_integration_phases[1], 3, std::vector<NekDouble>{2, 3});
116  break;
117 
118  default:
119  ASSERTL1(false,
120  "AdamsMoulton Time integration scheme bad order: " +
121  std::to_string(order));
122  }
123  }
124 
126  {
127  }
128 
130  std::string variant, unsigned int order,
131  std::vector<NekDouble> freeParams)
132  {
135  variant, order, freeParams);
136 
137  return p;
138  }
139 
140  static std::string className;
141 
142  LUE virtual std::string GetName() const
143  {
144  return std::string("AdamsMoulton");
145  }
146 
148  {
149  return 1.0;
150  }
151 
153  int order)
154  {
155  // The 3rd and 4th order tableaus have not been validated!!!!!
156 
157  // clang-format off
158  const NekDouble coefficients[5][4] =
159  { { 0., 0., 0., 0. },
160  // 1st Order
161  { 1., 0., 0., 0. },
162  // 2nd Order
163  { 1./ 2., 1./ 2., 0., 0. },
164  // 3rd Order
165  { 5./12., 8./12., -1./12., 0. },
166  // 4th Order
167  { 9./24., 19./24., -5./24., 1./24. } };
168  // clang-format on
169 
170  phase->m_schemeType = eDiagonallyImplicit;
171  phase->m_order = order;
172  phase->m_name =
173  std::string("AdamsMoultonOrder" + std::to_string(phase->m_order));
174 
175  phase->m_numsteps = phase->m_order;
176  phase->m_numstages = 1;
177 
178  phase->m_A = Array<OneD, Array<TwoD, NekDouble>>(1);
179  phase->m_B = Array<OneD, Array<TwoD, NekDouble>>(1);
180 
181  phase->m_A[0] =
182  Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numstages, 0.0);
183  phase->m_B[0] =
184  Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numstages, 0.0);
185  phase->m_U =
186  Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numsteps, 0.0);
187  phase->m_V =
188  Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numsteps, 0.0);
189 
190  // Coefficients
191 
192  // When multiple steps are taken A/B[0][0] and U/V[0][1...s]
193  // must be weighted so the time contribution is correct.
194 
195  // A/B Coefficient for first row first column
196  phase->m_A[0][0][0] = coefficients[phase->m_order][0];
197  phase->m_B[0][0][0] = coefficients[phase->m_order][0];
198 
199  // B evaluation value shuffling second row first column
200  if (phase->m_order > 1)
201  {
202  phase->m_B[0][1][0] = 1.0; // constant 1
203  }
204 
205  // U/V Coefficient for first row first column
206  phase->m_U[0][0] = 1.0;
207  phase->m_V[0][0] = 1.0;
208 
209  // U/V Coefficients for first row additional columns
210  for (int n = 1; n < phase->m_order; ++n)
211  {
212  phase->m_U[0][n] = coefficients[phase->m_order][n];
213  phase->m_V[0][n] = coefficients[phase->m_order][n];
214  }
215 
216  // V evaluation value shuffling row n column n-1
217  for (int n = 2; n < phase->m_order; ++n)
218  {
219  phase->m_V[n][n - 1] = 1.0;
220  }
221 
222  phase->m_numMultiStepValues = 1;
223  phase->m_numMultiStepDerivs = phase->m_order - 1;
224  phase->m_timeLevelOffset = Array<OneD, unsigned int>(phase->m_numsteps);
225  phase->m_timeLevelOffset[0] = 0;
226 
227  // For order > 1 derivatives are needed.
228  for (int n = 1; n < phase->m_order; ++n)
229  {
230  phase->m_timeLevelOffset[n] = n - 1;
231  }
232 
233  phase->CheckAndVerify();
234  }
235 
236 }; // end class AdamsMoultonTimeIntegrationScheme
237 
238 ////////////////////////////////////////////////////////////////////////////////
239 // Backwards compatibility
242 {
243 public:
245  unsigned int order,
246  std::vector<NekDouble> freeParams)
247  : AdamsMoultonTimeIntegrationScheme("", 1, freeParams)
248  {
249  boost::ignore_unused(variant);
250  boost::ignore_unused(order);
251  }
252 
254  std::string variant, unsigned int order,
255  std::vector<NekDouble> freeParams)
256  {
257  boost::ignore_unused(variant);
258  boost::ignore_unused(order);
259 
262  "", 1, freeParams);
263 
264  return p;
265  }
266 
267  static std::string className;
268 
269 }; // end class AdamsMoultonOrder1TimeIntegrationScheme
270 
273 {
274 public:
276  unsigned int order,
277  std::vector<NekDouble> freeParams)
278  : AdamsMoultonTimeIntegrationScheme("", 2, freeParams)
279  {
280  boost::ignore_unused(variant);
281  boost::ignore_unused(order);
282  }
283 
285  std::string variant, unsigned int order,
286  std::vector<NekDouble> freeParams)
287  {
288  boost::ignore_unused(variant);
289  boost::ignore_unused(order);
290 
293  "", 2, freeParams);
294 
295  return p;
296  }
297 
298  static std::string className;
299 
300 }; // end class AdamsMoultonOrder2TimeIntegrationScheme
301 
304 {
305 public:
307  unsigned int order,
308  std::vector<NekDouble> freeParams)
309  : AdamsMoultonTimeIntegrationScheme("", 3, freeParams)
310  {
311  boost::ignore_unused(variant);
312  boost::ignore_unused(order);
313  }
314 
316  std::string variant, unsigned int order,
317  std::vector<NekDouble> freeParams)
318  {
319  boost::ignore_unused(variant);
320  boost::ignore_unused(order);
321 
324  "", 3, freeParams);
325 
326  return p;
327  }
328 
329  static std::string className;
330 
331 }; // end class AdamsMoultonOrder3TimeIntegrationScheme
332 
335 {
336 public:
338  unsigned int order,
339  std::vector<NekDouble> freeParams)
340  : AdamsMoultonTimeIntegrationScheme("", 4, freeParams)
341  {
342  boost::ignore_unused(variant);
343  boost::ignore_unused(order);
344  }
345 
347  std::string variant, unsigned int order,
348  std::vector<NekDouble> freeParams)
349  {
350  boost::ignore_unused(variant);
351  boost::ignore_unused(order);
352 
355  "", 4, freeParams);
356 
357  return p;
358  }
359 
360  static std::string className;
361 
362 }; // end class AdamsMoultonOrder4TimeIntegrationScheme
363 
364 } // end namespace LibUtilities
365 } // end namespace Nektar
366 
367 #endif
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:250
AdamsMoultonOrder1TimeIntegrationScheme(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
static TimeIntegrationSchemeSharedPtr create(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
AdamsMoultonOrder2TimeIntegrationScheme(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
static TimeIntegrationSchemeSharedPtr create(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
AdamsMoultonOrder3TimeIntegrationScheme(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)
AdamsMoultonOrder4TimeIntegrationScheme(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
static LUE void SetupSchemeData(TimeIntegrationAlgorithmGLMSharedPtr &phase, int order)
AdamsMoultonTimeIntegrationScheme(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)
static LUE void SetupSchemeData(TimeIntegrationAlgorithmGLMSharedPtr &phase, unsigned int order, std::vector< NekDouble > freeParams)
Base class for GLM time integration schemes.
TimeIntegrationAlgorithmGLMVector m_integration_phases
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< TimeIntegrationAlgorithmGLM > TimeIntegrationAlgorithmGLMSharedPtr
@ eDiagonallyImplicit
Diagonally implicit scheme (e.g. the DIRK schemes)
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