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

Clean up time integration. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arrayfunctions_gpu.h>
#include <simulation_object.h>
#include <timeintegration.h>

Go to the source code of this file.

Functions

int TimeCleanup (void *ts)
 

Detailed Description

Clean up time integration.

Author
Debojyoti Ghosh

Definition in file TimeCleanup.c.

Function Documentation

◆ TimeCleanup()

int TimeCleanup ( void *  ts)

Clean up all allocations related to time integration

Parameters
tsObject of type TimeIntegration

Definition at line 18 of file TimeCleanup.c.

19 {
20  TimeIntegration* TS = (TimeIntegration*) ts;
22  int ns, nsims = TS->nsims;
23 
24  /* close files opened for writing */
25  if (!TS->rank) if (sim[0].solver.write_residual) fclose((FILE*)TS->ResidualFile);
26 
27 #if defined(HAVE_CUDA)
28  if (sim[0].solver.use_gpu) {
29  if (!strcmp(sim[0].solver.time_scheme,_RK_)) {
30  gpuFree(TS->gpu_U);
31  gpuFree(TS->gpu_Udot);
33  }
34  } else {
35 #endif
36  if (!strcmp(sim[0].solver.time_scheme,_RK_)) {
37  int i;
38  ExplicitRKParameters *params = (ExplicitRKParameters*) sim[0].solver.msti;
39  for (i=0; i<params->nstages; i++) free(TS->U[i]); free(TS->U);
40  for (i=0; i<params->nstages; i++) free(TS->Udot[i]); free(TS->Udot);
41  for (i=0; i<params->nstages; i++) free(TS->BoundaryFlux[i]); free(TS->BoundaryFlux);
42  } else if (!strcmp(sim[0].solver.time_scheme,_FORWARD_EULER_)) {
43  int nstages = 1, i;
44  for (i=0; i<nstages; i++) free(TS->BoundaryFlux[i]); free(TS->BoundaryFlux);
45  } else if (!strcmp(sim[0].solver.time_scheme,_GLM_GEE_)) {
46  int i;
47  GLMGEEParameters *params = (GLMGEEParameters*) sim[0].solver.msti;
48  for (i=0; i<2*params->r-1 ; i++) free(TS->U[i]); free(TS->U);
49  for (i=0; i<params->nstages; i++) free(TS->Udot[i]); free(TS->Udot);
50  for (i=0; i<params->nstages; i++) free(TS->BoundaryFlux[i]); free(TS->BoundaryFlux);
51  }
52 #if defined(HAVE_CUDA)
53  }
54 #endif
55 
56  /* deallocate arrays */
57  free(TS->u_offsets);
58  free(TS->u_sizes);
59  free(TS->bf_offsets);
60  free(TS->bf_sizes);
61  free(TS->u );
62  free(TS->rhs);
63  for (ns = 0; ns < nsims; ns++) {
64  sim[ns].solver.time_integrator = NULL;
65  }
66  return(0);
67 }
Structure of variables/parameters and function pointers for time integration.
Structure defining a simulation.
void * time_integrator
Definition: hypar.h:165
#define _FORWARD_EULER_
#define _GLM_GEE_
#define _RK_
Structure containing the parameters for an explicit Runge-Kutta method.
Structure containing the parameters for the General Linear Methods with Global Error Estimators (GLM-...
void gpuFree(void *)