Created
July 6, 2015 02:50
-
-
Save kaityo256/6f6f23db3a9dbe02f529 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| //---------------------------------------------------------------------- | |
| const int N = 32768; | |
| const double L = 10.0; | |
| const int D = 3; | |
| const int X = 0; | |
| const int Y = 1; | |
| const int Z = 2; | |
| double q[N][D],p[N][D]; | |
| const double dt = 0.001; | |
| const double C2 = 0.1; | |
| //---------------------------------------------------------------------- | |
| double | |
| myrand(void){ | |
| return static_cast<double>(rand())/(static_cast<double>(RAND_MAX)); | |
| } | |
| //---------------------------------------------------------------------- | |
| void | |
| calcforce(void){ | |
| for(int i=0;i<N-1;i++){ | |
| for(int j=i+1;j<N;j++){ | |
| double dx = q[j][X] - q[i][X]; | |
| double dy = q[j][Y] - q[i][Y]; | |
| double dz = q[j][Z] - q[i][Z]; | |
| double r2 = (dx*dx + dy*dy + dz*dz); | |
| double r6 = r2*r2*r2; | |
| double df = ((24.0*r6-48.0)/(r6*r6*r2)+C2*8.0)*dt; | |
| p[i][X] += df*dx; | |
| p[i][Y] += df*dy; | |
| p[i][Z] += df*dz; | |
| p[j][X] -= df*dx; | |
| p[j][Y] -= df*dy; | |
| p[j][Z] -= df*dz; | |
| } | |
| } | |
| } | |
| //---------------------------------------------------------------------- | |
| int | |
| main(void){ | |
| for(int i=0;i<N;i++){ | |
| p[i][X] = 0.0; | |
| p[i][Y] = 0.0; | |
| p[i][Z] = 0.0; | |
| q[i][X] = L*myrand(); | |
| q[i][Y] = L*myrand(); | |
| q[i][Z] = L*myrand(); | |
| } | |
| calcforce(); | |
| } | |
| //---------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment