HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
BCSponge.c File Reference

Sponge boundary condition. More...

#include <stdlib.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <boundaryconditions.h>

Go to the source code of this file.

Functions

int BCSpongeSource (void *b, int ndims, int nvars, int ghosts, int *size, double *grid, double *u, double *source)
 
int BCSpongeUDummy (void *b, void *m, int ndims, int nvars, int *size, int ghosts, double *phi, double waqt)
 

Detailed Description

Sponge boundary condition.

Author
Debojyoti Ghosh

Definition in file BCSponge.c.

Function Documentation

int BCSpongeSource ( void *  b,
int  ndims,
int  nvars,
int  ghosts,
int *  size,
double *  grid,
double *  u,
double *  source 
)

Applies the sponge boundary condition: This function computes the source term required to apply a sponge boundary condition that gradually relaxes the solution to a specified state. This boundary condition is different from other boundary conditions in the sense that it is applied at interior grid points (but within the defined sponge zone).

The source term for the sponge is computed as:

\begin{align} {\bf S}_i &= \sigma_i \left( {\bf U}_i - {\bf U}_{\rm ref} \right),\\ \sigma_i &= \frac {x_i - x_{\rm start}} {x_{\rm end} - x_{\rm start}} \end{align}

where \(i\) is the grid index along the spatial dimension of the sponge, \({\bf U}_{\rm ref}\) is the specified state to which the solution is relaxed, and \(x_i\), \(x_{\rm start}\), and \(x_{\rm end}\) are the spatial coordinates of the grid point, sponge start, and sponge end, respectively, along the spatial dimension of the sponge.

Parameters
bBoundary object of type DomainBoundary
ndimsNumber of spatial dimensions
nvarsNumber of variables/DoFs per grid point
ghostsNumber of ghost points
sizeInteger array with the number of grid points in each spatial dimension
grid1D array with the spatial coordinates of the grid points, one dimension after the other
uSolution
sourceSource term to which the sponge term is added

Definition at line 26 of file BCSponge.c.

36 {
37  DomainBoundary *boundary = (DomainBoundary*) b;
38  int dim = boundary->dim;
39  int face = boundary->face;
40  double *uref = boundary->SpongeValue;
41  double *xmin = boundary->xmin;
42  double *xmax = boundary->xmax;
43  int v;
44 
45  if (boundary->on_this_proc) {
46  int bounds[ndims], indexb[ndims];
47  _ArraySubtract1D_(bounds,boundary->ie,boundary->is,ndims);
48  _ArraySetValue_(indexb,ndims,0);
49  int done = 0;
50  while (!done) {
51  int i = indexb[dim] + boundary->is[dim];
52  double x, xstart, xend;
53  _GetCoordinate_(dim,i,size,ghosts,grid,x);
54  xstart = xmin[dim];
55  xend = xmax[dim];
56  /* calculate sigma */
57  double sigma;
58  if (face > 0) sigma = (x - xstart) / (xend - xstart);
59  else sigma = (x - xend ) / (xstart - xend);
60  /* add to the source term */
61  int p; _ArrayIndex1DWO_(ndims,size,indexb,boundary->is,ghosts,p);
62  for (v=0; v<nvars; v++) source[nvars*p+v] -= (sigma * (u[nvars*p+v]-uref[v]));
63  _ArrayIncrementIndex_(ndims,bounds,indexb,done);
64  }
65  }
66  return(0);
67 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _GetCoordinate_(dir, i, dim, ghosts, x, coord)
Definition: basic.h:31
#define _ArraySubtract1D_(x, a, b, size)
Structure containing the variables and function pointers defining a boundary.
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
int BCSpongeUDummy ( void *  b,
void *  m,
int  ndims,
int  nvars,
int *  size,
int  ghosts,
double *  phi,
double  waqt 
)

Dummy function to ensure consistency with the overall boundary condition implementation. The actual sponge boundary condition is implemented by BCSpongeSource()

Parameters
bBoundary object of type DomainBoundary
mMPI object of type MPIVariables
ndimsNumber of spatial dimensions
nvarsNumber of variables/DoFs per grid point
sizeInteger array with the number of grid points in each spatial dimension
ghostsNumber of ghost points
phiThe solution array on which to apply the boundary condition
waqtCurrent solution time

Definition at line 73 of file BCSponge.c.

83 {
84  return(0);
85 }