-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
59 lines (52 loc) · 2.16 KB
/
test.c
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
58
59
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include "libspaceturtle.h"
int main(){
struct body * earth, * cat, * root;
struct world_config ecsystem; //earthcatsystem
unsigned int seed = rand();
clock_t s, e;
ecsystem.tickspersec = 1000;
earth = add_body(0, 0, 0, 0, 5.972 * powl(10, 24), 0, NULL, NULL, NULL);
cat = add_body(6771000, 0, 0, 7667, 10, 0, NULL, earth, earth);
printf("simulating one ISS orbit with PP integrator\n");
for(int i = 0; i <= 100; i++){
step_forward(earth, ecsystem, 60000);
printf("minute: %5d, xpos: %12Lf, ypos: %12Lf, xvel: %12Lf, yvel: %12Lf\n", i + 1, cat->xpos / 1000, cat->ypos / 1000, cat->xvel, cat->yvel);
}
delete_body(NULL, earth);
earth = add_body(0, 0, 0, 0, 5.972 * powl(10, 24), 0, NULL, NULL, NULL);
cat = add_body(6771000, 0, 0, 7667, 10, 0, NULL, earth, earth);
printf("\nsimulating one ISS orbit with Barnes-Hut integrator\n");
for(int i = 0; i <= 100; i++){
step_forward_tctd(earth, ecsystem, 60000);
printf("minute: %5d, xpos: %12Lf, ypos: %12Lf, xvel: %12Lf, yvel: %12Lf\n", i + 1, cat->xpos / 1000, cat->ypos / 1000, cat->xvel, cat->yvel);
}
delete_body(NULL, earth);
printf("\nsanity check complete\n\n");
printf("\nrunning benchmarks:\n\n");
srand(seed);
root = add_body(rand(), rand(), rand(), rand(), rand(), 0, NULL, NULL, NULL);
for(int i = 0; i < 299; i++){
add_body(rand(), rand(), rand(), rand(), rand(), 0, NULL, NULL, root);
}
s = clock();
step_forward(root, ecsystem, 1000);
e = clock();
printf("took %f seconds to simulate 300 randomly aranged bodies for 1000 ticks with PP integrator\n", (double) (e - s) / CLOCKS_PER_SEC);
delete_body(NULL, root);
srand(seed);
root = add_body(rand(), rand(), rand(), rand(), rand(), 0, NULL, NULL, NULL);
for(int i = 0; i < 299; i++){
add_body(rand(), rand(), rand(), rand(), rand(), 0, NULL, NULL, root);
}
s = clock();
step_forward_tctd(root, ecsystem, 1000);
e = clock();
printf("took %f seconds to simulate 300 randomly aranged bodies for 1000 ticks with Barnes-Hut integrator\n", (double) (e - s) / CLOCKS_PER_SEC);
delete_body(NULL, root);
return 0;
}