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 
44 
45 namespace Nektar
46 {
47 namespace LibUtilities
48 {
49 
50 ///////////////////////////////////////////////////////////////////////////////
51 /// Class for spectral deferred correction integration.
53 {
54 public:
55  TimeIntegrationSchemeSDC(std::string variant, unsigned int order,
56  std::vector<NekDouble> freeParams)
57  : TimeIntegrationScheme(variant, order, freeParams),
58  m_name("SpectralDeferredCorrection")
59  {
60 
61  ASSERTL0(variant == "Equidistant" ||
62  variant == "GaussLobattoLegendre" ||
63  variant == "GaussRadauLegendre" ||
64  variant == "GaussLobattoChebyshev" ||
65  variant == "GaussRadauChebyshev",
66  "unknow variant (quadrature) type");
67 
68  ASSERTL0(1 <= order, "Spectral Deferred Correction Time integration "
69  "scheme bad order numbers (>=1): " +
70  std::to_string(order));
71  ASSERTL0(freeParams.size() == 2,
72  "SDC Time integration scheme invalid number "
73  "of free parameters, expected two "
74  "<theta, number of quadrature>, received " +
75  std::to_string(freeParams.size()));
76  ASSERTL0(0.0 <= freeParams[0] && freeParams[0] <= 1.0,
77  "Spectral Deferred Correction Time integration "
78  "scheme bad parameter numbers (0.0 - 1.0): " +
79  std::to_string(freeParams[0]));
80  ASSERTL0(1 <= int(freeParams[1]),
81  "Spectral Deferred Correction Time integration "
82  "scheme bad quadrature numbers (>=1): " +
83  std::to_string(int(freeParams[1])));
84 
85  m_variant = variant;
86  m_order = order;
87  m_freeParams = freeParams;
88  m_theta = freeParams[0];
89 
90  // Compute quadrature points and weights
91  if (variant == "Equidistant")
92  {
93  ASSERTL0(int(m_freeParams[1]) >= order,
94  "Spectral Deferred Correction Time integration "
95  "Maximum order (<= n): " +
96  std::to_string(int(m_freeParams[1])));
97 
98  ASSERTL0(2 <= freeParams[1],
99  "Spectral Deferred Correction Time integration "
100  "scheme bad quadrature numbers (>=1): " +
101  std::to_string(freeParams[1]));
102 
103  m_nQuadPts = int(m_freeParams[1]);
106  for (int i = 0; i < m_nQuadPts - 1; i++)
107  {
108  m_points[i + 1] = m_points[i] + 1.0 / (m_nQuadPts - 1);
109  }
110  }
111  else if (variant == "GaussLobattoLegendre")
112  {
113  ASSERTL0(2 * int(m_freeParams[1]) - 2 >= order,
114  "Spectral Deferred Correction Time integration "
115  "Maximum order (<= 2 * n - 2): " +
116  std::to_string(2 * int(m_freeParams[1]) - 2));
117 
118  // m_order = 2 * int(m_freeParams[1]) - 2;
119  m_nQuadPts = int(m_freeParams[1]);
122  Polylib::zwglj(&m_points[0], &m_weights[0], int(m_freeParams[1]),
123  0.0, 0.0);
124  }
125  else if (variant == "GaussRadauLegendre")
126  {
127  ASSERTL0(2 * int(m_freeParams[1]) - 1 >= order,
128  "Spectral Deferred Correction Time integration "
129  "Maximum order (<= 2 * n - 1): " +
130  std::to_string(2 * int(m_freeParams[1]) - 1));
131 
132  // m_order = 2 * int(m_freeParams[1]) - 1;
133  m_nQuadPts = int(m_freeParams[1]) + 1;
136  if (int(m_freeParams[1]) == 1)
137  {
138  m_points[1] = 1.0;
139  }
140  else
141  {
143  int(m_freeParams[1]), 0.0, 0.0);
144  }
145  }
146  else if (variant == "GaussLobattoChebyshev")
147  {
148  ASSERTL0(2 * int(m_freeParams[1]) - 2 >= order,
149  "Spectral Deferred Correction Time integration "
150  "Maximum order (<= 2 * n - 2): " +
151  std::to_string(2 * int(m_freeParams[1]) - 2));
152 
153  // m_order = 2 * int(m_freeParams[1]) - 2;
154  m_nQuadPts = int(m_freeParams[1]);
157  Polylib::zwglj(&m_points[0], &m_weights[0], int(m_freeParams[1]),
158  -0.5, -0.5);
159  }
160  else if (variant == "GaussRadauChebyshev")
161  {
162  ASSERTL0(2 * int(m_freeParams[1]) - 2 >= order,
163  "Spectral Deferred Correction Time integration "
164  "Maximum order (<= 2 * n - 2): " +
165  std::to_string(2 * int(m_freeParams[1]) - 2));
166 
167  // m_order = 2 * int(m_freeParams[1]) - 2;
168  m_nQuadPts = int(m_freeParams[1]) + 1;
171  if (int(m_freeParams[1]) == 1)
172  {
173  m_points[1] = 1.0;
174  }
175  else
176  {
178  int(m_freeParams[1]), -0.5, -0.5);
179  }
180  }
181  // Note: m_weights is not used
182 
183  // Rescale quadrature points to [0, 1]
184  NekDouble denom = m_points[m_nQuadPts - 1] - m_points[0];
185  NekDouble x0 = m_points[0];
186  for (int i = 0; i < m_nQuadPts; i++)
187  {
188  m_points[i] = (m_points[i] - x0) / denom;
189  }
190  }
191 
192  /// Destructor
194  {
195  }
196 
198  std::string variant, unsigned int order,
199  std::vector<NekDouble> freeParams)
200  {
203  variant, order, freeParams);
204 
205  return p;
206  }
207 
208  static std::string className;
209 
210  LUE void UpdateIntegratedResidual(const NekDouble &delta_t,
211  const int option = 0);
212 
213  LUE void ResidualEval(const NekDouble &delta_t, const int n,
215  {
216  v_ResidualEval(delta_t, n, op);
217  }
218 
219  LUE void ResidualEval(const NekDouble &delta_t,
221  {
222  v_ResidualEval(delta_t, op);
223  }
224 
225  LUE void ComputeInitialGuess(const NekDouble &delta_t,
227  {
228  v_ComputeInitialGuess(delta_t, op);
229  }
230 
231  LUE void SDCIterationLoop(const NekDouble &delta_t,
233  {
234  v_SDCIterationLoop(delta_t, op);
235  }
236 
237 protected:
238  LUE virtual std::string v_GetName() const override;
239  LUE virtual std::string v_GetVariant() const override;
240  LUE virtual unsigned int v_GetOrder() const override;
241  LUE virtual std::vector<NekDouble> v_GetFreeParams() const override;
243  const override;
244  LUE virtual NekDouble v_GetTimeStability() const override;
245  LUE virtual unsigned int v_GetNumIntegrationPhases() const override;
246 
247  /**
248  * \brief Gets the solution vector of the ODE
249  */
250  LUE virtual const TripleArray &v_GetSolutionVector() const override;
251 
252  /**
253  * \brief Sets the solution vector of the ODE
254  */
255  LUE virtual void v_SetSolutionVector(const int Offset,
256  const DoubleArray &y) override;
257 
258  // The worker methods from the base class that are virtual
260  const int timestep, const NekDouble delta_t,
261  const TimeIntegrationSchemeOperators &op) override;
262 
263  LUE virtual void v_InitializeScheme(
264  const NekDouble deltaT, ConstDoubleArray &y_0, const NekDouble time,
265  const TimeIntegrationSchemeOperators &op) override;
266 
267  LUE virtual void v_ResidualEval(const NekDouble &delta_t, const int n,
269  {
270  ASSERTL0(false, "Specific version of spectral deferred correction "
271  "not implemented");
272  boost::ignore_unused(delta_t, n, op);
273  }
274 
275  LUE virtual void v_ResidualEval(const NekDouble &delta_t,
277  {
278  ASSERTL0(false, "Specific version of spectral deferred correction "
279  "not implemented");
280  boost::ignore_unused(delta_t, op);
281  }
282 
284  const NekDouble &delta_t, const TimeIntegrationSchemeOperators &op)
285  {
286  ASSERTL0(false, "Specific version of spectral deferred correction "
287  "not implemented");
288  boost::ignore_unused(delta_t, op);
289  }
290 
291  LUE virtual void v_SDCIterationLoop(
292  const NekDouble &delta_t, const TimeIntegrationSchemeOperators &op)
293  {
294  ASSERTL0(false, "Specific version of spectral deferred correction "
295  "not implemented");
296  boost::ignore_unused(delta_t, op);
297  }
298 
299  LUE virtual void v_print(std::ostream &os) const override;
300  LUE virtual void v_printFull(std::ostream &os) const override;
301 
302  // Variables common to all schemes.
303  std::string m_name;
304  std::string m_variant;
305  unsigned int m_order{0}, m_nQuadPts{0};
306  bool m_initialized = false;
307  std::vector<NekDouble> m_freeParams;
309 
311 
312  // Storage of previous states and associated timesteps.
313  TripleArray m_Y; /// Array containing the stage values
314  TripleArray m_F; /// Array corresponding to the stage Derivatives
321 
322  int m_nvars{0}; // Number of variables in the integration scheme.
323  int m_npoints{0}; // Number of points in the integration scheme.
324 
325 }; // end class TimeIntegrationSchemeSDC
326 
327 } // end namespace LibUtilities
328 } // end namespace Nektar
329 
330 #endif
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#define LUE
Base class for time integration schemes.
Binds a set of functions for use by time integration schemes.
Class for spectral deferred correction integration.
LUE void SDCIterationLoop(const NekDouble &delta_t, const TimeIntegrationSchemeOperators &op)
virtual LUE unsigned int v_GetOrder() const override
virtual LUE void v_ResidualEval(const NekDouble &delta_t, const int n, const TimeIntegrationSchemeOperators &op)
LUE void ResidualEval(const NekDouble &delta_t, const TimeIntegrationSchemeOperators &op)
LUE void ResidualEval(const NekDouble &delta_t, const int n, const TimeIntegrationSchemeOperators &op)
LUE void UpdateIntegratedResidual(const NekDouble &delta_t, const int option=0)
Worker method that compute the integrated flux.
virtual LUE ConstDoubleArray & v_TimeIntegrate(const int timestep, const NekDouble delta_t, const TimeIntegrationSchemeOperators &op) override
Worker method that performs the time integration.
virtual LUE TimeIntegrationSchemeType v_GetIntegrationSchemeType() const override
virtual LUE void v_print(std::ostream &os) const override
Worker method to print details on the integration scheme.
virtual LUE std::string v_GetName() const override
static TimeIntegrationSchemeSharedPtr create(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
LUE void ComputeInitialGuess(const NekDouble &delta_t, const TimeIntegrationSchemeOperators &op)
virtual LUE void v_ResidualEval(const NekDouble &delta_t, const TimeIntegrationSchemeOperators &op)
TimeIntegrationSchemeSDC(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
virtual LUE void v_SetSolutionVector(const int Offset, const DoubleArray &y) override
Sets the solution vector of the ODE.
virtual LUE void v_printFull(std::ostream &os) const override
TripleArray m_Fint
Array corresponding to the stage Derivatives.
virtual LUE std::vector< NekDouble > v_GetFreeParams() const override
TripleArray m_F
Array containing the stage values.
virtual LUE void v_ComputeInitialGuess(const NekDouble &delta_t, const TimeIntegrationSchemeOperators &op)
virtual LUE unsigned int v_GetNumIntegrationPhases() const override
virtual LUE void v_InitializeScheme(const NekDouble deltaT, ConstDoubleArray &y_0, const NekDouble time, const TimeIntegrationSchemeOperators &op) override
Worker method to initialize the integration scheme.
virtual LUE void v_SDCIterationLoop(const NekDouble &delta_t, const TimeIntegrationSchemeOperators &op)
virtual LUE std::string v_GetVariant() const override
virtual LUE NekDouble v_GetTimeStability() const override
virtual 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.
std::shared_ptr< TimeIntegrationScheme > TimeIntegrationSchemeSharedPtr
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble
void zwgrjp(double *z, double *w, const int np, const double alpha, const double beta)
Gauss-Radau-Jacobi zeros and weights with end point at z=1.
Definition: Polylib.cpp:202
void zwglj(double *z, double *w, const int np, const double alpha, const double beta)
Gauss-Lobatto-Jacobi zeros and weights with end point at z=-1,1.
Definition: Polylib.cpp:241