|
|
|
|
@@ -8,9 +8,61 @@
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
#include "common/ScaLBL.h"
|
|
|
|
|
#include "common/Communication.h"
|
|
|
|
|
#include "analysis/TwoPhase.h"
|
|
|
|
|
#include "common/MPI_Helpers.h"
|
|
|
|
|
#include "models/ColorModel.h"
|
|
|
|
|
|
|
|
|
|
inline void InitializeBubble(ScaLBL_ColorModel &ColorModel, double BubbleRadius){
|
|
|
|
|
// initialize a bubble
|
|
|
|
|
int i,j,k,n;
|
|
|
|
|
int rank = ColorModel.Mask->rank();
|
|
|
|
|
int nprocx = ColorModel.Mask->nprocx();
|
|
|
|
|
int nprocy = ColorModel.Mask->nprocy();
|
|
|
|
|
int nprocz = ColorModel.Mask->nprocz();
|
|
|
|
|
int Nx = ColorModel.Mask->Nx;
|
|
|
|
|
int Ny = ColorModel.Mask->Ny;
|
|
|
|
|
int Nz = ColorModel.Mask->Nz;
|
|
|
|
|
if (rank == 0) cout << "Setting up bubble..." << endl;
|
|
|
|
|
for (k=0;k<Nz;k++){
|
|
|
|
|
for (j=0;j<Ny;j++){
|
|
|
|
|
for (i=0;i<Nx;i++){
|
|
|
|
|
n = k*Nx*Ny + j*Nz + i;
|
|
|
|
|
ColorModel.Averages->SDs(i,j,k) = 100.f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Initialize the bubble
|
|
|
|
|
int count_in_bubble=0;
|
|
|
|
|
int count_out_bubble=0;
|
|
|
|
|
for (k=0;k<Nz;k++){
|
|
|
|
|
for (j=0;j<Ny;j++){
|
|
|
|
|
for (i=0;i<Nx;i++){
|
|
|
|
|
n = k*Nx*Ny + j*Nz + i;
|
|
|
|
|
int iglobal= i+(Nx-2)*ColorModel.Mask->iproc();
|
|
|
|
|
int jglobal= j+(Ny-2)*ColorModel.Mask->jproc();
|
|
|
|
|
int kglobal= k+(Nz-2)*ColorModel.Mask->kproc();
|
|
|
|
|
// Initialize phase position field for parallel bubble test
|
|
|
|
|
if (jglobal < 40){
|
|
|
|
|
ColorModel.Mask->id[n] = 0;
|
|
|
|
|
}
|
|
|
|
|
else if ((iglobal-0.5*(Nx-2)*nprocx)*(iglobal-0.5*(Nx-2)*nprocx)
|
|
|
|
|
+(jglobal-0.5*(Ny-2)*nprocy)*(jglobal-0.5*(Ny-2)*nprocy)
|
|
|
|
|
+(kglobal-0.5*(Nz-2)*nprocz)*(kglobal-0.5*(Nz-2)*nprocz) < BubbleRadius*BubbleRadius){
|
|
|
|
|
ColorModel.Mask->id[n] = 2;
|
|
|
|
|
ColorModel.Mask->id[n] = 2;
|
|
|
|
|
count_in_bubble++;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
ColorModel.Mask->id[n]=1;
|
|
|
|
|
ColorModel.Mask->id[n]=1;
|
|
|
|
|
count_out_bubble++;
|
|
|
|
|
}
|
|
|
|
|
ColorModel.id[n] = ColorModel.Mask->id[n];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("Count in %i, out %i\n",count_in_bubble,count_out_bubble);
|
|
|
|
|
// initialize the phase indicator field
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
@@ -42,129 +94,139 @@ int main(int argc, char **argv)
|
|
|
|
|
printf("********************************************************\n");
|
|
|
|
|
printf("Running Unit Test for D3Q7 Mass Conservation \n");
|
|
|
|
|
printf("********************************************************\n");
|
|
|
|
|
if ( argc < 2 ) {
|
|
|
|
|
std::cerr << "Invalid number of arguments, no input file specified\n";
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double das=0.0;
|
|
|
|
|
double dbs=1.0;
|
|
|
|
|
double beta=0.95;
|
|
|
|
|
bool pBC=false;
|
|
|
|
|
{
|
|
|
|
|
auto filename = argv[1];
|
|
|
|
|
ScaLBL_ColorModel CM(rank,nprocs,comm);
|
|
|
|
|
CM.ReadParams(filename);
|
|
|
|
|
CM.SetDomain();
|
|
|
|
|
int i,j,k,n;
|
|
|
|
|
int Nx,Ny,Nz,N;
|
|
|
|
|
Nx=Nz=Ny=100;
|
|
|
|
|
int Nx,Ny,Nz,N,Np;
|
|
|
|
|
Nx = CM.Nx;
|
|
|
|
|
Ny = CM.Ny;
|
|
|
|
|
Nz = CM.Nz;
|
|
|
|
|
N = Nx*Ny*Nz;
|
|
|
|
|
int dist_mem_size = N*sizeof(double);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//CM.ReadInput();
|
|
|
|
|
double radius=0.4*double(Nx);
|
|
|
|
|
InitializeBubble(CM,radius);
|
|
|
|
|
CM.Create(); // creating the model will create data structure to match the pore structure and allocate variables
|
|
|
|
|
CM.Initialize(); // initializing the model will set initial conditions for variables
|
|
|
|
|
//CM.Run();
|
|
|
|
|
//CM.WriteDebug();
|
|
|
|
|
|
|
|
|
|
CM.timestepMax = 10;
|
|
|
|
|
CM.Run();
|
|
|
|
|
|
|
|
|
|
Np = CM.Np;
|
|
|
|
|
double *DenOriginal, *DenFinal;
|
|
|
|
|
DenOriginal = new double [2*N];
|
|
|
|
|
DenFinal = new double [2*N];
|
|
|
|
|
|
|
|
|
|
double *Vel;
|
|
|
|
|
Vel = new double [3*N];
|
|
|
|
|
char *id;
|
|
|
|
|
id = new char [N];
|
|
|
|
|
|
|
|
|
|
for (k=0;k<Nz;k++){
|
|
|
|
|
for (j=0;j<Ny;j++){
|
|
|
|
|
for (i=0;i<Nx;i++){
|
|
|
|
|
n = k*Nx*Ny+j*Nx+i;
|
|
|
|
|
if (k<10) id[n] = 0;
|
|
|
|
|
else if (k>80) id[n] = 0;
|
|
|
|
|
else if (i<50){
|
|
|
|
|
id[n]=1;
|
|
|
|
|
Vel[n]=0.1;
|
|
|
|
|
Vel[N+n]=0.1;
|
|
|
|
|
Vel[2*N+n]=0.1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
id[n]=2;
|
|
|
|
|
Vel[n]=0.1;
|
|
|
|
|
Vel[N+n]=0.1;
|
|
|
|
|
Vel[2*N+n]=0.1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DenOriginal = new double [2*Np];
|
|
|
|
|
DenFinal = new double [2*Np];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//......................device distributions.................................
|
|
|
|
|
double *A_even,*A_odd,*B_even,*B_odd;
|
|
|
|
|
//...........................................................................
|
|
|
|
|
ScaLBL_AllocateDeviceMemory((void **) &A_even, 4*dist_mem_size); // Allocate device memory
|
|
|
|
|
ScaLBL_AllocateDeviceMemory((void **) &A_odd, 3*dist_mem_size); // Allocate device memory
|
|
|
|
|
ScaLBL_AllocateDeviceMemory((void **) &B_even, 4*dist_mem_size); // Allocate device memory
|
|
|
|
|
ScaLBL_AllocateDeviceMemory((void **) &B_odd, 3*dist_mem_size); // Allocate device memory
|
|
|
|
|
//...........................................................................
|
|
|
|
|
double *Phi,*Den;
|
|
|
|
|
double *ColorGrad, *Velocity;
|
|
|
|
|
//...........................................................................
|
|
|
|
|
ScaLBL_AllocateDeviceMemory((void **) &Phi, dist_mem_size);
|
|
|
|
|
ScaLBL_AllocateDeviceMemory((void **) &Velocity, 3*dist_mem_size);
|
|
|
|
|
ScaLBL_AllocateDeviceMemory((void **) &ColorGrad, 3*dist_mem_size);
|
|
|
|
|
ScaLBL_AllocateDeviceMemory((void **) &Den, 2*dist_mem_size);
|
|
|
|
|
//...........device phase ID.................................................
|
|
|
|
|
if (rank==0) printf ("Copying phase ID to device \n");
|
|
|
|
|
char *ID;
|
|
|
|
|
ScaLBL_AllocateDeviceMemory((void **) &ID, N); // Allocate device memory
|
|
|
|
|
// Copy to the device
|
|
|
|
|
ScaLBL_CopyToDevice(ID, id, N);
|
|
|
|
|
ScaLBL_CopyToDevice(Velocity, Vel, 3*N*sizeof(double));
|
|
|
|
|
//...........................................................................
|
|
|
|
|
|
|
|
|
|
ScaLBL_Color_Init(ID, Den, Phi, das, dbs, Nx, Ny, Nz);
|
|
|
|
|
ScaLBL_CopyToHost(DenOriginal,Den,2*N*sizeof(double));
|
|
|
|
|
|
|
|
|
|
//......................................................................
|
|
|
|
|
ScaLBL_D3Q7_Init(ID, A_even, A_odd, &Den[0], Nx, Ny, Nz);
|
|
|
|
|
ScaLBL_D3Q7_Init(ID, B_even, B_odd, &Den[N], Nx, Ny, Nz);
|
|
|
|
|
ScaLBL_ComputePhaseField(ID, Phi, Den, N);
|
|
|
|
|
ScaLBL_D3Q19_ColorGradient(ID,Phi,ColorGrad,Nx,Ny,Nz);
|
|
|
|
|
//..................................................................................
|
|
|
|
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// Carry out the density streaming step for mass transport
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
ScaLBL_D3Q7_ColorCollideMass(ID, A_even, A_odd, B_even, B_odd, Den, Phi,
|
|
|
|
|
ColorGrad, Velocity, beta, N, pBC);
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
|
|
//..................................................................................
|
|
|
|
|
ScaLBL_D3Q7_Density(ID, A_even, A_odd, &Den[0], Nx, Ny, Nz);
|
|
|
|
|
ScaLBL_D3Q7_Density(ID, B_even, B_odd, &Den[N], Nx, Ny, Nz);
|
|
|
|
|
//..................................................................................
|
|
|
|
|
ScaLBL_ComputePhaseField(ID, Phi, Den, N);
|
|
|
|
|
ScaLBL_D3Q19_ColorGradient(ID,Phi,ColorGrad,Nx,Ny,Nz);
|
|
|
|
|
//..................................................................................
|
|
|
|
|
// Run the odd timestep
|
|
|
|
|
ScaLBL_CopyToHost(DenOriginal,CM.Den,2*Np*sizeof(double));
|
|
|
|
|
/*
|
|
|
|
|
CM.ScaLBL_Comm->BiSendD3Q7AA(CM.Aq,CM.Bq); //READ FROM NORMAL
|
|
|
|
|
ScaLBL_D3Q7_AAodd_PhaseField(CM.NeighborList, CM.dvcMap, CM.Aq, CM.Bq, CM.Den, CM.Phi, CM.ScaLBL_Comm->FirstInterior(), CM.ScaLBL_Comm->LastInterior(), CM.Np);
|
|
|
|
|
CM.ScaLBL_Comm->BiRecvD3Q7AA(CM.Aq,CM.Bq); //WRITE INTO OPPOSITE
|
|
|
|
|
ScaLBL_DeviceBarrier();
|
|
|
|
|
ScaLBL_D3Q7_AAodd_PhaseField(CM.NeighborList, CM.dvcMap, CM.Aq, CM.Bq, CM.Den, CM.Phi, 0, CM.ScaLBL_Comm->LastExterior(), CM.Np);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CM.timestepMax = 2;
|
|
|
|
|
CM.Run();
|
|
|
|
|
int D3Q7[7][3]={{0,0,0},{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
|
|
|
|
|
// Compare and make sure mass is conserved at every lattice site
|
|
|
|
|
double *Error;
|
|
|
|
|
Error = new double [N];
|
|
|
|
|
double *A_q, *B_q;
|
|
|
|
|
A_q = new double [7*Np];
|
|
|
|
|
B_q = new double [7*Np];
|
|
|
|
|
bool CleanCheck = true;
|
|
|
|
|
double original,final;
|
|
|
|
|
ScaLBL_CopyToHost(DenFinal,Den,2*N*sizeof(double));
|
|
|
|
|
for (k=0;k<Nz;k++){
|
|
|
|
|
for (j=0;j<Ny;j++){
|
|
|
|
|
for (i=0;i<Nx;i++){
|
|
|
|
|
double original,final, sum_q;
|
|
|
|
|
double total_mass_A_0 = 0.0;
|
|
|
|
|
double total_mass_B_0= 0.0;
|
|
|
|
|
double total_mass_A_1 = 0.0;
|
|
|
|
|
double total_mass_B_1= 0.0;
|
|
|
|
|
int count_negative_A = 0;
|
|
|
|
|
int count_negative_B = 0;
|
|
|
|
|
ScaLBL_CopyToHost(DenFinal,CM.Den,2*Np*sizeof(double));
|
|
|
|
|
ScaLBL_CopyToHost(A_q,CM.Aq,7*Np*sizeof(double));
|
|
|
|
|
for (i=0; i<N; i++) Error[i]=0.0;
|
|
|
|
|
for (k=1;k<Nz-1;k++){
|
|
|
|
|
for (j=1;j<Ny-1;j++){
|
|
|
|
|
for (i=1;i<Nx-1;i++){
|
|
|
|
|
n = k*Nx*Ny+j*Nx+i;
|
|
|
|
|
if (fabs(DenFinal[n] - DenOriginal[n]) > 1e-15){
|
|
|
|
|
final = DenFinal[n];
|
|
|
|
|
original = DenOriginal[n];
|
|
|
|
|
if (id[n] == 0) printf("Solid phase! \n");
|
|
|
|
|
if (id[n] == 1) printf("Wetting phase! \n");
|
|
|
|
|
if (id[n] == 2) printf("Non-wetting phase! \n");
|
|
|
|
|
printf("Mass not conserved: WP density, site=%i,%i,%i, original = %f, final = %f \n",i,j,k,original,final);
|
|
|
|
|
CleanCheck=false;
|
|
|
|
|
}
|
|
|
|
|
if (fabs(DenFinal[N+n] - DenOriginal[N+n]) > 1e-15){
|
|
|
|
|
if (id[n] == 0) printf("Solid phase! \n");
|
|
|
|
|
if (id[n] == 1) printf("Wetting phase! \n");
|
|
|
|
|
if (id[n] == 2) printf("Non-wetting phase! \n");
|
|
|
|
|
final = DenFinal[N+n];
|
|
|
|
|
original = DenOriginal[N+n];
|
|
|
|
|
printf("Mass not conserved: NWP density, site=%i,%i,%i, original = %f, final = %f \n",i,j,k,original,final);
|
|
|
|
|
CleanCheck=false;
|
|
|
|
|
int idx = CM.Map(i,j,k);
|
|
|
|
|
if (idx < Np && idx>-1){
|
|
|
|
|
//printf("idx=%i\n",idx);
|
|
|
|
|
final = DenFinal[idx];
|
|
|
|
|
if (final < 0.0) count_negative_A++;
|
|
|
|
|
original = DenOriginal[idx];
|
|
|
|
|
total_mass_A_0 += original;
|
|
|
|
|
total_mass_A_1 += final;
|
|
|
|
|
sum_q = A_q[idx];
|
|
|
|
|
for (int q=1; q<7; q++){
|
|
|
|
|
int Cqx = D3Q7[q][0];
|
|
|
|
|
int Cqy = D3Q7[q][1];
|
|
|
|
|
int Cqz = D3Q7[q][2];
|
|
|
|
|
int iq = CM.Map(i-Cqx,j-Cqy,k-Cqz);
|
|
|
|
|
if (iq < Np && iq > -1){
|
|
|
|
|
sum_q += A_q[q*Np+iq];
|
|
|
|
|
}
|
|
|
|
|
else if (q%2==0){
|
|
|
|
|
sum_q += A_q[(q-1)*Np+idx];
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
sum_q += A_q[(q+1)*Np+idx];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Error[n] = sum_q - original;
|
|
|
|
|
|
|
|
|
|
/*if (fabs(DenFinal[idx] - DenOriginal[idx]) > 1e-15){
|
|
|
|
|
//if (CM.Dm->id[n] == 0) printf("Solid phase! \n");
|
|
|
|
|
//if (CM.Dm->id[n] == 1) printf("Wetting phase! \n");
|
|
|
|
|
//if (CM.Dm->id[n] == 2) printf("Non-wetting phase! \n");
|
|
|
|
|
printf("Mass not conserved: WP density, site=%i,%i,%i, original = %f, final = %f \n",i,j,k,original,final);
|
|
|
|
|
CleanCheck=false;
|
|
|
|
|
Error[n] += final-original;
|
|
|
|
|
}*/
|
|
|
|
|
final = DenFinal[Np+idx];
|
|
|
|
|
if (final < 0.0) count_negative_B++;
|
|
|
|
|
original = DenOriginal[Np+idx];
|
|
|
|
|
total_mass_B_0 += original;
|
|
|
|
|
total_mass_B_1 += final;
|
|
|
|
|
/*if (fabs(DenFinal[Np+idx] - DenOriginal[Np+idx]) > 1e-15){
|
|
|
|
|
//if (CM.Dm->id[n] == 0) printf("Solid phase! \n");
|
|
|
|
|
//if (CM.Dm->id[n] == 1) printf("Wetting phase! \n");
|
|
|
|
|
//if (CM.Dm->id[n] == 2) printf("Non-wetting phase! \n");
|
|
|
|
|
printf("Mass not conserved: NWP density, site=%i,%i,%i, original = %f, final = %f \n",i,j,k,original,final);
|
|
|
|
|
CleanCheck=false;
|
|
|
|
|
Error[n] += final-original;
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("Negative density values for A = %i \n",count_negative_A);
|
|
|
|
|
printf("Negative density values for B = %i \n",count_negative_B);
|
|
|
|
|
printf("Global mass difference A = %.5g\n",total_mass_A_1-total_mass_A_0);
|
|
|
|
|
printf("Global mass difference B = %.5g\n",total_mass_B_1-total_mass_B_0);
|
|
|
|
|
|
|
|
|
|
if (count_negative_A > 0 ||count_negative_B > 0) CleanCheck=1;
|
|
|
|
|
if (fabs(total_mass_A_1-total_mass_A_0) > 1.0e-15||fabs(total_mass_B_1-total_mass_B_0) > 1.0e-15 ) CleanCheck=2;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
FILE *OUTFILE;
|
|
|
|
|
OUTFILE = fopen("error.raw","wb");
|
|
|
|
|
fwrite(Error,8,N,OUTFILE);
|
|
|
|
|
fclose(OUTFILE);
|
|
|
|
|
|
|
|
|
|
if (rank==0) printf("Checking that the correct velocity is retained \n");
|
|
|
|
|
// Swap convention is observed -- velocity is negative
|
|
|
|
|
double *Aeven,*Aodd,*Beven,*Bodd;
|
|
|
|
|
@@ -213,7 +275,7 @@ int main(int argc, char **argv)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
if (CleanCheck){
|
|
|
|
|
if (rank==0) printf("Test passed: mass conservation for D3Q7 \n");
|
|
|
|
|
}
|
|
|
|
|
@@ -221,7 +283,7 @@ int main(int argc, char **argv)
|
|
|
|
|
if (rank==0) printf("Test failed!: mass conservation for D3Q7 \n");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// ****************************************************
|
|
|
|
|
MPI_Barrier(comm);
|
|
|
|
|
MPI_Finalize();
|
|
|
|
|
|