[152] | 1 | /* SolarSim.h */ |
---|
| 2 | #include <stdio.h> |
---|
| 3 | #include <stdlib.h> |
---|
| 4 | #include <string.h> |
---|
| 5 | #include <math.h> |
---|
| 6 | #include <fcntl.h> |
---|
| 7 | #include <omp.h> |
---|
| 8 | |
---|
| 9 | #if __INTEL_COMPILER |
---|
| 10 | #include <pmmintrin.h> |
---|
| 11 | #endif |
---|
| 12 | |
---|
| 13 | #define _SINGLE_PRECISION_ |
---|
| 14 | //#define _DOUBLE_PRECISION_ |
---|
| 15 | |
---|
| 16 | #if defined _DOUBLE_PRECISION_ |
---|
| 17 | typedef double real; |
---|
| 18 | #elif defined _SINGLE_PRECISION_ |
---|
| 19 | typedef float real; |
---|
| 20 | #else |
---|
| 21 | #error "Must have either _DOUBLE_PRECISION_ or _SINGLE_PRECISION_ defined." |
---|
| 22 | #endif |
---|
| 23 | |
---|
| 24 | /* simulation constants */ |
---|
| 25 | //#define SIM_STEPS (24*365*25) // 250 years |
---|
| 26 | #define G 6.6743E-11 // m^3 kg^-1 s^-2 |
---|
| 27 | //#define DT 3600 // one hour |
---|
| 28 | //#define SAVE (24) // 1 day |
---|
| 29 | |
---|
| 30 | typedef struct vector { |
---|
| 31 | real x, y, z; |
---|
| 32 | real unused; |
---|
| 33 | } vector; |
---|
| 34 | |
---|
| 35 | typedef struct state { |
---|
| 36 | int particles; |
---|
| 37 | vector * positions; |
---|
| 38 | vector * velocities; |
---|
| 39 | vector * accelerations; |
---|
| 40 | real * masses; |
---|
| 41 | } TState, *AState; |
---|
| 42 | |
---|
| 43 | /* declared in "io.c" */ |
---|
| 44 | void read_initial( AState state, const char *filename ); |
---|
| 45 | |
---|
| 46 | int connect_to_server( char * servername, int portno, int protocol ); |
---|
| 47 | |
---|
| 48 | void send_state( int sock, AState state ); |
---|
| 49 | |
---|
| 50 | void write_state( int fd, AState state ); |
---|
| 51 | |
---|
| 52 | /* declared in "compute.c" */ |
---|
| 53 | inline void compute_acc( vector *rv1, vector *rv2, vector *vv1, vector *vv2, vector *av1, vector *av2, real m1, real m2 ); |
---|
| 54 | |
---|
| 55 | inline void update_pos_vel( vector *rv, vector *vv, vector *av, long DT ); |
---|
| 56 | |
---|
| 57 | inline void v_init( vector *v, real x, real y, real z ); |
---|
| 58 | |
---|