HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
SourceFunction.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <string.h>
8 #include <basic.h>
9 #if defined(HAVE_CUDA)
10 #include <arrayfunctions_gpu.h>
11 #else
12 #include <arrayfunctions.h>
13 #endif
14 #include <boundaryconditions.h>
15 #include <mpivars.h>
16 #include <hypar.h>
17 
23  double *source,
24  double *u,
25  void *s,
26  void *m,
27  double t
28  )
29 {
30  HyPar *solver = (HyPar*) s;
31  MPIVariables *mpi = (MPIVariables*) m;
32 
33  /* initialize to zero */
34  int size = solver->ndof_cells_wghosts;
35 #if defined(HAVE_CUDA)
36  if (solver->use_gpu) {
37  gpuArraySetValue(source,size, 0.0);
38  } else {
39 #endif
40  _ArraySetValue_(source,size,0.0);
41 #if defined(HAVE_CUDA)
42  }
43 #endif
44 
45  /* call the source function of the physics model, if available */
46  if (solver->SFunction) {
47  solver->SFunction(source,u,solver,mpi,t);
48  solver->count_sou++;
49  }
50 
51  /* Apart from other source terms, implement sponge BC as a source */
52  DomainBoundary* boundary = (DomainBoundary*) solver->boundary;
53  int n;
54  int nb = solver->nBoundaryZones;
55 #if defined(HAVE_CUDA)
56  if (solver->use_gpu) {
57  for (n = 0; n < nb; n++) {
58  if (!strcmp(boundary[n].bctype,_SPONGE_)) {
59  fprintf(stderr,"ERROR: Sponge BC not yet implemented on GPU.\n");
60  }
61  }
62  } else {
63 #endif
64  for (n = 0; n < nb; n++) {
65  if (!strcmp(boundary[n].bctype,_SPONGE_)) {
66  BCSpongeSource( &boundary[n],
67  solver->ndims,
68  solver->nvars,
69  solver->ghosts,
70  solver->dim_local,
71  solver->x,
72  u,
73  source );
74  }
75  }
76 #if defined(HAVE_CUDA)
77  }
78 #endif
79 
80 
81  return(0);
82 }
int nvars
Definition: hypar.h:29
Containts the structures and definitions for boundary condition implementation.
int BCSpongeSource(void *, int, int, int, int *, double *, double *, double *)
Definition: BCSponge.c:26
MPI related function definitions.
Contains function definitions for common array operations on GPU.
void * boundary
Definition: hypar.h:159
int SourceFunction(double *source, double *u, void *s, void *m, double t)
Some basic definitions and macros.
int(* SFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:317
double * x
Definition: hypar.h:107
#define _SPONGE_
Structure containing the variables and function pointers defining a boundary.
void gpuArraySetValue(double *, int, double)
int ndims
Definition: hypar.h:26
int ndof_cells_wghosts
Definition: hypar.h:47
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Contains structure definition for hypar.
int count_sou
Definition: hypar.h:418
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
int use_gpu
Definition: hypar.h:449
int nBoundaryZones
Definition: hypar.h:157
Contains macros and function definitions for common array operations.