Files
LBPM/tests/lbpm_electrokinetic_SingleFluid_simulator.cpp

132 lines
5.0 KiB
C++
Raw Normal View History

2020-08-06 15:41:40 -04:00
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <iostream>
#include <exception>
#include <stdexcept>
#include <fstream>
2020-08-14 14:23:22 -04:00
#include <math.h>
2020-08-06 15:41:40 -04:00
#include "models/IonModel.h"
2020-09-20 11:00:36 -04:00
#include "models/StokesModel.h"
2020-08-06 15:41:40 -04:00
#include "models/PoissonSolver.h"
2020-08-14 14:23:22 -04:00
#include "models/MultiPhysController.h"
#include "common/Utilities.h"
#include "analysis/ElectroChemistry.h"
2020-08-06 15:41:40 -04:00
using namespace std;
2020-08-14 14:23:22 -04:00
//***************************************************************************
2020-09-20 11:00:36 -04:00
// Test lattice-Boltzmann Ion Model coupled with Poisson equation
2020-08-14 14:23:22 -04:00
//***************************************************************************
2020-08-06 15:41:40 -04:00
int main(int argc, char **argv)
{
// Initialize MPI and error handlers
2021-01-06 11:58:43 -05:00
Utilities::startup( argc, argv );
Utilities::MPI comm( MPI_COMM_WORLD );
int rank = comm.getRank();
int nprocs = comm.getSize();
2021-01-15 14:41:10 -05:00
{ // Limit scope so variables that contain communicators will free before MPI_Finialize
2020-08-14 14:23:22 -04:00
if (rank == 0){
printf("********************************************************\n");
2020-09-20 11:00:36 -04:00
printf("Running LBPM electrokinetic single-fluid solver \n");
2020-08-14 14:23:22 -04:00
printf("********************************************************\n");
}
2021-01-06 11:58:43 -05:00
// Initialize compute device
int device=ScaLBL_SetDevice(rank);
NULL_USE( device );
ScaLBL_DeviceBarrier();
comm.barrier();
PROFILE_ENABLE(1);
2020-08-14 14:23:22 -04:00
//PROFILE_ENABLE_TRACE();
//PROFILE_ENABLE_MEMORY();
PROFILE_SYNCHRONIZE();
PROFILE_START("Main");
Utilities::setErrorHandlers();
auto filename = argv[1];
ScaLBL_StokesModel StokesModel(rank,nprocs,comm);
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
2020-08-14 14:23:22 -04:00
// Load controller information
Study.ReadParams(filename);
2020-09-20 11:00:36 -04:00
// Load user input database files for Navier-Stokes and Ion solvers
StokesModel.ReadParams(filename);
IonModel.ReadParams(filename);
// Setup other model specific structures
2020-08-14 14:23:22 -04:00
StokesModel.SetDomain();
StokesModel.ReadInput();
StokesModel.Create(); // creating the model will create data structure to match the pore structure and allocate variables
IonModel.SetDomain();
IonModel.ReadInput();
IonModel.Create();
// Create analysis object
ElectroChemistryAnalyzer Analysis(IonModel.Dm);
2020-09-20 11:00:36 -04:00
// Get internal iteration number
StokesModel.timestepMax = Study.getStokesNumIter_PNP_coupling(StokesModel.time_conv,IonModel.time_conv);
StokesModel.Initialize(); // initializing the model will set initial conditions for variables
IonModel.timestepMax = Study.getIonNumIter_PNP_coupling(StokesModel.time_conv,IonModel.time_conv);
2020-08-14 14:23:22 -04:00
IonModel.Initialize();
// Get maximal time converting factor based on Sotkes and Ion solvers
Study.getTimeConvMax_PNP_coupling(StokesModel.time_conv,IonModel.time_conv);
2020-08-14 14:23:22 -04:00
// Initialize LB-Poisson model
PoissonSolver.ReadParams(filename);
PoissonSolver.SetDomain();
PoissonSolver.ReadInput();
PoissonSolver.Create();
PoissonSolver.Initialize(Study.time_conv_max);
2020-08-06 15:41:40 -04:00
2020-09-20 11:00:36 -04:00
2020-08-14 14:23:22 -04:00
int timestep=0;
while (timestep < Study.timestepMax){
timestep++;
PoissonSolver.Run(IonModel.ChargeDensity,StokesModel.UseSlippingVelBC,timestep);//solve Poisson equtaion to get steady-state electrical potental
2020-08-14 14:23:22 -04:00
StokesModel.Run_Lite(IonModel.ChargeDensity, PoissonSolver.ElectricField);// Solve the N-S equations to get velocity
IonModel.Run(StokesModel.Velocity,PoissonSolver.ElectricField); //solve for ion transport and electric potential
timestep++;//AA operations
2020-09-20 11:00:36 -04:00
2021-01-04 00:07:11 -05:00
if (timestep%Study.analysis_interval==0){
Analysis.Basic(IonModel,PoissonSolver,StokesModel,timestep);
}
2020-09-20 11:00:36 -04:00
if (timestep%Study.visualization_interval==0){
Analysis.WriteVis(IonModel,PoissonSolver,StokesModel,Study.db,timestep);
2021-01-04 00:07:11 -05:00
/* PoissonSolver.getElectricPotential(timestep);
2020-09-20 11:00:36 -04:00
PoissonSolver.getElectricField(timestep);
IonModel.getIonConcentration(timestep);
StokesModel.getVelocity(timestep);
2021-01-04 00:07:11 -05:00
*/
2020-09-20 11:00:36 -04:00
}
2020-08-14 14:23:22 -04:00
}
2020-08-06 15:41:40 -04:00
2020-09-20 11:00:36 -04:00
if (rank==0) printf("Save simulation raw data at maximum timestep\n");
Analysis.WriteVis(IonModel,PoissonSolver,StokesModel,Study.db,timestep);
2020-08-06 15:41:40 -04:00
2020-08-20 22:47:10 -04:00
if (rank==0) printf("Maximum timestep is reached and the simulation is completed\n");
if (rank==0) printf("*************************************************************\n");
2020-08-14 14:23:22 -04:00
PROFILE_STOP("Main");
2020-09-20 11:00:36 -04:00
PROFILE_SAVE("lbpm_electrokinetic_SingleFluid_simulator",1);
2020-08-14 14:23:22 -04:00
// ****************************************************
2020-08-14 14:23:22 -04:00
} // Limit scope so variables that contain communicators will free before MPI_Finialize
Utilities::shutdown();
2020-08-06 15:41:40 -04:00
}