refactor Domain/color for reading input file sequence
This commit is contained in:
@@ -27,7 +27,7 @@ static inline void fgetl( char * str, int num, FILE * stream )
|
||||
********************************************************/
|
||||
Domain::Domain( int nx, int ny, int nz, int rnk, int npx, int npy, int npz,
|
||||
double lx, double ly, double lz, int BC):
|
||||
Nx(0), Ny(0), Nz(0),
|
||||
database(NULL), Nx(0), Ny(0), Nz(0),
|
||||
Lx(0), Ly(0), Lz(0), Volume(0), BoundaryCondition(0), voxel_length(1),
|
||||
Comm(MPI_COMM_WORLD),
|
||||
inlet_layers_x(0), inlet_layers_y(0), inlet_layers_z(0),
|
||||
@@ -73,7 +73,7 @@ Domain::Domain( int nx, int ny, int nz, int rnk, int npx, int npy, int npz,
|
||||
initialize( db );
|
||||
}
|
||||
Domain::Domain( std::shared_ptr<Database> db, MPI_Comm Communicator):
|
||||
Nx(0), Ny(0), Nz(0),
|
||||
database(db), Nx(0), Ny(0), Nz(0),
|
||||
Lx(0), Ly(0), Lz(0), Volume(0), BoundaryCondition(0),
|
||||
Comm(MPI_COMM_NULL),
|
||||
inlet_layers_x(0), inlet_layers_y(0), inlet_layers_z(0),
|
||||
@@ -226,7 +226,7 @@ void Domain::initialize( std::shared_ptr<Database> db )
|
||||
INSIST(nprocs == nproc[0]*nproc[1]*nproc[2],"Fatal error in processor count!");
|
||||
}
|
||||
|
||||
void Domain::Decomp(std::shared_ptr<Database> domain_db )
|
||||
void Domain::Decomp(std::string Filename)
|
||||
{
|
||||
//.......................................................................
|
||||
// Reading the domain information file
|
||||
@@ -251,38 +251,38 @@ void Domain::Decomp(std::shared_ptr<Database> domain_db )
|
||||
checkerSize = 32;
|
||||
|
||||
// Read domain parameters
|
||||
auto Filename = domain_db->getScalar<std::string>( "Filename" );
|
||||
//auto L = domain_db->getVector<double>( "L" );
|
||||
auto size = domain_db->getVector<int>( "n" );
|
||||
auto SIZE = domain_db->getVector<int>( "N" );
|
||||
auto nproc = domain_db->getVector<int>( "nproc" );
|
||||
if (domain_db->keyExists( "offset" )){
|
||||
auto offset = domain_db->getVector<int>( "offset" );
|
||||
//auto Filename = database->getScalar<std::string>( "Filename" );
|
||||
//auto L = database->getVector<double>( "L" );
|
||||
auto size = database->getVector<int>( "n" );
|
||||
auto SIZE = database->getVector<int>( "N" );
|
||||
auto nproc = database->getVector<int>( "nproc" );
|
||||
if (database->keyExists( "offset" )){
|
||||
auto offset = database->getVector<int>( "offset" );
|
||||
xStart = offset[0];
|
||||
yStart = offset[1];
|
||||
zStart = offset[2];
|
||||
}
|
||||
if (domain_db->keyExists( "InletLayers" )){
|
||||
auto InletCount = domain_db->getVector<int>( "InletLayers" );
|
||||
if (database->keyExists( "InletLayers" )){
|
||||
auto InletCount = database->getVector<int>( "InletLayers" );
|
||||
inlet_layers_x = InletCount[0];
|
||||
inlet_layers_y = InletCount[1];
|
||||
inlet_layers_z = InletCount[2];
|
||||
}
|
||||
if (domain_db->keyExists( "OutletLayers" )){
|
||||
auto OutletCount = domain_db->getVector<int>( "OutletLayers" );
|
||||
if (database->keyExists( "OutletLayers" )){
|
||||
auto OutletCount = database->getVector<int>( "OutletLayers" );
|
||||
outlet_layers_x = OutletCount[0];
|
||||
outlet_layers_y = OutletCount[1];
|
||||
outlet_layers_z = OutletCount[2];
|
||||
}
|
||||
if (domain_db->keyExists( "checkerSize" )){
|
||||
checkerSize = domain_db->getScalar<int>( "checkerSize" );
|
||||
if (database->keyExists( "checkerSize" )){
|
||||
checkerSize = database->getScalar<int>( "checkerSize" );
|
||||
}
|
||||
else {
|
||||
checkerSize = SIZE[0];
|
||||
}
|
||||
auto ReadValues = domain_db->getVector<int>( "ReadValues" );
|
||||
auto WriteValues = domain_db->getVector<int>( "WriteValues" );
|
||||
auto ReadType = domain_db->getScalar<std::string>( "ReadType" );
|
||||
auto ReadValues = database->getVector<int>( "ReadValues" );
|
||||
auto WriteValues = database->getVector<int>( "WriteValues" );
|
||||
auto ReadType = database->getScalar<std::string>( "ReadType" );
|
||||
|
||||
if (ReadType == "8bit"){
|
||||
}
|
||||
|
||||
@@ -107,6 +107,7 @@ private:
|
||||
|
||||
public: // Public variables (need to create accessors instead)
|
||||
|
||||
std::shared_ptr<Database> database;
|
||||
double Lx,Ly,Lz,Volume,voxel_length;
|
||||
int Nx,Ny,Nz,N;
|
||||
int inlet_layers_x, inlet_layers_y, inlet_layers_z;
|
||||
@@ -175,7 +176,7 @@ public: // Public variables (need to create accessors instead)
|
||||
signed char *id;
|
||||
|
||||
void ReadIDs();
|
||||
void Decomp(std::shared_ptr<Database> domain_db);
|
||||
void Decomp(std::string Filename);
|
||||
void CommunicateMeshHalo(DoubleArray &Mesh);
|
||||
void CommInit();
|
||||
int PoreCount();
|
||||
|
||||
@@ -152,19 +152,19 @@ void ScaLBL_ColorModel::SetDomain(){
|
||||
|
||||
void ScaLBL_ColorModel::ReadInput(){
|
||||
|
||||
if (domain_db->keyExists( "Filename" )){
|
||||
Mask->Decomp(domain_db);
|
||||
}
|
||||
else{
|
||||
size_t readID;
|
||||
Mask->ReadIDs();
|
||||
}
|
||||
for (int i=0; i<Nx*Ny*Nz; i++) id[i] = Mask->id[i]; // save what was read
|
||||
|
||||
sprintf(LocalRankString,"%05d",rank);
|
||||
sprintf(LocalRankFilename,"%s%s","ID.",LocalRankString);
|
||||
sprintf(LocalRestartFile,"%s%s","Restart.",LocalRankString);
|
||||
|
||||
if (domain_db->keyExists( "Filename" )){
|
||||
auto Filename = domain_db->getScalar<std::string>( "Filename" );
|
||||
Mask->Decomp(Filename);
|
||||
}
|
||||
else{
|
||||
Mask->ReadIDs();
|
||||
}
|
||||
for (int i=0; i<Nx*Ny*Nz; i++) id[i] = Mask->id[i]; // save what was read
|
||||
|
||||
// Generate the signed distance map
|
||||
// Initialize the domain and communication
|
||||
Array<char> id_solid(Nx,Ny,Nz);
|
||||
@@ -880,6 +880,48 @@ void ScaLBL_ColorModel::Run(){
|
||||
// ************************************************************************
|
||||
}
|
||||
|
||||
double ScaLBL_ColorModel::ImageInit(std::string Filename){
|
||||
|
||||
bool suppress = false;
|
||||
if (rank==0) printf("Re-initializing fluids from file: %s \n", Filename);
|
||||
Mask->Decomp(Filename);
|
||||
for (int i=0; i<Nx*Ny*Nz; i++) id[i] = Mask->id[i]; // save what was read
|
||||
|
||||
double *PhaseLabel;
|
||||
PhaseLabel = new double[N];
|
||||
AssignComponentLabels(PhaseLabel);
|
||||
|
||||
// consistency check
|
||||
double Count = 0.0;
|
||||
double PoreCount = 0.0;
|
||||
for (int k=0; k<Nz; k++){
|
||||
for (int j=0; j<Ny; j++){
|
||||
for (int i=0; i<Nx; i++){
|
||||
double distance = Averages->SDs(i,j,k);
|
||||
if (distance > 0.0){
|
||||
if (id[Nx*Ny*k+Nx*j+i] == 2){
|
||||
PoreCount++;
|
||||
Count++;
|
||||
}
|
||||
else if (id[Nx*Ny*k+Nx*j+i] == 1){
|
||||
PoreCount++;
|
||||
}
|
||||
else if (suppress == false){
|
||||
printf("WARNING (ScaLBLColorModel::ImageInit) image input file sequence may not be labeled correctly (rank=%i) \n",rank);
|
||||
suppress = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Count=sumReduce( Dm->Comm, Count);
|
||||
PoreCount=sumReduce( Dm->Comm, PoreCount);
|
||||
|
||||
ScaLBL_CopyToDevice(Phi, PhaseLabel, N*sizeof(double));
|
||||
MPI_Barrier(comm);
|
||||
|
||||
}
|
||||
|
||||
double ScaLBL_ColorModel::MorphOpenConnected(double target_volume_change){
|
||||
|
||||
int nx = Nx;
|
||||
|
||||
@@ -79,6 +79,7 @@ private:
|
||||
//int rank,nprocs;
|
||||
void LoadParams(std::shared_ptr<Database> db0);
|
||||
void AssignComponentLabels(double *phase);
|
||||
double ImageInit(std::string filename);
|
||||
double MorphInit(const double beta, const double morph_delta);
|
||||
double SeedPhaseField(const double seed_water_in_oil);
|
||||
double MorphOpenConnected(double target_volume_change);
|
||||
|
||||
Reference in New Issue
Block a user