2020-09-02 11:37:23 -04:00
# include <stdio.h>
# include <stdlib.h>
# include <sys/stat.h>
# include <iostream>
# include <exception>
# include <stdexcept>
# include <fstream>
# include <math.h>
# include "models/PoissonSolver.h"
2020-10-08 22:13:28 -04:00
# include "common/Utilities.h"
2020-09-02 11:37:23 -04:00
using namespace std ;
//********************************************************
// Test lattice-Boltzmann solver of Poisson equation
//********************************************************
int main ( int argc , char * * argv )
{
// Initialize MPI
2020-10-08 22:13:28 -04:00
Utilities : : startup ( argc , argv ) ;
2021-01-05 18:43:44 -05:00
Utilities : : MPI comm ( MPI_COMM_WORLD ) ;
int rank = comm . getRank ( ) ;
int nprocs = comm . getSize ( ) ;
2020-10-08 22:13:28 -04:00
{ // Limit scope so variables that contain communicators will free before MPI_Finialize
2020-09-02 11:37:23 -04:00
if ( rank = = 0 ) {
printf ( " ******************************************************** \n " ) ;
printf ( " Running Test for LB-Poisson Solver \n " ) ;
printf ( " ******************************************************** \n " ) ;
}
2021-01-05 18:43:44 -05:00
// Initialize compute device
int device = ScaLBL_SetDevice ( rank ) ;
NULL_USE ( device ) ;
ScaLBL_DeviceBarrier ( ) ;
comm . barrier ( ) ;
2020-10-08 22:13:28 -04:00
PROFILE_ENABLE ( 1 ) ;
2020-09-02 11:37:23 -04:00
//PROFILE_ENABLE_TRACE();
//PROFILE_ENABLE_MEMORY();
PROFILE_SYNCHRONIZE ( ) ;
PROFILE_START ( " Main " ) ;
Utilities : : setErrorHandlers ( ) ;
auto filename = argv [ 1 ] ;
ScaLBL_Poisson PoissonSolver ( rank , nprocs , comm ) ;
// Initialize LB-Poisson model
PoissonSolver . ReadParams ( filename ) ;
PoissonSolver . SetDomain ( ) ;
PoissonSolver . ReadInput ( ) ;
PoissonSolver . Create ( ) ;
2021-01-04 20:13:48 -05:00
if ( PoissonSolver . TestPeriodic = = true ) {
PoissonSolver . Initialize ( PoissonSolver . TestPeriodicTimeConv ) ;
}
else {
PoissonSolver . Initialize ( 0 ) ;
}
2020-09-02 11:37:23 -04:00
//Initialize dummy charge density for test
PoissonSolver . DummyChargeDensity ( ) ;
2021-01-04 20:13:48 -05:00
if ( PoissonSolver . TestPeriodic = = true ) {
2021-01-06 01:03:18 -05:00
if ( rank = = 0 ) printf ( " Testing periodic voltage input is enabled. Total test time is %.3g[s], saving data every %.3g[s]; user-specified time resolution is %.3g[s/lt] \n " ,
2021-01-04 20:13:48 -05:00
PoissonSolver . TestPeriodicTime , PoissonSolver . TestPeriodicSaveInterval , PoissonSolver . TestPeriodicTimeConv ) ;
int timestep = 0 ;
2021-01-06 01:03:18 -05:00
int timeMax = int ( PoissonSolver . TestPeriodicTime / PoissonSolver . TestPeriodicTimeConv ) ;
int timeSave = int ( PoissonSolver . TestPeriodicSaveInterval / PoissonSolver . TestPeriodicTimeConv ) ;
while ( timestep < timeMax ) {
2021-01-04 20:13:48 -05:00
timestep + + ;
PoissonSolver . Run ( PoissonSolver . ChargeDensityDummy , timestep ) ;
2021-01-06 01:03:18 -05:00
if ( timestep % timeSave = = 0 ) {
2021-01-04 20:13:48 -05:00
if ( rank = = 0 ) printf ( " Time = %.3g[s]; saving electric potential and field \n " , timestep * PoissonSolver . TestPeriodicTimeConv ) ;
2021-01-06 01:03:18 -05:00
PoissonSolver . getElectricPotential_debug ( timestep ) ;
PoissonSolver . getElectricField_debug ( timestep ) ;
2021-01-04 20:13:48 -05:00
}
}
}
else {
PoissonSolver . Run ( PoissonSolver . ChargeDensityDummy , 1 ) ;
PoissonSolver . getElectricPotential_debug ( 1 ) ;
PoissonSolver . getElectricField_debug ( 1 ) ;
}
2020-09-02 11:37:23 -04:00
if ( rank = = 0 ) printf ( " Maximum timestep is reached and the simulation is completed \n " ) ;
if ( rank = = 0 ) printf ( " ************************************************************* \n " ) ;
PROFILE_STOP ( " Main " ) ;
PROFILE_SAVE ( " TestPoissonSolver " , 1 ) ;
// ****************************************************
2020-10-08 22:13:28 -04:00
2020-09-02 11:37:23 -04:00
} // Limit scope so variables that contain communicators will free before MPI_Finialize
2020-10-08 22:13:28 -04:00
Utilities : : shutdown ( ) ;
2020-09-02 11:37:23 -04:00
}