HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TimePostStep.c File Reference

Post-time-step function. More...

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <basic.h>
#include <arrayfunctions_gpu.h>
#include <mpivars.h>
#include <simulation_object.h>
#include <timeintegration.h>

Go to the source code of this file.

Functions

int TimePostStep (void *ts)
 

Detailed Description

Post-time-step function.

Author
Debojyoti Ghosh

Definition in file TimePostStep.c.

Function Documentation

int TimePostStep ( void *  ts)

Post-time-step function: this function is called at the end of each time step.

  • It updates the current simulation time.
  • It calls functions to print information and to write transient solution to file.
  • It will also call any physics-specific post-time-step function, if defined.
Parameters
tsObject of type TimeIntegration

Definition at line 28 of file TimePostStep.c.

29 {
30  TimeIntegration* TS = (TimeIntegration*) ts;
32  int ns, nsims = TS->nsims;
33 
34  /* update current time */
35  TS->waqt += TS->dt;
36 
37  if ((TS->iter+1)%sim[0].solver.screen_op_iter == 0) {
38 
39 #if defined(HAVE_CUDA)
40  if (sim[0].solver.use_gpu) {
41  TS->norm = -1;
42  } else {
43 #endif
44  /* Calculate norm for this time step */
45  double sum = 0.0;
46  double npts = 0;
47  for (ns = 0; ns < nsims; ns++) {
48  _ArrayAXPY_(sim[ns].solver.u,-1.0,(TS->u+TS->u_offsets[ns]),TS->u_sizes[ns]);
49  sum += ArraySumSquarenD( sim[ns].solver.nvars,
50  sim[ns].solver.ndims,
51  sim[ns].solver.dim_local,
52  sim[ns].solver.ghosts,
53  sim[ns].solver.index,
54  (TS->u+TS->u_offsets[ns]) );
55  npts += (double)sim[ns].solver.npoints_global;
56  }
57 
58  double global_sum = 0;
59  MPISum_double( &global_sum,
60  &sum,1,
61  &(sim[0].mpi.world) );
62 
63  TS->norm = sqrt(global_sum/npts);
64 #if defined(HAVE_CUDA)
65  }
66 #endif
67 
68  /* write to file */
69  if (TS->ResidualFile) {
70  fprintf((FILE*)TS->ResidualFile,"%10d\t%E\t%E\n",TS->iter+1,TS->waqt,TS->norm);
71  }
72 
73  }
74 
75 
76 #if defined(HAVE_CUDA)
77  if (!sim[0].solver.use_gpu) {
78 #endif
79  for (ns = 0; ns < nsims; ns++) {
80 
81  if (!strcmp(sim[ns].solver.ConservationCheck,"yes")) {
82  /* calculate volume integral of the solution at this time step */
83  IERR sim[ns].solver.VolumeIntegralFunction( sim[ns].solver.VolumeIntegral,
84  sim[ns].solver.u,
85  &(sim[ns].solver),
86  &(sim[ns].mpi) ); CHECKERR(ierr);
87  /* calculate surface integral of the flux at this time step */
88  IERR sim[ns].solver.BoundaryIntegralFunction( &(sim[ns].solver),
89  &(sim[ns].mpi)); CHECKERR(ierr);
90  /* calculate the conservation error at this time step */
91  IERR sim[ns].solver.CalculateConservationError( &(sim[ns].solver),
92  &(sim[ns].mpi)); CHECKERR(ierr);
93  }
94 
95  if (sim[ns].solver.PostStep) {
96  sim[ns].solver.PostStep(sim[ns].solver.u,&(sim[ns].solver),&(sim[ns].mpi),TS->waqt,TS->iter);
97  }
98 
99  }
100 #if defined(HAVE_CUDA)
101  }
102 #endif
103 
104  gettimeofday(&TS->iter_end_time,NULL);
105  long long walltime;
106  walltime = ( (TS->iter_end_time.tv_sec * 1000000 + TS->iter_end_time.tv_usec)
107  - (TS->iter_start_time.tv_sec * 1000000 + TS->iter_start_time.tv_usec));
108  TS->iter_wctime = (double) walltime / 1000000.0;
109  TS->iter_wctime_total += TS->iter_wctime;
110 
111  double global_total = 0, global_wctime = 0, global_mpi_total = 0, global_mpi_wctime = 0;
112 
113  MPIMax_double(&global_wctime, &TS->iter_wctime, 1, &(sim[0].mpi.world));
114  MPIMax_double(&global_total, &TS->iter_wctime_total, 1, &(sim[0].mpi.world));
115 
116 #if defined(HAVE_CUDA)
117  MPIMax_double(&global_mpi_wctime, &sim[0].mpi.wctime, 1, &(sim[0].mpi.world));
118  MPIMax_double(&global_mpi_total, &sim[0].mpi.wctime_total, 1, &(sim[0].mpi.world));
119 #endif
120 
121  return(0);
122 }
double * u
Definition: hypar.h:116
Structure of variables/parameters and function pointers for time integration.
int * dim_local
Definition: hypar.h:37
int MPISum_double(double *, double *, int, void *)
Definition: MPISum.c:39
struct timeval iter_start_time
int MPIMax_double(double *, double *, int, void *)
Definition: MPIMax.c:38
int ghosts
Definition: hypar.h:52
int screen_op_iter
Definition: hypar.h:168
MPI_Comm world
INLINE double ArraySumSquarenD(int, int, int *, int, int *, double *)
int(* BoundaryIntegralFunction)(void *, void *)
Definition: hypar.h:390
struct timeval iter_end_time
int(* VolumeIntegralFunction)(double *, double *, void *, void *)
Definition: hypar.h:388
#define CHECKERR(ierr)
Definition: basic.h:18
long sum(const std::vector< int > &a_iv)
Definition: std_vec_ops.h:18
Structure defining a simulation.
int ndims
Definition: hypar.h:26
int * index
Definition: hypar.h:102
#define IERR
Definition: basic.h:16
int(* CalculateConservationError)(void *, void *)
Definition: hypar.h:392
#define _ArrayAXPY_(x, a, y, size)
int(* PostStep)(double *, void *, void *, double, int)
Definition: hypar.h:341