Nektar++
TimeIntegrationScheme.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: TimeIntegrationScheme.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 base class,
32 // this class is the parent class for the TimeIntegrationSchemeGLM,
33 // TimeIntegrationSchemeFIT, TimeIntegrationSchemeGEM, and
34 // TimeIntegrationSchemeSDC classes.
35 //
36 ///////////////////////////////////////////////////////////////////////////////
37 
38 #ifndef NEKTAR_LIB_UTILITIES_TIME_INTEGRATION_TIME_INTEGRATION_SCHEME
39 #define NEKTAR_LIB_UTILITIES_TIME_INTEGRATION_TIME_INTEGRATION_SCHEME
40 
41 #include <string>
42 
43 #include <boost/core/ignore_unused.hpp>
44 
50 
53 
54 #define LUE LIB_UTILITIES_EXPORT
55 
56 namespace Nektar
57 {
58 namespace LibUtilities
59 {
60 
61 /// Datatype of the NekFactory used to instantiate classes derived from the
62 /// EquationSystem class.
63 typedef NekFactory<std::string, TimeIntegrationScheme, std::string,
64  unsigned int, std::vector<NekDouble>>
66 
67 // Allows a code to create a TimeIntegrator. Usually used like this:
68 //
69 // LibUtilities::TimeIntegrationSchemeSharedPtr timeIntegrationScheme =
70 // LibUtilities::GetTimeIntegrationSchemeFactory().CreateInstance(
71 // "IMEX", "dirk", 3, std::vector<unsigned int>{2,3} );
73 
74 /**
75  * @brief Base class for time integration schemes.
76  */
78 {
79 public:
80  // Access methods
81  LUE std::string GetFullName() const
82  {
83  return v_GetFullName();
84  }
85  LUE std::string GetName() const
86  {
87  return v_GetName();
88  }
89  LUE std::string GetVariant() const
90  {
91  return v_GetVariant();
92  }
93  LUE unsigned int GetOrder() const
94  {
95  return v_GetOrder();
96  }
97  LUE std::vector<NekDouble> GetFreeParams()
98  {
99  return v_GetFreeParams();
100  }
102  {
104  }
106  {
107  return v_GetTimeStability();
108  }
110  {
111  return v_GetNumIntegrationPhases();
112  }
113 
114  /**
115  * \brief Gets the solution vector of the ODE
116  */
118  {
119  return v_GetSolutionVector();
120  }
121 
122  /**
123  * \brief Sets the solution vector of the ODE
124  */
125  void SetSolutionVector(const int Offset, const DoubleArray &y)
126  {
127  v_SetSolutionVector(Offset, y);
128  }
129 
130  // The worker methods
131  /**
132  * \brief Explicit integration of an ODE.
133  *
134  * This function explicitely perfroms a single integration step of the ODE
135  * system:
136  * \f[
137  * \frac{d\boldsymbol{y}}{dt}=\boldsymbol{f}(t,\boldsymbol{y})
138  * \f]
139  *
140  * \param timestep The size of the timestep, i.e. \f$\Delta t\f$.
141  * \param f an object of the class FuncType, where FuncType should have a
142  * method FuncType::ODEforcing
143  * to evaluate the right hand side \f$f(t,\boldsymbol{y})\f$ of the
144  * ODE.
145  * \param y on input: the vectors \f$\boldsymbol{y}^{[n-1]}\f$ and
146  * \f$t^{[n-1]}\f$ (which corresponds to the
147  * solution at the old time level)
148  * \param y on output: the vectors \f$\boldsymbol{y}^{[n]}\f$ and
149  * \f$t^{[n]}\f$ (which corresponds to the
150  * solution at the old new level)
151  * \return The actual solution \f$\boldsymbol{y}^{n}\f$ at the new time
152  * level
153  * (which in fact is also embedded in the argument y).
154  */
156  const NekDouble time,
158  {
159  v_InitializeScheme(deltaT, y_0, time, op);
160  }
161 
163  const int timestep, const NekDouble delta_t,
165  {
166  return v_TimeIntegrate(timestep, delta_t, op);
167  }
168 
169  LUE void print(std::ostream &os) const
170  {
171  v_print(os);
172  }
173  LUE void printFull(std::ostream &os) const
174  {
175  v_printFull(os);
176  }
177 
178  // Friend classes
179  LUE friend std::ostream &operator<<(std::ostream &os,
180  const TimeIntegrationScheme &rhs);
181  LUE friend std::ostream &operator<<(
182  std::ostream &os, const TimeIntegrationSchemeSharedPtr &rhs);
183 
184 protected:
185  LUE virtual std::string v_GetFullName() const;
186  LUE virtual std::string v_GetName() const = 0;
187  LUE virtual std::string v_GetVariant() const = 0;
188  LUE virtual unsigned int v_GetOrder() const = 0;
189  LUE virtual std::vector<NekDouble> v_GetFreeParams() const = 0;
191  const = 0;
192  LUE virtual NekDouble v_GetTimeStability() const = 0;
193  LUE virtual unsigned int v_GetNumIntegrationPhases() const = 0;
194  virtual const TripleArray &v_GetSolutionVector() const = 0;
195  virtual void v_SetSolutionVector(const int Offset,
196  const DoubleArray &y) = 0;
197  LUE virtual void v_InitializeScheme(
198  const NekDouble deltaT, ConstDoubleArray &y_0, const NekDouble time,
199  const TimeIntegrationSchemeOperators &op) = 0;
201  const int timestep, const NekDouble delta_t,
202  const TimeIntegrationSchemeOperators &op) = 0;
203  LUE virtual void v_print(std::ostream &os) const = 0;
204  LUE virtual void v_printFull(std::ostream &os) const = 0;
205 
206  // These methods should never be used directly, only used by child classes.
207  LUE TimeIntegrationScheme(std::string variant, unsigned int order,
208  std::vector<NekDouble> freeParams)
209  {
210  boost::ignore_unused(variant, order, freeParams);
211  }
212 
214  {
215  boost::ignore_unused(in);
216 
217  NEKERROR(ErrorUtil::efatal, "Copy Constructor for the "
218  "TimeIntegrationScheme class should not be "
219  "called");
220  }
221 
223  {
224  }
225 
226 }; // end class TimeIntegrationScheme
227 
228 LUE std::ostream &operator<<(std::ostream &os,
229  const TimeIntegrationScheme &rhs);
230 
231 LUE std::ostream &operator<<(std::ostream &os,
232  const TimeIntegrationSchemeSharedPtr &rhs);
233 
234 } // end of namespace LibUtilities
235 } // end of namespace Nektar
236 
237 #endif
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:209
#define LUE
Provides a generic Factory class.
Definition: NekFactory.hpp:105
Base class for time integration schemes.
LUE std::vector< NekDouble > GetFreeParams()
virtual LUE std::string v_GetName() const =0
LUE TimeIntegrationScheme(const TimeIntegrationScheme &in)
LUE TimeIntegrationSchemeType GetIntegrationSchemeType()
LUE void InitializeScheme(const NekDouble deltaT, ConstDoubleArray &y_0, const NekDouble time, const TimeIntegrationSchemeOperators &op)
Explicit integration of an ODE.
virtual LUE TimeIntegrationSchemeType v_GetIntegrationSchemeType() const =0
void SetSolutionVector(const int Offset, const DoubleArray &y)
Sets the solution vector of the ODE.
virtual void v_SetSolutionVector(const int Offset, const DoubleArray &y)=0
virtual LUE void v_print(std::ostream &os) const =0
virtual LUE std::string v_GetVariant() const =0
virtual LUE void v_printFull(std::ostream &os) const =0
virtual LUE unsigned int v_GetOrder() const =0
LUE friend std::ostream & operator<<(std::ostream &os, const TimeIntegrationScheme &rhs)
const TripleArray & GetSolutionVector() const
Gets the solution vector of the ODE.
virtual LUE void v_InitializeScheme(const NekDouble deltaT, ConstDoubleArray &y_0, const NekDouble time, const TimeIntegrationSchemeOperators &op)=0
LUE void printFull(std::ostream &os) const
virtual LUE NekDouble v_GetTimeStability() const =0
LUE TimeIntegrationScheme(std::string variant, unsigned int order, std::vector< NekDouble > freeParams)
virtual LUE std::vector< NekDouble > v_GetFreeParams() const =0
virtual const TripleArray & v_GetSolutionVector() const =0
virtual LUE ConstDoubleArray & v_TimeIntegrate(const int timestep, const NekDouble delta_t, const TimeIntegrationSchemeOperators &op)=0
LUE ConstDoubleArray & TimeIntegrate(const int timestep, const NekDouble delta_t, const TimeIntegrationSchemeOperators &op)
virtual LUE unsigned int v_GetNumIntegrationPhases() const =0
Binds a set of functions for use by time integration schemes.
NekFactory< std::string, TimeIntegrationScheme, std::string, unsigned int, std::vector< NekDouble > > TimeIntegrationSchemeFactory
Datatype of the NekFactory used to instantiate classes derived from the EquationSystem class.
TimeIntegrationSchemeFactory & GetTimeIntegrationSchemeFactory()
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:2
double NekDouble