diff --git a/tests/TestComputeSignDist.cpp b/tests/TestComputeSignDist.cpp index e444190f..62491b1d 100644 --- a/tests/TestComputeSignDist.cpp +++ b/tests/TestComputeSignDist.cpp @@ -11,13 +11,13 @@ #include #include -inline void SSO(DoubleArray &Distance, IntArray &ID, int timesteps){ +inline void SSO(DoubleArray &Distance, char *ID, int timesteps){ int Q=26; - int q,i,j,k; - int Nx = ID.m; - int Ny = ID.n; - int Nz = ID.o; + int q,i,j,k,n; + int Nx = Distance.m; + int Ny = Distance.n; + int Nz = Distance.o; const static int D3Q27[26][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},{1,1,1},{-1,-1,-1},{1,1,-1},{-1,-1,1}, @@ -30,40 +30,58 @@ inline void SSO(DoubleArray &Distance, IntArray &ID, int timesteps){ } // Initialize the Distance from ID - for (i=0; i 0.0){ - for (q=0; q<27; q++){ + for (q=0; q<26; q++){ Cqx = 1.0*D3Q27[q][0]; Cqy = 1.0*D3Q27[q][1]; Cqz = 1.0*D3Q27[q][2]; @@ -72,12 +90,19 @@ inline void SSO(DoubleArray &Distance, IntArray &ID, int timesteps){ jn = j + D3Q27[q][1]; kn = k + D3Q27[q][2]; // make sure the neighbor is in the domain (periodic BC) - if (in < 0 ) in +=Nx; + /* if (in < 0 ) in +=Nx; if (jn < 0 ) jn +=Ny; if (kn < 0 ) kn +=Nz; if (!(in < Nx) ) in -=Nx; if (!(jn < Ny) ) jn -=Ny; if (!(kn < Nz) ) kn -=Nz; + */ // symmetric boundary + if (in < 0 ) in = i; + if (jn < 0 ) jn = j; + if (kn < 0 ) kn = k; + if (!(in < Nx) ) in = i; + if (!(jn < Ny) ) jn = k; + if (!(kn < Nz) ) kn = k; // 1-D index nn = kn*Nx*Ny + jn*Nx + in; @@ -103,20 +128,18 @@ inline void SSO(DoubleArray &Distance, IntArray &ID, int timesteps){ norm = sqrt(Dx*Dx+Dy*Dy+Dz*Dz); } else{ - norm = 0.7; + norm = 0.0; } Distance.data[n] += dt*sign*(1.0 - norm); - // Disallow any change in phase position - if (Distance.data[n]*ID.data[n] < 0) Distance.data[n] = -Distance.data[n]; + // Disallow any change in phase + if (Distance.data[n]*2.0*(ID[n]-1.0) < 0) Distance.data[n] = -Distance.data[n]; } } } count++; } - - } int main(){ @@ -136,28 +159,31 @@ int main(){ double fxm,fym,fzm,fxp,fyp,fzp; double fxy,fXy,fxY,fXY,fxz,fXz,fxZ,fXZ,fyz,fYz,fyZ,fYZ; double nx,ny,nz; - int ip,im,jp,jm,kp,km; int count = 0; double sign; - double dt=0.01; + double dt=1.0; printf("Nx=%i, Ny=%i, Nz= %i, \n",Nx,Ny,Nz); - short int *id; + char *id; #ifdef READMEDIA Nx = 347; Ny = 347; Nz = 235; + Nx = 512; + Ny = 512; + Nz = 512; N = Nx*Ny*Nz; - id = new short int [N]; - FILE *INPUT = fopen("Solid.dat",'rb'); - fread(id,4,N*,Ny*Nz,INPUT) + id = new char [N]; + + FILE *INPUT = fopen("Solid.dat","rb"); + fread(id,1,Nx*Ny*Nz,INPUT); fclose(INPUT); #else - id = new short int [N]; + id = new char [N]; double BubbleRadius = 5; // Initialize the bubble for (k=0;k 1.0e-6){ + dt=1.0; + while (count < 10 && dt > 1.0e-6){ err = 0.0; for (k=0;k 0){ + if (id[n] < 0){ if ( nx > 0.0) f_x = fxp; else f_x = fxm; if ( ny > 0.0) f_y = fyp; @@ -348,8 +391,8 @@ int main(){ count++; } +*/ - */ FILE *DIST; DIST = fopen("SignDist","wb"); fwrite(Distance.data,8,N,DIST); diff --git a/tests/TestSegDist.cpp b/tests/TestSegDist.cpp new file mode 100644 index 00000000..c659abaf --- /dev/null +++ b/tests/TestSegDist.cpp @@ -0,0 +1,108 @@ +// Compute the signed distance from a digitized image +// Two phases are present +// Phase 1 has value -1 +// Phase 2 has value 1 +// this code uses the segmented image to generate the signed distance + +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + // Initialize MPI + int rank, nprocs; + MPI_Init(&argc,&argv); + MPI_Comm_rank(MPI_COMM_WORLD,&rank); + MPI_Comm_size(MPI_COMM_WORLD,&nprocs); + + int i,j,k,n,nn; + int nx,ny,nz; + int Nx, Ny, Nz, N; + Nx = Ny = Nz = 50; + N = Nx*Ny*Nz; + + if (nprocs != 8){ + ERROR("TestSegDist: Number of MPI processes must be equal to 8"); + } + + //....................................................................... + // Reading the domain information file + //....................................................................... + int nprocx, nprocy, nprocz, nx, ny, nz, nspheres; + double Lx, Ly, Lz; + ifstream domain("Domain.in"); + domain >> nprocx; + domain >> nprocy; + domain >> nprocz; + domain >> nx; + domain >> ny; + domain >> nz; + domain >> nspheres; + domain >> Lx; + domain >> Ly; + domain >> Lz; + + nprocx=nprocy=nprocz=2; + if (nprocx !=2 || nprocz !=2 || nprocy !=2 ){ + ERROR("TestSegDist: MPI process grid must be 2x2x2"); + } + + int BC=0; + // Get the rank info + Domain Dm(nx,ny,nz,rank,nprocx,nprocy,nprocz,Lx,Ly,Lz,BC); + nx+=2; ny+=2; nz+=2; + int count = 0; + + char *id; + id = new char [N]; + double BubbleRadius = 5; + // Initialize the bubble + int x,y,z; + for (k=1;k