HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
TimePreStep.c File Reference

Pre-time-step function. More...

#include <basic.h>
#include <arrayfunctions_gpu.h>
#include <timeintegration.h>
#include <mpivars.h>
#include <simulation_object.h>

Go to the source code of this file.

Functions

int TimePreStep (void *ts)
 

Detailed Description

Pre-time-step function.

Author
Debojyoti Ghosh, Youngdae Kim

Definition in file TimePreStep.c.

Function Documentation

◆ TimePreStep()

int TimePreStep ( void *  ts)

Pre-time-step function: This function is called before each time step. Some notable things this does are:

  • Computes CFL and diffusion numbers.
  • Call the physics-specific pre-time-step function, if defined.
Parameters
tsObject of type TimeIntegration

Definition at line 22 of file TimePreStep.c.

23 {
24  TimeIntegration* TS = (TimeIntegration*) ts;
26 
28  int ns, nsims = TS->nsims;
29 
30  gettimeofday(&TS->iter_start_time,NULL);
31 
32  for (ns = 0; ns < nsims; ns++) {
33 
34  HyPar* solver = &(sim[ns].solver);
35  MPIVariables* mpi = &(sim[ns].mpi);
36 
37  double *u = NULL;
38 #if defined(HAVE_CUDA)
39  if (solver->use_gpu) {
40  u = solver->gpu_u;
41  } else{
42 #endif
43  u = solver->u;
44 #if defined(HAVE_CUDA)
45  }
46 #endif
47 
48  /* apply boundary conditions and exchange data over MPI interfaces */
49 
50  solver->ApplyBoundaryConditions( solver,
51  mpi,
52  u,
53  NULL,
54  TS->waqt );
55 
56  solver->ApplyIBConditions( solver,
57  mpi,
58  u,
59  TS->waqt );
60 
61 #if defined(HAVE_CUDA)
62  if (solver->use_gpu) {
64  solver->nvars,
65  solver->gpu_dim_local,
66  solver->ghosts,
67  mpi,
68  u );
69  } else {
70 #endif
72  solver->nvars,
73  solver->dim_local,
74  solver->ghosts,
75  mpi,
76  u );
77 #if defined(HAVE_CUDA)
78  }
79 #endif
80 
81  if ((TS->iter+1)%solver->screen_op_iter == 0) {
82 
83 #if defined(HAVE_CUDA)
84  if (!solver->use_gpu) {
85 #endif
86  _ArrayCopy1D_( solver->u,
87  (TS->u + TS->u_offsets[ns]),
88  (solver->npoints_local_wghosts*solver->nvars) );
89 #if defined(HAVE_CUDA)
90  }
91 #endif
92 
93  /* compute max CFL and diffusion number over the domain */
94  if (solver->ComputeCFL) {
95  double local_max_cfl = -1.0;
96  local_max_cfl = solver->ComputeCFL (solver,mpi,TS->dt,TS->waqt);
97  MPIMax_double(&TS->max_cfl ,&local_max_cfl ,1,&mpi->world);
98  } else {
99  TS->max_cfl = -1;
100  }
101  if (solver->ComputeDiffNumber) {
102  double local_max_diff = -1.0;
103  local_max_diff = solver->ComputeDiffNumber (solver,mpi,TS->dt,TS->waqt);
104  MPIMax_double(&TS->max_diff,&local_max_diff,1,&mpi->world);
105  } else {
106  TS->max_diff = -1;
107  }
108 
109  }
110 
111  /* set the step boundary flux integral value to zero */
112 #if defined(HAVE_CUDA)
113  if (solver->use_gpu) {
114  gpuArraySetValue(solver->StepBoundaryIntegral,2*solver->ndims*solver->nvars,0.0);
115  } else {
116 #endif
117  _ArraySetValue_(solver->StepBoundaryIntegral,2*solver->ndims*solver->nvars,0.0);
118 #if defined(HAVE_CUDA)
119  }
120 #endif
121 
122  if (solver->PreStep) {
123  solver->PreStep(u,solver,mpi,TS->waqt);
124  }
125 
126  }
127 
128  return 0;
129 }
Structure of variables/parameters and function pointers for time integration.
int nvars
Definition: hypar.h:29
Structure defining a simulation.
int MPIExchangeBoundariesnD(int, int, int *, int, void *, double *)
int(* ApplyBoundaryConditions)(void *, void *, double *, double *, double)
Definition: hypar.h:214
double * u
Definition: hypar.h:116
int(* ApplyIBConditions)(void *, void *, double *, double)
Definition: hypar.h:217
void gpuArraySetValue(double *, int, double)
int ndims
Definition: hypar.h:26
double(* ComputeCFL)(void *, void *, double, double)
Definition: hypar.h:269
int * gpu_dim_local
Definition: hypar.h:455
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int MPIMax_double(double *, double *, int, void *)
Definition: MPIMax.c:38
double * gpu_u
Definition: hypar.h:459
MPI_Comm world
int(* PreStep)(double *, void *, void *, double)
Definition: hypar.h:339
double(* ComputeDiffNumber)(void *, void *, double, double)
Definition: hypar.h:272
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
int gpuMPIExchangeBoundariesnD(int, int, const int *, int, void *, double *)
int ghosts
Definition: hypar.h:52
double * StepBoundaryIntegral
Definition: hypar.h:384
Structure of MPI-related variables.
int use_gpu
Definition: hypar.h:449
int npoints_local_wghosts
Definition: hypar.h:42
#define _DECLARE_IERR_
Definition: basic.h:17
#define _ArrayCopy1D_(x, y, size)
struct timeval iter_start_time
int screen_op_iter
Definition: hypar.h:168