HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
PetscPreTimeStep.cpp
Go to the documentation of this file.
1 
5 #ifdef with_petsc
6 
7 #include <stdio.h>
8 #include <basic.h>
9 #include <arrayfunctions.h>
10 #include <mpivars_cpp.h>
11 #include <simulation_object.h>
12 #include <petscinterface.h>
13 
14 #ifdef with_librom
15 #include <librom_interface.h>
16 #endif
17 
18 int OutputSolution (void*,int,double);
20 #undef __FUNCT__
21 #define __FUNCT__ "PetscPreTimeStep"
22 
24 PetscErrorCode PetscPreTimeStep(TS ts )
25 {
26  PETScContext* context(nullptr);
27 
28  PetscFunctionBegin;
29 
30  TSGetApplicationContext(ts,&context);
31  if (!context) {
32  fprintf(stderr,"Error in PetscPreTimeStep: Null context!\n");
33  return(1);
34  }
35  gettimeofday(&(context->iter_start_time),NULL);
36  SimulationObject* sim = (SimulationObject*) context->simobj;
37  int nsims = context->nsims;
38 
39  Vec Y;
40  TSGetSolution(ts,&Y);
41 
42  double waqt;
43  TSGetTime(ts,&waqt);
44  double dt;
45  TSGetTimeStep(ts,&dt);
46  int iter;
47  TSGetStepNumber(ts,&iter);
48 
49  context->dt = dt;
50  context->waqt = waqt;
51  context->t_start = waqt;
52 
53  TSType time_scheme;
54  TSGetType(ts,&time_scheme);
55 
56  for (int ns = 0; ns < nsims; ns++) {
57 
58  HyPar* solver = &(sim[ns].solver);
59  MPIVariables* mpi = &(sim[ns].mpi);
60 
61  /* get solution */
62  TransferVecFromPETSc(solver->u,Y,context,ns,context->offsets[ns]);
63 
64  /* save a copy of the solution to compute norm at end of time step */
65  _ArrayCopy1D_(solver->u,solver->u0,(solver->npoints_local_wghosts*solver->nvars));
66 
67  /* apply boundary conditions and exchange data over MPI interfaces */
68  solver->ApplyBoundaryConditions(solver,mpi,solver->u,NULL,waqt);
69  solver->ApplyIBConditions(solver,mpi,solver->u,waqt);
71  solver->nvars,
72  solver->dim_local,
73  solver->ghosts,
74  mpi,
75  solver->u );
76 
77  /* Call any physics-specific pre-step function */
78  if (solver->PreStep) solver->PreStep(solver->u,solver,mpi,waqt);
79 
80  /* If using a non-linear scheme with ARKIMEX methods,
81  compute the non-linear finite-difference operator */
82  if (!strcmp(time_scheme,TSARKIMEX)) {
83  solver->NonlinearInterp(solver->u,solver,mpi,waqt,solver->FFunction);
84  }
85 
86  /* set the step boundary flux integral value to zero */
87  _ArraySetValue_(solver->StepBoundaryIntegral,2*solver->ndims*solver->nvars,0.0);
88 
89  TransferVecToPETSc(solver->u,Y,context,ns,context->offsets[ns]);
90 
91  }
92 
93 
94  if (!iter) {
95  for (int ns = 0; ns < nsims; ns++) {
96  HyPar* solver = &(sim[ns].solver);
97  MPIVariables* mpi = &(sim[ns].mpi);
98  if (solver->PhysicsOutput) solver->PhysicsOutput(solver,mpi,waqt);
99  }
100  OutputSolution(sim, nsims,waqt);
101 #ifdef with_librom
102  context->op_times_arr.push_back(waqt);
103 #endif
104  }
105 
106 #ifdef with_librom
107  if ( (context->rom_mode == _ROM_MODE_TRAIN_)
108  && (iter%((libROMInterface*)context->rom_interface)->samplingFrequency() == 0) ) {
109  ((libROMInterface*)context->rom_interface)->takeSample( sim, waqt );
110  }
111 #endif
112 
113  PetscFunctionReturn(0);
114 }
115 
116 #endif
int OutputSolution(void *, int, double)
int(* PhysicsOutput)(void *, void *, double)
Definition: hypar.h:347
int TransferVecToPETSc(const double *const, Vec, void *, const int, const int)
int nvars
Definition: hypar.h:29
Structure defining a simulation.
C++ declarations for MPI-related functions.
int MPIExchangeBoundariesnD(int, int, int *, int, void *, double *)
int(* ApplyBoundaryConditions)(void *, void *, double *, double *, double)
Definition: hypar.h:214
int(* NonlinearInterp)(double *, void *, void *, double, int(*)(double *, double *, int, void *, double))
Definition: hypar.h:228
double * u
Definition: hypar.h:116
Some basic definitions and macros.
Simulation object.
int(* ApplyIBConditions)(void *, void *, double *, double)
Definition: hypar.h:217
double * u0
Definition: hypar.h:396
int ndims
Definition: hypar.h:26
struct timeval iter_start_time
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _ROM_MODE_TRAIN_
std::vector< double > op_times_arr
int(* PreStep)(double *, void *, void *, double)
Definition: hypar.h:339
Structure containing the variables for time-integration with PETSc.
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
libROM interface class
Class implementing interface with libROM.
int ghosts
Definition: hypar.h:52
double * StepBoundaryIntegral
Definition: hypar.h:384
Structure of MPI-related variables.
int npoints_local_wghosts
Definition: hypar.h:42
PetscErrorCode PetscPreTimeStep(TS ts)
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
int TransferVecFromPETSc(double *const, const Vec, void *, const int, const int)