/* * Pre-processor to generate signed distance function from segmented data * segmented data should be stored in a raw binary file as 1-byte integer (type char) * will output distance functions for phases */ #include #include #include #include #include #include #include #include int main(int argc, char **argv) { // Initialize MPI int rank, nprocs; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&rank); MPI_Comm_size(MPI_COMM_WORLD,&nprocs); //....................................................................... // Reading the domain information file //....................................................................... int nprocx, nprocy, nprocz, nx, ny, nz, nspheres; double Lx, Ly, Lz; int Nx,Ny,Nz; int i,j,k,n; int BC=0; char Filename[40]; int xStart,yStart,zStart; // char fluidValue,solidValue; std::vector solidValues; std::vector nwpValues; std::string line; if (rank==0){ ifstream domain("Domain.in"); domain >> nprocx; domain >> nprocy; domain >> nprocz; domain >> nx; domain >> ny; domain >> nz; domain >> nspheres; domain >> Lx; domain >> Ly; domain >> Lz; ifstream image("Segmented.in"); image >> Filename; // Name of data file containing segmented data image >> Nx; // size of the binary file image >> Ny; image >> Nz; image >> xStart; // offset for the starting voxel image >> yStart; image >> zStart; } MPI_Barrier(MPI_COMM_WORLD); // Computational domain //................................................. MPI_Bcast(&nx,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&ny,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&nz,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&nprocx,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&nprocy,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&nprocz,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&nspheres,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&Lx,1,MPI_DOUBLE,0,MPI_COMM_WORLD); MPI_Bcast(&Ly,1,MPI_DOUBLE,0,MPI_COMM_WORLD); MPI_Bcast(&Lz,1,MPI_DOUBLE,0,MPI_COMM_WORLD); //................................................. MPI_Bcast(&Ny,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&Ny,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&Nz,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&xStart,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&yStart,1,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&zStart,1,MPI_INT,0,MPI_COMM_WORLD); //................................................. MPI_Barrier(MPI_COMM_WORLD); // Check that the number of processors >= the number of ranks if ( rank==0 ) { printf("Number of MPI ranks required: %i \n", nprocx*nprocy*nprocz); printf("Number of MPI ranks used: %i \n", nprocs); printf("Full domain size: %i x %i x %i \n",nx*nprocx,ny*nprocy,nz*nprocz); } if ( nprocs < nprocx*nprocy*nprocz ){ ERROR("Insufficient number of processors"); } char *SegData = NULL; // Rank=0 reads the entire segmented data and distributes to worker processes if (rank==0){ printf("Dimensions of segmented image: %i x %i x %i \n",Nx,Ny,Nz); SegData = new char[Nx*Ny*Nz]; FILE *SEGDAT = fopen(Filename,"rb"); if (SEGDAT==NULL) ERROR("Error reading segmented data"); fread(SegData,1,Nx*Ny*Nz,SEGDAT); fclose(SEGDAT); printf("Read segmented data from %s \n",Filename); } MPI_Barrier(MPI_COMM_WORLD); // Get the rank info int N = (nx+2)*(ny+2)*(nz+2); Domain Dm(nx,ny,nz,rank,nprocx,nprocy,nprocz,Lx,Ly,Lz,BC); for (k=0;k