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 File Reference

Evaluate the source term. More...

#include <stdlib.h>
#include <string.h>
#include <basic.h>
#include <arrayfunctions_gpu.h>
#include <boundaryconditions.h>
#include <mpivars.h>
#include <hypar.h>

Go to the source code of this file.

Functions

int SourceFunction (double *source, double *u, void *s, void *m, double t)
 

Detailed Description

Evaluate the source term.

Author
Debojyoti Ghosh, Youngdae Kim

Definition in file SourceFunction.c.

Function Documentation

int SourceFunction ( double *  source,
double *  u,
void *  s,
void *  m,
double  t 
)

Evaluate the source term \({\bf S}\left({\bf u}\right)\) in the governing equation, if the physical model specifies one. In addition, if the simulation requires a sponge boundary treatment, the sponge BC function is called.

Parameters
sourcethe computed source term
usolution
ssolver object of type HyPar
mMPI object of type MPIVariables
tCurrent simulation time

Definition at line 22 of file SourceFunction.c.

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
int * dim_local
Definition: hypar.h:37
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_
int nBoundaryZones
Definition: hypar.h:157
int(* SFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:317
int nvars
Definition: hypar.h:29
int use_gpu
Definition: hypar.h:449
int count_sou
Definition: hypar.h:418
int ndims
Definition: hypar.h:26
Structure of MPI-related variables.
double * x
Definition: hypar.h:107
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23