Nektar++
Loading...
Searching...
No Matches
IMEXTimeIntegrationSchemes.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: IMEXTimeIntegrationSchemes.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 basic IMEX time integration
33// 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_IMEX_TIME_INTEGRATION_SCHEME
42#define NEKTAR_LIB_UTILITIES_TIME_INTEGRATION_IMEX_TIME_INTEGRATION_SCHEME
43
44#define LUE LIB_UTILITIES_EXPORT
45
48
50{
51
52///////////////////////////////////////////////////////////////////////////////
53// IMEX Order N
54
56{
57public:
58 IMEXTimeIntegrationScheme(std::string variant, size_t order,
59 std::vector<NekDouble> freeParams)
60 : TimeIntegrationSchemeGLM(variant, order, freeParams)
61 {
62 if (variant == "dirk" || variant == "DIRK")
63 {
64 ASSERTL1(freeParams.size() == 2,
65 "IMEX DIRK Time integration scheme invalid number "
66 "of free parameters, expected two "
67 "<implicit stages, explicit stages>, received " +
68 std::to_string(freeParams.size()));
69
70 size_t s = freeParams[0];
71 size_t sigma = freeParams[1];
72
76
77 if (order == 1 && s == 1 && sigma == 1)
78 {
79 // This phase is Forward Backward Euler which has two steps.
82 }
83 else
84 {
86 m_integration_phases[0], order, freeParams);
87 }
88 }
89 else if (variant == "")
90 {
91 // Currently up to 4th order is implemented.
92 ASSERTL1(1 <= order && order <= 4,
93 "IMEX Time integration scheme bad order (1-4): " +
94 std::to_string(order));
95
97
98 for (size_t n = 0; n < order; ++n)
99 {
102 }
103
104 // Last phase
106 m_integration_phases[order - 1], order);
107
108 // Initial phases
109 switch (order)
110 {
111 case 1:
112 // No intial phase.
113 break;
114
115 case 2:
118 break;
119
120 case 3:
123 std::vector<NekDouble>{3, 4});
126 std::vector<NekDouble>{3, 4});
127 break;
128
129 case 4:
132 std::vector<NekDouble>{3, 4});
135 std::vector<NekDouble>{3, 4});
138 std::vector<NekDouble>{3, 4});
139 break;
140
141 default:
142 ASSERTL1(false, "IMEX Time integration scheme bad order: " +
143 std::to_string(order));
144 }
145 }
146 else
147 {
148 ASSERTL1(false, "IMEX Time integration scheme bad variant: " +
149 variant + ". Must be blank or 'dirk'");
150 }
151 }
152
153 ~IMEXTimeIntegrationScheme() override = default;
154
156 std::string variant, size_t order, std::vector<NekDouble> freeParams)
157 {
160 variant, order, freeParams);
161
162 return p;
163 }
164
165 static std::string className;
166
168 size_t order)
169 {
170 constexpr NekDouble ABcoefficients[5] = {0.,
171 1., // 1st Order
172 2. / 3., // 2nd Order
173 6. / 11., // 3rd Order
174 12. / 25.}; // 4th Order
175
176 // Nsteps = 2 * order
177
178 // clang-format off
179 constexpr NekDouble UVcoefficients[5][8] =
180 { { 0., 0., 0., 0.,
181 0., 0., 0., 0. },
182 // 1st Order
183 { 1., 1., 0., 0.,
184 0., 0., 0., 0. },
185 // 2nd Order
186 { 4./ 3., -1./ 3., 4./3., -2./ 3.,
187 0., 0., 0., 0. },
188 // 3rd Order
189 { 18./11., -9./11., 2./11., 18./11.,
190 -18./11., 6./11., 0., 0. },
191 // 4th Order
192 { 48./25., -36./25., 16./25., -3./25.,
193 48./25., -72./25., 48./25., -12./25. } };
194 // clang-format on
195
196 phase->m_schemeType = eIMEX;
197 phase->m_order = order;
198 phase->m_name =
199 std::string("IMEXOrder" + std::to_string(phase->m_order));
200
201 phase->m_numsteps = 2 * phase->m_order;
202 phase->m_numstages = 1;
203
204 phase->m_A = Array<OneD, Array<TwoD, NekDouble>>(2);
205 phase->m_B = Array<OneD, Array<TwoD, NekDouble>>(2);
206
207 phase->m_A[0] =
208 Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numstages, 0.0);
209 phase->m_B[0] =
210 Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numstages, 0.0);
211 phase->m_A[1] =
212 Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numstages, 0.0);
213 phase->m_B[1] =
214 Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numstages, 0.0);
215 phase->m_U =
216 Array<TwoD, NekDouble>(phase->m_numstages, phase->m_numsteps, 0.0);
217 phase->m_V =
218 Array<TwoD, NekDouble>(phase->m_numsteps, phase->m_numsteps, 0.0);
219
220 // Coefficients
221 phase->m_B[1][phase->m_order][0] = 1.0;
222
223 phase->m_A[0][0][0] = ABcoefficients[phase->m_order];
224 phase->m_B[0][0][0] = ABcoefficients[phase->m_order];
225
226 for (size_t n = 0; n < 2 * phase->m_order; ++n)
227 {
228 phase->m_U[0][n] = UVcoefficients[phase->m_order][n];
229 phase->m_V[0][n] = UVcoefficients[phase->m_order][n];
230 }
231
232 // V evaluation value shuffling row n column n-1
233 for (size_t n = 1; n < 2 * phase->m_order; ++n)
234 {
235 if (n != phase->m_order)
236 {
237 phase->m_V[n][n - 1] = 1.0; // constant 1
238 }
239 }
240
241 phase->m_numMultiStepValues = phase->m_order;
242 phase->m_numMultiStepImplicitDerivs = 0;
243 phase->m_numMultiStepExplicitDerivs = phase->m_order;
244
245 phase->m_timeLevelOffset = Array<OneD, size_t>(phase->m_numsteps);
246
247 // Values and derivatives needed.
248 for (size_t n = 0; n < phase->m_order; ++n)
249 {
250 phase->m_timeLevelOffset[n] = n;
251 phase->m_timeLevelOffset[phase->m_order + n] = n;
252 }
253
254 phase->CheckAndVerify();
255 }
256
257protected:
258 LUE std::string v_GetFullName() const override
259 {
260 return m_integration_phases.back()->m_name;
261 }
262
263 LUE std::string v_GetName() const override
264 {
265 return std::string("IMEX");
266 }
267
269 {
270 return 1.0;
271 }
272
273}; // end class IMEXTimeIntegrationScheme
274
275} // namespace Nektar::LibUtilities
276
277#endif
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
IMEXTimeIntegrationScheme(std::string variant, size_t order, std::vector< NekDouble > freeParams)
static LUE void SetupSchemeData(TimeIntegrationAlgorithmGLMSharedPtr &phase, size_t order)
static TimeIntegrationSchemeSharedPtr create(std::string variant, size_t order, std::vector< NekDouble > freeParams)
static LUE void SetupSchemeData(TimeIntegrationAlgorithmGLMSharedPtr &phase, size_t order, std::vector< NekDouble > freeParams)
static LUE void SetupSchemeData_1_1_1(TimeIntegrationAlgorithmGLMSharedPtr &phase)
Base class for GLM time integration schemes.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< TimeIntegrationAlgorithmGLM > TimeIntegrationAlgorithmGLMSharedPtr
@ eIMEX
Implicit Explicit General Linear Method.
std::vector< TimeIntegrationAlgorithmGLMSharedPtr > TimeIntegrationAlgorithmGLMVector
std::shared_ptr< TimeIntegrationScheme > TimeIntegrationSchemeSharedPtr