HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 }
#define _ArraySetValue_(x, size, value)
int BCSpongeSource(void *, int, int, int, int *, double *, double *, double *)
Definition: BCSponge.c:26
Containts the structures and definitions for boundary condition implementation.
int * dim_local
Definition: hypar.h:37
MPI related function definitions.
void gpuArraySetValue(double *, int, double)
int ghosts
Definition: hypar.h:52
void * boundary
Definition: hypar.h:159
Structure containing the variables and function pointers defining a boundary.
int ndof_cells_wghosts
Definition: hypar.h:47
#define _SPONGE_
Contains function definitions for common array operations on GPU.
int nBoundaryZones
Definition: hypar.h:157
int(* SFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:317
int nvars
Definition: hypar.h:29
Contains structure definition for hypar.
int use_gpu
Definition: hypar.h:449
Some basic definitions and macros.
int count_sou
Definition: hypar.h:418
int SourceFunction(double *source, double *u, void *s, void *m, double t)
int ndims
Definition: hypar.h:26
Contains macros and function definitions for common array operations.
Structure of MPI-related variables.
double * x
Definition: hypar.h:107
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23