#include #include #include #define NVTS 3.3 #ifndef M_PI #define M_PI 3.14159265358979323846 #endif // Function void maxwellv(float *vx, float *vy, float *vz, float vth) {{{ void maxwellv(float *vx, float *vy, float *vz, float vth) { static int nvel, init_flag= 1; static float *vsave_x, *vsave_y, *vsave_z; extern float F(float), frand(void); int i, n; float vmag, aphi, dv, rr, sintheta, costheta; if (init_flag) { nvel= 1./(1-F((float)NVTS)); dv = sqrt(M_PI)/(4.0*nvel); if (nvel > 100000) puts("Warning: Your choice of NVTS has made nvel > 1e5"); vsave_x= (float *) malloc(nvel*sizeof(float)); vsave_y= (float *) malloc(nvel*sizeof(float)); vsave_z= (float *) malloc(nvel*sizeof(float)); if (vsave_x == NULL || vsave_y == NULL || vsave_z == NULL) { fprintf(stderr, "NULL pointer in %s: %d", __FILE__, __LINE__); } init_flag= 0; i=n=0; for (n=0; n