From e1ebbce812550a0711f92c351f52930ef17ba2d6 Mon Sep 17 00:00:00 2001 From: Zhe Rex Li Date: Tue, 12 Apr 2022 11:40:39 +1000 Subject: [PATCH] initialize nernst-planck simulator; to be built subject to debugging --- models/MultiPhysController.cpp | 46 +++++++++ models/MultiPhysController.h | 2 +- tests/CMakeLists.txt | 1 + tests/lbpm_nernst_planck_simulator.cpp | 135 +++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 tests/lbpm_nernst_planck_simulator.cpp diff --git a/models/MultiPhysController.cpp b/models/MultiPhysController.cpp index 8935bca7..9120471b 100644 --- a/models/MultiPhysController.cpp +++ b/models/MultiPhysController.cpp @@ -151,6 +151,52 @@ vector ScaLBL_Multiphys_Controller::getIonNumIter_PNP_coupling( return num_iter_ion; } +vector ScaLBL_Multiphys_Controller::getIonNumIter_NernstPlanck_coupling( + const vector &IonTimeConv) { + //Return number of internal iterations for the Ion transport solver + vector num_iter_ion; + vector::iterator it_max = + max_element(IonTimeConv.begin(), IonTimeConv.end()); + unsigned int idx_max = distance(IonTimeConv.begin(), it_max); + if (idx_max == 0) { + num_iter_ion.push_back(2); + for (unsigned int idx = 1; idx < IonTimeConv.size(); idx++) { + double temp = + 2 * TimeConv[idx_max] / + TimeConv + [idx]; //the factor 2 is the number of iterations for the element has max time_conv + num_iter_ion.push_back(int(round(temp / 2) * 2)); + } + } else if (idx_max == IonTimeConv.size() - 1) { + for (unsigned int idx = 0; idx < TimeConv.size() - 1; idx++) { + double temp = + 2 * TimeConv[idx_max] / + TimeConv + [idx]; //the factor 2 is the number of iterations for the element has max time_conv + num_iter_ion.push_back(int(round(temp / 2) * 2)); + } + num_iter_ion.push_back(2); + } else { + for (unsigned int idx = 0; idx < idx_max; idx++) { + double temp = + 2 * TimeConv[idx_max] / + TimeConv + [idx]; //the factor 2 is the number of iterations for the element has max time_conv + num_iter_ion.push_back(int(round(temp / 2) * 2)); + } + num_iter_ion.push_back(2); + for (unsigned int idx = idx_max + 1; idx < IonTimeConv.size(); idx++) { + double temp = + 2 * TimeConv[idx_max] / + TimeConv + [idx]; //the factor 2 is the number of iterations for the element has max time_conv + num_iter_ion.push_back(int(round(temp / 2) * 2)); + } + } + return num_iter_ion; +} + + void ScaLBL_Multiphys_Controller::getTimeConvMax_PNP_coupling( double StokesTimeConv, const vector &IonTimeConv) { //Return maximum of the time converting factor from Stokes and ion solvers diff --git a/models/MultiPhysController.h b/models/MultiPhysController.h index 13aa05a2..d41a6db8 100644 --- a/models/MultiPhysController.h +++ b/models/MultiPhysController.h @@ -28,7 +28,7 @@ public: const vector &IonTimeConv); vector getIonNumIter_PNP_coupling(double StokesTimeConv, const vector &IonTimeConv); - //void getIonNumIter_PNP_coupling(double StokesTimeConv,vector &IonTimeConv,vector &IonTimeMax); + vector getIonNumIter_NernstPlanck_coupling(const vector &IonTimeConv); void getTimeConvMax_PNP_coupling(double StokesTimeConv, const vector &IonTimeConv); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5e4441e3..2ff1aa88 100755 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,6 +6,7 @@ ADD_LBPM_EXECUTABLE( lbpm_permeability_simulator ) ADD_LBPM_EXECUTABLE( lbpm_greyscale_simulator ) ADD_LBPM_EXECUTABLE( lbpm_greyscaleColor_simulator ) ADD_LBPM_EXECUTABLE( lbpm_electrokinetic_SingleFluid_simulator ) +ADD_LBPM_EXECUTABLE( lbpm_nernst_planck_simulator ) ADD_LBPM_EXECUTABLE( lbpm_freelee_simulator ) ADD_LBPM_EXECUTABLE( lbpm_freelee_SingleFluidBGK_simulator ) #ADD_LBPM_EXECUTABLE( lbpm_BGK_simulator ) diff --git a/tests/lbpm_nernst_planck_simulator.cpp b/tests/lbpm_nernst_planck_simulator.cpp new file mode 100644 index 00000000..bc697bd9 --- /dev/null +++ b/tests/lbpm_nernst_planck_simulator.cpp @@ -0,0 +1,135 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "models/IonModel.h" +#include "models/PoissonSolver.h" +#include "models/MultiPhysController.h" +#include "common/Utilities.h" +#include "analysis/ElectroChemistry.h" + +using namespace std; + +int main(int argc, char **argv) +{ + // Initialize MPI and error handlers + Utilities::startup( argc, argv ); + Utilities::MPI comm( MPI_COMM_WORLD ); + int rank = comm.getRank(); + int nprocs = comm.getSize(); + + { // Limit scope so variables that contain communicators will free before MPI_Finialize + + if (rank == 0){ + printf("*************************************************\n"); + printf("Running LBPM Nernst-Planck solver \n"); + printf("*************************************************\n"); + } + // Initialize compute device + int device=ScaLBL_SetDevice(rank); + NULL_USE( device ); + ScaLBL_DeviceBarrier(); + comm.barrier(); + + PROFILE_ENABLE(1); + //PROFILE_ENABLE_TRACE(); + //PROFILE_ENABLE_MEMORY(); + PROFILE_SYNCHRONIZE(); + PROFILE_START("Main"); + Utilities::setErrorHandlers(); + + auto filename = argv[1]; + ScaLBL_IonModel IonModel(rank,nprocs,comm); + ScaLBL_Poisson PoissonSolver(rank,nprocs,comm); + ScaLBL_Multiphys_Controller Study(rank,nprocs,comm);//multiphysics controller coordinating multi-model coupling + + // Load controller information + Study.ReadParams(filename); + + // Load user input database files for Ion solvers + IonModel.ReadParams(filename); + IonModel.SetDomain(); + IonModel.ReadInput(); + IonModel.Create(); + + // Create analysis object + //ElectroChemistryAnalyzer Analysis(IonModel.Dm); + + + //IonModel.timestepMax = Study.getIonNumIter_PNP_coupling(StokesModel.time_conv,IonModel.time_conv); + IonModel.timestepMax = Study.getIonNumIter_NernstPlanck_coupling(IonModel.time_conv); + IonModel.Initialize(); + + // Get maximal time converting factor based on Sotkes and Ion solvers + //Study.getTimeConvMax_PNP_coupling(StokesModel.time_conv,IonModel.time_conv); + // Get time conversion factor for the main iteration loop in electrokinetic single fluid simulator + Study.time_conv_MainLoop = IonModel.timestepMax[0]*IonModel.time_conv[0]; + + //----------------------------------- print out for debugging ------------------------------------------// + if (rank==0){ + for (size_t i=0;i