HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
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

◆ SourceFunction()

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 }
int nvars
Definition: hypar.h:29
int BCSpongeSource(void *, int, int, int, int *, double *, double *, double *)
Definition: BCSponge.c:26
void * boundary
Definition: hypar.h:159
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
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