HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
TimeRHSFunctionExplicit.c
Go to the documentation of this file.
1 
6 #include <basic.h>
7 #if defined(HAVE_CUDA)
8 #include <arrayfunctions_gpu.h>
9 #else
10 #include <arrayfunctions.h>
11 #endif
12 #include <mpivars.h>
13 #include <hypar.h>
14 
15 #include <time.h>
16 
31  double *rhs,
32  double *u,
33  void *s,
34  void *m,
35  double t
36  )
37 {
38  HyPar *solver = (HyPar*) s;
39  MPIVariables *mpi = (MPIVariables*) m;
40  int d;
41 
42  int size = 1;
43  for (d=0; d<solver->ndims; d++) size *= (solver->dim_local[d]+2*solver->ghosts);
44 
45  /* apply boundary conditions and exchange data over MPI interfaces */
46  solver->ApplyBoundaryConditions(solver,mpi,u,NULL,t);
47  solver->ApplyIBConditions(solver,mpi,u,t);
48 
49  /* Evaluate hyperbolic, parabolic and source terms and the RHS */
50 #if defined(HAVE_CUDA)
51  if (solver->use_gpu) {
53  solver->nvars,
54  solver->gpu_dim_local,
55  solver->ghosts,
56  mpi,
57  u );
58  } else {
59 #endif
61  solver->nvars,
62  solver->dim_local,
63  solver->ghosts,
64  mpi,
65  u);
66 #if defined(HAVE_CUDA)
67  }
68 #endif
69 
70  solver->HyperbolicFunction( solver->hyp,
71  u,
72  solver,
73  mpi,
74  t,
75  1,
76  solver->FFunction,
77  solver->Upwind );
78  solver->ParabolicFunction(solver->par,u,solver,mpi,t);
79  solver->SourceFunction(solver->source,u,solver,mpi,t);
80 
81 #if defined(HAVE_CUDA)
82  if (solver->use_gpu) {
83  gpuArraySetValue(rhs, size*solver->nvars, 0.0);
84  gpuArrayAXPY(solver->hyp, -1.0, rhs, size*solver->nvars);
85  gpuArrayAXPY(solver->par, 1.0, rhs, size*solver->nvars);
86  gpuArrayAXPY(solver->source, 1.0, rhs, size*solver->nvars);
87  } else {
88 #endif
89  _ArraySetValue_(rhs,size*solver->nvars,0.0);
90  _ArrayAXPY_(solver->hyp ,-1.0,rhs,size*solver->nvars);
91  _ArrayAXPY_(solver->par , 1.0,rhs,size*solver->nvars);
92  _ArrayAXPY_(solver->source, 1.0,rhs,size*solver->nvars);
93 #if defined(HAVE_CUDA)
94  }
95 #endif
96 
97  return(0);
98 }
int nvars
Definition: hypar.h:29
MPI related function definitions.
Contains function definitions for common array operations on GPU.
int(* ParabolicFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:256
double * par
Definition: hypar.h:122
int MPIExchangeBoundariesnD(int, int, int *, int, void *, double *)
int(* ApplyBoundaryConditions)(void *, void *, double *, double *, double)
Definition: hypar.h:214
Some basic definitions and macros.
int(* ApplyIBConditions)(void *, void *, double *, double)
Definition: hypar.h:217
int(* Upwind)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:295
void gpuArrayAXPY(const double *, double, double *, int)
int(* SourceFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:259
void gpuArraySetValue(double *, int, double)
int ndims
Definition: hypar.h:26
int(* HyperbolicFunction)(double *, double *, void *, void *, double, int, int(*)(double *, double *, int, void *, double), int(*)(double *, double *, double *, double *, double *, double *, int, void *, double))
Definition: hypar.h:250
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
int * gpu_dim_local
Definition: hypar.h:455
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _ArrayAXPY_(x, a, y, size)
Contains structure definition for hypar.
int TimeRHSFunctionExplicit(double *rhs, double *u, void *s, void *m, double t)
#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
Structure of MPI-related variables.
int use_gpu
Definition: hypar.h:449
Contains macros and function definitions for common array operations.
double * source
Definition: hypar.h:125
double * hyp
Definition: hypar.h:119