First draft of lbpm_morphdrain_pp

This commit is contained in:
James E McClure
2016-04-13 21:43:31 -04:00
parent f94f6df3d1
commit 24093354e0
2 changed files with 146 additions and 153 deletions

View File

@@ -3,6 +3,7 @@ ADD_LBPM_EXECUTABLE( lbpm_permeability_simulator )
ADD_LBPM_EXECUTABLE( lbpm_color_simulator )
ADD_LBPM_EXECUTABLE( lbpm_sphere_pp )
ADD_LBPM_EXECUTABLE( lbpm_random_pp )
ADD_LBPM_EXECUTABLE( lbpm_morphdrain_pp )
ADD_LBPM_EXECUTABLE( lbpm_segmented_pp )
ADD_LBPM_EXECUTABLE( lbpm_segmented_decomp )
ADD_LBPM_EXECUTABLE( lbpm_disc_pp )

View File

@@ -145,7 +145,7 @@ int main(int argc, char **argv)
n = k*nx*ny+j*nx+i;
if (SignDist(i,j,k) < 0.0) id[n] = 0;
else{
// initially saturated with wetting phase
// initially saturated with wetting phase
id[n] = 2;
count++;
}
@@ -165,76 +165,9 @@ int main(int argc, char **argv)
// Generate the NWP configuration
if (rank==0) printf("Performing morphological drainage with critical radius %f \n", Rcrit);
// GenerateResidual(id,nx,ny,nz,Saturation);
int count=1;
int x,y,z;
int ii,jj,kk;
int Nx = nx;
int Ny = ny;
int Nz = nz;
float sat = 0.f;
int Number = 0; // number of features
while (count != 0){
for(k=0; k<Nz; k++){
for(j=0; j<Ny; j++){
for(i=0; i<Nx; i++){
}
}
}
for (k=z;k<z+sizeZ;k++){
for (j=y;j<y+sizeY;j++){
for (i=x;i<x+sizeX;i++){
// Identify nodes in the domain (periodic BC)
ii = i;
jj = j;
kk = k;
if (ii>nprocx*(Nx-2)) ii-=nprocx*(Nx-2);
if (jj>nprocy*(Ny-2)) jj-=nprocy*(Ny-2);
if (kk>nprocz*(Nz-2)) kk-=nprocz*(Nz-2);
// Check if this is in the subdomain
if (ii < (iproc+1)*(Nx-2)+1 && jj < (jproc+1)*(Ny-2)+1 && kk < (kproc+1)*(Nz-2)+1 &&
ii > iproc*(Nx-2) && jj > jproc*(Ny-2) && kk > kproc*(Nz-2) ){
// Map from global to local coordinates
ii -= iproc*(Nx-2);
jj -= jproc*(Ny-2);
kk -= kproc*(Nz-2);
n = kk*Nx*Ny+jj*Nx+ii;
if (id[n] == 2){
id[n] = 1;
//count++;
}
}
}
}
}
count = 0;
for (int k=1; k<Nz-1; k++){
for (int j=1; j<Ny-1; j++){
for (int i=1; i<Nx-1; i++){
n=k*Nx*Ny+j*Nx+i;
if (id[n] == 1){
count++;
}
}
}
}
MPI_Allreduce(&count,&countGlobal,1,MPI_INT,MPI_SUM,comm);
sat = float(countGlobal)/totalGlobal;
//if (rank==0) printf("New count=%i\n",countGlobal);
//if (rank==0) printf("New saturation=%f\n",sat);
}
// Fill in the phase ID from neighboring processors
// Communication buffers
char *sendID_x, *sendID_y, *sendID_z, *sendID_X, *sendID_Y, *sendID_Z;
char *sendID_xy, *sendID_yz, *sendID_xz, *sendID_Xy, *sendID_Yz, *sendID_xZ;
char *sendID_xY, *sendID_yZ, *sendID_Xz, *sendID_XY, *sendID_YZ, *sendID_XZ;
@@ -283,94 +216,153 @@ int main(int argc, char **argv)
//......................................................................................
int sendtag,recvtag;
sendtag = recvtag = 7;
PackID(Dm.sendList_x, Dm.sendCount_x ,sendID_x, id);
PackID(Dm.sendList_X, Dm.sendCount_X ,sendID_X, id);
PackID(Dm.sendList_y, Dm.sendCount_y ,sendID_y, id);
PackID(Dm.sendList_Y, Dm.sendCount_Y ,sendID_Y, id);
PackID(Dm.sendList_z, Dm.sendCount_z ,sendID_z, id);
PackID(Dm.sendList_Z, Dm.sendCount_Z ,sendID_Z, id);
PackID(Dm.sendList_xy, Dm.sendCount_xy ,sendID_xy, id);
PackID(Dm.sendList_Xy, Dm.sendCount_Xy ,sendID_Xy, id);
PackID(Dm.sendList_xY, Dm.sendCount_xY ,sendID_xY, id);
PackID(Dm.sendList_XY, Dm.sendCount_XY ,sendID_XY, id);
PackID(Dm.sendList_xz, Dm.sendCount_xz ,sendID_xz, id);
PackID(Dm.sendList_Xz, Dm.sendCount_Xz ,sendID_Xz, id);
PackID(Dm.sendList_xZ, Dm.sendCount_xZ ,sendID_xZ, id);
PackID(Dm.sendList_XZ, Dm.sendCount_XZ ,sendID_XZ, id);
PackID(Dm.sendList_yz, Dm.sendCount_yz ,sendID_yz, id);
PackID(Dm.sendList_Yz, Dm.sendCount_Yz ,sendID_Yz, id);
PackID(Dm.sendList_yZ, Dm.sendCount_yZ ,sendID_yZ, id);
PackID(Dm.sendList_YZ, Dm.sendCount_YZ ,sendID_YZ, id);
//......................................................................................
MPI_Sendrecv(sendID_x,Dm.sendCount_x,MPI_CHAR,Dm.rank_x,sendtag,
recvID_X,Dm.recvCount_X,MPI_CHAR,Dm.rank_X,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_X,Dm.sendCount_X,MPI_CHAR,Dm.rank_X,sendtag,
recvID_x,Dm.recvCount_x,MPI_CHAR,Dm.rank_x,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_y,Dm.sendCount_y,MPI_CHAR,Dm.rank_y,sendtag,
recvID_Y,Dm.recvCount_Y,MPI_CHAR,Dm.rank_Y,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_Y,Dm.sendCount_Y,MPI_CHAR,Dm.rank_Y,sendtag,
recvID_y,Dm.recvCount_y,MPI_CHAR,Dm.rank_y,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_z,Dm.sendCount_z,MPI_CHAR,Dm.rank_z,sendtag,
recvID_Z,Dm.recvCount_Z,MPI_CHAR,Dm.rank_Z,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_Z,Dm.sendCount_Z,MPI_CHAR,Dm.rank_Z,sendtag,
recvID_z,Dm.recvCount_z,MPI_CHAR,Dm.rank_z,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_xy,Dm.sendCount_xy,MPI_CHAR,Dm.rank_xy,sendtag,
recvID_XY,Dm.recvCount_XY,MPI_CHAR,Dm.rank_XY,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_XY,Dm.sendCount_XY,MPI_CHAR,Dm.rank_XY,sendtag,
recvID_xy,Dm.recvCount_xy,MPI_CHAR,Dm.rank_xy,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_Xy,Dm.sendCount_Xy,MPI_CHAR,Dm.rank_Xy,sendtag,
recvID_xY,Dm.recvCount_xY,MPI_CHAR,Dm.rank_xY,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_xY,Dm.sendCount_xY,MPI_CHAR,Dm.rank_xY,sendtag,
recvID_Xy,Dm.recvCount_Xy,MPI_CHAR,Dm.rank_Xy,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_xz,Dm.sendCount_xz,MPI_CHAR,Dm.rank_xz,sendtag,
recvID_XZ,Dm.recvCount_XZ,MPI_CHAR,Dm.rank_XZ,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_XZ,Dm.sendCount_XZ,MPI_CHAR,Dm.rank_XZ,sendtag,
recvID_xz,Dm.recvCount_xz,MPI_CHAR,Dm.rank_xz,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_Xz,Dm.sendCount_Xz,MPI_CHAR,Dm.rank_Xz,sendtag,
recvID_xZ,Dm.recvCount_xZ,MPI_CHAR,Dm.rank_xZ,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_xZ,Dm.sendCount_xZ,MPI_CHAR,Dm.rank_xZ,sendtag,
recvID_Xz,Dm.recvCount_Xz,MPI_CHAR,Dm.rank_Xz,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_yz,Dm.sendCount_yz,MPI_CHAR,Dm.rank_yz,sendtag,
recvID_YZ,Dm.recvCount_YZ,MPI_CHAR,Dm.rank_YZ,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_YZ,Dm.sendCount_YZ,MPI_CHAR,Dm.rank_YZ,sendtag,
recvID_yz,Dm.recvCount_yz,MPI_CHAR,Dm.rank_yz,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_Yz,Dm.sendCount_Yz,MPI_CHAR,Dm.rank_Yz,sendtag,
recvID_yZ,Dm.recvCount_yZ,MPI_CHAR,Dm.rank_yZ,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_yZ,Dm.sendCount_yZ,MPI_CHAR,Dm.rank_yZ,sendtag,
recvID_Yz,Dm.recvCount_Yz,MPI_CHAR,Dm.rank_Yz,recvtag,comm,MPI_STATUS_IGNORE);
//......................................................................................
UnpackID(Dm.recvList_x, Dm.recvCount_x ,recvID_x, id);
UnpackID(Dm.recvList_X, Dm.recvCount_X ,recvID_X, id);
UnpackID(Dm.recvList_y, Dm.recvCount_y ,recvID_y, id);
UnpackID(Dm.recvList_Y, Dm.recvCount_Y ,recvID_Y, id);
UnpackID(Dm.recvList_z, Dm.recvCount_z ,recvID_z, id);
UnpackID(Dm.recvList_Z, Dm.recvCount_Z ,recvID_Z, id);
UnpackID(Dm.recvList_xy, Dm.recvCount_xy ,recvID_xy, id);
UnpackID(Dm.recvList_Xy, Dm.recvCount_Xy ,recvID_Xy, id);
UnpackID(Dm.recvList_xY, Dm.recvCount_xY ,recvID_xY, id);
UnpackID(Dm.recvList_XY, Dm.recvCount_XY ,recvID_XY, id);
UnpackID(Dm.recvList_xz, Dm.recvCount_xz ,recvID_xz, id);
UnpackID(Dm.recvList_Xz, Dm.recvCount_Xz ,recvID_Xz, id);
UnpackID(Dm.recvList_xZ, Dm.recvCount_xZ ,recvID_xZ, id);
UnpackID(Dm.recvList_XZ, Dm.recvCount_XZ ,recvID_XZ, id);
UnpackID(Dm.recvList_yz, Dm.recvCount_yz ,recvID_yz, id);
UnpackID(Dm.recvList_Yz, Dm.recvCount_Yz ,recvID_Yz, id);
UnpackID(Dm.recvList_yZ, Dm.recvCount_yZ ,recvID_yZ, id);
UnpackID(Dm.recvList_YZ, Dm.recvCount_YZ ,recvID_YZ, id);
//......................................................................................
count = 0;
for (int k=1; k<Nz-1; k++){
for (int j=1; j<Ny-1; j++){
for (int i=1; i<Nx-1; i++){
n=k*Nx*Ny+j*Nx+i;
if (id[n] == 1){
count++;
int x,y,z;
int ii,jj,kk;
int Nx = nx;
int Ny = ny;
int Nz = nz;
float sat = 0.f;
int GlobalNumber = 1;
int Window=int(Rcrit);
// Layer the inlet with NWP
if (kproc == 0){
for(j=0; j<Ny; j++){
for(i=0; i<Nx; i++){
n = nx*ny + j*nx+i;
if (id[n] == 0) id[n]=1;
}
}
}
int imin,jmin,kmin,imax,jmax,kmax;
while (GlobalNumber != 0){
int LocalNumber=0;
for(k=1; k<Nz; k++){
for(j=0; j<Ny; j++){
for(i=0; i<Nx; i++){
n = k*nx*ny + j*nx+i;
if (id[n] == 1 && SignDist(i,j,k) > Rcrit){
// loop over the window and update
imin=max(0,i-Window);
jmin=max(0,j-Window);
kmin=max(0,k-Window);
imax=min(Nx,i+Window);
jmax=min(Ny,j+Window);
kmax=min(Nz,k+Window);
for (kk=kmin; kk<kmax; kk++){
for (jj=jmin; jj<jmax; jj++){
for (ii=imin; ii<imax; ii++){
nn = kk*nx*ny+jj*nx+ii;
if (id[nn] == 2){
LocalNumber++;
id[nn]=1;
}
}
}
}
}
// move on
}
}
}
MPI_Allreduce(&count,&countGlobal,1,MPI_INT,MPI_SUM,comm);
sat = float(countGlobal)/totalGlobal;
// Pack and send the updated ID values
PackID(Dm.sendList_x, Dm.sendCount_x ,sendID_x, id);
PackID(Dm.sendList_X, Dm.sendCount_X ,sendID_X, id);
PackID(Dm.sendList_y, Dm.sendCount_y ,sendID_y, id);
PackID(Dm.sendList_Y, Dm.sendCount_Y ,sendID_Y, id);
PackID(Dm.sendList_z, Dm.sendCount_z ,sendID_z, id);
PackID(Dm.sendList_Z, Dm.sendCount_Z ,sendID_Z, id);
PackID(Dm.sendList_xy, Dm.sendCount_xy ,sendID_xy, id);
PackID(Dm.sendList_Xy, Dm.sendCount_Xy ,sendID_Xy, id);
PackID(Dm.sendList_xY, Dm.sendCount_xY ,sendID_xY, id);
PackID(Dm.sendList_XY, Dm.sendCount_XY ,sendID_XY, id);
PackID(Dm.sendList_xz, Dm.sendCount_xz ,sendID_xz, id);
PackID(Dm.sendList_Xz, Dm.sendCount_Xz ,sendID_Xz, id);
PackID(Dm.sendList_xZ, Dm.sendCount_xZ ,sendID_xZ, id);
PackID(Dm.sendList_XZ, Dm.sendCount_XZ ,sendID_XZ, id);
PackID(Dm.sendList_yz, Dm.sendCount_yz ,sendID_yz, id);
PackID(Dm.sendList_Yz, Dm.sendCount_Yz ,sendID_Yz, id);
PackID(Dm.sendList_yZ, Dm.sendCount_yZ ,sendID_yZ, id);
PackID(Dm.sendList_YZ, Dm.sendCount_YZ ,sendID_YZ, id);
//......................................................................................
MPI_Sendrecv(sendID_x,Dm.sendCount_x,MPI_CHAR,Dm.rank_x,sendtag,
recvID_X,Dm.recvCount_X,MPI_CHAR,Dm.rank_X,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_X,Dm.sendCount_X,MPI_CHAR,Dm.rank_X,sendtag,
recvID_x,Dm.recvCount_x,MPI_CHAR,Dm.rank_x,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_y,Dm.sendCount_y,MPI_CHAR,Dm.rank_y,sendtag,
recvID_Y,Dm.recvCount_Y,MPI_CHAR,Dm.rank_Y,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_Y,Dm.sendCount_Y,MPI_CHAR,Dm.rank_Y,sendtag,
recvID_y,Dm.recvCount_y,MPI_CHAR,Dm.rank_y,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_z,Dm.sendCount_z,MPI_CHAR,Dm.rank_z,sendtag,
recvID_Z,Dm.recvCount_Z,MPI_CHAR,Dm.rank_Z,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_Z,Dm.sendCount_Z,MPI_CHAR,Dm.rank_Z,sendtag,
recvID_z,Dm.recvCount_z,MPI_CHAR,Dm.rank_z,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_xy,Dm.sendCount_xy,MPI_CHAR,Dm.rank_xy,sendtag,
recvID_XY,Dm.recvCount_XY,MPI_CHAR,Dm.rank_XY,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_XY,Dm.sendCount_XY,MPI_CHAR,Dm.rank_XY,sendtag,
recvID_xy,Dm.recvCount_xy,MPI_CHAR,Dm.rank_xy,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_Xy,Dm.sendCount_Xy,MPI_CHAR,Dm.rank_Xy,sendtag,
recvID_xY,Dm.recvCount_xY,MPI_CHAR,Dm.rank_xY,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_xY,Dm.sendCount_xY,MPI_CHAR,Dm.rank_xY,sendtag,
recvID_Xy,Dm.recvCount_Xy,MPI_CHAR,Dm.rank_Xy,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_xz,Dm.sendCount_xz,MPI_CHAR,Dm.rank_xz,sendtag,
recvID_XZ,Dm.recvCount_XZ,MPI_CHAR,Dm.rank_XZ,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_XZ,Dm.sendCount_XZ,MPI_CHAR,Dm.rank_XZ,sendtag,
recvID_xz,Dm.recvCount_xz,MPI_CHAR,Dm.rank_xz,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_Xz,Dm.sendCount_Xz,MPI_CHAR,Dm.rank_Xz,sendtag,
recvID_xZ,Dm.recvCount_xZ,MPI_CHAR,Dm.rank_xZ,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_xZ,Dm.sendCount_xZ,MPI_CHAR,Dm.rank_xZ,sendtag,
recvID_Xz,Dm.recvCount_Xz,MPI_CHAR,Dm.rank_Xz,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_yz,Dm.sendCount_yz,MPI_CHAR,Dm.rank_yz,sendtag,
recvID_YZ,Dm.recvCount_YZ,MPI_CHAR,Dm.rank_YZ,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_YZ,Dm.sendCount_YZ,MPI_CHAR,Dm.rank_YZ,sendtag,
recvID_yz,Dm.recvCount_yz,MPI_CHAR,Dm.rank_yz,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_Yz,Dm.sendCount_Yz,MPI_CHAR,Dm.rank_Yz,sendtag,
recvID_yZ,Dm.recvCount_yZ,MPI_CHAR,Dm.rank_yZ,recvtag,comm,MPI_STATUS_IGNORE);
MPI_Sendrecv(sendID_yZ,Dm.sendCount_yZ,MPI_CHAR,Dm.rank_yZ,sendtag,
recvID_Yz,Dm.recvCount_Yz,MPI_CHAR,Dm.rank_Yz,recvtag,comm,MPI_STATUS_IGNORE);
//......................................................................................
UnpackID(Dm.recvList_x, Dm.recvCount_x ,recvID_x, id);
UnpackID(Dm.recvList_X, Dm.recvCount_X ,recvID_X, id);
UnpackID(Dm.recvList_y, Dm.recvCount_y ,recvID_y, id);
UnpackID(Dm.recvList_Y, Dm.recvCount_Y ,recvID_Y, id);
UnpackID(Dm.recvList_z, Dm.recvCount_z ,recvID_z, id);
UnpackID(Dm.recvList_Z, Dm.recvCount_Z ,recvID_Z, id);
UnpackID(Dm.recvList_xy, Dm.recvCount_xy ,recvID_xy, id);
UnpackID(Dm.recvList_Xy, Dm.recvCount_Xy ,recvID_Xy, id);
UnpackID(Dm.recvList_xY, Dm.recvCount_xY ,recvID_xY, id);
UnpackID(Dm.recvList_XY, Dm.recvCount_XY ,recvID_XY, id);
UnpackID(Dm.recvList_xz, Dm.recvCount_xz ,recvID_xz, id);
UnpackID(Dm.recvList_Xz, Dm.recvCount_Xz ,recvID_Xz, id);
UnpackID(Dm.recvList_xZ, Dm.recvCount_xZ ,recvID_xZ, id);
UnpackID(Dm.recvList_XZ, Dm.recvCount_XZ ,recvID_XZ, id);
UnpackID(Dm.recvList_yz, Dm.recvCount_yz ,recvID_yz, id);
UnpackID(Dm.recvList_Yz, Dm.recvCount_Yz ,recvID_Yz, id);
UnpackID(Dm.recvList_yZ, Dm.recvCount_yZ ,recvID_yZ, id);
UnpackID(Dm.recvList_YZ, Dm.recvCount_YZ ,recvID_YZ, id);
//......................................................................................
MPI_Allreduce(&LocalNumber,&GlobalNumber,1,MPI_INT,MPI_SUM,comm);
}
count = 0;
for (int k=1; k<Nz-1; k++){
for (int j=1; j<Ny-1; j++){
for (int i=1; i<Nx-1; i++){
n=k*Nx*Ny+j*Nx+i;
if (id[n] == 1){
count++;
}
}
}
}
MPI_Allreduce(&count,&countGlobal,1,MPI_INT,MPI_SUM,comm);
sat = float(countGlobal)/totalGlobal;
if (rank==0) printf("Final saturation=%f\n",sat);
sprintf(LocalRankFilename,"ID.%05i",rank);