2018-03-19 12:58:25 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <exception>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include "common/ScaLBL.h"
|
|
|
|
#include "common/Communication.h"
|
|
|
|
#include "analysis/TwoPhase.h"
|
2020-03-17 20:44:45 -05:00
|
|
|
#include "common/MPI_Helpers.h"
|
2018-03-19 12:58:25 -05:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2020-03-17 20:44:45 -05:00
|
|
|
//*****************************************
|
|
|
|
// ***** MPI STUFF ****************
|
|
|
|
//*****************************************
|
2018-03-19 12:58:25 -05:00
|
|
|
// Initialize MPI
|
2020-10-08 10:03:42 -05:00
|
|
|
Utilities::startup( argc, argv );
|
2021-01-04 18:33:27 -06:00
|
|
|
Utilities::MPI comm( MPI_COMM_WORLD );
|
|
|
|
int rank = comm.getRank();
|
|
|
|
int nprocs = comm.getSize();
|
2018-03-19 12:58:25 -05:00
|
|
|
{
|
|
|
|
// parallel domain size (# of sub-domains)
|
|
|
|
int nprocx,nprocy,nprocz;
|
|
|
|
int iproc,jproc,kproc;
|
|
|
|
int sendtag,recvtag;
|
|
|
|
//*****************************************
|
2020-03-17 20:23:18 -05:00
|
|
|
MPI_Request req1[18],req2[18];
|
|
|
|
MPI_Status stat1[18],stat2[18];
|
|
|
|
//**********************************
|
2018-03-19 12:58:25 -05:00
|
|
|
|
2018-03-19 13:14:27 -05:00
|
|
|
int nsph,ncyl, BC;
|
2018-03-19 13:09:51 -05:00
|
|
|
nsph = atoi(argv[1]);
|
|
|
|
ncyl = atoi(argv[2]);
|
2018-03-19 13:14:27 -05:00
|
|
|
BC = 0;
|
2018-03-19 12:58:25 -05:00
|
|
|
if (rank == 0){
|
|
|
|
printf("********************************************************\n");
|
|
|
|
printf("Generate LBM input geometry from simple pore network");
|
|
|
|
printf("********************************************************\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Variables that specify the computational domain
|
|
|
|
string FILENAME;
|
|
|
|
int Nx,Ny,Nz; // local sub-domain size
|
|
|
|
int nspheres; // number of spheres in the packing
|
|
|
|
double Lx,Ly,Lz; // Domain length
|
|
|
|
int i,j,k,n;
|
|
|
|
|
|
|
|
// pmmc threshold values
|
|
|
|
|
|
|
|
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 >> Lx;
|
|
|
|
domain >> Ly;
|
|
|
|
domain >> Lz;
|
|
|
|
//.......................................................................
|
|
|
|
}
|
|
|
|
// **************************************************************
|
|
|
|
// Broadcast simulation parameters from rank 0 to all other procs
|
2020-03-17 20:44:45 -05:00
|
|
|
MPI_Barrier(comm);
|
2018-03-19 12:58:25 -05:00
|
|
|
// Computational domain
|
2020-03-17 20:23:18 -05:00
|
|
|
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);
|
2018-03-19 12:58:25 -05:00
|
|
|
//.................................................
|
2020-03-17 20:44:45 -05:00
|
|
|
MPI_Barrier(comm);
|
2018-03-19 12:58:25 -05:00
|
|
|
|
|
|
|
// **************************************************************
|
|
|
|
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");
|
2018-03-23 08:13:04 -05:00
|
|
|
printf("Sub-domain size = %i x %i x %i\n",Nx,Ny,Nz);
|
2018-03-19 12:58:25 -05:00
|
|
|
printf("Parallel domain size = %i x %i x %i\n",nprocx,nprocy,nprocz);
|
|
|
|
printf("********************************************************\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialized domain and averaging framework for Two-Phase Flow
|
2018-05-17 20:03:11 -05:00
|
|
|
// Domain Dm(Nx,Ny,Nz,rank,nprocx,nprocy,nprocz,Lx,Ly,Lz,BC);
|
2018-05-19 06:49:32 -05:00
|
|
|
//Dm.CommInit();
|
2018-05-17 20:03:11 -05:00
|
|
|
//TwoPhase Averages(Dm);
|
2018-03-19 12:58:25 -05:00
|
|
|
|
2018-05-17 20:03:11 -05:00
|
|
|
std::shared_ptr<Domain> Dm (new Domain(Nx,Ny,Nz,rank,nprocx,nprocy,nprocz,Lx,Ly,Lz,BC));
|
2018-05-19 06:49:32 -05:00
|
|
|
Dm->CommInit();
|
2018-05-17 20:03:11 -05:00
|
|
|
std::shared_ptr<TwoPhase> Averages( new TwoPhase(Dm) );
|
|
|
|
|
2020-03-17 20:44:45 -05:00
|
|
|
MPI_Barrier(comm);
|
2018-03-19 12:58:25 -05:00
|
|
|
|
2018-03-23 08:13:04 -05:00
|
|
|
Nx += 2; Ny += 2; Nz += 2;
|
2018-03-19 12:58:25 -05:00
|
|
|
|
|
|
|
int N = Nx*Ny*Nz;
|
|
|
|
int dist_mem_size = N*sizeof(double);
|
|
|
|
|
|
|
|
//.......................................................................
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// printf("Local File Name = %s \n",LocalRankFilename);
|
|
|
|
// .......... READ THE INPUT FILE .......................................
|
|
|
|
// char value;
|
|
|
|
char *id;
|
|
|
|
id = new char[N];
|
|
|
|
int sum = 0;
|
|
|
|
double sum_local;
|
|
|
|
double iVol_global = 1.0/(1.0*(Nx-2)*(Ny-2)*(Nz-2)*nprocs);
|
|
|
|
//if (pBC) iVol_global = 1.0/(1.0*(Nx-2)*nprocx*(Ny-2)*nprocy*((Nz-2)*nprocz-6));
|
|
|
|
double pore_vol;
|
|
|
|
|
2018-03-19 13:03:11 -05:00
|
|
|
DoubleArray cylinders(7,ncyl); // (x, y, z, X, Y, Z, radius)
|
|
|
|
DoubleArray spheres(4,nsph); // ( x, y, z, radius)
|
|
|
|
|
|
|
|
// Read from text file
|
2018-03-21 14:13:45 -05:00
|
|
|
printf("Reading spheres \n");
|
2018-03-19 13:03:11 -05:00
|
|
|
ifstream SPHERES ( "spheres.csv" ); // declare file stream: http://www.cplusplus.com/reference/iostream/ifstream/
|
|
|
|
string value;
|
2018-03-21 10:47:50 -05:00
|
|
|
int index=0;
|
2018-03-21 14:13:45 -05:00
|
|
|
while ( index < nsph ) {
|
2018-03-21 10:47:50 -05:00
|
|
|
getline ( SPHERES, value, ' ' ); // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
|
2018-03-22 15:29:39 -05:00
|
|
|
spheres(0,index)=strtod(value.c_str(),NULL)*double(Nx-1)/Lx;
|
2018-03-21 10:47:50 -05:00
|
|
|
getline ( SPHERES, value, ' ' ); // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
|
2018-03-22 15:29:39 -05:00
|
|
|
spheres(1,index)=strtod(value.c_str(),NULL)*double(Nx-1)/Lx;
|
2018-03-21 10:47:50 -05:00
|
|
|
getline ( SPHERES, value, ' ' ); // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
|
2018-03-22 15:29:39 -05:00
|
|
|
spheres(2,index)=strtod(value.c_str(),NULL)*double(Nx-1)/Lx;
|
2018-03-21 14:13:45 -05:00
|
|
|
getline ( SPHERES, value ); // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
|
2018-03-22 15:29:39 -05:00
|
|
|
spheres(3,index)=strtod(value.c_str(),NULL)*double(Nx-1)/Lx;
|
2018-03-21 10:47:50 -05:00
|
|
|
printf("cx=%f,cy=%f,cz=%f,r=%f\n",spheres(0,index),spheres(1,index),spheres(2,index),spheres(3,index));
|
|
|
|
index++;
|
|
|
|
//cout << string( value, 1, value.length()-2 ); // display value removing the first and the last character from it
|
2018-03-19 13:03:11 -05:00
|
|
|
}
|
2018-03-19 12:58:25 -05:00
|
|
|
|
2018-03-22 15:24:17 -05:00
|
|
|
printf("Reading cylinders \n");
|
2018-03-21 14:13:45 -05:00
|
|
|
ifstream CYLINDERS ( "cylinders.csv" ); // declare file stream: http://www.cplusplus.com/reference/iostream/ifstream/
|
|
|
|
index=0;
|
|
|
|
while ( index < ncyl ) {
|
|
|
|
getline ( CYLINDERS, value, ' ' ); // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
|
2018-03-22 15:29:39 -05:00
|
|
|
cylinders(0,index)=strtod(value.c_str(),NULL)*double(Nx-1)/Lx;
|
2018-03-21 14:13:45 -05:00
|
|
|
getline ( CYLINDERS, value, ' ' ); // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
|
2018-03-22 15:29:39 -05:00
|
|
|
cylinders(1,index)=strtod(value.c_str(),NULL)*double(Nx-1)/Lx;
|
2018-03-21 14:13:45 -05:00
|
|
|
getline ( CYLINDERS, value, ' ' ); // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
|
2018-03-22 15:29:39 -05:00
|
|
|
cylinders(2,index)=strtod(value.c_str(),NULL)*double(Nx-1)/Lx;
|
2018-03-21 14:13:45 -05:00
|
|
|
getline ( CYLINDERS, value, ' ' ); // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
|
2018-03-22 15:29:39 -05:00
|
|
|
cylinders(3,index)=strtod(value.c_str(),NULL)*double(Nx-1)/Lx;
|
2018-03-21 14:13:45 -05:00
|
|
|
getline ( CYLINDERS, value, ' ' ); // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
|
2018-03-22 15:29:39 -05:00
|
|
|
cylinders(4,index)=strtod(value.c_str(),NULL)*double(Nx-1)/Lx;
|
2018-03-21 14:13:45 -05:00
|
|
|
getline ( CYLINDERS, value, ' ' ); // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
|
2018-03-22 15:29:39 -05:00
|
|
|
cylinders(5,index)=strtod(value.c_str(),NULL)*double(Nx-1)/Lx;
|
2018-03-21 14:13:45 -05:00
|
|
|
getline ( CYLINDERS, value ); // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
|
2018-03-22 15:29:39 -05:00
|
|
|
cylinders(6,index)=strtod(value.c_str(),NULL)*double(Nx-1)/Lx;
|
2018-03-21 14:13:45 -05:00
|
|
|
printf("x=%f,y=%f,z=%f,r=%f\n",cylinders(0,index),cylinders(1,index),cylinders(2,index),cylinders(6,index));
|
|
|
|
index++;
|
|
|
|
//cout << string( value, 1, value.length()-2 ); // display value removing the first and the last character from it
|
|
|
|
}
|
|
|
|
|
2018-03-22 15:32:14 -05:00
|
|
|
for (k=0;k<Nz;k++){
|
|
|
|
for (j=0;j<Ny;j++){
|
|
|
|
for (i=0;i<Nx;i++){
|
2018-05-17 20:03:11 -05:00
|
|
|
Averages->SDs(i,j,k) = -2.f*Nx;
|
2018-03-22 15:32:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-19 12:58:25 -05:00
|
|
|
sum=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;
|
|
|
|
|
|
|
|
// Compute the distance to each cylinder
|
|
|
|
for (int p=0; p<ncyl; p++){
|
2018-03-22 15:24:17 -05:00
|
|
|
double x = cylinders(0,p);
|
|
|
|
double y = cylinders(1,p);
|
|
|
|
double z = cylinders(2,p);
|
|
|
|
double X = cylinders(3,p);
|
|
|
|
double Y = cylinders(4,p);
|
|
|
|
double Z = cylinders(5,p);
|
|
|
|
double radius = cylinders(6,p);
|
2018-03-19 12:58:25 -05:00
|
|
|
double length = sqrt(x*x+y*y+z*z);
|
|
|
|
double alpha = (X - x)/length;
|
|
|
|
double beta = (Y - y)/length;
|
|
|
|
double gamma = (Z - z)/length;
|
|
|
|
double xi = double(i) - x;
|
|
|
|
double yj = double(j) - y;
|
|
|
|
double zk = double(k) - z;
|
|
|
|
// value of s along center line {x=alpha*s, y = beta*s, z=gamma*s} that is closest to i,j,k
|
|
|
|
double s = (alpha*xi + beta*yj + gamma*zk)/(alpha*alpha + beta*beta + gamma*gamma);
|
2018-05-17 20:03:11 -05:00
|
|
|
double distance=Averages->SDs(i,j,k);
|
2018-03-23 08:25:52 -05:00
|
|
|
if (s > length){
|
2018-04-26 10:03:22 -05:00
|
|
|
//distance = radius - sqrt((xi-X)*(xi-X) + (yj-Y)*(yj-Y) + (zk-Z)*(zk-Z));
|
2018-03-19 12:58:25 -05:00
|
|
|
}
|
2018-03-23 08:13:04 -05:00
|
|
|
else if (s<0){
|
2018-04-26 10:03:22 -05:00
|
|
|
//distance = radius - sqrt((xi-x)*(xi-x) + (yj-y)*(yj-y) + (zk-z)*(zk-z));
|
2018-03-19 12:58:25 -05:00
|
|
|
}
|
2018-03-23 08:25:52 -05:00
|
|
|
else{
|
2018-03-23 08:21:18 -05:00
|
|
|
double xs = alpha*s;
|
|
|
|
double ys = beta*s;
|
|
|
|
double zs = gamma*s;
|
2018-03-19 13:05:14 -05:00
|
|
|
distance = radius - sqrt((xi-xs)*(xi-xs) + (yj-ys)*(yj-ys) + (zk-zs)*(zk-zs));
|
2018-03-23 08:13:04 -05:00
|
|
|
//if (distance>0)printf("s=%f,alpha=%f,beta=%f,gamma=%f,distance=%f\n",s,alpha,beta,gamma,distance);
|
2018-03-23 08:25:52 -05:00
|
|
|
}
|
2018-05-17 20:03:11 -05:00
|
|
|
if (distance > Averages->SDs(i,j,k)) Averages->SDs(i,j,k) = distance;
|
2018-03-19 12:58:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the distance to each sphere
|
|
|
|
for (int p=0; p<nsph; p++){
|
2018-03-22 15:24:17 -05:00
|
|
|
double x = spheres(0,p);
|
|
|
|
double y = spheres(1,p);
|
|
|
|
double z = spheres(2,p);
|
|
|
|
double radius = spheres(3,p);
|
2018-03-19 12:58:25 -05:00
|
|
|
double xi = double(i);
|
|
|
|
double yj = double(j);
|
|
|
|
double zk = double(k);
|
|
|
|
|
|
|
|
double distance = radius - sqrt((xi-x)*(xi-x) + (yj-y)*(yj-y) + (zk-z)*(zk-z));
|
|
|
|
|
2018-05-17 20:03:11 -05:00
|
|
|
if (distance > Averages->SDs(i,j,k)) Averages->SDs(i,j,k) = distance;
|
2018-03-19 12:58:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
// Initialize phase positions
|
2018-05-17 20:03:11 -05:00
|
|
|
if (Averages->SDs(i,j,k) < 0.0){
|
2018-03-19 12:58:25 -05:00
|
|
|
id[n] = 0;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
id[n] = 2;
|
|
|
|
sum++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Compute the pore volume
|
|
|
|
sum_local = 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 (id[n] > 0){
|
|
|
|
sum_local += 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 20:23:18 -05:00
|
|
|
MPI_Allreduce(&sum_local,&pore_vol,1,MPI_DOUBLE,MPI_SUM,comm);
|
2018-03-22 15:20:05 -05:00
|
|
|
if (rank==0) printf("Pore volume = %f \n",pore_vol/double(Nx*Ny*Nz));
|
2018-03-19 12:58:25 -05:00
|
|
|
//.........................................................
|
|
|
|
// don't perform computations at the eight corners
|
|
|
|
id[0] = id[Nx-1] = id[(Ny-1)*Nx] = id[(Ny-1)*Nx + Nx-1] = 0;
|
|
|
|
id[(Nz-1)*Nx*Ny] = id[(Nz-1)*Nx*Ny+Nx-1] = id[(Nz-1)*Nx*Ny+(Ny-1)*Nx] = id[(Nz-1)*Nx*Ny+(Ny-1)*Nx + Nx-1] = 0;
|
|
|
|
//.........................................................
|
|
|
|
|
|
|
|
sprintf(LocalRankFilename,"SignDist.%05i",rank);
|
|
|
|
FILE *DIST = fopen(LocalRankFilename,"wb");
|
2018-05-17 20:03:11 -05:00
|
|
|
fwrite(Averages->SDs.data(),8,Averages->SDs.length(),DIST);
|
2018-03-19 12:58:25 -05:00
|
|
|
fclose(DIST);
|
|
|
|
|
|
|
|
sprintf(LocalRankFilename,"ID.%05i",rank);
|
|
|
|
FILE *ID = fopen(LocalRankFilename,"wb");
|
|
|
|
fwrite(id,1,N,ID);
|
|
|
|
fclose(ID);
|
|
|
|
|
|
|
|
}
|
|
|
|
// ****************************************************
|
2020-01-28 07:51:32 -06:00
|
|
|
comm.barrier();
|
2020-10-08 10:03:42 -05:00
|
|
|
Utilities::shutdown();
|
2018-03-19 12:58:25 -05:00
|
|
|
// ****************************************************
|
|
|
|
}
|