int main (int argc, char *argv[]) { /******************* ** INIT VARI *******************/ /*Calcola il numero di istanti temporali che verranno salvati*/ NUM_TEMPI_SALVATI = (int) (floor( (double) TIME_MAX / DeltaT)+1); unsigned int i ; srand(time(NULL)); double dist_tot=0; double fraz_imp=0.1; //double pression_bin[N_BIN_PRESS]; if (argc > 1){ fraz_imp = atof(argv[1]); } SIGMA = sqrt(4*fraz_imp/ number_of_particles / M_PI); /* DA dove salta fuori?*/ DIST_RET = sqrt(4*0.74/ number_of_particles / M_PI); printf("\n\n*****************************************************\n"); printf("Starting simulation with:\n"); printf("SIGMA = %e\t",SIGMA); printf("Frazione di impacchettamento: %e\n", fraz_imp); collTable = malloc (number_of_particles*number_of_particles*sizeof(double)); particleList = malloc ( number_of_particles * sizeof(particle_s)); time_list = malloc (NUM_TEMPI_SALVATI*number_of_particles * sizeof(particle_s)); reticolo (); fix_boundaries(); if ( check_distance() != 0){ printf("Sfere troppo vicine tra loro. Avvio annullato\n"); exit(EXIT_FAILURE); } temperature = 2*kin_en()/((double) N)/(double) number_of_particles/K_BOLTZ; printf(" K = %e \t P= %e \t", kin_en(), total_momentum()); printf("Temperature is: %f \n",temperature ); riscala_vel_temp(); temperature = 2*kin_en()/((double) N)/(double) number_of_particles/K_BOLTZ; printf(" K = %e \t P= %e \t", kin_en(), total_momentum()); printf("Temperature is: %f \n",temperature ); /****** GESTIONE FILE ******/ char r2_file[64] = ""; snprintf(r2_file,64,"data/dr2/dr2_%d_%.6lf.dat",(int)time(NULL),fraz_imp); //char * press_file = "data/press.dat"; char tc_filename[64] = ""; snprintf(tc_filename, 64, "data/tc/%d/tc%6f.dat",number_of_particles, fraz_imp); char tcpdf_filename[64] = ""; snprintf(tcpdf_filename, 64, "data/pdf_tc/%d/%6f.dat",number_of_particles, fraz_imp); char mfp_filename[64] = ""; snprintf(mfp_filename,64,"data/mfp/%d/mfp%.6lf.dat",number_of_particles,fraz_imp); /****FINE GESTIONE FILE***/ char pression_filename[128] = ""; snprintf(pression_filename,128,"data/pression/%d/pression%.6lf.dat",number_of_particles,fraz_imp); print_coordinate(); printf("#Collisions: %d \n", numOfCollisions); FILE *pdf_tc_file = fopen(tcpdf_filename,"w"); /***************** EVOLUZIONE *****************/ collision_table(); while ( numOfCollisions < TERM_TIME){ evolve_therm(); } numOfCollisions=0; reset_mfp_variables(); boltzmann_file_save(); total_time = 0; pression=0; printf("Termalizzato: %d urti ---- kin_en = %lf\n",numOfCollisions,kin_en()); while (total_time < TIME_MAX){ evolve(); fprintf(pdf_tc_file,"%lf\n",time_collision*number_of_particles/2.0); } printf("Num collisioni: %d\n",numOfCollisions); fclose(pdf_tc_file); if (time_counted > NUM_TEMPI_SALVATI){ printf("ERROR \n"); } r_squared_save(r2_file); /****** CALCOLO PV/NKT = 1 + 1/(3*number_of_particles*k_boltz*temp)*massa*diametro*Somma collisioni******/ pression /= (double) (3*(total_time)*kin_en()); pression *= SIGMA; pression +=1.0; pression *= (fraz_imp/0.9069); //dovuto a PV_0/NKT FILE *f_collision=fopen(tc_filename,"a"); fprintf(f_collision,"%e\t%e\n",fraz_imp,total_time/(2*numOfCollisions)*(number_of_particles)); FILE * file_pression = fopen(pression_filename,"a"); fprintf(file_pression,"%e\n",pression); fclose(file_pression); FILE *f_mean_mfp = fopen( mfp_filename,"a"); for ( i = 0; i<number_of_particles;i++){ dist_tot += particleList[i].distance/(double)(particleList[i].n_collision); } dist_tot /= (double) (number_of_particles); fprintf(f_mean_mfp,"%.14e\t%.14e\t\n",fraz_imp, dist_tot); fclose(f_mean_mfp); fclose(f_collision); //fclose(f_pression); free(particleList); free(collTable); free(time_list); exit(EXIT_SUCCESS); }
void draw_dash(struct BALL ba,double w) /**********瞄准线**********/ { int i,j,R=DASH_LENTH; int n,m,in=0; int x=0,y=0,butt=0; struct LOCATION { int x; int y; }*cir; struct BALL temp={{0.0,0.0,2.0},{0.0,0.0},{0.0,0.0},0,0,0}; cir=malloc(sizeof(struct LOCATION)*R/6); temp.velo.vx=-temp.velo.v*cos(w); temp.velo.vy=-temp.velo.v*sin(w); collision_table(&temp); temp.posi.x=ba.posi.x+temp.velo.vx; temp.posi.y=ba.posi.y+temp.velo.vy; cir[0].x=(int)temp.posi.x; cir[0].y=(int)temp.posi.y; for (m=1;m<R/6;m++) { for (n=0;n<6;n++) { collision_table(&temp); temp.posi.x+=temp.velo.vx; temp.posi.y+=temp.velo.vy; if (ball_in(temp)) { in=1; break; } } cir[m].x = (int)temp.posi.x; cir[m].y = (int)temp.posi.y; if (in) { in=0; break; } } if (Line_on) direction(ball[0],ww); i=0; do { for (n=0;n<2;n++) { for (j=i;j<=m;j+=3) putimage(cir[j].x-DOT_R,cir[j].y-DOT_R,dash_dot,XOR_PUT); delay(6000); } i=(i+1)%3; }while(!check_change(&x,&y,&butt)); if (Line_on) direction(ball[0],ww); if (bioskey(2) & 0x04) neww=ww+x/700.0; else neww=ww+x/100.0; free(cir); }