Nektar++
Loading...
Searching...
No Matches
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
52///////////////////////////////////////////////////////////////////////////////
53// Adams Bashforth Order N
54
56{
57public:
58 AdamsBashforthTimeIntegrationScheme(std::string variant, size_t order,
59 std::vector<NekDouble> freeParams)
60 : TimeIntegrationSchemeGLM(variant, order, freeParams)
61 {
62 // Currently up to 4th order is implemented.
63 ASSERTL1(1 <= order && order <= 4,
64 "AdamsBashforth Time integration scheme bad order (1-4): " +
65 std::to_string(order));
66
68
69 for (size_t n = 0; n < order; ++n)
70 {
73 }
74
75 // Next to last phase
76 if (order > 1)
77 {
79 m_integration_phases[order - 2], order - 1);
80 }
81
82 // Last phase
84 m_integration_phases[order - 1], order);
85
86 // Initial phases
87 switch (order)
88 {
89 case 1:
90 // No intial phases.
91 break;
92
93 case 2:
94 // Intial phase set above
95 break;
96
97 case 3:
98 // Order 2
100 m_integration_phases[0], "", 2, std::vector<NekDouble>());
101 break;
102
103 case 4:
104 // SSP Order 3
106 m_integration_phases[0], "SSP", 3,
107 std::vector<NekDouble>());
108 // SSP Order 3
110 m_integration_phases[1], "SSP", 3,
111 std::vector<NekDouble>());
112 break;
113
114 default:
115 ASSERTL1(false,
116 "AdamsBashforth Time integration scheme bad order: " +
117 std::to_string(order));
118 }
119 }
120
122
124 std::string variant, size_t order, std::vector<NekDouble> freeParams)
125 {
127 AdamsBashforthTimeIntegrationScheme>::AllocateSharedPtr(variant,
128 order,
129 freeParams);
130
131 return p;
132 }
133
134 static std::string className;
135
137 size_t order)
138 {
139 // clang-format off
140 constexpr NekDouble coefficients[5][4] =
141 { { 0., 0., 0., 0. },
142 // 1st Order
143 { 1., 0., 0., 0. },
144 // 2nd Order
145 { 3./ 2., -1./ 2., 0., 0. },
146 // 3rd Order
147 { 23./12., -16./12., 5./12., 0. },
148 // 4th Order
149 { 55./24., -59./24., 37./24., -9./24.} };
150 // clang-format on
151
152 phase->m_schemeType = eExplicit;
153 phase->m_order = order;
154 phase->m_name =
155 std::string("AdamsBashforthOrder" + std::to_string(phase->m_order));
156
157 phase->m_numsteps = phase->m_order;
158 phase->m_numstages = 1;
159
160 phase->m_A = Array<OneD, Array<TwoD, NekDouble>>(1);
161 phase->m_B = Array<OneD, Array<TwoD, NekDouble>>(1);
162
163 phase->m_A[0] =
164 Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numstages, 0.0);
165 phase->m_B[0] =
166 Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numstages, 0.0);
167 phase->m_U =
168 Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numsteps, 0.0);
169 phase->m_V =
170 Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numsteps, 0.0);
171
172 // Coefficients
173
174 // B Coefficient for first row first column
175 phase->m_B[0][0][0] = coefficients[phase->m_order][0];
176
177 // B evaluation value shuffling second row first column
178 if (phase->m_order > 1)
179 {
180 phase->m_B[0][1][0] = 1.0;
181 }
182
183 // U Curent time step evaluation first row first column
184 phase->m_U[0][0] = 1.0;
185 phase->m_V[0][0] = 1.0;
186
187 // V Coefficients for first row additional columns
188 for (size_t n = 1; n < phase->m_order; ++n)
189 {
190 phase->m_V[0][n] = coefficients[phase->m_order][n];
191 }
192
193 // V evaluation value shuffling row n column n-1
194 for (size_t n = 2; n < phase->m_order; ++n)
195 {
196 phase->m_V[n][n - 1] = 1.0;
197 }
198
199 phase->m_numMultiStepValues = 1;
200 phase->m_numMultiStepImplicitDerivs = 0;
201 phase->m_numMultiStepExplicitDerivs = phase->m_order - 1;
202 phase->m_timeLevelOffset = Array<OneD, size_t>(phase->m_numsteps);
203 phase->m_timeLevelOffset[0] = 0;
204
205 // For order > 1 derivatives are needed.
206 for (size_t n = 1; n < phase->m_order; ++n)
207 {
208 phase->m_timeLevelOffset[n] = n;
209 }
210
211 phase->CheckAndVerify();
212 }
213
214protected:
215 LUE std::string v_GetName() const override
216 {
217 return std::string("AdamsBashforth");
218 }
219
221 {
222 if (GetOrder() == 1)
223 {
224 return 2.0;
225 }
226 else if (GetOrder() == 2)
227 {
228 return 1.0;
229 }
230 else if (GetOrder() == 3)
231 {
232 return 0.545454545454545;
233 }
234 else if (GetOrder() == 4)
235 {
236 return 0.3;
237 }
238 else
239 {
240 return 2.0;
241 }
242 }
243
244}; // end class AdamsBashforthTimeIntegrationScheme
245
246} // namespace Nektar::LibUtilities
247
248#endif
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
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.
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