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
46#include <boost/core/ignore_unused.hpp>
47
50
52{
53
54///////////////////////////////////////////////////////////////////////////////
55// Adams Bashforth Order N
56
58{
59public:
60 AdamsBashforthTimeIntegrationScheme(std::string variant, size_t order,
61 std::vector<NekDouble> freeParams)
62 : TimeIntegrationSchemeGLM(variant, order, freeParams)
63 {
64 // Currently up to 4th order is implemented.
65 ASSERTL1(1 <= order && order <= 4,
66 "AdamsBashforth Time integration scheme bad order (1-4): " +
67 std::to_string(order));
68
70
71 for (size_t n = 0; n < order; ++n)
72 {
75 }
76
77 // Next to last phase
78 if (order > 1)
79 {
81 m_integration_phases[order - 2], order - 1);
82 }
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 // Intial phase set 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, size_t order, std::vector<NekDouble> freeParams)
129 {
131 AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr(variant,
132 order,
133 freeParams);
134
135 return p;
136 }
137
138 static std::string className;
139
141 size_t order)
142 {
143 // clang-format off
144 constexpr NekDouble coefficients[5][4] =
145 { { 0., 0., 0., 0. },
146 // 1st Order
147 { 1., 0., 0., 0. },
148 // 2nd Order
149 { 3./ 2., -1./ 2., 0., 0. },
150 // 3rd Order
151 { 23./12., -16./12., 5./12., 0. },
152 // 4th Order
153 { 55./24., -59./24., 37./24., -9./24.} };
154 // clang-format on
155
156 phase->m_schemeType = eExplicit;
157 phase->m_order = order;
158 phase->m_name =
159 std::string("AdamsBashforthOrder" + std::to_string(phase->m_order));
160
161 phase->m_numsteps = phase->m_order;
162 phase->m_numstages = 1;
163
164 phase->m_A = Array<OneD, Array<TwoD, NekDouble>>(1);
165 phase->m_B = Array<OneD, Array<TwoD, NekDouble>>(1);
166
167 phase->m_A[0] =
168 Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numstages, 0.0);
169 phase->m_B[0] =
170 Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numstages, 0.0);
171 phase->m_U =
172 Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numsteps, 0.0);
173 phase->m_V =
174 Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numsteps, 0.0);
175
176 // Coefficients
177
178 // B Coefficient for first row first column
179 phase->m_B[0][0][0] = coefficients[phase->m_order][0];
180
181 // B evaluation value shuffling second row first column
182 if (phase->m_order > 1)
183 {
184 phase->m_B[0][1][0] = 1.0;
185 }
186
187 // U Curent time step evaluation first row first column
188 phase->m_U[0][0] = 1.0;
189 phase->m_V[0][0] = 1.0;
190
191 // V Coefficients for first row additional columns
192 for (size_t n = 1; n < phase->m_order; ++n)
193 {
194 phase->m_V[0][n] = coefficients[phase->m_order][n];
195 }
196
197 // V evaluation value shuffling row n column n-1
198 for (size_t n = 2; n < phase->m_order; ++n)
199 {
200 phase->m_V[n][n - 1] = 1.0;
201 }
202
203 phase->m_numMultiStepValues = 1;
204 phase->m_numMultiStepImplicitDerivs = 0;
205 phase->m_numMultiStepExplicitDerivs = phase->m_order - 1;
206 phase->m_timeLevelOffset = Array<OneD, size_t>(phase->m_numsteps);
207 phase->m_timeLevelOffset[0] = 0;
208
209 // For order > 1 derivatives are needed.
210 for (size_t n = 1; n < phase->m_order; ++n)
211 {
212 phase->m_timeLevelOffset[n] = n;
213 }
214
215 phase->CheckAndVerify();
216 }
217
218protected:
219 LUE std::string v_GetName() const override
220 {
221 return std::string("AdamsBashforth");
222 }
223
225 {
226 if (GetOrder() == 1)
227 {
228 return 2.0;
229 }
230 else if (GetOrder() == 2)
231 {
232 return 1.0;
233 }
234 else if (GetOrder() == 3)
235 {
236 return 0.545454545454545;
237 }
238 else if (GetOrder() == 4)
239 {
240 return 0.3;
241 }
242 else
243 {
244 return 2.0;
245 }
246 }
247
248}; // end class AdamsBashforthTimeIntegrationScheme
249
250////////////////////////////////////////////////////////////////////////////////
251// Backwards compatibility
254{
255public:
256 AdamsBashforthOrder1TimeIntegrationScheme(std::string variant, size_t order,
257 std::vector<NekDouble> freeParams)
258 : AdamsBashforthTimeIntegrationScheme("", 1, freeParams)
259 {
260 boost::ignore_unused(variant, order);
261 }
262
264 [[maybe_unused]] std::string variant, [[maybe_unused]] size_t order,
265 std::vector<NekDouble> freeParams)
266 {
268 AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 1,
269 freeParams);
270 return p;
271 }
272
273 static std::string className;
274
275protected:
277
278}; // end class AdamsBashforthOrder1TimeIntegrationScheme
279
282{
283public:
284 AdamsBashforthOrder2TimeIntegrationScheme(std::string variant, size_t order,
285 std::vector<NekDouble> freeParams)
286 : AdamsBashforthTimeIntegrationScheme("", 2, freeParams)
287 {
288 boost::ignore_unused(variant, order);
289 }
290
292 [[maybe_unused]] std::string variant, [[maybe_unused]] size_t order,
293 std::vector<NekDouble> freeParams)
294 {
296 AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 2,
297 freeParams);
298 return p;
299 }
300
301 static std::string className;
302
303protected:
305
306}; // end class AdamsBashforthOrder2TimeIntegrationScheme
307
310{
311public:
312 AdamsBashforthOrder3TimeIntegrationScheme(std::string variant, size_t order,
313 std::vector<NekDouble> freeParams)
314 : AdamsBashforthTimeIntegrationScheme("", 3, freeParams)
315 {
316 boost::ignore_unused(variant, order);
317 }
318
320 [[maybe_unused]] std::string variant, [[maybe_unused]] size_t order,
321 std::vector<NekDouble> freeParams)
322 {
324 AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 3,
325 freeParams);
326 return p;
327 }
328
329 static std::string className;
330
331protected:
333
334}; // end class AdamsBashforthOrder3TimeIntegrationScheme
335
338{
339public:
340 AdamsBashforthOrder4TimeIntegrationScheme(std::string variant, size_t order,
341 std::vector<NekDouble> freeParams)
342 : AdamsBashforthTimeIntegrationScheme("", 4, freeParams)
343 {
344 boost::ignore_unused(variant, order);
345 }
346
348 [[maybe_unused]] std::string variant, [[maybe_unused]] size_t order,
349 std::vector<NekDouble> freeParams)
350 {
352 AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr("", 4,
353 freeParams);
354 return p;
355 }
356
357 static std::string className;
358
359protected:
361
362}; // end class AdamsBashforthOrder4TimeIntegrationScheme
363
364} // namespace Nektar::LibUtilities
365
366#endif
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
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
double NekDouble