diff --git a/CMakeLists.txt b/CMakeLists.txt index 31518d86..c9b7e66a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,7 @@ SET( TEST_MAX_PROCS 16 ) # Initialize the project -PROJECT( ${PROJ} LANGUAGES CXX ) - +PROJECT( ${PROJ} LANGUAGES CXX) # Prevent users from building in place IF ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}" ) diff --git a/analysis/ElectroChemistry.cpp b/analysis/ElectroChemistry.cpp index 2a0b7169..dc932f91 100644 --- a/analysis/ElectroChemistry.cpp +++ b/analysis/ElectroChemistry.cpp @@ -53,19 +53,32 @@ void ElectroChemistryAnalyzer::Basic(ScaLBL_IonModel &Ion, ScaLBL_Poisson &Poiss Poisson.getElectricPotential(ElectricalPotential); /* local sub-domain averages */ - double rho_avg_local[Ion.number_ion_species]; - double rho_mu_avg_local[Ion.number_ion_species]; - double rho_mu_fluctuation_local[Ion.number_ion_species]; - double rho_psi_avg_local[Ion.number_ion_species]; - double rho_psi_fluctuation_local[Ion.number_ion_species]; + double *rho_avg_local; + double *rho_mu_avg_local; + double *rho_mu_fluctuation_local; + double *rho_psi_avg_local; + double *rho_psi_fluctuation_local; /* global averages */ - double rho_avg_global[Ion.number_ion_species]; - double rho_mu_avg_global[Ion.number_ion_species]; - double rho_mu_fluctuation_global[Ion.number_ion_species]; - double rho_psi_avg_global[Ion.number_ion_species]; - double rho_psi_fluctuation_global[Ion.number_ion_species]; + double *rho_avg_global; + double *rho_mu_avg_global; + double *rho_mu_fluctuation_global; + double *rho_psi_avg_global; + double *rho_psi_fluctuation_global; - for (int ion=0; ionrank()==0){ fprintf(TIMELOG,"%i ",timestep); - for (int ion=0; ion( Dm->rank_info,Dm->Nx-2,Dm->Ny-2,Dm->Nz-2,Dm->Lx,Dm->Ly,Dm->Lz ); auto ElectricPotential = std::make_shared(); std::vector> IonConcentration; - for (int ion=0; ion()); } auto VxVar = std::make_shared(); @@ -163,8 +176,8 @@ void ElectroChemistryAnalyzer::WriteVis( ScaLBL_IonModel &Ion, ScaLBL_Poisson &P } if (vis_db->getWithDefault( "save_concentration", true )){ - for (int ion=0; ionname = VisName; IonConcentration[ion]->type = IO::VariableType::VolumeVariable; IonConcentration[ion]->dim = 1; @@ -199,8 +212,8 @@ void ElectroChemistryAnalyzer::WriteVis( ScaLBL_IonModel &Ion, ScaLBL_Poisson &P } if (vis_db->getWithDefault( "save_concentration", true )){ - for (int ion=0; ionname = VisName; ASSERT(visData[0].vars[1+ion]->name==VisName); Array& IonConcentrationData = visData[0].vars[1+ion]->data; diff --git a/analysis/FreeEnergy.cpp b/analysis/FreeEnergy.cpp index 6a641a95..b49f2ec5 100644 --- a/analysis/FreeEnergy.cpp +++ b/analysis/FreeEnergy.cpp @@ -47,8 +47,6 @@ void FreeEnergyAnalyzer::SetParams(){ void FreeEnergyAnalyzer::Basic(ScaLBL_FreeLeeModel &LeeModel, int timestep){ - int i,j,k; - if (Dm->rank()==0){ fprintf(TIMELOG,"%i ",timestep); /*for (int ion=0; ion input_db, int timestep){ auto vis_db = input_db->getDatabase( "Visualization" ); - char VisName[40]; std::vector visData; fillHalo fillData(Dm->Comm,Dm->rank_info,{Dm->Nx-2,Dm->Ny-2,Dm->Nz-2},{1,1,1},0,1); diff --git a/analysis/morphology.cpp b/analysis/morphology.cpp index 324c45cb..4b023db6 100644 --- a/analysis/morphology.cpp +++ b/analysis/morphology.cpp @@ -120,6 +120,7 @@ double MorphOpen(DoubleArray &SignDist, signed char *id, std::shared_ptr sendtag = recvtag = 7; int ii,jj,kk; + int imin,jmin,kmin,imax,jmax,kmax; int Nx = nx; int Ny = ny; int Nz = nz; @@ -128,17 +129,13 @@ double MorphOpen(DoubleArray &SignDist, signed char *id, std::shared_ptr double void_fraction_new=1.0; double void_fraction_diff_old = 1.0; double void_fraction_diff_new = 1.0; - - // Increase the critical radius until the target saturation is met - double deltaR=0.05; // amount to change the radius in voxel units - double Rcrit_old; - - int imin,jmin,kmin,imax,jmax,kmax; - if (ErodeLabel == 1){ VoidFraction = 1.0 - VoidFraction; } + // Increase the critical radius until the target saturation is met + double deltaR=0.05; // amount to change the radius in voxel units + double Rcrit_old = maxdistGlobal; double Rcrit_new = maxdistGlobal; while (void_fraction_new > VoidFraction) @@ -406,6 +403,7 @@ double MorphDrain(DoubleArray &SignDist, signed char *id, std::shared_ptr2){ // Rcrit_new = strtod(argv[2],NULL); @@ -457,7 +452,6 @@ double MorphDrain(DoubleArray &SignDist, signed char *id, std::shared_ptrComm.dup(); d_Np = ColorModel.Np; - bool Regular = false; auto input_db = ColorModel.db; auto db = input_db->getDatabase( "Analysis" ); diff --git a/common/ScaLBL.cpp b/common/ScaLBL.cpp index fa3ecc74..dcb99a47 100644 --- a/common/ScaLBL.cpp +++ b/common/ScaLBL.cpp @@ -1062,29 +1062,28 @@ void ScaLBL_Communicator::SetupBounceBackList(IntArray &Map, signed char *id, in } } } - + int *bb_dist_tmp = new int [local_count]; int *bb_interactions_tmp = new int [local_count]; ScaLBL_AllocateDeviceMemory((void **) &bb_dist, sizeof(int)*local_count); ScaLBL_AllocateDeviceMemory((void **) &bb_interactions, sizeof(int)*local_count); - int *fluid_boundary_tmp; - double *lattice_weight_tmp; - float *lattice_cx_tmp; - float *lattice_cy_tmp; - float *lattice_cz_tmp; - if(SlippingVelBC==true){ - fluid_boundary_tmp = new int [local_count]; - lattice_weight_tmp = new double [local_count]; - lattice_cx_tmp = new float [local_count]; - lattice_cy_tmp = new float [local_count]; - lattice_cz_tmp = new float [local_count]; - ScaLBL_AllocateDeviceMemory((void **) &fluid_boundary, sizeof(int)*local_count); - ScaLBL_AllocateDeviceMemory((void **) &lattice_weight, sizeof(double)*local_count); - ScaLBL_AllocateDeviceMemory((void **) &lattice_cx, sizeof(float)*local_count); - ScaLBL_AllocateDeviceMemory((void **) &lattice_cy, sizeof(float)*local_count); - ScaLBL_AllocateDeviceMemory((void **) &lattice_cz, sizeof(float)*local_count); - } - + int *fluid_boundary_tmp; + double *lattice_weight_tmp; + float *lattice_cx_tmp; + float *lattice_cy_tmp; + float *lattice_cz_tmp; + /* allocate memory for bounce-back sites */ + fluid_boundary_tmp = new int [local_count]; + lattice_weight_tmp = new double [local_count]; + lattice_cx_tmp = new float [local_count]; + lattice_cy_tmp = new float [local_count]; + lattice_cz_tmp = new float [local_count]; + ScaLBL_AllocateDeviceMemory((void **) &fluid_boundary, sizeof(int)*local_count); + ScaLBL_AllocateDeviceMemory((void **) &lattice_weight, sizeof(double)*local_count); + ScaLBL_AllocateDeviceMemory((void **) &lattice_cx, sizeof(float)*local_count); + ScaLBL_AllocateDeviceMemory((void **) &lattice_cy, sizeof(float)*local_count); + ScaLBL_AllocateDeviceMemory((void **) &lattice_cz, sizeof(float)*local_count); + local_count=0; for (k=1;k. */ extern "C" void ScaLBL_D3Q19_AAeven_BGK(double *dist, int start, int finish, int Np, double rlx, double Fx, double Fy, double Fz){ - int n; // conserved momemnts double rho,ux,uy,uz,uu; // non-conserved moments @@ -127,14 +126,12 @@ extern "C" void ScaLBL_D3Q19_AAeven_BGK(double *dist, int start, int finish, int } extern "C" void ScaLBL_D3Q19_AAodd_BGK(int *neighborList, double *dist, int start, int finish, int Np, double rlx, double Fx, double Fy, double Fz){ - int n; // conserved momemnts double rho,ux,uy,uz,uu; // non-conserved moments double f0,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18; int nr1,nr2,nr3,nr4,nr5,nr6,nr7,nr8,nr9,nr10,nr11,nr12,nr13,nr14,nr15,nr16,nr17,nr18; - int nread; for (int n=start; nkeyExists( "BC" )){ BoundaryCondition = domain_db->getScalar( "BC" ); } + if (domain_db->keyExists( "InletLayersPhase" )){ + int inlet_layers_phase = domain_db->getScalar( "InletLayersPhase" ); + if (inlet_layers_phase == 2 ) { + inletA = 0.0; + inletB = 1.0; + } + } + if (domain_db->keyExists( "OutletLayersPhase" )){ + int outlet_layers_phase = domain_db->getScalar( "OutletLayersPhase" ); + if (outlet_layers_phase == 1 ) { + inletA = 1.0; + inletB = 0.0; + } + } // Override user-specified boundary condition for specific protocols auto protocol = color_db->getWithDefault( "protocol", "none" ); @@ -192,6 +206,21 @@ void ScaLBL_ColorModel::ReadParams(string filename){ } domain_db->putScalar( "BC", BoundaryCondition ); } + else if (protocol == "centrifuge"){ + if (BoundaryCondition != 3 ){ + BoundaryCondition = 3; + if (rank==0) printf("WARNING: protocol (centrifuge) supports only constant pressure boundary condition \n"); + } + domain_db->putScalar( "BC", BoundaryCondition ); + } + else if (protocol == "core flooding"){ + if (BoundaryCondition != 4){ + BoundaryCondition = 4; + if (rank==0) printf("WARNING: protocol (core flooding) supports only volumetric flux boundary condition \n"); + } + domain_db->putScalar( "BC", BoundaryCondition ); + } + } void ScaLBL_ColorModel::SetDomain(){ @@ -322,11 +351,12 @@ void ScaLBL_ColorModel::AssignComponentLabels(double *phase) if (WettingConvention == "SCAL"){ for (size_t idx=0; idxkeyExists( "tolerance" )){ tolerance = analysis_db->getScalar( "tolerance" ); } - + runAnalysis analysis( current_db, rank_info, ScaLBL_Comm, Dm, Np, Regular, Map ); auto t1 = std::chrono::system_clock::now(); int CURRENT_TIMESTEP = 0; @@ -894,32 +924,7 @@ void ScaLBL_ColorModel::Run(){ if (color_db->keyExists( "krA_morph_factor" )){ KRA_MORPH_FACTOR = color_db->getScalar( "krA_morph_factor" ); } - /* defaults for simulation protocols */ - auto protocol = color_db->getWithDefault( "protocol", "none" ); - if (protocol == "image sequence"){ - // Get the list of images - USE_DIRECT = true; - ImageList = color_db->getVector( "image_sequence"); - IMAGE_INDEX = color_db->getWithDefault( "image_index", 0 ); - IMAGE_COUNT = ImageList.size(); - morph_interval = 10000; - USE_MORPH = true; - } - else if (protocol == "seed water"){ - morph_delta = -0.05; - seed_water = 0.01; - USE_SEED = true; - USE_MORPH = true; - } - else if (protocol == "open connected oil"){ - morph_delta = -0.05; - USE_MORPH = true; - USE_MORPHOPEN_OIL = true; - } - else if (protocol == "shell aggregation"){ - morph_delta = -0.05; - USE_MORPH = true; - } + if (color_db->keyExists( "capillary_number" )){ capillary_number = color_db->getScalar( "capillary_number" ); SET_CAPILLARY_NUMBER=true; @@ -938,7 +943,6 @@ void ScaLBL_ColorModel::Run(){ if (analysis_db->keyExists( "seed_water" )){ seed_water = analysis_db->getScalar( "seed_water" ); if (rank == 0) printf("Seed water in oil %f (seed_water) \n",seed_water); - ASSERT(protocol == "seed water"); } if (analysis_db->keyExists( "morph_delta" )){ morph_delta = analysis_db->getScalar( "morph_delta" ); @@ -968,7 +972,54 @@ void ScaLBL_ColorModel::Run(){ if (analysis_db->keyExists( "max_morph_timesteps" )){ MAX_MORPH_TIMESTEPS = analysis_db->getScalar( "max_morph_timesteps" ); } - + + /* defaults for simulation protocols */ + auto protocol = color_db->getWithDefault( "protocol", "none" ); + if (protocol == "image sequence"){ + // Get the list of images + USE_DIRECT = true; + ImageList = color_db->getVector( "image_sequence"); + IMAGE_INDEX = color_db->getWithDefault( "image_index", 0 ); + IMAGE_COUNT = ImageList.size(); + morph_interval = 10000; + USE_MORPH = true; + USE_SEED = false; + } + else if (protocol == "seed water"){ + morph_delta = -0.05; + seed_water = 0.01; + USE_SEED = true; + USE_MORPH = true; + } + else if (protocol == "open connected oil"){ + morph_delta = -0.05; + USE_SEED = false; + USE_MORPH = true; + USE_MORPHOPEN_OIL = true; + } + else if (protocol == "shell aggregation"){ + morph_delta = -0.05; + USE_MORPH = true; + USE_SEED = false; + } + else if (protocol == "fractional flow"){ + USE_MORPH = false; + USE_SEED = false; + } + else if (protocol == "centrifuge"){ + USE_MORPH = false; + USE_SEED = false; + } + else if (protocol == "core flooding"){ + USE_MORPH = false; + USE_SEED = false; + if (SET_CAPILLARY_NUMBER){ + double MuB = rhoB*(tauB - 0.5)/3.0; + double IFT = 6.0*alpha; + double CrossSectionalArea = (double) (nprocx*(Nx-2)*nprocy*(Ny-2)); + flux = Dm->Porosity()*CrossSectionalArea*IFT*capillary_number/MuB; + } + } if (rank==0){ printf("********************************************************\n"); if (protocol == "image sequence"){ @@ -1006,7 +1057,20 @@ void ScaLBL_ColorModel::Run(){ printf(" min_steady_timesteps = %i \n",MIN_STEADY_TIMESTEPS); printf(" max_steady_timesteps = %i \n",MAX_STEADY_TIMESTEPS); printf(" tolerance = %f \n",tolerance); - printf(" morph_delta = %f \n",morph_delta); + } + else if (protocol == "centrifuge"){ + printf(" using protocol = centrifuge \n"); + printf(" driving force = %f \n",Fz); + if (Fz < 0){ + printf(" Component B displacing component A \n"); + } + else if (Fz > 0){ + printf(" Component A displacing component B \n"); + } + } + else if (protocol == "core flooding"){ + printf(" using protocol = core flooding \n"); + printf(" capillary number = %f \n", capillary_number); } printf("No. of timesteps: %i \n", timestepMax); fflush(stdout); @@ -1120,7 +1184,7 @@ void ScaLBL_ColorModel::Run(){ double volB = Averages->gwb.V; double volA = Averages->gnb.V; volA /= Dm->Volume; - volB /= Dm->Volume;; + volB /= Dm->Volume; //initial_volume = volA*Dm->Volume; double vA_x = Averages->gnb.Px/Averages->gnb.M; double vA_y = Averages->gnb.Py/Averages->gnb.M; @@ -1944,12 +2008,11 @@ FlowAdaptor::~FlowAdaptor(){ double FlowAdaptor::UpdateFractionalFlow(ScaLBL_ColorModel &M){ - double MASS_FRACTION_CHANGE = 0.05; - if (M.db->keyExists( "FlowAdaptor" )){ - auto flow_db = M.db->getDatabase( "FlowAdaptor" ); - MASS_FRACTION_CHANGE = flow_db->getWithDefault( "fractional_flow_increment", 0.05); - } - + double MASS_FRACTION_CHANGE = 0.0005; + if (M.db->keyExists( "FlowAdaptor" )){ + auto flow_db = M.db->getDatabase( "FlowAdaptor" ); + MASS_FRACTION_CHANGE = flow_db->getWithDefault( "mass_fraction_factor", 0.0005); + } int Np = M.Np; double dA, dB, phi; double vx,vy,vz; @@ -1975,12 +2038,53 @@ double FlowAdaptor::UpdateFractionalFlow(ScaLBL_ColorModel &M){ ScaLBL_CopyToHost(Vel_x, &M.Velocity[0], Np*sizeof(double)); ScaLBL_CopyToHost(Vel_y, &M.Velocity[Np], Np*sizeof(double)); ScaLBL_CopyToHost(Vel_z, &M.Velocity[2*Np], Np*sizeof(double)); - + + /* DEBUG STRUCTURES */ + int Nx = M.Nx; int Ny = M.Ny; int Nz = M.Nz; + int N = Nx*Ny*Nz; + double * DebugMassA, *DebugMassB; + DebugMassA = new double[Np]; + DebugMassB = new double[Np]; + /* compute the total momentum */ vax = vay = vaz = 0.0; vbx = vby = vbz = 0.0; mass_a = mass_b = 0.0; - for (int n=0; n < M.ScaLBL_Comm->LastExterior(); n++){ + + double maxSpeed = 0.0; + double localMaxSpeed = 0.0; + for (int k=1; kSDs(i,j,k); + if (!(n<0) ){ + dA = Aq_tmp[n] + Aq_tmp[n+Np] + Aq_tmp[n+2*Np] + Aq_tmp[n+3*Np] + Aq_tmp[n+4*Np] + Aq_tmp[n+5*Np] + Aq_tmp[n+6*Np]; + dB = Bq_tmp[n] + Bq_tmp[n+Np] + Bq_tmp[n+2*Np] + Bq_tmp[n+3*Np] + Bq_tmp[n+4*Np] + Bq_tmp[n+5*Np] + Bq_tmp[n+6*Np]; + phi = (dA - dB) / (dA + dB); + Phase[n] = phi; + mass_a += dA; + mass_b += dB; + if (phi > 0.0){ + vax += Vel_x[n]; + vay += Vel_y[n]; + vaz += Vel_z[n]; + } + else { + vbx += Vel_x[n]; + vby += Vel_y[n]; + vbz += Vel_z[n]; + } + double speed = sqrt(vax*vax + vay*vay + vaz*vaz + vbx*vbx + vby*vby + vbz*vbz); + if (distance > 3.0 && speed > localMaxSpeed){ + localMaxSpeed = speed; + } + } + } + } + } + maxSpeed = M.Dm->Comm.maxReduce(localMaxSpeed); + /* for (int n=0; n < M.ScaLBL_Comm->LastExterior(); n++){ dA = Aq_tmp[n] + Aq_tmp[n+Np] + Aq_tmp[n+2*Np] + Aq_tmp[n+3*Np] + Aq_tmp[n+4*Np] + Aq_tmp[n+5*Np] + Aq_tmp[n+6*Np]; dB = Bq_tmp[n] + Bq_tmp[n+Np] + Bq_tmp[n+2*Np] + Bq_tmp[n+3*Np] + Bq_tmp[n+4*Np] + Bq_tmp[n+5*Np] + Bq_tmp[n+6*Np]; phi = (dA - dB) / (dA + dB); @@ -2016,27 +2120,65 @@ double FlowAdaptor::UpdateFractionalFlow(ScaLBL_ColorModel &M){ vbz += Vel_z[n]; } } - mass_a_global = M.Dm->Comm.sumReduce(mass_a); - mass_b_global = M.Dm->Comm.sumReduce(mass_b); - vax_global = M.Dm->Comm.sumReduce(vax); - vay_global = M.Dm->Comm.sumReduce(vay); - vaz_global = M.Dm->Comm.sumReduce(vaz); - vbx_global = M.Dm->Comm.sumReduce(vbx); - vby_global = M.Dm->Comm.sumReduce(vby); - vbz_global = M.Dm->Comm.sumReduce(vbz); - - double total_momentum_A = sqrt(vax_global*vax_global+vay_global*vay_global+vaz_global*vaz_global); - double total_momentum_B = sqrt(vbx_global*vbx_global+vby_global*vby_global+vbz_global*vbz_global); - - /* compute the total mass change */ - double TOTAL_MASS_CHANGE = MASS_FRACTION_CHANGE*(mass_a_global + mass_b_global); - if (fabs(TOTAL_MASS_CHANGE) > 0.1*mass_a_global ) - TOTAL_MASS_CHANGE = 0.1*mass_a_global; - if (fabs(TOTAL_MASS_CHANGE) > 0.1*mass_b_global ) - TOTAL_MASS_CHANGE = 0.1*mass_b_global; - - double LOCAL_MASS_CHANGE = 0.0; - for (int n=0; n < M.ScaLBL_Comm->LastExterior(); n++){ + */ + mass_a_global = M.Dm->Comm.sumReduce(mass_a); + mass_b_global = M.Dm->Comm.sumReduce(mass_b); + vax_global = M.Dm->Comm.sumReduce(vax); + vay_global = M.Dm->Comm.sumReduce(vay); + vaz_global = M.Dm->Comm.sumReduce(vaz); + vbx_global = M.Dm->Comm.sumReduce(vbx); + vby_global = M.Dm->Comm.sumReduce(vby); + vbz_global = M.Dm->Comm.sumReduce(vbz); + + double total_momentum_A = sqrt(vax_global*vax_global+vay_global*vay_global+vaz_global*vaz_global); + double total_momentum_B = sqrt(vbx_global*vbx_global+vby_global*vby_global+vbz_global*vbz_global); + /* compute the total mass change */ + double TOTAL_MASS_CHANGE = MASS_FRACTION_CHANGE*(mass_a_global + mass_b_global); + if (fabs(TOTAL_MASS_CHANGE) > 0.1*mass_a_global ) + TOTAL_MASS_CHANGE = 0.1*mass_a_global; + if (fabs(TOTAL_MASS_CHANGE) > 0.1*mass_b_global ) + TOTAL_MASS_CHANGE = 0.1*mass_b_global; + + double LOCAL_MASS_CHANGE = 0.0; + for (int k=1; k maxSpeed) local_momentum = maxSpeed; + if (phi > 0.0){ + LOCAL_MASS_CHANGE = TOTAL_MASS_CHANGE*local_momentum/total_momentum_A; + Aq_tmp[n] -= 0.3333333333333333*LOCAL_MASS_CHANGE; + Aq_tmp[n+Np] -= 0.1111111111111111*LOCAL_MASS_CHANGE; + Aq_tmp[n+2*Np] -= 0.1111111111111111*LOCAL_MASS_CHANGE; + Aq_tmp[n+3*Np] -= 0.1111111111111111*LOCAL_MASS_CHANGE; + Aq_tmp[n+4*Np] -= 0.1111111111111111*LOCAL_MASS_CHANGE; + Aq_tmp[n+5*Np] -= 0.1111111111111111*LOCAL_MASS_CHANGE; + Aq_tmp[n+6*Np] -= 0.1111111111111111*LOCAL_MASS_CHANGE; + DebugMassA[n] = (-1.0)*LOCAL_MASS_CHANGE; + } + else{ + LOCAL_MASS_CHANGE = TOTAL_MASS_CHANGE*local_momentum/total_momentum_B; + Bq_tmp[n] += 0.3333333333333333*LOCAL_MASS_CHANGE; + Bq_tmp[n+Np] += 0.1111111111111111*LOCAL_MASS_CHANGE; + Bq_tmp[n+2*Np] += 0.1111111111111111*LOCAL_MASS_CHANGE; + Bq_tmp[n+3*Np] += 0.1111111111111111*LOCAL_MASS_CHANGE; + Bq_tmp[n+4*Np] += 0.1111111111111111*LOCAL_MASS_CHANGE; + Bq_tmp[n+5*Np] += 0.1111111111111111*LOCAL_MASS_CHANGE; + Bq_tmp[n+6*Np] += 0.1111111111111111*LOCAL_MASS_CHANGE; + DebugMassB[n] = LOCAL_MASS_CHANGE; + } + } + } + } + } +/* for (int n=0; n < M.ScaLBL_Comm->LastExterior(); n++){ phi = Phase[n]; vx = Vel_x[n]; vy = Vel_y[n]; @@ -2051,6 +2193,7 @@ double FlowAdaptor::UpdateFractionalFlow(ScaLBL_ColorModel &M){ Aq_tmp[n+4*Np] -= 0.1111111111111111*LOCAL_MASS_CHANGE; Aq_tmp[n+5*Np] -= 0.1111111111111111*LOCAL_MASS_CHANGE; Aq_tmp[n+6*Np] -= 0.1111111111111111*LOCAL_MASS_CHANGE; + DebugMassA[n] = (-1.0)*LOCAL_MASS_CHANGE; } else{ LOCAL_MASS_CHANGE = TOTAL_MASS_CHANGE*local_momentum/total_momentum_B; @@ -2061,6 +2204,7 @@ double FlowAdaptor::UpdateFractionalFlow(ScaLBL_ColorModel &M){ Bq_tmp[n+4*Np] += 0.1111111111111111*LOCAL_MASS_CHANGE; Bq_tmp[n+5*Np] += 0.1111111111111111*LOCAL_MASS_CHANGE; Bq_tmp[n+6*Np] += 0.1111111111111111*LOCAL_MASS_CHANGE; + DebugMassB[n] = LOCAL_MASS_CHANGE; } } @@ -2079,6 +2223,7 @@ double FlowAdaptor::UpdateFractionalFlow(ScaLBL_ColorModel &M){ Aq_tmp[n+4*Np] -= 0.1111111111111111*LOCAL_MASS_CHANGE; Aq_tmp[n+5*Np] -= 0.1111111111111111*LOCAL_MASS_CHANGE; Aq_tmp[n+6*Np] -= 0.1111111111111111*LOCAL_MASS_CHANGE; + DebugMassA[n] = (-1.0)*LOCAL_MASS_CHANGE; } else{ LOCAL_MASS_CHANGE = TOTAL_MASS_CHANGE*local_momentum/total_momentum_B; @@ -2089,11 +2234,54 @@ double FlowAdaptor::UpdateFractionalFlow(ScaLBL_ColorModel &M){ Bq_tmp[n+4*Np] += 0.1111111111111111*LOCAL_MASS_CHANGE; Bq_tmp[n+5*Np] += 0.1111111111111111*LOCAL_MASS_CHANGE; Bq_tmp[n+6*Np] += 0.1111111111111111*LOCAL_MASS_CHANGE; + DebugMassB[n] = LOCAL_MASS_CHANGE; } } - + */ if (M.rank == 0) printf("Update Fractional Flow: change mass of fluid B by %f \n",TOTAL_MASS_CHANGE/mass_b_global); + /* Print out debugging info with mass update */ + // initialize the array + double value; + char LocalRankFilename[40]; + DoubleArray regdata(Nx,Ny,Nz); + regdata.fill(0.f); + for (int k=0; kLastExterior(); n++){ dA = Aq_tmp[n] + Aq_tmp[n+Np] + Aq_tmp[n+2*Np] + Aq_tmp[n+3*Np] + Aq_tmp[n+4*Np] + Aq_tmp[n+5*Np] + Aq_tmp[n+6*Np]; dB = Bq_tmp[n] + Bq_tmp[n+Np] + Bq_tmp[n+2*Np] + Bq_tmp[n+3*Np] + Bq_tmp[n+4*Np] + Bq_tmp[n+5*Np] + Bq_tmp[n+6*Np]; @@ -2202,22 +2386,6 @@ double FlowAdaptor::MoveInterface(ScaLBL_ColorModel &M){ } } ScaLBL_CopyToDevice( M.Phi, phi_t.data(), Nx*Ny*Nz* sizeof( double ) ); - - -/* ScaLBL_PhaseField_Init(dvcMap, Phi, Den, Aq, Bq, 0, ScaLBL_Comm->LastExterior(), Np); - ScaLBL_PhaseField_Init(dvcMap, Phi, Den, Aq, Bq, ScaLBL_Comm->FirstInterior(), ScaLBL_Comm->LastInterior(), Np); - if (BoundaryCondition == 1 || BoundaryCondition == 2 || BoundaryCondition == 3 || BoundaryCondition == 4){ - if (Dm->kproc()==0){ - ScaLBL_SetSlice_z(Phi,1.0,Nx,Ny,Nz,0); - ScaLBL_SetSlice_z(Phi,1.0,Nx,Ny,Nz,1); - ScaLBL_SetSlice_z(Phi,1.0,Nx,Ny,Nz,2); - } - if (Dm->kproc() == nprocz-1){ - ScaLBL_SetSlice_z(Phi,-1.0,Nx,Ny,Nz,Nz-1); - ScaLBL_SetSlice_z(Phi,-1.0,Nx,Ny,Nz,Nz-2); - ScaLBL_SetSlice_z(Phi,-1.0,Nx,Ny,Nz,Nz-3); - } - } - */ + return total_interface_sites; } diff --git a/models/FreeLeeModel.cpp b/models/FreeLeeModel.cpp index b1c0e99f..19a2afa8 100644 --- a/models/FreeLeeModel.cpp +++ b/models/FreeLeeModel.cpp @@ -63,7 +63,6 @@ void ScaLBL_FreeLeeModel::getData_RegularLayout(const double *data, DoubleArray // Gets data (in optimized layout) from the HOST and stores in regular layout // Primarly for debugging int i,j,k,idx; - int n; // initialize the array regdata.fill(0.f); @@ -72,7 +71,6 @@ void ScaLBL_FreeLeeModel::getData_RegularLayout(const double *data, DoubleArray for (k=0; kLastExterior(); n++){ -// va = cDen[n]; -// vb = cDen[Np + n]; -// value = (va-vb)/(va+vb); -// idx = TmpMap[n]; -// if (!(idx < 0) && idxFirstInterior(); nLastInterior(); n++){ -// va = cDen[n]; -// vb = cDen[Np + n]; -// value = (va-vb)/(va+vb); -// idx = TmpMap[n]; -// if (!(idx < 0) && idxBarrier(); -// comm.barrier(); -// -// if (rank==0) printf ("Initializing phase and density fields on device from Restart\n"); -// //TODO the following function is to be updated. -// //ScaLBL_FreeLeeModel_PhaseField_InitFromRestart(Den, hq, 0, ScaLBL_Comm->LastExterior(), Np); -// //ScaLBL_FreeLeeModel_PhaseField_InitFromRestart(Den, hq, ScaLBL_Comm->FirstInterior(), ScaLBL_Comm->LastInterior(), Np); } } double ScaLBL_FreeLeeModel::Run_TwoFluid(int returntime){ - int nprocs=nprocx*nprocy*nprocz; int START_TIME = timestep; int EXIT_TIME = min(returntime, timestepMax); diff --git a/models/GreyscaleModel.cpp b/models/GreyscaleModel.cpp index cb560ec2..d15cdf7f 100644 --- a/models/GreyscaleModel.cpp +++ b/models/GreyscaleModel.cpp @@ -165,7 +165,6 @@ void ScaLBL_GreyscaleModel::ReadInput(){ // Generate the signed distance map // Initialize the domain and communication Array id_solid(Nx,Ny,Nz); - int count = 0; // Solve for the position of the solid phase for (int k=0;kid[i] = Mask->id[i]; - for (int idx=0; idxComm.sumReduce( label_count[idx]); + for (size_t idx=0; idxComm.sumReduce( label_count[idx]); //Initialize a weighted porosity after considering grey voxels GreyPorosity=0.0; for (unsigned int idx=0; idx0 @@ -706,23 +706,22 @@ void ScaLBL_GreyscaleModel::Run(){ //double absperm = h*h*mu*Mask->Porosity()*flow_rate / force_mag; double absperm = h*h*mu*GreyPorosity*flow_rate / force_mag; - if (rank==0){ + if (rank==0){ printf(" AbsPerm = %.5g [micron^2]\n",absperm); - bool WriteHeader=false; - FILE * log_file = fopen("Permeability.csv","r"); - if (log_file != NULL) - fclose(log_file); - else - WriteHeader=true; - log_file = fopen("Permeability.csv","a"); - if (WriteHeader) - fprintf(log_file,"timestep Fx Fy Fz mu Vs As Hs Xs vax vay vaz AbsPerm \n", - timestep,Fx,Fy,Fz,mu,h*h*h*Vs,h*h*As,h*Hs,Xs,vax,vay,vaz,absperm); + bool WriteHeader=false; + FILE * log_file = fopen("Permeability.csv","r"); + if (log_file != NULL) + fclose(log_file); + else + WriteHeader=true; + log_file = fopen("Permeability.csv","a"); + if (WriteHeader) + fprintf(log_file,"timestep Fx Fy Fz mu Vs As Hs Xs vax vay vaz AbsPerm \n"); - fprintf(log_file,"%i %.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g\n",timestep, Fx, Fy, Fz, mu, - h*h*h*Vs,h*h*As,h*Hs,Xs,vax,vay,vaz, absperm); - fclose(log_file); - } + fprintf(log_file,"%i %.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g\n",timestep, Fx, Fy, Fz, mu, + h*h*h*Vs,h*h*As,h*Hs,Xs,vax,vay,vaz, absperm); + fclose(log_file); + } } if (timestep%visualization_interval==0){ diff --git a/models/IonModel.cpp b/models/IonModel.cpp index 136af02f..f86bc6d2 100644 --- a/models/IonModel.cpp +++ b/models/IonModel.cpp @@ -97,7 +97,7 @@ void ScaLBL_IonModel::ReadParams(string filename,vector &num_iter){ } else{ time_conv.clear(); - for (int i=0; i &num_iter){ ERROR("Error: number_ion_species and IonDiffusivityList must be the same length! \n"); } else{ - for (int i=0; i &num_iter){ ERROR("Error: number_ion_species and IonConcentrationList must be the same length! \n"); } else{ - for (int i=0; i &num_iter){ else { ERROR("Error: Non-periodic BCs are specified but InletValueList cannot be found! \n"); } - for (unsigned int i=0;i &num_iter){ else { ERROR("Error: Non-periodic BCs are specified but OutletValueList cannot be found! \n"); } - for (unsigned int i=0;iid[n]; AFFINITY=0.f; // Assign the affinity from the paired list - for (unsigned int idx=0; idx < NLABELS; idx++){ + for (size_t idx=0; idx < NLABELS; idx++){ //printf("idx=%i, value=%i, %i, \n",idx, VALUE,LabelList[idx]); if (VALUE == LabelList[idx]){ AFFINITY=AffinityList[idx]; @@ -701,23 +703,23 @@ void ScaLBL_IonModel::Initialize(){ auto File_ion = ion_db->getVector( "IonConcentrationFile" ); double *Ci_host; Ci_host = new double[number_ion_species*Np]; - for (int ic=0; icFirstInterior(), ScaLBL_Comm->LastInterior(), Np); ScaLBL_D3Q7_Ion_ChargeDensity(Ci, ChargeDensity, IonValence[ic], ic, 0, ScaLBL_Comm->LastExterior(), Np); } @@ -734,35 +736,35 @@ void ScaLBL_IonModel::Initialize(){ break; } - for (int i=0; i rlx; - for (unsigned int ic=0;icBarrier(); comm.barrier(); //auto t1 = std::chrono::system_clock::now(); - for (int ic=0; icFirstInterior(), ScaLBL_Comm->LastInterior(), Np); ScaLBL_D3Q7_Ion_ChargeDensity(Ci, ChargeDensity, IonValence[ic], ic, 0, ScaLBL_Comm->LastExterior(), Np); } @@ -901,7 +903,7 @@ void ScaLBL_IonModel::Run(double *Velocity, double *ElectricField){ //if (rank==0) printf("********************************************************\n"); } -void ScaLBL_IonModel::getIonConcentration(DoubleArray &IonConcentration, const int ic){ +void ScaLBL_IonModel::getIonConcentration(DoubleArray &IonConcentration, const size_t ic){ //This function wirte out the data in a normal layout (by aggregating all decomposed domains) ScaLBL_Comm->RegularLayout(Map,&Ci[ic*Np],IonConcentration); @@ -913,13 +915,13 @@ void ScaLBL_IonModel::getIonConcentration(DoubleArray &IonConcentration, const i void ScaLBL_IonModel::getIonConcentration_debug(int timestep){ //This function write out decomposed data DoubleArray PhaseField(Nx,Ny,Nz); - for (int ic=0; icRegularLayout(Map,&Ci[ic*Np],PhaseField); ScaLBL_Comm->Barrier(); comm.barrier(); IonConcentration_LB_to_Phys(PhaseField); FILE *OUTFILE; - sprintf(LocalRankFilename,"Ion%02i_Time_%i.%05i.raw",ic+1,timestep,rank); + sprintf(LocalRankFilename,"Ion%02zu_Time_%i.%05i.raw",ic+1,timestep,rank); OUTFILE = fopen(LocalRankFilename,"wb"); fwrite(PhaseField.data(),8,N,OUTFILE); fclose(OUTFILE); @@ -986,7 +988,7 @@ double ScaLBL_IonModel::CalIonDenConvergence(vector &ci_avg_previous){ Ci_host = new double[Np]; vector error(number_ion_species,0.0); - for (int ic=0; ic BoundaryConditionInlet; vector BoundaryConditionOutlet; vector IonDiffusivity;//User input unit [m^2/sec] diff --git a/tests/DataAggregator.cpp b/tests/DataAggregator.cpp index 7fcbfb0f..137ebd61 100644 --- a/tests/DataAggregator.cpp +++ b/tests/DataAggregator.cpp @@ -9,8 +9,8 @@ using namespace std; int main(int argc, char **argv){ - - printf("Aggregating block data into single file \n"); + + printf("Aggregating block data into single file \n"); unsigned int Bx,By,Bz; uint64_t Nx,Ny,Nz; uint64_t N; @@ -22,25 +22,25 @@ int main(int argc, char **argv){ //Read the block size if (argc>9){ - printf("Input arguments accepted \n"); - Nx = atoi(argv[1]); - Ny = atoi(argv[2]); - Nz = atoi(argv[3]); - x0 = atoi(argv[4]); - y0 = atoi(argv[5]); - z0 = atoi(argv[6]); - NX = atol(argv[7]); - NY = atol(argv[8]); - NZ = atol(argv[9]); - printf("Size %i X %i X %i \n",NX,NY,NZ); - fflush(stdout); + printf("Input arguments accepted \n"); + Nx = atoi(argv[1]); + Ny = atoi(argv[2]); + Nz = atoi(argv[3]); + x0 = atoi(argv[4]); + y0 = atoi(argv[5]); + z0 = atoi(argv[6]); + NX = atol(argv[7]); + NY = atol(argv[8]); + NZ = atol(argv[9]); + printf("Size %llu X %llu X %llu \n",(unsigned long long) NX, (unsigned long long) NY, (unsigned long long) NZ); + fflush(stdout); } else{ - printf("setting defaults \n"); - Nx=Ny=Nz=1024; - x0=y0=z0=0; - NX=NY=8640; - NZ=6480; + printf("setting defaults \n"); + Nx=Ny=Nz=1024; + x0=y0=z0=0; + NX=NY=8640; + NZ=6480; } //Bx = By = Bz = 9; //Nx = Ny = Nz = 1024; @@ -53,29 +53,28 @@ int main(int argc, char **argv){ if (By>8) By=8; if (Bz>8) Bz=8; - printf("System size (output) is: %i x %i x %i \n",NX,NY,NZ); - printf("Block size (read) is: %i x %i x %i \n",Nx,Ny,Nz); - printf("Starting location (read) is: %i, %i, %i \n", x0,y0,z0); - printf("Block number (read): %i x %i x %i \n",Bx,By,Bz); + printf("System size (output) is: %llu x %llu x %llu \n",(unsigned long long) NX,(unsigned long long) NY, (unsigned long long) NZ); + printf("Block size (read) is: %llu x %llu x %llu \n",(unsigned long long) Nx,(unsigned long long) Ny,(unsigned long long) Nz); + printf("Starting location (read) is: %llu, %llu, %llu \n", (unsigned long long) x0,(unsigned long long) y0,(unsigned long long) z0); + printf("Block number (read): %llu x %llu x %llu \n",(unsigned long long) Bx,(unsigned long long) By,(unsigned long long) Bz); fflush(stdout); - + // Filenames used //char LocalRankString[8]; char LocalRankFilename[40]; char sx[2]; char sy[2]; char sz[2]; - char tmpstr[10]; //sprintf(LocalRankString,"%05d",rank); N = Nx*Ny*Nz; N_full=NX*NY*NZ; - + char *id; id = new char [N]; char *ID; ID = new char [N_full]; - + for (unsigned int bz=0; bz SW) { sw_diff_old = sw_diff_new; diff --git a/tests/lbpm_color_simulator.cpp b/tests/lbpm_color_simulator.cpp index 51ffe96e..56b6d3dd 100644 --- a/tests/lbpm_color_simulator.cpp +++ b/tests/lbpm_color_simulator.cpp @@ -9,8 +9,6 @@ #include "common/Utilities.h" #include "models/ColorModel.h" -//#define WRE_SURFACES - /* * Simulator for two-phase flow in porous media * James E. McClure 2013-2014 @@ -69,30 +67,69 @@ int main( int argc, char **argv ) ColorModel.Initialize(); // initializing the model will set initial conditions for variables if (SimulationMode == "development"){ - double MLUPS=0.0; - int timestep = 0; - /* flow adaptor keys to control */ - auto flow_db = ColorModel.db->getDatabase( "FlowAdaptor" ); - int MAX_STEADY_TIME = flow_db->getWithDefault( "max_steady_timesteps", 1000000 ); - int SKIP_TIMESTEPS = flow_db->getWithDefault( "skip_timesteps", 100000 ); - - int ANALYSIS_INTERVAL = ColorModel.timestepMax; + double MLUPS=0.0; + int timestep = 0; + bool ContinueSimulation = true; + int ANALYSIS_INTERVAL = ColorModel.timestepMax; + /* flow adaptor keys to control */ + int SKIP_TIMESTEPS = 0; + int MAX_STEADY_TIME = 1000000; + double ENDPOINT_THRESHOLD = 0.1; + double FRACTIONAL_FLOW_INCREMENT = 0.05; + if (ColorModel.db->keyExists( "FlowAdaptor" )){ + auto flow_db = ColorModel.db->getDatabase( "FlowAdaptor" ); + MAX_STEADY_TIME = flow_db->getWithDefault( "max_steady_timesteps", 1000000 ); + SKIP_TIMESTEPS = flow_db->getWithDefault( "skip_timesteps", 100000 ); + FRACTIONAL_FLOW_INCREMENT = flow_db->getWithDefault( "fractional_flow_increment", 0.05); + ENDPOINT_THRESHOLD = flow_db->getWithDefault( "endpoint_threshold", 0.1); + } if (ColorModel.analysis_db->keyExists( "analysis_interval" )){ ANALYSIS_INTERVAL = ColorModel.analysis_db->getScalar( "analysis_interval" ); } /* Launch the simulation */ FlowAdaptor Adapt(ColorModel); runAnalysis analysis(ColorModel); - - while (ColorModel.timestep < ColorModel.timestepMax){ - /* this will run steady points */ - timestep += MAX_STEADY_TIME; - MLUPS = ColorModel.Run(timestep); - if (rank==0) printf("Lattice update rate (per MPI process)= %f MLUPS \n", MLUPS); - Adapt.UpdateFractionalFlow(ColorModel); - - /* apply timestep skipping algorithm to accelerate steady-state */ + while (ContinueSimulation){ + /* this will run steady points */ + timestep += MAX_STEADY_TIME; + MLUPS = ColorModel.Run(timestep); + if (rank==0) printf("Lattice update rate (per MPI process)= %f MLUPS \n", MLUPS); + if (ColorModel.timestep > ColorModel.timestepMax){ + ContinueSimulation = false; + } + /* update the fractional flow by adding mass */ int skip_time = 0; + timestep = ColorModel.timestep; + double SaturationChange = 0.0; + double volB = ColorModel.Averages->gwb.V; + double volA = ColorModel.Averages->gnb.V; + double initialSaturation = volB/(volA + volB); + + double vA_x = ColorModel.Averages->gnb.Px/ColorModel.Averages->gnb.M; + double vA_y = ColorModel.Averages->gnb.Py/ColorModel.Averages->gnb.M; + double vA_z = ColorModel.Averages->gnb.Pz/ColorModel.Averages->gnb.M; + double vB_x = ColorModel.Averages->gwb.Px/ColorModel.Averages->gwb.M; + double vB_y = ColorModel.Averages->gwb.Py/ColorModel.Averages->gwb.M; + double vB_z = ColorModel.Averages->gwb.Pz/ColorModel.Averages->gwb.M; + double speedA = sqrt(vA_x*vA_x + vA_y*vA_y + vA_z*vA_z); + double speedB = sqrt(vB_x*vB_x + vB_y*vB_y + vB_z*vB_z); + if (volA*speedA < ENDPOINT_THRESHOLD*volB*speedB) ContinueSimulation = false; + if (ContinueSimulation){ + while (skip_time < SKIP_TIMESTEPS && fabs(SaturationChange) < fabs(FRACTIONAL_FLOW_INCREMENT) ){ + timestep += ANALYSIS_INTERVAL; + Adapt.UpdateFractionalFlow(ColorModel); + MLUPS = ColorModel.Run(timestep); + double volB = ColorModel.Averages->gwb.V; + double volA = ColorModel.Averages->gnb.V; + SaturationChange = volB/(volA + volB) - initialSaturation; + skip_time += ANALYSIS_INTERVAL; + } + if (rank==0) printf(" ********************************************************************* \n"); + if (rank==0) printf(" Updated fractional flow with saturation change = %f \n", SaturationChange); + if (rank==0) printf(" ********************************************************************* \n"); + } + /* apply timestep skipping algorithm to accelerate steady-state */ + /* skip_time = 0; timestep = ColorModel.timestep; while (skip_time < SKIP_TIMESTEPS){ timestep += ANALYSIS_INTERVAL; @@ -100,10 +137,9 @@ int main( int argc, char **argv ) Adapt.MoveInterface(ColorModel); skip_time += ANALYSIS_INTERVAL; } - //Adapt.Flatten(ColorModel); - + */ } - ColorModel.WriteDebug(); + //ColorModel.WriteDebug(); } else @@ -112,6 +148,7 @@ int main( int argc, char **argv ) PROFILE_STOP( "Main" ); auto file = db->getWithDefault( "TimerFile", "lbpm_color_simulator" ); auto level = db->getWithDefault( "TimerLevel", 1 ); + NULL_USE(level); PROFILE_SAVE( file, level ); // **************************************************** diff --git a/tests/lbpm_freelee_SingleFluidBGK_simulator.cpp b/tests/lbpm_freelee_SingleFluidBGK_simulator.cpp index 19d99b9c..30ec4fec 100644 --- a/tests/lbpm_freelee_SingleFluidBGK_simulator.cpp +++ b/tests/lbpm_freelee_SingleFluidBGK_simulator.cpp @@ -59,6 +59,7 @@ int main( int argc, char **argv ) PROFILE_STOP("Main"); auto file = db->getWithDefault( "TimerFile", "lbpm_freelee_SingleFluidBGK_simulator" ); auto level = db->getWithDefault( "TimerLevel", 1 ); + NULL_USE(level); PROFILE_SAVE( file,level ); // **************************************************** diff --git a/tests/lbpm_freelee_simulator.cpp b/tests/lbpm_freelee_simulator.cpp index cdba5082..e2ca2d64 100644 --- a/tests/lbpm_freelee_simulator.cpp +++ b/tests/lbpm_freelee_simulator.cpp @@ -83,6 +83,7 @@ int main( int argc, char **argv ) PROFILE_STOP("Main"); auto file = db->getWithDefault( "TimerFile", "lbpm_freelee_simulator" ); auto level = db->getWithDefault( "TimerLevel", 1 ); + NULL_USE(level); PROFILE_SAVE( file,level ); // ****************************************************