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], 2);
107  m_integration_phases[1], 3);
108  break;
109 
110  case 4:
111  // The first and second phases needed to be set correctly
113  m_integration_phases[0], 3);
115  m_integration_phases[1], 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 
143  int order)
144  {
145  // The 3rd and 4th order tableaus have not been validated!!!!!
146 
147  // clang-format off
148  const NekDouble coefficients[5][4] =
149  { { 0., 0., 0., 0. },
150  // 1st Order
151  { 1., 0., 0., 0. },
152  // 2nd Order
153  { 1./ 2., 1./ 2., 0., 0. },
154  // 3rd Order
155  { 5./12., 8./12., -1./12., 0. },
156  // 4th Order
157  { 9./24., 19./24., -5./24., 1./24. } };
158  // clang-format on
159 
160  phase->m_schemeType = eDiagonallyImplicit;
161  phase->m_order = order;
162  phase->m_name =
163  std::string("AdamsMoultonOrder" + std::to_string(phase->m_order));
164 
165  phase->m_numsteps = phase->m_order;
166  phase->m_numstages = 1;
167 
168  phase->m_A = Array<OneD, Array<TwoD, NekDouble>>(1);
169  phase->m_B = Array<OneD, Array<TwoD, NekDouble>>(1);
170 
171  phase->m_A[0] =
172  Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numstages, 0.0);
173  phase->m_B[0] =
174  Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numstages, 0.0);
175  phase->m_U =
176  Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numsteps, 0.0);
177  phase->m_V =
178  Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numsteps, 0.0);
179 
180  // Coefficients
181 
182  // When multiple steps are taken A/B[0][0] and U/V[0][1...s]
183  // must be weighted so the time contribution is correct.
184 
185  // A/B Coefficient for first row first column
186  phase->m_A[0][0][0] = coefficients[phase->m_order][0];
187  phase->m_B[0][0][0] = coefficients[phase->m_order][0];
188 
189  // B evaluation value shuffling second row first column
190  if (phase->m_order > 1)
191  {
192  phase->m_B[0][1][0] = 1.0; // constant 1
193  }
194 
195  // U/V Coefficient for first row first column
196  phase->m_U[0][0] = 1.0;
197  phase->m_V[0][0] = 1.0;
198 
199  // U/V Coefficients for first row additional columns
200  for (int n = 1; n < phase->m_order; ++n)
201  {
202  phase->m_U[0][n] = coefficients[phase->m_order][n];
203  phase->m_V[0][n] = coefficients[phase->m_order][n];
204  }
205 
206  // V evaluation value shuffling row n column n-1
207  for (int n = 2; n < phase->m_order; ++n)
208  {
209  phase->m_V[n][n - 1] = 1.0;
210  }
211 
212  phase->m_numMultiStepValues = 1;
213  phase->m_numMultiStepDerivs = phase->m_order - 1;
214  phase->m_timeLevelOffset = Array<OneD, unsigned int>(phase->m_numsteps);
215  phase->m_timeLevelOffset[0] = 0;
216 
217  // For order > 1 derivatives are needed.
218  for (int n = 1; n < phase->m_order; ++n)
219  {
220  phase->m_timeLevelOffset[n] = n - 1;
221  }
222 
223  phase->CheckAndVerify();
224  }
225 
226 protected:
227  LUE virtual std::string v_GetName() const override
228  {
229  return std::string("AdamsMoulton");
230  }
231 
232  LUE virtual NekDouble v_GetTimeStability() const override
233  {
234  return 1.0;
235  }
236 
237 }; // end class AdamsMoultonTimeIntegrationScheme
238 
239 ////////////////////////////////////////////////////////////////////////////////
240 // Backwards compatibility
243 {
244 public:
246  unsigned int order,
247  std::vector<NekDouble> freeParams)
248  : AdamsMoultonTimeIntegrationScheme("", 1, freeParams)
249  {
250  boost::ignore_unused(variant);
251  boost::ignore_unused(order);
252  }
253 
255  std::string variant, unsigned int order,
256  std::vector<NekDouble> freeParams)
257  {
258  boost::ignore_unused(variant);
259  boost::ignore_unused(order);
260 
263  "", 1, freeParams);
264 
265  return p;
266  }
267 
268  static std::string className;
269 
270 }; // end class AdamsMoultonOrder1TimeIntegrationScheme
271 
274 {
275 public:
277  unsigned int order,
278  std::vector<NekDouble> freeParams)
279  : AdamsMoultonTimeIntegrationScheme("", 2, freeParams)
280  {
281  boost::ignore_unused(variant);
282  boost::ignore_unused(order);
283  }
284 
286  std::string variant, unsigned int order,
287  std::vector<NekDouble> freeParams)
288  {
289  boost::ignore_unused(variant);
290  boost::ignore_unused(order);
291 
294  "", 2, freeParams);
295 
296  return p;
297  }
298 
299  static std::string className;
300 
301 }; // end class AdamsMoultonOrder2TimeIntegrationScheme
302 
305 {
306 public:
308  unsigned int order,
309  std::vector<NekDouble> freeParams)
310  : AdamsMoultonTimeIntegrationScheme("", 3, freeParams)
311  {
312  boost::ignore_unused(variant);
313  boost::ignore_unused(order);
314  }
315 
317  std::string variant, unsigned int order,
318  std::vector<NekDouble> freeParams)
319  {
320  boost::ignore_unused(variant);
321  boost::ignore_unused(order);
322 
325  "", 3, freeParams);
326 
327  return p;
328  }
329 
330  static std::string className;
331 
332 }; // end class AdamsMoultonOrder3TimeIntegrationScheme
333 
336 {
337 public:
339  unsigned int order,
340  std::vector<NekDouble> freeParams)
341  : AdamsMoultonTimeIntegrationScheme("", 4, freeParams)
342  {
343  boost::ignore_unused(variant);
344  boost::ignore_unused(order);
345  }
346 
348  std::string variant, unsigned int order,
349  std::vector<NekDouble> freeParams)
350  {
351  boost::ignore_unused(variant);
352  boost::ignore_unused(order);
353 
356  "", 4, freeParams);
357 
358  return p;
359  }
360 
361  static std::string className;
362 
363 }; // end class AdamsMoultonOrder4TimeIntegrationScheme
364 
365 } // end namespace LibUtilities
366 } // end namespace Nektar
367 
368 #endif
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:249
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, unsigned int order)
static LUE void SetupSchemeData(TimeIntegrationAlgorithmGLMSharedPtr &phase, std::string variant)
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:2
double NekDouble