-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfwd_euler.hpp
41 lines (28 loc) · 835 Bytes
/
fwd_euler.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* Forward Euler time stepper class header file.
D.R. Reynolds
Math 6321 @ SMU
Fall 2020 */
#ifndef FORWARD_EULER_DEFINED__
#define FORWARD_EULER_DEFINED__
// Inclusions
#include <cmath>
#include "rhs.hpp"
// Forward Euler time stepper class
class ForwardEulerStepper {
private:
// private reusable local data
arma::vec f; // storage for ODE RHS vector
RHSFunction *frhs; // pointer to ODE RHS function
public:
// number of steps in last call
unsigned long int nsteps;
// constructor (sets RHS function pointer, copies y for local data)
ForwardEulerStepper(RHSFunction& frhs_, arma::vec& y) {
frhs = &frhs_;
f = y;
nsteps = 0;
};
// Evolve routine (evolves the solution via forward Euler)
arma::mat Evolve(arma::vec tspan, double h, arma::vec y);
};
#endif