-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
51 lines (36 loc) · 854 Bytes
/
main.cpp
File metadata and controls
51 lines (36 loc) · 854 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
39
40
41
42
43
44
45
46
47
48
49
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include "Nbody.h"
#ifndef INTGRT
#define INTGRT KDKDK_4th
#endif
int main(int argc, char **argv){
Nbody sys;
assert(argc > 2);
FILE *fp = fopen(argv[1], "r");
assert(fp);
sys.read(fp);
fclose(fp);
sys.set_eps(1./64.);
double en0 = sys.energy(stderr);
sys.calc_acc();
const int invtick = atoi(argv[2]);
const double tick = 1.0 / invtick;
const int nloop = invtick / 64;
double err_max = 0.0;
for(int i=0; i<nloop; i++){
sys.INTGRT(tick);
// sys.DKD_2nd(tick);
// sys.KDK_2nd(tick);
// sys.KDKDK_2nd(tick);
// sys.KDKDK_4th(tick);
double en1 = sys.energy();
double de = (en1 - en0) / en0;
printf("%e %e\n", sys.tsys, de);
err_max = std::max(err_max, fabs(de));
}
printf("%e %e (dt,error_max)\n", 12.*tick, err_max);
return 0;
}