// To Compile gcc -lglut -lGL -fopenmp diffuse2d.c // #include #include #include #include #include #include #define N 512 #define ES 100.0 //空間の大きさ x,y,zそれぞれ-ES~ESの大きさを持つ空間になる GLubyte image[N][N][4]; float q_odd[N][N],q_even[N][N]; unsigned char KEY = '1'; double all_t1, all_t2; const float Q = 1.0; const float ka = 8987.7424380; //クーロン定数 float theta = 0.0; int nz, ny, nx; float q_max, q_min; struct color{ unsigned char R; unsigned char G; unsigned char B; float A; } color[256]; struct C{ float R; float G; float B; float A; } C[N][N]; int step=0; float prop[N][N][5]; // 熱伝導係数 float x=0.25; //係数 delta_t/delta_x unsigned char kabe[N][N]; //障害物がある格子では PROP = 0 にしたい! .... 未実装 20120427 unsigned char log_mode=1; //表示モード normal scale or log scale int Px =511; //東尋坊 120 int Py =0; //東尋坊 230 ..... x,y 逆だったかな? double gettimeofday_sec() { struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec + (double)tv.tv_usec*1e-6; } void simulation() { //double t1, t2; //t1 = gettimeofday_sec(); float Qx, Qy, Qz; float rx, ry, rz, r, rzy; int i, j, k; float intensity,log_intensity; float h=0.75; // 境界補正 /* q_odd[0][0]=100.0;*/ /* q_even[0][0]=100.0;*/ /*********************************************************************************************/ q_even[Px][Py]=255.0;/* FIXED Heat Source*/ /*********************************************************************************************/ #pragma omp parallel for private(j) for(i = 0; i < N; i++){ if(i==0){/**********************************************************************************************/ j=0; //q_odd[i][j]=0.0; for(j=1;j255.0? 255.0: q_even[i][j]; log_intensity=(log10(intensity)+6)*32; log_intensity= (log_intensity <0.0) ? 0.0:log_intensity; log_intensity= (log_intensity >255.0) ? 255.0:log_intensity; if(log_mode==0){ C[i][j].R=intensity; C[i][j].G= (intensity >1e-9)? intensity:(128 - intensity*1e11); C[i][j].B= (intensity >1e-9)? intensity:(255 - 2.5*intensity*1e11); }else{ C[i][j].R=log_intensity; C[i][j].G= (intensity >1e-9)? log_intensity:(128 - intensity*1e11); C[i][j].B= (intensity >1e-9)? log_intensity:(255 - 2.5*intensity*1e11); // C[i][j].B= log_intensity; } if(kabe[i][j]==0){ C[i][j].R=255.0; C[i][j].G=128.0; C[i][j].B=64.0; } C[i][j].A=1.0; } } step++; if(step%5000==0) printf("Step=%6d W=%4.2f E=%4.2f N=%4.2f S=%4.2f\n",step,prop[1][1][0],prop[1][1][1],prop[1][1][2],prop[1][1][3]); //if(step%2000==0) printf("Step=%6d q[N/2-1][N/2]=%f q[N/2-1][N/2-1]=%f %f\n",step,q_even[N/2-1][N/2],q_even[N/2-1][N/2-1],log10(q_even[N/2-1][N/2-1])); //printf("Step=%d q[N-1][N-1]=%f\n",step,q_even[N-1][N-1]); //t2 = gettimeofday_sec(); //printf("simulation : %f\n", t2 - t1); } void Keyboard(unsigned char key, int x, int y) { int i,j; if (key == 27) exit(0); else if (key >= '1' && key <= '6') KEY = key; if (key == 'l') log_mode=(log_mode==0)?1:0 ; if (key == 'w') { for(i=0;i= 0.2 ){ prop[i][j][0] -= 0.2; prop[i][j][4] -= 0.2; } } // printf("W=%4.2f E=%4.2f N=%4.2f S=%4.2f\n",prop[1][1][0],prop[1][1][1],prop[1][1][2],prop[1][1][3]); printf("W=%4.2f E=%4.2f N=%4.2f S=%4.2f\n",prop[1][1][1],prop[1][1][0],prop[1][1][2],prop[1][1][3]); } if (key == 'q') { for(i=0;i= 0.2 ){ prop[i][j][1] -= 0.2; prop[i][j][4] -= 0.2; } } // printf("W=%4.2f E=%4.2f N=%4.2f S=%4.2f\n",prop[1][1][0],prop[1][1][1],prop[1][1][2],prop[1][1][3]); printf("W=%4.2f E=%4.2f N=%4.2f S=%4.2f\n",prop[1][1][1],prop[1][1][0],prop[1][1][2],prop[1][1][3]); } if (key == 'r') { for(i=0;i=128){ kabe[N-i-1][j]=1; prop[N-i-1][j][0]=1.0; //W prop[N-i-1][j][1]=0.2; //E prop[N-i-1][j][2]=1.0; //N prop[N-i-1][j][3]=1.0; //S }else{ kabe[N-i-1][j]=0; prop[N-i-1][j][0]=0.0; //W prop[N-i-1][j][1]=0.0; //E prop[N-i-1][j][2]=0.0; //N prop[N-i-1][j][3]=0.0; //S } prop[N-i-1][j][4]=prop[N-i-1][j][0]+prop[N-i-1][j][1]+prop[N-i-1][j][2]+prop[N-i-1][j][3]; } } glutInit(&argc, argv); Init(argv[0]); glutDisplayFunc(Display); glutIdleFunc(Idle); glutKeyboardFunc(Keyboard); glutMouseFunc(mouse); glutMainLoop(); return 0; }