/* ** main program: ** initialise, timestep loop, finalise */ int main(int argc, char* argv[]) { char * final_state_file = NULL; char * av_vels_file = NULL; char * param_file = NULL; accel_area_t accel_area; param_t params; /* struct to hold parameter values */ speed_t* cells = NULL; /* grid containing fluid densities */ speed_t* tmp_cells = NULL; /* scratch space */ int* obstacles = NULL; /* grid indicating which cells are blocked */ double* av_vels = NULL; /* a record of the av. velocity computed for each timestep */ int ii; /* generic counter */ struct timeval timstr; /* structure to hold elapsed time */ struct rusage ru; /* structure to hold CPU time--system and user */ double tic,toc; /* floating point numbers to calculate elapsed wallclock time */ double usrtim; /* floating point number to record elapsed user CPU time */ double systim; /* floating point number to record elapsed system CPU time */ parse_args(argc, argv, &final_state_file, &av_vels_file, ¶m_file); initialise(param_file, &accel_area, ¶ms, &cells, &tmp_cells, &obstacles, &av_vels); /* iterate for max_iters timesteps */ gettimeofday(&timstr,NULL); tic=timstr.tv_sec+(timstr.tv_usec/1000000.0); for (ii = 0; ii < params.max_iters; ii++) { timestep(params, accel_area, cells, tmp_cells, obstacles); av_vels[ii] = av_velocity(params, cells, obstacles); #ifdef DEBUG printf("==timestep: %d==\n", ii); printf("av velocity: %.12E\n", av_vels[ii]); printf("tot density: %.12E\n", total_density(params, cells)); #endif } gettimeofday(&timstr,NULL); toc=timstr.tv_sec+(timstr.tv_usec/1000000.0); getrusage(RUSAGE_SELF, &ru); timstr=ru.ru_utime; usrtim=timstr.tv_sec+(timstr.tv_usec/1000000.0); timstr=ru.ru_stime; systim=timstr.tv_sec+(timstr.tv_usec/1000000.0); printf("==done==\n"); printf("Reynolds number:\t\t%.12E\n", calc_reynolds(params,cells,obstacles)); printf("Elapsed time:\t\t\t%.6f (s)\n", toc-tic); printf("Elapsed user CPU time:\t\t%.6f (s)\n", usrtim); printf("Elapsed system CPU time:\t%.6f (s)\n", systim); write_values(final_state_file, av_vels_file, params, cells, obstacles, av_vels); finalise(&cells, &tmp_cells, &obstacles, &av_vels); return EXIT_SUCCESS; }
/* ** main program: ** initialise, timestep loop, finalise */ int main(int argc, char* argv[]) { char* paramfile; /* name of the input parameter file */ char* obstaclefile; /* name of a the input obstacle file */ t_param params; /* struct to hold parameter values */ t_speed* cells = NULL; /* grid containing fluid densities */ t_speed* tmp_cells = NULL; /* scratch space */ int* obstacles = NULL; /* grid indicating which cells are blocked */ float* av_vels = NULL; /* a record of the av. velocity computed for each timestep */ int ii; /* generic counter */ struct timeval timstr; /* structure to hold elapsed time */ struct rusage ru; /* structure to hold CPU time--system and user */ double tic,toc; /* floating point numbers to calculate elapsed wallclock time */ double usrtim; /* floating point number to record elapsed user CPU time */ double systim; /* floating point number to record elapsed system CPU time */ /* parse the command line */ if(argc != 3) { usage(argv[0]); } else{ paramfile = argv[1]; obstaclefile = argv[2]; } /* initialise our data structures and load values from file */ initialise(paramfile, obstaclefile, ¶ms, &cells, &tmp_cells, &obstacles, &av_vels); /* iterate for maxIters timesteps */ gettimeofday(&timstr,NULL); tic=timstr.tv_sec+(timstr.tv_usec/1000000.0); for (ii=0;ii<params.maxIters;ii++) { timestep(params,cells,tmp_cells,obstacles); av_vels[ii] = av_velocity(params,cells,obstacles); #ifdef DEBUG printf("==timestep: %d==\n",ii); printf("av velocity: %.12E\n", av_vels[ii]); printf("tot density: %.12E\n",total_density(params,cells)); #endif } gettimeofday(&timstr,NULL); toc=timstr.tv_sec+(timstr.tv_usec/1000000.0); getrusage(RUSAGE_SELF, &ru); timstr=ru.ru_utime; usrtim=timstr.tv_sec+(timstr.tv_usec/1000000.0); timstr=ru.ru_stime; systim=timstr.tv_sec+(timstr.tv_usec/1000000.0); /* write final values and free memory */ printf("==done==\n"); printf("Reynolds number:\t\t%.12E\n",calc_reynolds(params,cells,obstacles)); printf("Elapsed time:\t\t\t%.6lf (s)\n", toc-tic); printf("Elapsed user CPU time:\t\t%.6lf (s)\n", usrtim); printf("Elapsed system CPU time:\t%.6lf (s)\n", systim); write_values(params,cells,obstacles,av_vels); finalise(¶ms, &cells, &tmp_cells, &obstacles, &av_vels); return EXIT_SUCCESS; }
double calc_reynolds(const param_t params, speed_t* cells, int* obstacles) { const double viscosity = 1.0 / 6.0 * (2.0 / params.omega - 1.0); return av_velocity(params,cells,obstacles) * params.reynolds_dim / viscosity; }
float calc_reynolds(const t_param params, t_speed* cells, int* obstacles) { const float viscosity = 1.0 / 6.0 * (2.0 / params.omega - 1.0); return av_velocity(params,cells,obstacles) * params.reynolds_dim / viscosity; }