explicit_timesteppers.h
Go to the documentation of this file.
1 //LIC// ====================================================================
2 //LIC// This file forms part of oomph-lib, the object-oriented,
3 //LIC// multi-physics finite-element library, available
4 //LIC// at http://www.oomph-lib.org.
5 //LIC//
6 //LIC// Version 1.0; svn revision $LastChangedRevision: 1097 $
7 //LIC//
8 //LIC// $LastChangedDate: 2015-12-17 11:53:17 +0000 (Thu, 17 Dec 2015) $
9 //LIC//
10 //LIC// Copyright (C) 2006-2016 Matthias Heil and Andrew Hazel
11 //LIC//
12 //LIC// This library is free software; you can redistribute it and/or
13 //LIC// modify it under the terms of the GNU Lesser General Public
14 //LIC// License as published by the Free Software Foundation; either
15 //LIC// version 2.1 of the License, or (at your option) any later version.
16 //LIC//
17 //LIC// This library is distributed in the hope that it will be useful,
18 //LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 //LIC// Lesser General Public License for more details.
21 //LIC//
22 //LIC// You should have received a copy of the GNU Lesser General Public
23 //LIC// License along with this library; if not, write to the Free Software
24 //LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 //LIC// 02110-1301 USA.
26 //LIC//
27 //LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
28 //LIC//
29 //LIC//====================================================================
30 //Header functions for classes that represent explicit time-stepping schemes
31 
32 //Include guards to prevent multiple inclusion of this header
33 #ifndef OOMPH_EXPLICIT_TIMESTEPPERS
34 #define OOMPH_EXPLICIT_TIMESTEPPERS
35 
36 // Config header generated by autoconfig
37 #ifdef HAVE_CONFIG_H
38  #include <oomph-lib-config.h>
39 #endif
40 
41 
42 #ifdef OOMPH_HAS_MPI
43 #include "mpi.h"
44 #endif
45 
46 #include "Vector.h"
47 #include "double_vector.h"
48 #include "oomph_utilities.h"
49 
50 namespace oomph
51 {
52 
53  class Time;
54 
55 //===============================================================
56 /// Class for objects than can be advanced in time by an Explicit
57 /// Timestepper.
58 /// WARNING: For explicit time stepping to work the object's residual
59 /// function (as used by get_inverse_mass_matrix_times_residuals(..)) MUST
60 /// be in the form r = f(t, u) - [timestepper approximation to dudt]!
61 /// Standard implicit time stepping will work with plenty of residuals that
62 /// don't fit into this form. Some examples where implicit time stepping
63 /// will work fine but explicit will fail:
64 /// 1) The negation of the above formula, this implementation will end up
65 /// using dudt = - f(u,t).
66 /// 2) A residual which is implicit or non-linear in dudt, such as r = dudt
67 /// - u x dudt.
68 //===============================================================
70 {
71  //Dummy double value for time
72  static double Dummy_time_value;
73 public:
74 
75  ///Empty constructor
77 
78  /// Broken copy constructor
80  {
81  BrokenCopy::broken_copy("ExplicitTimeSteppableObject");
82  }
83 
84  /// Broken assignment operator
86  {
87  BrokenCopy::broken_assign("ExplicitTimeSteppableObject");
88  }
89 
90  ///Empty destructor
92 
93  ///\short A single virtual function that returns the residuals
94  ///vector multiplied by the inverse mass matrix
95  virtual void get_dvaluesdt(DoubleVector &minv_res);
96 
97  /// Function that gets the values of the dofs in the object
98  virtual void get_dofs(DoubleVector &dofs) const;
99 
100  /// Function that gets the history values of the dofs in the object
101  virtual void get_dofs(const unsigned &t, DoubleVector &dofs) const;
102 
103  /// Function that sets the values of the dofs in the object
104  virtual void set_dofs(const DoubleVector &dofs);
105 
106  ///Function that adds the values to the dofs
107  virtual void add_to_dofs(const double &lambda,
108  const DoubleVector &increment_dofs);
109 
110  /// \short Empty virtual function to do anything needed before a stage of
111  /// an explicit time step (Runge-Kutta steps contain multiple stages per
112  /// time step, most others only contain one).
114 
115  /// \short Empty virtual function that should be overloaded to update and
116  /// slaved data or boundary conditions that should be advanced after each
117  /// stage of an explicit time step (Runge-Kutta steps contain multiple
118  /// stages per time step, most others only contain one).
120 
121  /// \short Empty virtual function that can be overloaded to do anything
122  /// needed before an explicit step.
124 
125  /// \short Empty virtual function that can be overloaded to do anything
126  /// needed after an explicit step.
128 
129  ///\short Broken virtual function that should be overloaded to
130  ///return access to the local time in the object
131  virtual double &time();
132 
133  /// \short Virtual function that should be overloaded to return a pointer to a
134  /// Time object.
135  virtual Time* time_pt() const;
136 };
137 
138 
139 //=====================================================================
140 /// A Base class for explicit timesteppers
141 //=====================================================================
143 {
144  protected:
145 
146  /// \short String that indicates the type of the timestepper
147  ///(e.g. "RungeKutta", etc.)
149 
150 public:
151 
152  /// \short Empty Constructor.
154 
155  /// Broken copy constructor
157  {
158  BrokenCopy::broken_copy("ExplicitTimeStepper");
159  }
160 
161  /// Broken assignment operator
163  {
164  BrokenCopy::broken_assign("ExplicitTimeStepper");
165  }
166 
167  /// Empty virtual destructor --- no memory is allocated in this class
169 
170  /// Pure virtual function that is used to advance time in the object
171  // referenced by object_pt by an amount dt
172  virtual void timestep(ExplicitTimeSteppableObject* const &object_pt,
173  const double &dt)=0;
174 
175 };
176 
177 
178 ///===========================================================
179 ///Simple first-order Euler Timestepping
180 //============================================================
182 {
183 public:
184 
185  ///Constructor, set the type
186  Euler() {Type="Euler";}
187 
188  /// Broken copy constructor
189  Euler(const Euler&)
190  {
191  BrokenCopy::broken_copy("Euler");
192  }
193 
194  /// Broken assignment operator
195  void operator=(const Euler&)
196  {
197  BrokenCopy::broken_assign("Euler");
198  }
199 
200  /// \short Overload function that is used to advance time in the object
201  /// reference by object_pt by an amount dt
202  void timestep(ExplicitTimeSteppableObject* const &object_pt,
203  const double &dt);
204 };
205 
206 ///===========================================================
207 ///Standard Runge Kutta Timestepping
208 //============================================================
209 template<unsigned ORDER>
211 {
212 public:
213 
214  ///Constructor, set the type
216  {
217  Type="RungeKutta";
218  }
219 
220  /// Broken copy constructor
222  {
223  BrokenCopy::broken_copy("RungeKutta");
224  }
225 
226  /// Broken assignment operator
227  void operator=(const RungeKutta&)
228  {
229  BrokenCopy::broken_assign("RungeKutta");
230  }
231 
232  /// Function that is used to advance time in the object
233  // reference by object_pt by an amount dt
234  void timestep(ExplicitTimeSteppableObject* const &object_pt,
235  const double &dt);
236 };
237 
238 
239 ///===========================================================
240 ///Runge Kutta Timestepping that uses low storage
241 //============================================================
242 template<unsigned ORDER>
244 {
245  //Storage for the coefficients
247 
248 public:
249 
250  ///Constructor, set the type
252 
253  /// Broken copy constructor
255  {
256  BrokenCopy::broken_copy("LowStorageRungeKutta");
257  }
258 
259  /// Broken assignment operator
261  {
262  BrokenCopy::broken_assign("LowStorageRungeKutta");
263  }
264 
265  /// Function that is used to advance the solution by time dt
266  void timestep(ExplicitTimeSteppableObject* const &object_pt,
267  const double &dt);
268 
269 };
270 
271 
272  ///===========================================================
273  /// An explicit version of BDF3 (i.e. uses derivative evaluation at y_n
274  /// instead of y_{n+1}). Useful as a predictor because it is third order
275  /// accurate but requires only one function evaluation (i.e. only one mass
276  /// matrix inversion + residual calculation).
277  //============================================================
278  class EBDF3 : public ExplicitTimeStepper
279  {
280  double Yn_weight;
281  double Ynm1_weight;
282  double Ynm2_weight;
283  double Fn_weight;
284 
285  public:
286 
287  ///Constructor, set the type
288  EBDF3() {}
289 
290  /// Broken copy constructor
291  EBDF3(const EBDF3&)
292  {
293  BrokenCopy::broken_copy("EBDF3");
294  }
295 
296  /// Broken assignment operator
297  void operator=(const EBDF3&)
298  {
299  BrokenCopy::broken_assign("EBDF3");
300  }
301 
302  void set_weights(const double &dtn, const double &dtnm1, const double &dtnm2);
303 
304  /// Function that is used to advance the solution by time dt
305  void timestep(ExplicitTimeSteppableObject* const &object_pt,
306  const double &dt);
307 
308  };
309 
310 }
311 
312 #endif
void timestep(ExplicitTimeSteppableObject *const &object_pt, const double &dt)
Function that is used to advance time in the object.
LowStorageRungeKutta()
Constructor, set the type.
void broken_copy(const std::string &class_name)
Issue error message and terminate execution.
virtual void actions_after_explicit_timestep()
Empty virtual function that can be overloaded to do anything needed after an explicit step...
ExplicitTimeSteppableObject(const ExplicitTimeSteppableObject &)
Broken copy constructor.
void timestep(ExplicitTimeSteppableObject *const &object_pt, const double &dt)
Function that is used to advance the solution by time dt.
virtual double & time()
Broken virtual function that should be overloaded to return access to the local time in the object...
Class to keep track of discrete/continous time. It is essential to have a single Time object when usi...
Definition: timesteppers.h:67
void operator=(const ExplicitTimeStepper &)
Broken assignment operator.
virtual void set_dofs(const DoubleVector &dofs)
Function that sets the values of the dofs in the object.
char t
Definition: cfortran.h:572
virtual void actions_after_explicit_stage()
Empty virtual function that should be overloaded to update and slaved data or boundary conditions tha...
virtual Time * time_pt() const
Virtual function that should be overloaded to return a pointer to a Time object.
virtual ~ExplicitTimeStepper()
Empty virtual destructor — no memory is allocated in this class.
void operator=(const Euler &)
Broken assignment operator.
virtual void actions_before_explicit_stage()
Empty virtual function to do anything needed before a stage of an explicit time step (Runge-Kutta ste...
void operator=(const LowStorageRungeKutta &)
Broken assignment operator.
void set_weights(const double &dtn, const double &dtnm1, const double &dtnm2)
Calculate the weights for this set of step sizes.
RungeKutta()
Constructor, set the type.
ExplicitTimeSteppableObject()
Empty constructor.
void timestep(ExplicitTimeSteppableObject *const &object_pt, const double &dt)
Function that is used to advance the solution by time dt.
Euler()
Constructor, set the type.
ExplicitTimeStepper()
Empty Constructor.
void timestep(ExplicitTimeSteppableObject *const &object_pt, const double &dt)
Overload function that is used to advance time in the object reference by object_pt by an amount dt...
virtual void actions_before_explicit_timestep()
Empty virtual function that can be overloaded to do anything needed before an explicit step...
virtual void add_to_dofs(const double &lambda, const DoubleVector &increment_dofs)
Function that adds the values to the dofs.
void operator=(const ExplicitTimeSteppableObject &)
Broken assignment operator.
Euler(const Euler &)
Broken copy constructor.
RungeKutta(const RungeKutta &)
Broken copy constructor.
void broken_assign(const std::string &class_name)
Issue error message and terminate execution.
void operator=(const RungeKutta &)
Broken assignment operator.
EBDF3(const EBDF3 &)
Broken copy constructor.
std::string string(const unsigned &i)
Return the i-th string or "" if the relevant string hasn't been defined.
virtual void timestep(ExplicitTimeSteppableObject *const &object_pt, const double &dt)=0
Pure virtual function that is used to advance time in the object.
virtual void get_dofs(DoubleVector &dofs) const
Function that gets the values of the dofs in the object.
A vector in the mathematical sense, initially developed for linear algebra type applications. If MPI then this vector can be distributed - its distribution is described by the LinearAlgebraDistribution object at Distribution_pt. Data is stored in a C-style pointer vector (double*)
Definition: double_vector.h:61
LowStorageRungeKutta(const LowStorageRungeKutta &)
Broken copy constructor.
virtual void get_dvaluesdt(DoubleVector &minv_res)
A single virtual function that returns the residuals vector multiplied by the inverse mass matrix...
virtual ~ExplicitTimeSteppableObject()
Empty destructor.
EBDF3()
Constructor, set the type.
A Base class for explicit timesteppers.
static double Dummy_time_value
Dummy value of time always set to zero.
void operator=(const EBDF3 &)
Broken assignment operator.
ExplicitTimeStepper(const ExplicitTimeStepper &)
Broken copy constructor.
std::string Type
String that indicates the type of the timestepper (e.g. "RungeKutta", etc.)