148 #include <sys/time.h>
157 #ifdef with_python_numpy
158 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
159 #include <numpy/arrayobject.h>
166 static const char help[] =
"HyPar - A finite-difference algorithm for solving hyperbolic-parabolic PDEs";
178 int main(
int argc,
char **argv)
181 struct timeval main_start, solve_start;
182 struct timeval main_end , solve_end ;
184 PetscBool use_petscts;
192 printf(
"HyPar - Serial Version\n");
196 MPI_Init(&argc,&argv);
197 MPI_Comm_dup(MPI_COMM_WORLD, &world);
198 MPI_Comm_rank(MPI_COMM_WORLD,&rank );
199 MPI_Comm_size(MPI_COMM_WORLD,&nproc);
200 if (!rank) printf(
"HyPar - Parallel (MPI) version with %d processes\n",nproc);
204 PetscInitialize(&argc,&argv,(
char*)0,
help);
205 if (!rank) printf(
"Compiled with PETSc time integration.\n");
213 gettimeofday(&main_start,NULL);
223 FILE *f_ensemble_sim = fopen(ensemble_sim_fname.c_str(),
"r");
224 FILE *f_sparsegrids_sim = fopen(sparsegrids_sim_fname.c_str(),
"r");
226 if (f_ensemble_sim && f_sparsegrids_sim) {
228 fprintf(stderr,
"Error: Cannot have both %s and %s input files.\n",
230 fprintf(stderr,
"Remove one or both of them depending on the kind of simulation you want to run.\n");
231 fclose(f_ensemble_sim);
232 fclose(f_sparsegrids_sim);
234 }
else if (f_ensemble_sim) {
237 fclose(f_ensemble_sim);
239 }
else if (f_sparsegrids_sim) {
242 fclose(f_sparsegrids_sim);
253 MPI_Bcast(&sim_type, 1, MPI_INT, 0, MPI_COMM_WORLD);
259 if (!rank) printf(
"-- Ensemble Simulation --\n");
262 if (!rank) printf(
"-- Sparse Grids Simulation --\n");
265 fprintf(stderr,
"ERROR: invalid sim_type (%d) on rank %d.\n",
270 fprintf(stderr,
"ERROR: unable to create sim on rank %d.\n",
276 ierr = sim->
define(rank, nproc);
278 printf(
"Error: Simulation::define() failed on rank %d\n",
283 printf(
"Error: Simulation::define() returned with status %d on process %d.\n",
293 use_petscts = PETSC_FALSE;
294 ierr = PetscOptionsGetBool(
nullptr,
nullptr,
297 nullptr); CHKERRQ(ierr);
298 if (use_petscts == PETSC_TRUE) use_petsc = 1;
305 printf(
"Error: Simulation::ReadInputs() returned with status %d on process %d.\n",ierr,rank);
312 printf(
"Error: Simulation::Initialize() returned with status %d on process %d.\n",ierr,rank);
319 printf(
"Error: Simulation::InitialSolution() returned with status %d on process %d.\n",ierr,rank);
326 printf(
"Error: Simulation::InitializeBoundaries() returned with status %d on process %d.\n",ierr,rank);
333 printf(
"Error: Simulation::InitializeImmersedBoundaries() returned with status %d on process %d.\n",ierr,rank);
340 printf(
"Error: Simulation::InitializeSolvers() returned with status %d on process %d.\n",ierr,rank);
347 printf(
"Error: Simulation::InitializePhysics() returned with status %d on process %d.\n",ierr,rank);
354 printf(
"Error: Simulation::InitializePhysicsData() returned with status %d on process %d.\n",ierr,rank);
361 printf(
"Error: Simulation::InitializationWrapup() returned with status %d on process %d.\n",ierr,rank);
369 MPI_Barrier(MPI_COMM_WORLD);
371 gettimeofday(&solve_start,NULL);
373 if (use_petsc == 1) {
377 printf(
"Error: Simulation::SolvePETSc() returned with status %d on process %d.\n",ierr,rank);
384 printf(
"Error: Simulation::Solve() returned with status %d on process %d.\n",ierr,rank);
392 printf(
"Error: Simulation::Solve() returned with status %d on process %d.\n",ierr,rank);
396 gettimeofday(&solve_end,NULL);
398 MPI_Barrier(MPI_COMM_WORLD);
400 gettimeofday(&main_end,NULL);
404 walltime = ( (main_end.tv_sec * 1000000 + main_end.tv_usec )
405 - (main_start.tv_sec * 1000000 + main_start.tv_usec));
406 double main_runtime = (double) walltime / 1000000.0;
407 ierr =
MPIMax_double(&main_runtime,&main_runtime,1,&world);
if(ierr)
return(ierr);
408 walltime = ( (solve_end.tv_sec * 1000000 + solve_end.tv_usec )
409 - (solve_start.tv_sec * 1000000 + solve_start.tv_usec));
410 double solver_runtime = (double) walltime / 1000000.0;
411 ierr =
MPIMax_double(&solver_runtime,&solver_runtime,1,&world);
if(ierr)
return(ierr);
418 if (!rank) printf(
"Finished.\n");
429 MPI_Comm_free(&world);
441 if (!a_rank) printf(
"Initialized Python.\n");
442 PyRun_SimpleString(
"import os");
443 PyRun_SimpleString(
"hypar_dir = os.environ.get('HYPAR_DIR')");
445 MPI_Barrier(MPI_COMM_WORLD);
454 PyRun_SimpleString(
"hypar_dir_plt_py = hypar_dir + '/src/PlottingFunctions'");
455 PyRun_SimpleString(
"import sys");
456 PyRun_SimpleString(
"sys.path.append(hypar_dir_plt_py)");
459 (
"print('Added plotting script directory (%s) to Python path.' % hypar_dir_plt_py)");
462 MPI_Barrier(MPI_COMM_WORLD);
static void initializePython(int)
Class describing sparse grids simulations.
#define _SPARSEGRIDS_SIM_INP_FNAME_
virtual int InitializePhysicsData()=0
virtual int mpiCommDup()=0
#define _SIM_TYPE_SINGLE_
virtual void usePetscTS(PetscBool)=0
Class describing a single simulation.
Class describing ensemble simulations.
int MPIMax_double(double *, double *, int, void *)
#define _SIM_TYPE_SPARSE_GRIDS_
virtual int Initialize()=0
virtual void WriteErrors(double, double)=0
#define _SIM_TYPE_ENSEMBLE_
virtual int SolvePETSc()=0
virtual bool isDefined() const =0
#define _ENSEMBLE_SIM_INP_FNAME_
virtual int InitializationWrapup()
virtual int InitialSolution()=0
virtual int define(int, int)=0
static void initializePythonPlotting(int)
virtual int InitializePhysics()=0
virtual int InitializeImmersedBoundaries()=0
C++ declarations for MPI-related functions.
virtual int InitializeBoundaries()=0
virtual int ReadInputs()=0
virtual int InitializeSolvers()=0
int main(int argc, char **argv)
Main driver.
Base class for a simulation.