-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
executable file
·61 lines (55 loc) · 1.57 KB
/
main.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
60
61
#include "allvars.h"
/*Usage:
./TreeCode.out
* <parameter_file>
* <IC_file>
* <Out_tree_filename>
* <Out_force_filename>
*/
int main( int argc, char *argv[] )
{
int i, it;
double t, et, ep;
char out_filename[NMAX1];
printf( "\n\n******************************** NBODY CODE ********************************\n" );
printf( " by: Sebastian Bustamante ([email protected])\n" );
//Loading Configuration File
read_parameters( argv[1] );
//Allocating memory for particles
part = (struct particle *)calloc( (int)(p[NPAR]), sizeof( struct particle ) );
//Loading or generating initial conditions
#ifdef INITIAL_CONDITIONS
#else
//Reading ICs
if( IC_reader( argv[2] ) )
return 0;
#endif
//Integration
printf( " * Starting integration\n" );
t = 0; it = 0;
while( t<=p[TMAX] )
{
//Leap-frog
for( i=0; i<(int)p[NPAR]; i++ )
leap_frog( i, t, part[i].r, part[i].v, part[i].a );
//printing snapshot every snapshot step
if( t/p[SSTP] - (int)(t/p[SSTP]) <= p[TSTP]/p[SSTP] )
{
sprintf( out_filename, "%s_%d", argv[3], it );
out_snapshot( out_filename );
it ++;
}
#ifdef EVAL_POTENTIAL
//Evaluating energy
energy( &et, &ep );
sprintf( out_filename, "%s_energy", argv[3] );
out_energy( out_filename, t, et, ep );
#endif
//Time step
t += p[TSTP];
}
printf( " * %d snapshots produced\n", it-1 );
printf( " * Nbody done successfully\n" );
printf( "****************************************************************************\n\n" );
return 0;
}