Nektar++
TimeIntegrationSchemeFIT.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: TimeIntegrationSchemeFIT.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 FIT base class
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 // Note: The file is named TimeIntegrationSchemeFIT to parallel the
36 // TimeIntegrationSchemeGLM file but the class is named
37 // FractionalInTimeIntegrationScheme so keep with the factory naming
38 // convention.
39 
40 #ifndef NEKTAR_LIB_UTILITIES_TIME_INTEGRATION_TIME_INTEGRATION_SCHEME_FIT
41 #define NEKTAR_LIB_UTILITIES_TIME_INTEGRATION_TIME_INTEGRATION_SCHEME_FIT
42 
43 #define LUE LIB_UTILITIES_EXPORT
44 
45 #include <string>
46 
48 
49 namespace Nektar
50 {
51 namespace LibUtilities
52 {
53 
54 ///////////////////////////////////////////////////////////////////////////////
55 /// Class for fractional-in-time integration.
57 {
58 public:
59  /// Constructor
60  FractionalInTimeIntegrationScheme(std::string variant, unsigned int order,
61  std::vector<NekDouble> freeParams);
62 
63  /// Destructor
65  {
66  }
67 
68  /// Creator
70  create(std::string variant,
71  unsigned int order,
72  std::vector<NekDouble> freeParams)
73  {
75  FractionalInTimeIntegrationScheme>::AllocateSharedPtr(variant,
76  order,
77  freeParams);
78 
79  return p;
80  }
81 
82  static std::string className;
83 
84  // Access methods from the base class that are virtual
85  LUE virtual std::string GetName() const
86  {
87  return m_name;
88  }
89 
90  LUE virtual std::string GetVariant() const
91  {
92  return m_variant;
93  }
94 
95  LUE virtual unsigned int GetOrder() const
96  {
97  return m_order;
98  }
99 
100  LUE virtual std::vector< NekDouble > GetFreeParams() const
101  {
102  return m_freeParams;
103  }
104 
106  {
107  return m_schemeType;
108  }
109 
111  {
112  return 1.0;
113  }
114 
115  LUE unsigned int GetNumIntegrationPhases() const
116  {
117  return 1;
118  }
119 
120  /**
121  * \brief Gets the solution vector of the ODE
122  */
123  inline const TripleArray &GetSolutionVector() const
124  {
125  return m_u;
126  }
127 
128  /**
129  * \brief Sets the solution vector of the ODE
130  */
131  inline void SetSolutionVector(const int Offset, const DoubleArray &y)
132  {
133  m_u[Offset] = y;
134  }
135 
136  // The worker methods from the base class that are virtual
137  LUE virtual void InitializeScheme(
138  const NekDouble deltaT, ConstDoubleArray &y_0,
139  const NekDouble time, const TimeIntegrationSchemeOperators &op);
140 
142  const int timestep, const NekDouble delta_t,
144 
145  LUE virtual void print(std::ostream &os) const;
146  LUE virtual void printFull(std::ostream &os) const;
147 
148  // Friend classes
149  LUE friend std::ostream &operator<<(std::ostream &os,
151  LUE friend std::ostream &operator<<(std::ostream &os,
153 
154 protected:
155  struct Instance
156  {
157  int base;
158 
159  int index; // Index of this instance
160  bool active; // Used to determine if active
161  int activecounter; // counter used to flip active bit
163 
164  // Major storage for auxilliary ODE solutions.
165  // Storage for values of y currently used to update u
167  std::pair< int, int > stage_ind; // Time-step counters indicating the
168  // interval ymain is associated with
169 
170  // Staging allocation
173  int stage_cbase; // This base is halved after the first cycle
175  int stage_fbase; // This base is halved after the first cycle
176 
177  // Ceiling stash allocation
178  int cstash_counter; // Counter used to determine
179  // when to stash
180  int cstash_base; // base for counter
182  std::pair< int, int > cstash_ind; // ind(1) is never used:
183  // it always matches main.ind(1)
184 
185  // Ceiling sandbox allocation
186  bool csandbox_active; // Flag to determine when
187  // stash 2 is utilized
190  std::pair< int, int > csandbox_ind;
191 
192  // Floor stash
195  std::pair< int, int > fstash_ind;
196 
197  // Floor sandbox
202  std::pair< int, int > fsandbox_ind;
203 
204  // Talbot quadrature rule
207 
209 
213  };
214 
215  inline unsigned int modIncrement(const unsigned int counter,
216  const unsigned int base) const;
217 
218  inline unsigned int computeL( const unsigned int base,
219  const unsigned int m ) const;
220 
221  inline unsigned int computeQML( const unsigned int base,
222  const unsigned int m );
223 
224  inline unsigned int computeTaus( const unsigned int base,
225  const unsigned int m );
226 
227  void talbotQuadrature(const unsigned int nQuadPts,
228  const NekDouble mu,
229  const NekDouble nu,
230  const NekDouble sigma,
231  ComplexSingleArray &lamb,
232  ComplexSingleArray &w) const;
233 
234  void integralClassInitialize(const unsigned int index,
235  Instance &instance) const;
236 
237  void updateStage(const unsigned int timeStep,
238  Instance &instance);
239 
240  void finalIncrement(const unsigned int timeStep,
242 
243  void integralContribution(const unsigned int timeStep,
244  const unsigned int tauml,
245  const Instance &instance);
246 
247  void timeAdvance(const unsigned int timeStep,
249  Instance &instance,
250  ComplexTripleArray &y);
251 
252  void advanceSandbox(const unsigned int timeStep,
254  Instance &instance);
255 
256  // Variables common to all schemes.
257  std::string m_name;
258  std::string m_variant;
259  unsigned int m_order{0};
260  std::vector< NekDouble > m_freeParams;
261 
263 
264  // Varaibles and methods specific to FIT integration schemes.
266  NekDouble m_T{0}; // Finial time
267  unsigned int m_maxTimeSteps; // Number of time steps.
268  NekDouble m_alpha{0.3}; // Value for exp integration.
269  unsigned int m_base{4}; // "Base" of the algorithm.
270  unsigned int m_nQuadPts{20}; // Number of Talbot quadrature rule points
274 
275  int m_nvars{0}; // Number of variables in the integration scheme.
276  int m_npoints{0}; // Number of points in the integration scheme.
277 
278  unsigned int m_Lmax{0}; // Maxium number of integral groups.
280 
281  // Demarcation integers
283  // Demarcation interval markers
285 
286  // Storage of the initial values.
288  // Storage of the next solution from the final increment.
290  // Storage for the integral contribution.
292  // Storage for the exponential factor in the integral contribution.
294 
295  // Storage of previous states and associated timesteps.
297 
298  // Storage for the stage derivative as the data will be re-used to
299  // update the solution.
301 
302  // J
304 
305  // Ahat array one for each order.
307 
308  // Mulitply the last Ahat array, transposed by J
310 
311 }; // end class FractionalInTimeIntegrator
312 
313 LUE std::ostream &operator<<(
314  std::ostream &os,
316 LUE std::ostream &operator<<(
317  std::ostream &os,
319 
320 } // end namespace LibUtilities
321 } // end namespace Nektar
322 
323 #endif
#define LUE
unsigned int modIncrement(const unsigned int counter, const unsigned int base) const
Method that increments the counter then performs mod calculation.
virtual LUE void print(std::ostream &os) const
Worker method to print details on the integration scheme.
void updateStage(const unsigned int timeStep, Instance &instance)
Method to rearrange of staging/stashing for current time.
void integralClassInitialize(const unsigned int index, Instance &instance) const
Method to initialize the integral class.
unsigned int computeQML(const unsigned int base, const unsigned int m)
Method to compute the demarcation integers q_{m, ell}.
virtual LUE TimeIntegrationSchemeType GetIntegrationSchemeType() const
unsigned int computeL(const unsigned int base, const unsigned int m) const
Method to compute the smallest integer L such that base < 2.
void timeAdvance(const unsigned int timeStep, const TimeIntegrationSchemeOperators &op, Instance &instance, ComplexTripleArray &y)
Method to get the solution to y' = z*y + f(u), using an exponential integrator with implicit order (m...
static TimeIntegrationSchemeSharedPtr create(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
Creator.
virtual LUE void InitializeScheme(const NekDouble deltaT, ConstDoubleArray &y_0, const NekDouble time, const TimeIntegrationSchemeOperators &op)
Worker method to initialize the integration scheme.
virtual LUE ConstDoubleArray & TimeIntegrate(const int timestep, const NekDouble delta_t, const TimeIntegrationSchemeOperators &op)
Worker method that performs the time integration.
unsigned int computeTaus(const unsigned int base, const unsigned int m)
Method to compute the demarcation interval marker tau_{m, ell}.
void talbotQuadrature(const unsigned int nQuadPts, const NekDouble mu, const NekDouble nu, const NekDouble sigma, ComplexSingleArray &lamb, ComplexSingleArray &w) const
Method to compute the quadrature rule over Tablot contour.
void advanceSandbox(const unsigned int timeStep, const TimeIntegrationSchemeOperators &op, Instance &instance)
Method to update sandboxes to the current time.
virtual LUE std::vector< NekDouble > GetFreeParams() const
FractionalInTimeIntegrationScheme(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
Constructor.
LUE friend std::ostream & operator<<(std::ostream &os, const FractionalInTimeIntegrationScheme &rhs)
void finalIncrement(const unsigned int timeStep, const TimeIntegrationSchemeOperators &op)
Method to approximate the integral.
void integralContribution(const unsigned int timeStep, const unsigned int tauml, const Instance &instance)
Method to get the integral contribution over [taus(i+1) taus(i)]. Stored in m_uInt.
const TripleArray & GetSolutionVector() const
Gets the solution vector of the ODE.
void SetSolutionVector(const int Offset, const DoubleArray &y)
Sets the solution vector of the ODE.
Base class for time integration schemes.
Binds a set of functions for use by time integration schemes.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
@ eFractionalInTime
Fractional in Time scheme.
std::shared_ptr< FractionalInTimeIntegrationScheme > FractionalInTimeIntegrationSchemeSharedPtr
std::ostream & operator<<(std::ostream &os, const BasisKey &rhs)
std::shared_ptr< TimeIntegrationScheme > TimeIntegrationSchemeSharedPtr
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble