/* This code computes TCAT averages on a blob-by-blob basis in parallel It requires that the blobs be labeled using BlobIdentify.cpp James E. McClure 2015 */ #include #include #include #include #include #include #include #include "Domain.h" #include "TwoPhase.h" #include "common/MPI_Helpers.h" #include "common/Utilities.h" inline void ReadBlobFile(char *FILENAME, int *Data, int N) { int n; int value; ifstream File(FILENAME,ios::binary); if (File.good()){ for (n=0; n 1){ nblobs_global = atoi(argv[1]); if (rank==0) printf("Number of global blobs is: %i \n",nblobs_global); } else{ ERROR("Number of blobs was not specified"); } */ int *CubeList; if (rank==0){ //....................................................................... // Reading the domain information file //....................................................................... ifstream domain("Domain.in"); domain >> nprocx; domain >> nprocy; domain >> nprocz; domain >> Nx; domain >> Ny; domain >> Nz; domain >> nspheres; domain >> Lx; domain >> Ly; domain >> Lz; //....................................................................... } //................................................. 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_Barrier(MPI_COMM_WORLD); //................................................. Domain Dm(Nx,Ny,Nz,rank,nprocx,nprocy,nprocz,Lx,Ly,Lz,BC); TwoPhase Averages(Dm); // BlobTwoPhase ComponentAverages_NWP(nblobs_global); Nx+=2;Ny+=2;Nz+=2; N=Nx*Ny*Nz; // number of lattice points //....................................................................... // Filenames used char LocalRankString[8]; char LocalRankFilename[40]; char LocalRestartFile[40]; char tmpstr[10]; sprintf(LocalRankString,"%05d",rank); sprintf(LocalRankFilename,"%s%s","ID.",LocalRankString); sprintf(LocalRestartFile,"%s%s","Restart.",LocalRankString); //........................................................................... if (rank == 0) cout << "Reading in domain from signed distance function..." << endl; //....................................................................... sprintf(LocalRankFilename,"%s%s","SignDist.",LocalRankString); ReadBinaryFile(LocalRankFilename, Averages.SDs.get(), N); MPI_Barrier(MPI_COMM_WORLD); // sprintf(LocalRankFilename,"%s%s","Pressure.",LocalRankString); //ReadBinaryFile(LocalRankFilename, Averages.Press.get(), N); //MPI_Barrier(MPI_COMM_WORLD); if (rank == 0) cout << "Domain set." << endl; //....................................................................... sprintf(LocalRankFilename,"%s%s","Label_NWP.",LocalRankString); ReadBlobFile(LocalRankFilename, Averages.Label_NWP.get(), N); MPI_Barrier(MPI_COMM_WORLD); if (rank == 0) cout << "Label_NWP set." << endl; //....................................................................... //copies of data needed to perform checkpointing from cpu double *Den, *DistEven, *DistOdd; Den = new double[2*N]; DistEven = new double[10*N]; DistOdd = new double[9*N]; //......................................................................... if (rank==0) printf("Reading restart file! \n"); // Read in the restart file to CPU buffers ReadCheckpoint(LocalRestartFile, Den, DistEven, DistOdd, N); MPI_Barrier(MPI_COMM_WORLD); //......................................................................... // Populate the arrays needed to perform averaging if (rank==0) printf("Populate arrays \n"); // Compute porosity double porosity,sum,sum_global; sum=0.0; for (int n=0; n 0.0){ Dm.id[n]=1; sum += 1.0; } else Dm.id[n]=0; } delete [] DistEven; delete [] DistOdd; MPI_Allreduce(&sum,&sum_global,1,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD); porosity = sum_global/Dm.Volume; if (rank==0) printf("Porosity = %f \n",porosity); Dm.CommInit(MPI_COMM_WORLD); for (int i=0; i 0.0){ double Vn,pn,awn,ans,Jwn,Kwn,lwns,cwns,trawn,trJwn; Vn = Averages.ComponentAverages_NWP(1,b); pn = Averages.ComponentAverages_NWP(2,b)/Averages.ComponentAverages_NWP(0,b); awn = Averages.ComponentAverages_NWP(3,b); ans = Averages.ComponentAverages_NWP(4,b); if (awn != 0.0){ Jwn = Averages.ComponentAverages_NWP(5,b)/Averages.ComponentAverages_NWP(3,b); Kwn = Averages.ComponentAverages_NWP(6,b)/Averages.ComponentAverages_NWP(3,b); } else Jwn=Kwn=0.0; trawn = Averages.ComponentAverages_NWP(12,b); if (trawn != 0.0){ trJwn = Averages.ComponentAverages_NWP(13,b)/trawn; } else trJwn=0.0; lwns = Averages.ComponentAverages_NWP(7,b); if (lwns != 0.0) cwns = Averages.ComponentAverages_NWP(8,b)/Averages.ComponentAverages_NWP(7,b); else cwns=0.0; Averages.ComponentAverages_NWP(2,b) = pn; Averages.ComponentAverages_NWP(5,b) = trJwn; Averages.ComponentAverages_NWP(6,b) = Kwn; Averages.ComponentAverages_NWP(8,b) = cwns; // Averages.ComponentAverages_NWP(13,b) = trJwn; } } Averages.SortBlobs(); if (rank==0){ // printf("Reduced blob %i \n",b); fprintf(BLOBLOG,"%.5g %.5g %.5g\n",Averages.vol_w_global,Averages.paw_global,Averages.aws_global); for (int b=0; b<(int)Averages.ComponentAverages_NWP.size(1); b++){ if (Averages.ComponentAverages_NWP(0,b) > 0.0){ double Vn,pn,awn,ans,Jwn,Kwn,lwns,cwns; Vn = Averages.ComponentAverages_NWP(1,b); pn = Averages.ComponentAverages_NWP(2,b); awn = Averages.ComponentAverages_NWP(3,b); ans = Averages.ComponentAverages_NWP(4,b); Jwn = Averages.ComponentAverages_NWP(5,b); Kwn = Averages.ComponentAverages_NWP(6,b); lwns = Averages.ComponentAverages_NWP(7,b); cwns = Averages.ComponentAverages_NWP(8,b); fprintf(BLOBLOG,"%.5g ", Vn); //Vn fprintf(BLOBLOG,"%.5g ", pn); //pn fprintf(BLOBLOG,"%.5g ", awn); //awn fprintf(BLOBLOG,"%.5g ", ans); //ans fprintf(BLOBLOG,"%.5g ", Jwn); //Jwn fprintf(BLOBLOG,"%.5g ", Kwn); //Kwn fprintf(BLOBLOG,"%.5g ", lwns); //lwns fprintf(BLOBLOG,"%.5g\n",cwns); //cwns } } } if (rank==0) fclose(BLOBLOG); double Length=1.0; if (rank==0) WriteBlobStates(Averages,Length,porosity); //MPI_Barrier(MPI_COMM_WORLD); //printf("Exit, rank=%i \n",rank); // **************************************************** MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); // **************************************************** } inline void WriteBlobStates(TwoPhase TCAT, double D, double porosity){ FILE *BLOBSTATES= fopen("blobstates.tcat","w"); int a; double iVol=1.0/TCAT.Dm.Volume; double PoreVolume; double nwp_volume,vol_n,pan,pn,pw,pawn,pwn,awn,ans,aws,Jwn,Kwn,lwns,cwns,clwns; double sw,awnD,awsD,ansD,lwnsDD,JwnD,pc; nwp_volume=vol_n=pan=awn=ans=Jwn=Kwn=lwns=clwns=pawn=0.0; pw = TCAT.paw_global; aws = TCAT.aws; // Compute the averages over the entire non-wetting phsae for (a=0; a<(int)TCAT.ComponentAverages_NWP.size(1); a++){ vol_n += TCAT.ComponentAverages_NWP(0,a); pan += TCAT.ComponentAverages_NWP(2,a)*TCAT.ComponentAverages_NWP(0,a); awn += TCAT.ComponentAverages_NWP(3,a); ans += TCAT.ComponentAverages_NWP(4,a); Jwn += TCAT.ComponentAverages_NWP(5,a)*TCAT.ComponentAverages_NWP(3,a); Kwn += TCAT.ComponentAverages_NWP(6,a)*TCAT.ComponentAverages_NWP(3,a); lwns += TCAT.ComponentAverages_NWP(7,a); clwns += TCAT.ComponentAverages_NWP(8,a)*TCAT.ComponentAverages_NWP(7,a); nwp_volume += TCAT.ComponentAverages_NWP(1,a); pawn += TCAT.ComponentAverages_NWP(2,a)*TCAT.ComponentAverages_NWP(3,a); } // Compute the pore voume (sum of wetting an non-wetting phase volumes) PoreVolume=TCAT.wp_volume_global + nwp_volume; // Subtract off portions of non-wetting phase in order of size for (a=TCAT.ComponentAverages_NWP.size(1)-1; a>0; a--){ // Subtract the features one-by-one vol_n -= TCAT.ComponentAverages_NWP(0,a); pan -= TCAT.ComponentAverages_NWP(2,a)*TCAT.ComponentAverages_NWP(0,a); awn -= TCAT.ComponentAverages_NWP(3,a); ans -= TCAT.ComponentAverages_NWP(4,a); Jwn -= TCAT.ComponentAverages_NWP(5,a)*TCAT.ComponentAverages_NWP(3,a); Kwn -= TCAT.ComponentAverages_NWP(6,a)*TCAT.ComponentAverages_NWP(3,a); lwns -= TCAT.ComponentAverages_NWP(7,a); clwns -= TCAT.ComponentAverages_NWP(8,a)*TCAT.ComponentAverages_NWP(7,a); nwp_volume -= TCAT.ComponentAverages_NWP(1,a); pawn -= TCAT.ComponentAverages_NWP(2,a)*TCAT.ComponentAverages_NWP(3,a); // Update wetting phase averages aws += TCAT.ComponentAverages_NWP(4,a); if (vol_n > 64){ // Only consider systems with "large enough" blobs -- 4^3 if (fabs(1.0 - nwp_volume/PoreVolume - sw) > 0.005 || a == 1){ sw = 1.0 - nwp_volume/PoreVolume; JwnD = Jwn*D/awn; //trJwnD = -trJwn*D/trawn; cwns = clwns / lwns; pwn = (pawn/awn-pw)*D/0.058; pn = pan/vol_n; awnD = awn*D*iVol; awsD = aws*D*iVol; ansD = ans*D*iVol; lwnsDD = lwns*D*D*iVol; pc = (pn-pw)*D/0.058; // hard-coded surface tension due to being lazy fprintf(BLOBSTATES,"%.5g %.5g %.5g ",sw,pn,pw); fprintf(BLOBSTATES,"%.5g %.5g %.5g %.5g ",awnD,awsD,ansD,lwnsDD); fprintf(BLOBSTATES,"%.5g %.5g %.5g %.5g %i\n",pc,pwn,JwnD,cwns,a); } } } fclose(BLOBSTATES); }