add a routine for single-fluid greyscale to read from file - voxel porosity and perm

This commit is contained in:
Rex Zhe Li
2020-09-24 21:57:04 -04:00
parent 471f71d690
commit 33fdfeb29d
3 changed files with 29 additions and 26 deletions

View File

@@ -1289,7 +1289,7 @@ void ReadBinaryFile(char *FILENAME, double *Data, size_t N)
}
void ReadFromFile(const std::string& Filename,const std::string& Datatype, double *UserData)
void Domain::ReadFromFile(const std::string& Filename,const std::string& Datatype, double *UserData)
{
//........................................................................................
// Reading the user-defined input file
@@ -1306,8 +1306,8 @@ void ReadFromFile(const std::string& Filename,const std::string& Datatype, doubl
int64_t global_Nx,global_Ny,global_Nz;
int64_t i,j,k,n;
//TODO These offset we may still need them
//int64_t xStart,yStart,zStart;
//xStart=yStart=zStart=0;
int64_t xStart,yStart,zStart;
xStart=yStart=zStart=0;
// Read domain parameters
// TODO currently the size of the data is still read from Domain{};
@@ -1316,12 +1316,12 @@ void ReadFromFile(const std::string& Filename,const std::string& Datatype, doubl
auto SIZE = database->getVector<int>( "N" );
auto nproc = database->getVector<int>( "nproc" );
//TODO currently the funcationality "offset" is disabled as the user-defined input data may have a different size from that of the input domain
//if (database->keyExists( "offset" )){
// auto offset = database->getVector<int>( "offset" );
// xStart = offset[0];
// yStart = offset[1];
// zStart = offset[2];
//}
if (database->keyExists( "offset" )){
auto offset = database->getVector<int>( "offset" );
xStart = offset[0];
yStart = offset[1];
zStart = offset[2];
}
nx = size[0];
ny = size[1];
@@ -1334,7 +1334,6 @@ void ReadFromFile(const std::string& Filename,const std::string& Datatype, doubl
global_Nz = SIZE[2];
nprocs=nprocx*nprocy*nprocz;
auto ReadType = Datatype.c_str();
double *SegData = NULL;
if (RANK==0){
printf("User-defined input file: %s (data type: %s)\n",Filename.c_str(),Datatype.c_str());
@@ -1343,11 +1342,11 @@ void ReadFromFile(const std::string& Filename,const std::string& Datatype, doubl
printf("Dimensions of the user-defined input file: %ld x %ld x %ld \n",global_Nx,global_Ny,global_Nz);
int64_t SIZE = global_Nx*global_Ny*global_Nz;
if (ReadType == "double"){
if (Datatype == "double"){
printf("Reading input data as double precision floating number\n");
SegData = new double[SIZE];
FILE *SEGDAT = fopen(Filename.c_str(),"rb");
if (SEGDAT==NULL) ERROR("Domain.cpp: Error reading file: %s\n",Filename.c_str());
if (SEGDAT==NULL) ERROR("Domain.cpp: Error reading user-defined file!\n");
size_t ReadSeg;
ReadSeg=fread(SegData,8,SIZE,SEGDAT);
if (ReadSeg != size_t(SIZE)) printf("Domain.cpp: Error reading file: %s\n",Filename.c_str());
@@ -1367,7 +1366,7 @@ void ReadFromFile(const std::string& Filename,const std::string& Datatype, doubl
//if (z_transition_size < 0) z_transition_size=0;
int64_t z_transition_size = 0;
char LocalRankFilename[40];//just for debug
//char LocalRankFilename[1000];//just for debug
double *loc_id;
loc_id = new double [(nx+2)*(ny+2)*(nz+2)];
@@ -1420,10 +1419,10 @@ void ReadFromFile(const std::string& Filename,const std::string& Datatype, doubl
}
// Write the data for this rank data
// NOTE just for debug
sprintf(LocalRankFilename,"%s.%05i",Filename.c_str(),rnk+rank_offset);
FILE *ID = fopen(LocalRankFilename,"wb");
fwrite(loc_id,1,(nx+2)*(ny+2)*(nz+2),ID);
fclose(ID);
//sprintf(LocalRankFilename,"%s.%05i",Filename.c_str(),rnk+rank_offset);
//FILE *ID = fopen(LocalRankFilename,"wb");
//fwrite(loc_id,8,(nx+2)*(ny+2)*(nz+2),ID);
//fclose(ID);
}
}
}

View File

@@ -178,6 +178,7 @@ public: // Public variables (need to create accessors instead)
void ReadIDs();
void Decomp( const std::string& filename );
void ReadFromFile(const std::string& Filename,const std::string& Datatype, double *UserData);
void CommunicateMeshHalo(DoubleArray &Mesh);
void CommInit();
int PoreCount();
@@ -244,7 +245,7 @@ private:
};
void ReadFromFile(const std::string& Filename,const std::string& Datatype, double *UserData);
//void ReadFromFile(const std::string& Filename,const std::string& Datatype, double *UserData);
//void ReadFromFile(const std::string& Filename, DoubleArray &Mesh);
void WriteCheckpoint(const char *FILENAME, const double *cDen, const double *cfq, size_t Np);

View File

@@ -290,18 +290,19 @@ void ScaLBL_GreyscaleModel::AssignComponentLabels(double *Porosity, double *Perm
void ScaLBL_GreyscaleModel::AssignComponentLabels(double *Porosity,double *Permeability,const vector<std::string> &File_poro,const vector<std::string> &File_perm)
{
double *Porosity_host, Permeability_host;
double *Porosity_host, *Permeability_host;
Porosity_host = new double[N];
Permeability_host = new double[N];
double POROSITY=0.f;
double PERMEABILITY=0.f;
//Initialize a weighted porosity after considering grey voxels
double GreyPorosity=0.0;
double GreyPorosity_loc=0.0;
GreyPorosity=0.0;
//double label_count_loc = 0.0;
//double label_count_glb = 0.0;
ReadFromFile(File_poro[0],File_poro[1],Porosity_host);
ReadFromFile(File_perm[0],File_perm[1],Permeability_host);
Mask->ReadFromFile(File_poro[0],File_poro[1],Porosity_host);
Mask->ReadFromFile(File_perm[0],File_perm[1],Permeability_host);
for (int k=0;k<Nz;k++){
for (int j=0;j<Ny;j++){
@@ -320,20 +321,22 @@ void ScaLBL_GreyscaleModel::AssignComponentLabels(double *Porosity,double *Perme
else{
Porosity[idx] = POROSITY;
Permeability[idx] = PERMEABILITY;
GreyPorosity += POROSITY;
GreyPorosity_loc += POROSITY;
//label_count_loc += 1.0;
}
}
}
}
}
//label_count_global = sumReduce( Dm->Comm, label_count_loc);
GreyPorosity = sumReduce( Dm->Comm, GreyPorosity_loc);
GreyPorosity = GreyPorosity/double((Nx-2)*(Ny-2)*(Nz-2)*nprocs);
if (rank==0){
printf("Image resolution: %.5g [um/voxel]\n",Dm->voxel_length);
printf("The weighted porosity, considering both open and grey voxels, is %.3g\n",GreyPorosity);
}
delete [] Porosity_host;
delete [] Permeability_host;
}
void ScaLBL_GreyscaleModel::Create(){
@@ -390,8 +393,8 @@ void ScaLBL_GreyscaleModel::Create(){
Perm = new double[Np];
if (greyscale_db->keyExists("FileVoxelPorosityMap")){
//NOTE: FileVoxel**Map is a vector, including "file_name, datatype"
auto File_poro = domain_db->getVector<std::string>( "FileVoxelPorosityMap" );
auto File_perm = domain_db->getVector<std::string>( "FileVoxelPermeabilityMap" );
auto File_poro = greyscale_db->getVector<std::string>( "FileVoxelPorosityMap" );
auto File_perm = greyscale_db->getVector<std::string>( "FileVoxelPermeabilityMap" );
AssignComponentLabels(Poros,Perm,File_poro,File_perm);
}
else if (greyscale_db->keyExists("PorosityList")){