add .gitignore
[xgalaxy.git] / galaxy.h
1 #ifndef __GALAXY_H__
2 #define __GALAXY_H__
3
4 #include <sys/types.h>
5 #include <pthread.h>
6
7 /* sort forces by fabs before additinal. Additional by pair */ 
8 #define SORT_STAR
9
10 /* add third part of taylor series */ 
11 #define TAYLOR3
12
13 /* sort energy. impulse and moment by fabs before additinal. Additional by pair. Very slow */ 
14 /* #define SORT_ENERGYSTAR */
15
16 typedef struct {
17         double  x;
18         double  y;
19         double  z;
20 } Vector;
21
22 typedef struct {
23         double  mass;
24         Vector  c; /* coordinate */
25         Vector  v; /* velocity */
26         Vector  a; /* acceleration */
27 #ifdef TAYLOR3
28         Vector  pa;
29 #endif
30 } Star;
31
32 typedef struct {
33         u_int32_t       nstars;
34         Star    *stars;
35         Vector  *forces; /* forces between i-th and j-th stars */
36
37         /* stat data */
38         double Impulse;
39         double Moment;
40         double potentialEnergy;
41         double kineticEnergy;
42         double elapsedTime;
43
44         /* cfg options */
45         double delta;
46         double desiredDelta;
47         
48         double errorLimit;
49         double error;
50
51 #ifdef TAYLOR3
52         int     firsttime;
53 #endif
54 } Galaxy;
55
56
57 #define CNT_FARRAY(n)   ( (((n)+1)*((n)+2)) >> 1 )
58 /* 
59   XXX 0<=i<j<nstars 
60   #define GET_FORCE(g, i, j)  ( (g)->forces + CNT_FARRAY(n) - CNT_FARRAY(n-i) + (j) - (i) - 1)
61 */ 
62 #define GET_FORCE(g, i, j)  ( (g)->forces + (((j)*((j)+1))>>1) + i )
63
64
65 void initGalaxy(Galaxy *galaxy, u_int32_t nstars);
66 void forceGalaxy(Galaxy *galaxy);
67 void accelerationGalaxy(Galaxy *galaxy);
68 void stepGalaxy(Galaxy *galaxy, double delta);
69 void unstepGalaxy(Galaxy *galaxy, double delta);
70 void freeGalaxy(Galaxy *galaxy);
71 void EnergyImpulseGalaxy(Galaxy *galaxy); 
72 void initLiveGalaxy(Galaxy *galaxy);
73 void liveGalaxy(Galaxy *galaxy, pthread_mutex_t *mutex);
74 void printStar(Star *star);
75
76 #define G       (6.742e-11)
77 #endif