void PoiseuilleFlowSystem::reset(){ elapsedTime = 0.0f; float jitter = params.particleRadius * 0.01f; float spacing = params.particleRadius * 2.0f; initFluid(spacing, jitter, numParticles); initBoundaryParticles(spacing); setArray(POSITION, hPos, 0, numParticles); setArray(VELOCITY, hVel, 0, numParticles); setArray(MEASURES, hMeasures, 0, numParticles); setArray(ACCELERATION, hAcceleration, 0, numParticles); setArray(VELOCITYLEAPFROG, hVelLeapFrog, 0, numParticles); }
int main (int argc, char **argv) { // Reading command line arguments iterations = 100; imageSize = 512; if(argc == 3){ iterations = atoi(argv[1]); imageSize = atoi(argv[2]); } // MPI initialization, getting rank and size MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Creating cartesian communicator MPI_Dims_create(size, 2, dims); MPI_Cart_create( MPI_COMM_WORLD, 2, dims, periods, 0, &cart_comm ); MPI_Cart_coords( cart_comm, rank, 2, coords ); // Finding neighbours processes MPI_Cart_shift(cart_comm, 0, 1, &north, &south); MPI_Cart_shift(cart_comm, 1, 1, &west, &east); // Determining size of local subdomain local_height = imageSize/dims[0]; local_width = imageSize/dims[1]; // Creating and commiting MPI datatypes for message passing create_types(); // Allocating memory for local arrays local_pres = (float*)malloc(sizeof(float)*(local_width + 2*border)*(local_height+2*border)); local_pres0 = (float*)malloc(sizeof(float)*(local_width + 2*border)*(local_height+2*border)); local_diverg = (float*)malloc(sizeof(float)*local_width*local_height); // Initializing the CFD computation, only one process should do this. if(rank == 0){ initFluid( &config, imageSize, imageSize); pres = config.pres; diverg = config.div; imageBuffer = (unsigned char*)malloc(sizeof(unsigned char)*imageSize*imageSize); } // Solving the CFD equations, one iteration for each timestep. // These are not the same iterations used in the Jacobi solver. // The solveFluid function call the Jacobi solver, wich runs for // 100 iterations for each of these iterations. for(int i = 0; i < iterations; i++){ solveFluid(&config); } // Converting the density to an image and writing it to file. if(rank == 0){ densityToColor(imageBuffer, config.dens, config.N); write_bmp(imageBuffer, imageSize, imageSize); // Free fluid simulation memory freeFluid( &config ); } // Finalize MPI_Finalize(); }