//************************************************************************* // Lattice Boltzmann Simulator for Single Phase Flow in Porous Media // James E. McCLure //************************************************************************* #include #include #include #include "common/ScaLBL.h" #include "common/MPI_Helpers.h" using namespace std; extern void GlobalFlipScaLBL_D3Q19_Init(double *dist, IntArray Map, int Np, int Nx, int Ny, int Nz, int iproc, int jproc, int kproc, int nprocx, int nprocy, int nprocz) { // Set of Discrete velocities for the D3Q19 Model static int D3Q19[18][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}, {1,1,0},{-1,-1,0},{1,-1,0},{-1,1,0},{1,0,1},{-1,0,-1},{1,0,-1},{-1,0,1}, {0,1,1},{0,-1,-1},{0,1,-1},{0,-1,1}}; int q,i,j,k,n,N; int Cqx,Cqy,Cqz; // Discrete velocity int x,y,z; // Global indices int xn,yn,zn; // Global indices of neighbor int X,Y,Z; // Global size int idx; X = Nx*nprocx; Y = Ny*nprocy; Z = Nz*nprocz; NULL_USE(Z); N = (Nx+2)*(Ny+2)*(Nz+2); // size of the array including halo for (k=0; k 0){ // Get the 'global' index x = iproc*Nx+i; y = jproc*Ny+j; z = kproc*Nz+k; for (q=0; q<18; q++){ // Odd distribution Cqx = D3Q19[q][0]; Cqy = D3Q19[q][1]; Cqz = D3Q19[q][2]; xn = x - Cqx; yn = y - Cqy; zn = z - Cqz; xn=x; yn=y;zn=z; if (xn < 0) xn += nprocx*Nx; if (yn < 0) yn += nprocy*Ny; if (zn < 0) zn += nprocz*Nz; if (!(xn < nprocx*Nx)) xn -= nprocx*Nx; if (!(yn < nprocy*Ny)) yn -= nprocy*Ny; if (!(zn < nprocz*Nz)) zn -= nprocz*Nz; dist[(q+1)*Np+idx] = (zn*X*Y+yn*X+xn) + (q+1)*0.01; } } } } } } extern int GlobalCheckDebugDist(double *dist, IntArray Map, int Np, int Nx, int Ny, int Nz, int iproc, int jproc, int kproc, int nprocx, int nprocy, int nprocz, int start, int finish) { int returnValue = 0; int q,i,j,k,n,N,idx; int Cqx,Cqy,Cqz; // Discrete velocity int x,y,z; // Global indices int xn,yn,zn; // Global indices of neighbor int X,Y,Z; // Global size X = Nx*nprocx; Y = Ny*nprocy; Z = Nz*nprocz; NULL_USE(Z); N = (Nx+2)*(Ny+2)*(Nz+2); // size of the array including halo for (k=0; k start && idx< finish){ // Get the 'global' index x = iproc*Nx+i; y = jproc*Ny+j; z = kproc*Nz+k; for (q=0; q<18; q++){ if (dist[(q+1)*Np+idx] != (z*X*Y+y*X+x) + (q+1)*0.01){ printf("******************************************\n"); printf("error in distribution q = %i \n", (q+1)); printf("i,j,k= %i, %i, %i \n", x,y,z); printf("dist = %5.2f \n", dist[(q+1)*Np+idx]); printf("n= %i \n",z*X*Y+y*X+x); returnValue++; } } } } } } return returnValue; } 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; } else if (nprocs==1){ nprocx=nprocy=nprocz=1; Nx=Ny=Nz=50; nspheres=0; Lx=Ly=Lz=1; } else if (nprocs==2){ nprocx=nprocy=1; nprocz=2; Nx=Ny=Nz=50; nspheres=0; Lx=Ly=Lz=1; } else if (nprocs==4){ nprocx=nprocy=2; nprocz=1; Nx=Ny=Nz=50; nspheres=0; Lx=Ly=Lz=1; } else if (nprocs==8){ nprocx=nprocy=nprocz=2; Nx=Ny=Nz=50; nspheres=0; Lx=Ly=Lz=1; } //....................................................................... } // ************************************************************** // Broadcast simulation parameters from rank 0 to all other procs MPI_Barrier(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(&nBlocks,1,MPI_UNSIGNED,0,comm); MPI_Bcast(&nthreads,1,MPI_UNSIGNED,0,comm); MPI_Bcast(×tepMax,1,MPI_INT,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(&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); // ************************************************************** // ************************************************************** if (nprocs != nprocx*nprocy*nprocz){ printf("nprocx = %i \n",nprocx); printf("nprocy = %i \n",nprocy); printf("nprocz = %i \n",nprocz); INSIST(nprocs == nprocx*nprocy*nprocz,"Fatal error in processor count!"); } if (rank==0){ printf("********************************************************\n"); printf("Sub-domain size = %i x %i x %i\n",Nz,Nz,Nz); printf("Parallel domain size = %i x %i x %i\n",nprocx,nprocy,nprocz); printf("********************************************************\n"); } MPI_Barrier(comm); kproc = rank/(nprocx*nprocy); jproc = (rank-nprocx*nprocy*kproc)/nprocx; iproc = rank-nprocx*nprocy*kproc-nprocz*jproc; double iVol_global = 1.0/Nx/Ny/Nz/nprocx/nprocy/nprocz; int BoundaryCondition=0; Domain Dm(Nx,Ny,Nz,rank,nprocx,nprocy,nprocz,Lx,Ly,Lz,BoundaryCondition); InitializeRanks( rank, nprocx, nprocy, nprocz, iproc, jproc, kproc, rank_x, rank_y, rank_z, rank_X, rank_Y, rank_Z, rank_xy, rank_XY, rank_xY, rank_Xy, rank_xz, rank_XZ, rank_xZ, rank_Xz, rank_yz, rank_YZ, rank_yZ, rank_Yz ); Nx += 2; Ny += 2; Nz += 2; int N = Nx*Ny*Nz; int dist_mem_size = N*sizeof(double); //....................................................................... // Assign the phase ID field //....................................................................... char LocalRankString[8]; sprintf(LocalRankString,"%05d",rank); char LocalRankFilename[40]; sprintf(LocalRankFilename,"ID.%05i",rank); char *id; id = new char[Nx*Ny*Nz]; if (rank==0) printf("Assigning phase ID from file \n"); if (rank==0) printf("Initialize from segmented data: solid=0, NWP=1, WP=2 \n"); FILE *IDFILE = fopen(LocalRankFilename,"rb"); if (IDFILE==NULL) ERROR("Error opening file: ID.xxxxx"); fread(id,1,N,IDFILE); fclose(IDFILE); // Setup the domain for (k=0;k