-
Notifications
You must be signed in to change notification settings - Fork 0
/
lorenz-solve.cc
57 lines (48 loc) · 1.26 KB
/
lorenz-solve.cc
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdlib.h>
#include "lorenz.h"
#include "euler.h"
#include "runge-kutta.h"
#include "adams-bashforth.h"
// Print a line
// time x[0] x[1] ...
// to standard out
void PrintState(double n, double t, const double *x) {
printf("%15.8f", t);
for (int i = 0; i < n; ++i) {
printf("%15.8f", x[i]);
}
printf("\n");
}
int main(int argc, char *argv[]) {
if (argc != 3) {
printf("USAGE: %s <timestep> <numsteps>\n", argv[0]);
exit(1);
}
const double dt = atof(argv[1]);
const int nsteps = atoi(argv[2]);
const double sigma = 10.;
const double rho = 28.;
const double beta = 8./3.;
Model *model = new Lorenz(sigma, rho, beta);
// Initial condition
const int dimen = model->dimen(); // number of states
double x[dimen];
x[0] = 0;
x[1]=0.01;
x[2]=0;
// Set up integration scheme
Integrator *integrator = new Euler(dt, *model);
// Integrator *first_step_integrator = new RungeKutta4(dt, *model);
// Integrator *integrator = new AdamsBashforth(dt, *model, first_step_integrator );
double t = 0;
PrintState(dimen, t, x);
for (int i = 0; i < nsteps; ++i) {
integrator->Step(t, x);
t = (i+1) * dt;
PrintState(dimen, t, x);
}
delete integrator;
delete model;
return 0;
}