Main driver.
The main driver function that calls the initialization, solving, and cleaning up functions.
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);
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
virtual int InitializeBoundaries()=0
virtual int ReadInputs()=0
virtual int InitializeSolvers()=0
Base class for a simulation.