#ifndef __GALAXY_H__ #define __GALAXY_H__ #include #include /* sort forces by fabs before additinal. Additional by pair */ #define SORT_STAR /* add third part of taylor series */ #define TAYLOR3 /* sort energy. impulse and moment by fabs before additinal. Additional by pair. Very slow */ /* #define SORT_ENERGYSTAR */ typedef struct { double x; double y; double z; } Vector; typedef struct { double mass; Vector c; /* coordinate */ Vector v; /* velocity */ Vector a; /* acceleration */ #ifdef TAYLOR3 Vector pa; #endif } Star; typedef struct { u_int32_t nstars; Star *stars; Vector *forces; /* forces between i-th and j-th stars */ /* stat data */ double Impulse; double Moment; double potentialEnergy; double kineticEnergy; double elapsedTime; /* cfg options */ double delta; double desiredDelta; double errorLimit; double error; #ifdef TAYLOR3 int firsttime; #endif } Galaxy; #define CNT_FARRAY(n) ( (((n)+1)*((n)+2)) >> 1 ) /* XXX 0<=iforces + CNT_FARRAY(n) - CNT_FARRAY(n-i) + (j) - (i) - 1) */ #define GET_FORCE(g, i, j) ( (g)->forces + (((j)*((j)+1))>>1) + i ) void initGalaxy(Galaxy *galaxy, u_int32_t nstars); void forceGalaxy(Galaxy *galaxy); void accelerationGalaxy(Galaxy *galaxy); void stepGalaxy(Galaxy *galaxy, double delta); void unstepGalaxy(Galaxy *galaxy, double delta); void freeGalaxy(Galaxy *galaxy); void EnergyImpulseGalaxy(Galaxy *galaxy); void initLiveGalaxy(Galaxy *galaxy); void liveGalaxy(Galaxy *galaxy, pthread_mutex_t *mutex); void printStar(Star *star); #define G (6.742e-11) #endif