/* * 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 "common/Array.h" #include "common/Domain.h" int main(int argc, char **argv) { // Initialize MPI int rank, nprocs; MPI_Init(&argc,&argv); MPI_Comm comm = MPI_COMM_WORLD; MPI_Comm_rank(comm,&rank); MPI_Comm_size(comm,&nprocs); { bool MULTINPUT=false; int NWP,SOLID,rank_offset; int NLABELS=atoi(argv[1]); //SOLID=atoi(argv[1]); //NWP=atoi(argv[2]); if (rank==0){ //printf("Solid Label: %i \n",SOLID); //printf("NWP Label: %i \n",NWP); } if (argc > 2){ MULTINPUT=true; rank_offset = atoi(argv[3]); } else{ rank_offset=0; } //....................................................................... // 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(comm); // Computational domain //................................................. MPI_Bcast(&nx,1,MPI_INT,0,comm); MPI_Bcast(&ny,1,MPI_INT,0,comm); MPI_Bcast(&nz,1,MPI_INT,0,comm); MPI_Bcast(&nprocx,1,MPI_INT,0,comm); MPI_Bcast(&nprocy,1,MPI_INT,0,comm); MPI_Bcast(&nprocz,1,MPI_INT,0,comm); MPI_Bcast(&nspheres,1,MPI_INT,0,comm); MPI_Bcast(&Lx,1,MPI_DOUBLE,0,comm); MPI_Bcast(&Ly,1,MPI_DOUBLE,0,comm); MPI_Bcast(&Lz,1,MPI_DOUBLE,0,comm); //................................................. MPI_Bcast(&Nx,1,MPI_INT,0,comm); MPI_Bcast(&Ny,1,MPI_INT,0,comm); MPI_Bcast(&Nz,1,MPI_INT,0,comm); MPI_Bcast(&xStart,1,MPI_INT,0,comm); MPI_Bcast(&yStart,1,MPI_INT,0,comm); MPI_Bcast(&zStart,1,MPI_INT,0,comm); //................................................. MPI_Barrier(comm); // 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"); size_t ReadSeg; ReadSeg=fread(SegData,1,Nx*Ny*Nz,SEGDAT); if (ReadSeg != size_t(Nx*Ny*Nz)) printf("lbpm_segmented_decomp: Error reading segmented data (rank=%i)\n",rank); fclose(SEGDAT); printf("Read segmented data from %s \n",Filename); } MPI_Barrier(comm); // 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>oldlabel; iFILE>>newlabel; LabelList[2*label] = (oldlabel); LabelList[2*label+1] = (newlabel); label++; } } else{ printf("Using default labels: Solid (0 --> -1), NWP (1 --> 1), WP (2 --> 2)\n"); // Set default values NLABELS=3; for (int label=0; label