done cleaning up the code

This commit is contained in:
Rex Zhe Li 2020-08-19 22:22:35 -04:00
parent d8a1837ba0
commit d24198e76a
4 changed files with 110 additions and 88 deletions

View File

@ -596,15 +596,15 @@ void ScaLBL_GreyscaleColorModel::AssignGreyPoroPermLabels()
if (rank==0){ if (rank==0){
printf("Image resolution: %.5g [um/voxel]\n",Dm->voxel_length); printf("Image resolution: %.5g [um/voxel]\n",Dm->voxel_length);
printf("Number of component labels: %lu \n",NLABELS); printf("Number of Grey-fluid labels: %lu \n",NLABELS);
for (unsigned int idx=0; idx<NLABELS; idx++){ for (unsigned int idx=0; idx<NLABELS; idx++){
VALUE=LabelList[idx]; VALUE=LabelList[idx];
POROSITY=PorosityList[idx]; POROSITY=PorosityList[idx];
PERMEABILITY=PermeabilityList[idx]; PERMEABILITY=PermeabilityList[idx];
double volume_fraction = double(label_count_global[idx])/double((Nx-2)*(Ny-2)*(Nz-2)*nprocs); double volume_fraction = double(label_count_global[idx])/double((Nx-2)*(Ny-2)*(Nz-2)*nprocs);
printf(" label=%d: porosity=%.3g, permeability=%.3g [um^2] (=%.3g [voxel^2]), volume fraction=%.3g\n", printf(" grey-fluid label=%d, porosity=%.3g, permeability=%.3g [um^2] (=%.3g [voxel^2]), volume fraction=%.3g\n",
VALUE,POROSITY,PERMEABILITY,PERMEABILITY/Dm->voxel_length/Dm->voxel_length,volume_fraction); VALUE,POROSITY,PERMEABILITY,PERMEABILITY/Dm->voxel_length/Dm->voxel_length,volume_fraction);
printf(" effective porosity=%.3g\n",volume_fraction*POROSITY); printf(" effective porosity=%.3g\n",volume_fraction*POROSITY);
} }
printf("The weighted porosity, considering both open and grey voxels, is %.3g\n",GreyPorosity); printf("The weighted porosity, considering both open and grey voxels, is %.3g\n",GreyPorosity);
} }

View File

@ -274,7 +274,7 @@ void ScaLBL_GreyscaleModel::AssignComponentLabels(double *Porosity, double *Perm
if (rank==0){ if (rank==0){
printf("Image resolution: %.5g [um/voxel]\n",Dm->voxel_length); printf("Image resolution: %.5g [um/voxel]\n",Dm->voxel_length);
printf("Component labels: %lu \n",NLABELS); printf("Number of component labels: %lu \n",NLABELS);
for (unsigned int idx=0; idx<NLABELS; idx++){ for (unsigned int idx=0; idx<NLABELS; idx++){
VALUE=LabelList[idx]; VALUE=LabelList[idx];
POROSITY=PorosityList[idx]; POROSITY=PorosityList[idx];

View File

@ -6,53 +6,66 @@
#include <stdexcept> #include <stdexcept>
#include <fstream> #include <fstream>
#include "common/ScaLBL.h"
#include "common/Communication.h"
#include "common/MPI.h"
#include "models/GreyscaleColorModel.h" #include "models/GreyscaleColorModel.h"
#include "common/Utilities.h"
//#define WRITE_SURFACES //#define WRITE_SURFACES
//*************************************************************************
// Implementation of Greyscale Two-Fluid Color LBM using CUDA
//*************************************************************************
using namespace std; using namespace std;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
//*****************************************
// ***** MPI STUFF ****************
//*****************************************
// Initialize MPI
int rank,nprocs;
MPI_Init(&argc,&argv);
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Comm_rank(comm,&rank);
MPI_Comm_size(comm,&nprocs);
{
// parallel domain size (# of sub-domains)
int nprocx,nprocy,nprocz;
int iproc,jproc,kproc;
if (rank == 0){ // Initialize MPI and error handlers
printf("****************************************\n"); Utilities::startup( argc, argv );
printf("Running Greyscale Two-Phase Calculation \n");
printf("****************************************\n"); { // Limit scope so variables that contain communicators will free before MPI_Finialize
}
// Initialize compute device MPI_Comm comm;
int device=ScaLBL_SetDevice(rank); MPI_Comm_dup(MPI_COMM_WORLD,&comm);
ScaLBL_DeviceBarrier(); int rank = comm_rank(comm);
MPI_Barrier(comm); int nprocs = comm_size(comm);
ScaLBL_GreyscaleColorModel GreyscaleColor(rank,nprocs,comm); if (rank == 0){
auto filename = argv[1]; printf("****************************************\n");
GreyscaleColor.ReadParams(filename); printf("Running Greyscale Two-Phase Calculation \n");
GreyscaleColor.SetDomain(); // this reads in the domain printf("****************************************\n");
GreyscaleColor.ReadInput(); }
GreyscaleColor.Create(); // creating the model will create data structure to match the pore structure and allocate variables // Initialize compute device
GreyscaleColor.Initialize(); // initializing the model will set initial conditions for variables ScaLBL_SetDevice(rank);
GreyscaleColor.Run(); ScaLBL_DeviceBarrier();
GreyscaleColor.WriteDebug(); MPI_Barrier(comm);
}
// **************************************************** PROFILE_ENABLE(1);
MPI_Barrier(comm); //PROFILE_ENABLE_TRACE();
MPI_Finalize(); //PROFILE_ENABLE_MEMORY();
// **************************************************** PROFILE_SYNCHRONIZE();
PROFILE_START("Main");
Utilities::setErrorHandlers();
auto filename = argv[1];
ScaLBL_GreyscaleColorModel GreyscaleColor(rank,nprocs,comm);
GreyscaleColor.ReadParams(filename);
GreyscaleColor.SetDomain();
GreyscaleColor.ReadInput();
GreyscaleColor.Create(); // creating the model will create data structure to match the pore structure and allocate variables
GreyscaleColor.Initialize(); // initializing the model will set initial conditions for variables
GreyscaleColor.Run();
GreyscaleColor.WriteDebug();
PROFILE_STOP("Main");
PROFILE_SAVE("lbpm_greyscaleColor_simulator",1);
// ****************************************************
MPI_Barrier(comm);
MPI_Comm_free(&comm);
} // Limit scope so variables that contain communicators will free before MPI_Finialize
Utilities::shutdown();
} }

View File

@ -6,58 +6,67 @@
#include <stdexcept> #include <stdexcept>
#include <fstream> #include <fstream>
#include "common/ScaLBL.h"
#include "common/Communication.h"
#include "common/MPI_Helpers.h"
#include "models/GreyscaleModel.h" #include "models/GreyscaleModel.h"
#include "common/Utilities.h"
//#define WRITE_SURFACES //#define WRITE_SURFACES
/* //****************************************************************
* Simulator for two-phase flow in porous media // Implementation of Greyscale Single-Fluid LBM using CUDA
* James E. McClure 2013-2014 //****************************************************************
*/
using namespace std; using namespace std;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
//*****************************************
// ***** MPI STUFF ****************
//*****************************************
// Initialize MPI
int rank,nprocs;
MPI_Init(&argc,&argv);
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Comm_rank(comm,&rank);
MPI_Comm_size(comm,&nprocs);
{
// parallel domain size (# of sub-domains)
if (rank == 0){ // Initialize MPI and error handlers
printf("********************************************************\n"); Utilities::startup( argc, argv );
printf("Running Greyscale Single Phase Permeability Calculation \n");
printf("********************************************************\n"); { // Limit scope so variables that contain communicators will free before MPI_Finialize
}
// Initialize compute device MPI_Comm comm;
int device=ScaLBL_SetDevice(rank); MPI_Comm_dup(MPI_COMM_WORLD,&comm);
NULL_USE(device); int rank = comm_rank(comm);
ScaLBL_DeviceBarrier(); int nprocs = comm_size(comm);
MPI_Barrier(comm);
if (rank == 0){
ScaLBL_GreyscaleModel Greyscale(rank,nprocs,comm); printf("********************************************************\n");
auto filename = argv[1]; printf("Running Greyscale Single Phase Permeability Calculation \n");
Greyscale.ReadParams(filename); printf("********************************************************\n");
Greyscale.SetDomain(); // this reads in the domain }
Greyscale.ReadInput(); // Initialize compute device
Greyscale.Create(); // creating the model will create data structure to match the pore structure and allocate variables ScaLBL_SetDevice(rank);
Greyscale.Initialize(); // initializing the model will set initial conditions for variables ScaLBL_DeviceBarrier();
Greyscale.Run(); MPI_Barrier(comm);
Greyscale.VelocityField();
//Greyscale.WriteDebug(); PROFILE_ENABLE(1);
} //PROFILE_ENABLE_TRACE();
// **************************************************** //PROFILE_ENABLE_MEMORY();
MPI_Barrier(comm); PROFILE_SYNCHRONIZE();
MPI_Finalize(); PROFILE_START("Main");
// **************************************************** Utilities::setErrorHandlers();
auto filename = argv[1];
ScaLBL_GreyscaleModel Greyscale(rank,nprocs,comm);
Greyscale.ReadParams(filename);
Greyscale.SetDomain();
Greyscale.ReadInput();
Greyscale.Create(); // creating the model will create data structure to match the pore structure and allocate variables
Greyscale.Initialize(); // initializing the model will set initial conditions for variables
Greyscale.Run();
Greyscale.VelocityField();
//Greyscale.WriteDebug();
PROFILE_STOP("Main");
PROFILE_SAVE("lbpm_greyscale_simulator",1);
// ****************************************************
MPI_Barrier(comm);
MPI_Comm_free(&comm);
} // Limit scope so variables that contain communicators will free before MPI_Finialize
Utilities::shutdown();
} }