/* * 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" //************************************************************************* // Morpohological drainage pre-processor // Generate states on primary drainage using morphological approach // Signed distance function is used to determine fluid configuration //************************************************************************* inline void PackID(int *list, int count, char *sendbuf, char *ID){ // Fill in the phase ID values from neighboring processors // This packs up the values that need to be sent from one processor to another int idx,n; for (idx=0; idx> nprocx; domain >> nprocy; domain >> nprocz; domain >> nx; domain >> ny; domain >> nz; domain >> nspheres; domain >> Lx; domain >> Ly; domain >> Lz; } 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_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 LocalRankFilename[40]; int BoundaryCondition=1; Domain Dm(nx,ny,nz,rank,nprocx,nprocy,nprocz,Lx,Ly,Lz,BoundaryCondition); nx+=2; ny+=2; nz+=2; int N = nx*ny*nz; char *id; id = new char[N]; // Define communication sub-domain -- everywhere for (int k=0; k radius){ radius=SignDist(i,j,0); } } } } MPI_Allreduce(&radius,&Rcrit_new,1,MPI_DOUBLE,MPI_MAX,comm); if (rank==0) printf("Starting morhpological drainage with critical radius = %f \n",Rcrit_new); int imin,jmin,kmin,imax,jmax,kmax; // Decrease the critical radius until the target saturation is met double deltaR=0.01; // amount to change the radius in voxel units double Rcrit_old; double sw_old=1.0; // initial WP saturation set to one double sw_new=1.0; // initial WP saturation set to one double sw_diff_old = 1.0; double sw_diff_new = 1.0; while (sw_new > SW && Rcrit_new > 0.99){ Rcrit_old = Rcrit_new; Rcrit_new -= deltaR*Rcrit_old;// decrease critical radius sw_old = sw_new; sw_diff_old = sw_diff_new; int Window=round(Rcrit_new); GlobalNumber = 1.0; while (GlobalNumber > 0){ //if (rank==0) printf("GlobalNumber=%f \n",GlobalNumber); double LocalNumber=GlobalNumber=0.f; for(k=0; k Rcrit_new){ // loop over the window and update imin=max(1,i-Window); jmin=max(1,j-Window); kmin=max(1,k-Window); imax=min(Nx-1,i+Window); jmax=min(Ny-1,j+Window); kmax=min(Nz-1,k+Window); for (kk=kmin; kk