-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdyn.cpp
More file actions
39 lines (25 loc) · 887 Bytes
/
dyn.cpp
File metadata and controls
39 lines (25 loc) · 887 Bytes
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
#include "dyn.hpp"
#include "ode.hpp"
#include <iostream>
using namespace Eigen;
// Constructor
DynamicModel::DynamicModel(const stf& f_, int n_, double abstol_,
double reltol_) : f(f_), n(n_), abstol(abstol_), reltol(reltol_),
work(100+21*n_) {}
// Propagate state from ti to tf with noise w
Eigen::VectorXd DynamicModel::operator() (double ti, double tf,
const Eigen::VectorXd& xi, const Eigen::VectorXd& w) {
VectorXd x = xi;
if (tf > ti) {
odefun fode = [this, &w] (double t, double* y, double* yd) -> void {
Map<VectorXd> x(y,n), xd(yd,n);
xd = f(t, x, w);
};
double t = ti;
int flag = 1;
ode(fode, n, x.data(), t, tf, reltol, abstol, flag, work.data(), iwork);
// if (flag != 2)
// std::cout << "ODE Error: " << flag << std::endl;
}
return x;
}