MFEM  v3.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
ode.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_ODE
13 #define MFEM_ODE
14 
15 #include "../config/config.hpp"
16 #include "operator.hpp"
17 
18 namespace mfem
19 {
20 
22 class ODESolver
23 {
24 protected:
25  TimeDependentOperator *f; // f(.,t) : R^n --> R^n
26 
27 public:
28  ODESolver() : f(NULL) { }
29 
30  virtual void Init(TimeDependentOperator &_f) { f = &_f; }
31 
32  virtual void Step(Vector &x, double &t, double &dt) = 0;
33 
34  virtual ~ODESolver() { }
35 };
36 
37 
40 {
41 private:
42  Vector dxdt;
43 
44 public:
45  virtual void Init(TimeDependentOperator &_f);
46 
47  virtual void Step(Vector &x, double &t, double &dt);
48 };
49 
50 
56 class RK2Solver : public ODESolver
57 {
58 private:
59  double a;
60  Vector dxdt, x1;
61 
62 public:
63  RK2Solver(const double _a = 2./3.) : a(_a) { }
64 
65  virtual void Init(TimeDependentOperator &_f);
66 
67  virtual void Step(Vector &x, double &t, double &dt);
68 };
69 
70 
72 class RK3SSPSolver : public ODESolver
73 {
74 private:
75  Vector y, k;
76 
77 public:
78  virtual void Init(TimeDependentOperator &_f);
79 
80  virtual void Step(Vector &x, double &t, double &dt);
81 };
82 
83 
85 class RK4Solver : public ODESolver
86 {
87 private:
88  Vector y, k, z;
89 
90 public:
91  virtual void Init(TimeDependentOperator &_f);
92 
93  virtual void Step(Vector &x, double &t, double &dt);
94 };
95 
96 
107 {
108 private:
109  int s;
110  const double *a, *b, *c;
111  Vector y, *k;
112 
113 public:
114  ExplicitRKSolver(int _s, const double *_a, const double *_b,
115  const double *_c);
116 
117  virtual void Init(TimeDependentOperator &_f);
118 
119  virtual void Step(Vector &x, double &t, double &dt);
120 
121  virtual ~ExplicitRKSolver();
122 };
123 
124 
128 {
129 private:
130  static const double a[28], b[8], c[7];
131 
132 public:
133  RK6Solver() : ExplicitRKSolver(8, a, b, c) { }
134 };
135 
136 
140 {
141 private:
142  static const double a[66], b[12], c[11];
143 
144 public:
145  RK8Solver() : ExplicitRKSolver(12, a, b, c) { }
146 };
147 
148 
151 {
152 protected:
154 
155 public:
156  virtual void Init(TimeDependentOperator &_f);
157 
158  virtual void Step(Vector &x, double &t, double &dt);
159 };
160 
161 
164 {
165 protected:
167 
168 public:
169  virtual void Init(TimeDependentOperator &_f);
170 
171  virtual void Step(Vector &x, double &t, double &dt);
172 };
173 
174 
181 class SDIRK23Solver : public ODESolver
182 {
183 protected:
184  double gamma;
186 
187 public:
188  SDIRK23Solver(int gamma_opt = 1);
189 
190  virtual void Init(TimeDependentOperator &_f);
191 
192  virtual void Step(Vector &x, double &t, double &dt);
193 };
194 
195 
198 class SDIRK34Solver : public ODESolver
199 {
200 protected:
201  Vector k, y, z;
202 
203 public:
204  virtual void Init(TimeDependentOperator &_f);
205 
206  virtual void Step(Vector &x, double &t, double &dt);
207 };
208 
209 
212 class SDIRK33Solver : public ODESolver
213 {
214 protected:
216 
217 public:
218  virtual void Init(TimeDependentOperator &_f);
219 
220  virtual void Step(Vector &x, double &t, double &dt);
221 };
222 
223 }
224 
225 #endif
virtual void Init(TimeDependentOperator &_f)
Definition: ode.cpp:33
virtual void Init(TimeDependentOperator &_f)
Definition: ode.cpp:391
virtual void Step(Vector &x, double &t, double &dt)
Definition: ode.cpp:103
Base abstract class for time dependent operators: (x,t) -> f(x,t)
Definition: operator.hpp:68
virtual void Step(Vector &x, double &t, double &dt)=0
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
Definition: ode.hpp:22
virtual void Step(Vector &x, double &t, double &dt)
Definition: ode.cpp:153
virtual void Init(TimeDependentOperator &_f)
Definition: ode.hpp:30
Backward Euler ODE solver. L-stable.
Definition: ode.hpp:150
virtual void Step(Vector &x, double &t, double &dt)
Definition: ode.cpp:462
virtual ~ODESolver()
Definition: ode.hpp:34
virtual void Step(Vector &x, double &t, double &dt)
Definition: ode.cpp:426
virtual void Init(TimeDependentOperator &_f)
Definition: ode.cpp:356
virtual void Init(TimeDependentOperator &_f)
Definition: ode.cpp:94
virtual ~ExplicitRKSolver()
Definition: ode.cpp:183
virtual void Step(Vector &x, double &t, double &dt)
Definition: ode.cpp:41
virtual void Init(TimeDependentOperator &_f)
Definition: ode.cpp:62
virtual void Step(Vector &x, double &t, double &dt)
Definition: ode.cpp:362
ExplicitRKSolver(int _s, const double *_a, const double *_b, const double *_c)
Definition: ode.cpp:132
virtual void Step(Vector &x, double &t, double &dt)
Definition: ode.cpp:347
virtual void Init(TimeDependentOperator &_f)
Definition: ode.cpp:341
virtual void Init(TimeDependentOperator &_f)
Definition: ode.cpp:418
The classical explicit forth-order Runge-Kutta method, RK4.
Definition: ode.hpp:85
virtual void Init(TimeDependentOperator &_f)
Definition: ode.cpp:18
Third-order, strong stability preserving (SSP) Runge-Kutta method.
Definition: ode.hpp:72
RK2Solver(const double _a=2./3.)
Definition: ode.hpp:63
Implicit midpoint method. A-stable, not L-stable.
Definition: ode.hpp:163
virtual void Step(Vector &x, double &t, double &dt)
Definition: ode.cpp:70
Vector data type.
Definition: vector.hpp:33
virtual void Init(TimeDependentOperator &_f)
Definition: ode.cpp:455
virtual void Step(Vector &x, double &t, double &dt)
Definition: ode.cpp:398
TimeDependentOperator * f
Definition: ode.hpp:25
The classical forward Euler method.
Definition: ode.hpp:39
virtual void Step(Vector &x, double &t, double &dt)
Definition: ode.cpp:24
SDIRK23Solver(int gamma_opt=1)
Definition: ode.cpp:371
virtual void Init(TimeDependentOperator &_f)
Definition: ode.cpp:142