Nektar++
TimeIntegrationSchemeSDC.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TimeIntegrationSchemeSDC.h
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 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// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Header file of time integration scheme SDC base class
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#ifndef NEKTAR_LIB_UTILITIES_TIME_INTEGRATION_TIME_INTEGRATION_SCHEME_SDC
36#define NEKTAR_LIB_UTILITIES_TIME_INTEGRATION_TIME_INTEGRATION_SCHEME_SDC
37
38#define LUE LIB_UTILITIES_EXPORT
39
40#include <string>
41
48
50{
51
52///////////////////////////////////////////////////////////////////////////////
53/// Class for spectral deferred correction integration.
55{
56public:
57 TimeIntegrationSchemeSDC(std::string variant, size_t order,
58 std::vector<NekDouble> freeParams)
59 : TimeIntegrationScheme(variant, order, freeParams),
60 m_name("SpectralDeferredCorrection")
61 {
62 ASSERTL0(freeParams.size() == 2,
63 "SDC Time integration scheme invalid number "
64 "of free parameters, expected two "
65 "<theta, number of quadrature>, received " +
66 std::to_string(freeParams.size()));
67
68 ASSERTL0(0.0 <= freeParams[0] && freeParams[0] <= 1.0,
69 "Spectral Deferred Correction Time integration "
70 "scheme bad parameter numbers (0.0 - 1.0): " +
71 std::to_string(freeParams[0]));
72
73 // Set scheme properties
74 m_variant = variant;
75 m_order = order;
76 m_freeParams = freeParams;
79
80 if (m_variant == "Equidistant")
81 {
83 m_variant +
84 " quadrature require quadrature "
85 "numbers (>=1" +
86 "): " + std::to_string(freeParams[1]));
87
88 m_first_quadrature = (m_nQuadPts == 1) ? false : true;
89 m_last_quadrature = (m_nQuadPts == 1) ? false : true;
90 m_ordermin = 1;
94 }
95 else if (m_variant == "GaussLobattoLegendre")
96 {
98 m_variant +
99 " quadrature require quadrature "
100 "numbers (>=2" +
101 "): " + std::to_string(freeParams[1]));
102
103 m_first_quadrature = true;
104 m_last_quadrature = true;
105 m_ordermin = 1;
106 m_ordermax = 2 * m_nQuadPts - 2;
109 }
110 else if (m_variant == "GaussRadauLegendre")
111 {
112 ASSERTL0(2 <= m_nQuadPts,
113 m_variant +
114 " quadrature require quadrature "
115 "numbers (>=1" +
116 "): " + std::to_string(freeParams[1]));
117
118 m_first_quadrature = false;
119 m_last_quadrature = true;
120 m_ordermin = 1;
121 m_ordermax = 2 * m_nQuadPts - 1;
124 }
125 else if (m_variant == "GaussGaussLegendre")
126 {
127 ASSERTL0(1 <= m_nQuadPts,
128 m_variant +
129 " quadrature require quadrature "
130 "numbers (>=1" +
131 "): " + std::to_string(freeParams[1]));
132
133 m_first_quadrature = false;
134 m_last_quadrature = false;
135 m_ordermin = 1;
139 }
140 else
141 {
142 ASSERTL0(false, "unknow variant (quadrature) type");
143 }
144
146 "Spectral Deferred Correction Time integration "
147 "scheme bad order numbers (>=" +
148 std::to_string(m_ordermin) +
149 "): " + std::to_string(m_order));
150
152 "Spectral Deferred Correction Time integration "
153 "scheme bad order numbers (<=" +
154 std::to_string(m_ordermax) +
155 "): " + std::to_string(m_order));
156
157 // Add one extra quadrature points for i.c., if necessary
159 {
161 }
162
163 // Get quadrature points and rescale to [0, 1]
165 size_t offset = m_first_quadrature ? 0 : 1;
166 for (size_t i = offset; i < m_nQuadPts; i++)
167 {
168 NekDouble tau = PointsManager()[m_pointsKey]->GetZ()[i - offset];
169 m_tau[i] = (tau + 1.0) / 2.0;
170 }
171 }
172
173 /// Destructor
175 {
176 }
177
179 std::string variant, size_t order, std::vector<NekDouble> freeParams)
180 {
183 variant, order, freeParams);
184
185 return p;
186 }
187
188 static std::string className;
189
190 LUE void SetPFASST(bool pfasst)
191 {
192 m_PFASST = pfasst;
193 }
194
195 LUE void SetTime(double time)
196 {
197 m_time = time;
198 }
199
200 LUE size_t GetMaxOrder() const
201 {
202 return m_ordermax;
203 }
204
206 {
207 return m_first_quadrature;
208 }
209
211 {
212 return m_last_quadrature;
213 }
214
215 LUE size_t GetQuadPtsNumber() const
216 {
217 return m_nQuadPts;
218 }
219
220 LUE size_t GetNpoints() const
221 {
222 return m_npoints;
223 }
224
225 LUE size_t GetNvars() const
226 {
227 return m_nvars;
228 }
229
231 {
232 return m_pointsKey;
233 }
234
236 {
237 return m_Y[0];
238 }
239
241 {
242 return m_Y[0];
243 }
244
246 {
247 return m_last_quadrature ? m_Y[m_nQuadPts - 1] : m_Y_f;
248 }
249
251 {
252 return m_last_quadrature ? m_Y[m_nQuadPts - 1] : m_Y_f;
253 }
254
256 {
257 return m_F;
258 }
259
261 {
262 return m_F;
263 }
264
266 {
267 return m_QFint;
268 }
269
271 {
272 return m_QFint;
273 }
274
276 {
277 return m_FAScorr;
278 }
279
281 {
282 return m_FAScorr;
283 }
284
285 LUE void ResidualEval(const NekDouble &delta_t, const size_t n)
286 {
287 v_ResidualEval(delta_t, n);
288 }
289
290 LUE void ResidualEval(const NekDouble &delta_t)
291 {
292 v_ResidualEval(delta_t);
293 }
294
295 LUE void ComputeInitialGuess(const NekDouble &delta_t)
296 {
297 v_ComputeInitialGuess(delta_t);
298 }
299
300 LUE void SDCIterationLoop(const NekDouble &delta_t)
301 {
302 v_SDCIterationLoop(delta_t);
303 }
304
305 LUE void UpdateFirstQuadrature(void);
306 LUE void UpdateLastQuadrature(void);
307 LUE void AddFASCorrectionToSFint(void);
308 LUE void UpdateIntegratedResidualSFint(const NekDouble &delta_t);
309 LUE void UpdateIntegratedResidualQFint(const NekDouble &delta_t);
310
311protected:
312 LUE std::string v_GetName() const override;
313 LUE std::string v_GetVariant() const override;
314 LUE size_t v_GetOrder() const override;
315 LUE std::vector<NekDouble> v_GetFreeParams() const override;
317 LUE NekDouble v_GetTimeStability() const override;
318 LUE size_t v_GetNumIntegrationPhases() const override;
319
320 /**
321 * \brief Gets the solution vector of the ODE
322 */
323 LUE const TripleArray &v_GetSolutionVector() const override;
325
326 /**
327 * \brief Sets the solution vector of the ODE
328 */
329 LUE void v_SetSolutionVector(const size_t Offset,
330 const DoubleArray &y) override;
331
332 // The worker methods from the base class that are virtual
334 const NekDouble deltaT, ConstDoubleArray &y_0, const NekDouble time,
335 const TimeIntegrationSchemeOperators &op) override;
336
337 LUE ConstDoubleArray &v_TimeIntegrate(const size_t timestep,
338 const NekDouble delta_t) override;
339
340 LUE virtual void v_ResidualEval([[maybe_unused]] const NekDouble &delta_t,
341 [[maybe_unused]] const size_t n)
342 {
343 ASSERTL0(false, "Specific version of spectral deferred correction "
344 "not implemented");
345 }
346
347 LUE virtual void v_ResidualEval([[maybe_unused]] const NekDouble &delta_t)
348 {
349 ASSERTL0(false, "Specific version of spectral deferred correction "
350 "not implemented");
351 }
352
354 [[maybe_unused]] const NekDouble &delta_t)
355 {
356 ASSERTL0(false, "Specific version of spectral deferred correction "
357 "not implemented");
358 }
359
361 [[maybe_unused]] const NekDouble &delta_t)
362 {
363 ASSERTL0(false, "Specific version of spectral deferred correction "
364 "not implemented");
365 }
366
367 LUE void v_print(std::ostream &os) const override;
368 LUE void v_printFull(std::ostream &os) const override;
369
370 // Variables common to all schemes
372 std::string m_name;
373 std::string m_variant;
374 std::vector<NekDouble> m_freeParams;
377
378 // Storage of states and associated timesteps
379 PointsKey m_pointsKey; /// Object containing quadrature data
380 SingleArray m_tau; /// Array containing the quadrature points
381 DoubleArray m_Y_f; /// Array containing the last stage values
382 TripleArray m_Y; /// Array containing the stage values
383 TripleArray m_F; /// Array containing the stage derivatives
384 TripleArray m_FAScorr; /// Array containing the FAS correction term
385 TripleArray m_SFint; /// Array containing the integrated residual term
386 TripleArray m_QFint; /// Array containing the integrated residual term
387 SingleArray m_QMat; /// Array containing the integration matrix
388 SingleArray m_interp; /// Array containing the interpolation coefficients
389
390 // SDC parameter
391 NekDouble m_theta{1.0}; /// SDC parameter
392 size_t m_ordermin{0}; /// Minimum order of the integration scheme
393 size_t m_ordermax{0}; /// Maximum order of the integration scheme
394 size_t m_order{0}; /// Order of the integration scheme
395 size_t m_nQuadPts{0}; /// Number of quadrature points
396 size_t m_nvars{0}; /// Number of variables in the integration scheme
397 size_t m_npoints{0}; /// Number of points in the integration scheme
400 bool m_initialized{false};
401 bool m_PFASST{false};
402
403}; // end class TimeIntegrationSchemeSDC
404
405} // namespace Nektar::LibUtilities
406
407#endif
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
#define LUE
Defines a specification for a set of points.
Definition: Points.h:50
Base class for time integration schemes.
Binds a set of functions for use by time integration schemes.
Class for spectral deferred correction integration.
LUE const TripleArray & GetIntegratedResidualVector() const
size_t m_ordermax
Minimum order of the integration scheme.
static TimeIntegrationSchemeSharedPtr create(std::string variant, size_t order, std::vector< NekDouble > freeParams)
LUE void UpdateIntegratedResidualSFint(const NekDouble &delta_t)
Worker method that compute residual integral.
LUE const DoubleArray & GetLastQuadratureSolutionVector() const
SingleArray m_interp
Array containing the integration matrix.
virtual LUE void v_ComputeInitialGuess(const NekDouble &delta_t)
LUE TimeIntegrationSchemeType v_GetIntegrationSchemeType() const override
TripleArray m_Y
Array containing the last stage values.
LUE void v_print(std::ostream &os) const override
Worker method to print details on the integration scheme.
TripleArray m_QFint
Array containing the integrated residual term.
LUE void UpdateIntegratedResidualQFint(const NekDouble &delta_t)
size_t m_nQuadPts
Order of the integration scheme.
LUE void AddFASCorrectionToSFint(void)
Worker method that add the FASCorrection.
bool m_first_quadrature
Number of points in the integration scheme.
size_t m_npoints
Number of variables in the integration scheme.
SingleArray m_QMat
Array containing the integrated residual term.
LUE void ComputeInitialGuess(const NekDouble &delta_t)
LUE void v_printFull(std::ostream &os) const override
TripleArray m_FAScorr
Array containing the stage derivatives.
TripleArray m_SFint
Array containing the FAS correction term.
virtual LUE void v_SDCIterationLoop(const NekDouble &delta_t)
DoubleArray m_Y_f
Array containing the quadrature points.
NekDouble m_theta
Array containing the interpolation coefficients.
LUE std::vector< NekDouble > v_GetFreeParams() const override
size_t m_order
Maximum order of the integration scheme.
SingleArray m_tau
Object containing quadrature data.
LUE void UpdateFirstQuadrature(void)
Worker method that update the first quadrature.
TripleArray m_F
Array containing the stage values.
LUE const DoubleArray & GetFirstQuadratureSolutionVector() const
virtual LUE void v_ResidualEval(const NekDouble &delta_t, const size_t n)
LUE void v_SetSolutionVector(const size_t Offset, const DoubleArray &y) override
Sets the solution vector of the ODE.
LUE void v_InitializeScheme(const NekDouble deltaT, ConstDoubleArray &y_0, const NekDouble time, const TimeIntegrationSchemeOperators &op) override
Worker method to initialize the integration scheme.
LUE void UpdateLastQuadrature(void)
Worker method that update the last quadrature.
LUE ConstDoubleArray & v_TimeIntegrate(const size_t timestep, const NekDouble delta_t) override
Worker method that performs the time integration.
virtual LUE void v_ResidualEval(const NekDouble &delta_t)
LUE void ResidualEval(const NekDouble &delta_t, const size_t n)
LUE void SDCIterationLoop(const NekDouble &delta_t)
TimeIntegrationSchemeSDC(std::string variant, size_t order, std::vector< NekDouble > freeParams)
LUE const TripleArray & v_GetSolutionVector() const override
Gets the solution vector of the ODE.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
PointsManagerT & PointsManager(void)
std::shared_ptr< TimeIntegrationScheme > TimeIntegrationSchemeSharedPtr
@ eGaussLobattoLegendre
1D Gauss-Lobatto-Legendre quadrature points
Definition: PointsType.h:51
@ ePolyEvenlySpaced
1D Evenly-spaced points using Lagrange polynomial
Definition: PointsType.h:73
@ eGaussGaussLegendre
1D Gauss-Gauss-Legendre quadrature points
Definition: PointsType.h:46
@ eGaussRadauPLegendre
1D Gauss-Radau-Legendre quadrature points, pinned at x=1
Definition: PointsType.h:49
double NekDouble