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
47
49
50namespace Nektar
51{
52namespace LibUtilities
53{
54
55///////////////////////////////////////////////////////////////////////////////
56// Adams Bashforth Order N
57
59{
60public:
61 AdamsBashforthTimeIntegrationScheme(std::string variant, size_t order,
62 std::vector<NekDouble> freeParams)
63 : TimeIntegrationSchemeGLM(variant, order, freeParams)
64 {
65 // Currently up to 4th order is implemented.
66 ASSERTL1(1 <= order && order <= 4,
67 "AdamsBashforth Time integration scheme bad order (1-4): " +
68 std::to_string(order));
69
71
72 for (size_t n = 0; n < order; ++n)
73 {
76 }
77
78 // Next to last phase
79 if (order > 1)
80 {
82 m_integration_phases[order - 2], order - 1);
83 }
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 // Intial phase set above
98 break;
99
100 case 3:
101 // Order 2
103 m_integration_phases[0], "", 2, std::vector<NekDouble>());
104 break;
105
106 case 4:
107 // SSP Order 3
109 m_integration_phases[0], "SSP", 3,
110 std::vector<NekDouble>());
111 // SSP Order 3
113 m_integration_phases[1], "SSP", 3,
114 std::vector<NekDouble>());
115 break;
116
117 default:
118 ASSERTL1(false,
119 "AdamsBashforth Time integration scheme bad order: " +
120 std::to_string(order));
121 }
122 }
123
125 {
126 }
127
129 std::string variant, size_t order, 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 size_t order)
143 {
144 // clang-format off
145 constexpr 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 // B Coefficient for first row first column
180 phase->m_B[0][0][0] = coefficients[phase->m_order][0];
181
182 // B evaluation value shuffling second row first column
183 if (phase->m_order > 1)
184 {
185 phase->m_B[0][1][0] = 1.0;
186 }
187
188 // U Curent time step evaluation first row first column
189 phase->m_U[0][0] = 1.0;
190 phase->m_V[0][0] = 1.0;
191
192 // V Coefficients for first row additional columns
193 for (size_t n = 1; n < phase->m_order; ++n)
194 {
195 phase->m_V[0][n] = coefficients[phase->m_order][n];
196 }
197
198 // V evaluation value shuffling row n column n-1
199 for (size_t n = 2; n < phase->m_order; ++n)
200 {
201 phase->m_V[n][n - 1] = 1.0;
202 }
203
204 phase->m_numMultiStepValues = 1;
205 phase->m_numMultiStepImplicitDerivs = 0;
206 phase->m_numMultiStepExplicitDerivs = phase->m_order - 1;
207 phase->m_timeLevelOffset = Array<OneD, size_t>(phase->m_numsteps);
208 phase->m_timeLevelOffset[0] = 0;
209
210 // For order > 1 derivatives are needed.
211 for (size_t n = 1; n < phase->m_order; ++n)
212 {
213 phase->m_timeLevelOffset[n] = n;
214 }
215
216 phase->CheckAndVerify();
217 }
218
219protected:
220 LUE virtual std::string v_GetName() const override
221 {
222 return std::string("AdamsBashforth");
223 }
224
225 LUE virtual NekDouble v_GetTimeStability() const override
226 {
227 if (GetOrder() == 1)
228 {
229 return 2.0;
230 }
231 else if (GetOrder() == 2)
232 {
233 return 1.0;
234 }
235 else if (GetOrder() == 3)
236 {
237 return 0.545454545454545;
238 }
239 else if (GetOrder() == 4)
240 {
241 return 0.3;
242 }
243 else
244 {
245 return 2.0;
246 }
247 }
248
249}; // end class AdamsBashforthTimeIntegrationScheme
250
251////////////////////////////////////////////////////////////////////////////////
252// Backwards compatibility
255{
256public:
257 AdamsBashforthOrder1TimeIntegrationScheme(std::string variant, size_t order,
258 std::vector<NekDouble> freeParams)
259 : AdamsBashforthTimeIntegrationScheme("", 1, freeParams)
260 {
261 boost::ignore_unused(variant);
262 boost::ignore_unused(order);
263 }
264
266 std::string variant, size_t order, std::vector<NekDouble> freeParams)
267 {
268 boost::ignore_unused(variant);
269 boost::ignore_unused(order);
270
272 AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 1,
273 freeParams);
274 return p;
275 }
276
277 static std::string className;
278
279protected:
281
282}; // end class AdamsBashforthOrder1TimeIntegrationScheme
283
286{
287public:
288 AdamsBashforthOrder2TimeIntegrationScheme(std::string variant, size_t order,
289 std::vector<NekDouble> freeParams)
290 : AdamsBashforthTimeIntegrationScheme("", 2, freeParams)
291 {
292 boost::ignore_unused(variant);
293 boost::ignore_unused(order);
294 }
295
297 std::string variant, size_t order, std::vector<NekDouble> freeParams)
298 {
299 boost::ignore_unused(variant);
300 boost::ignore_unused(order);
301
303 AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 2,
304 freeParams);
305 return p;
306 }
307
308 static std::string className;
309
310protected:
312
313}; // end class AdamsBashforthOrder2TimeIntegrationScheme
314
317{
318public:
319 AdamsBashforthOrder3TimeIntegrationScheme(std::string variant, size_t order,
320 std::vector<NekDouble> freeParams)
321 : AdamsBashforthTimeIntegrationScheme("", 3, freeParams)
322 {
323 boost::ignore_unused(variant);
324 boost::ignore_unused(order);
325 }
326
328 std::string variant, size_t order, std::vector<NekDouble> freeParams)
329 {
330 boost::ignore_unused(variant);
331 boost::ignore_unused(order);
332
334 AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 3,
335 freeParams);
336 return p;
337 }
338
339 static std::string className;
340
341protected:
343
344}; // end class AdamsBashforthOrder3TimeIntegrationScheme
345
348{
349public:
350 AdamsBashforthOrder4TimeIntegrationScheme(std::string variant, size_t order,
351 std::vector<NekDouble> freeParams)
352 : AdamsBashforthTimeIntegrationScheme("", 4, freeParams)
353 {
354 boost::ignore_unused(variant);
355 boost::ignore_unused(order);
356 }
357
359 std::string variant, size_t order, std::vector<NekDouble> freeParams)
360 {
361 boost::ignore_unused(variant);
362 boost::ignore_unused(order);
363
365 AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 4,
366 freeParams);
367 return p;
368 }
369
370 static std::string className;
371
372protected:
374
375}; // end class AdamsBashforthOrder4TimeIntegrationScheme
376
377} // end namespace LibUtilities
378} // end namespace Nektar
379
380#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, size_t order, std::vector< NekDouble > freeParams)
static TimeIntegrationSchemeSharedPtr create(std::string variant, size_t order, std::vector< NekDouble > freeParams)
static TimeIntegrationSchemeSharedPtr create(std::string variant, size_t order, std::vector< NekDouble > freeParams)
AdamsBashforthOrder2TimeIntegrationScheme(std::string variant, size_t order, std::vector< NekDouble > freeParams)
AdamsBashforthOrder3TimeIntegrationScheme(std::string variant, size_t order, std::vector< NekDouble > freeParams)
static TimeIntegrationSchemeSharedPtr create(std::string variant, size_t order, std::vector< NekDouble > freeParams)
static TimeIntegrationSchemeSharedPtr create(std::string variant, size_t order, std::vector< NekDouble > freeParams)
AdamsBashforthOrder4TimeIntegrationScheme(std::string variant, size_t order, std::vector< NekDouble > freeParams)
static LUE void SetupSchemeData(TimeIntegrationAlgorithmGLMSharedPtr &phase, size_t order)
AdamsBashforthTimeIntegrationScheme(std::string variant, size_t order, std::vector< NekDouble > freeParams)
static TimeIntegrationSchemeSharedPtr create(std::string variant, size_t order, std::vector< NekDouble > freeParams)
static LUE void SetupSchemeData(TimeIntegrationAlgorithmGLMSharedPtr &phase, std::string variant, size_t 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