HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
ShallowWater1DSource.c File Reference

Contains the functions to compute the source terms for the 1D shallow water equations. More...

#include <stdlib.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <physicalmodels/shallowwater1d.h>
#include <mpivars.h>
#include <hypar.h>

Go to the source code of this file.

Functions

static int ShallowWater1DSourceFunction1 (double *, double *, double *, void *, void *, double)
 
static int ShallowWater1DSourceFunction2 (double *, double *, double *, void *, void *, double)
 
int ShallowWater1DSource (double *source, double *u, void *s, void *m, double t)
 

Detailed Description

Contains the functions to compute the source terms for the 1D shallow water equations.

Author
Debojyoti Ghosh

Definition in file ShallowWater1DSource.c.

Function Documentation

◆ ShallowWater1DSourceFunction1()

int ShallowWater1DSourceFunction1 ( double *  f,
double *  u,
double *  x,
void *  s,
void *  m,
double  t 
)
static

Compute the first source function that is then "discretized" in a way similar to the hyperbolic flux function for the balanced formulation introduced in the reference below. The source term is reformulated and "discretized" in a similar fashion as the hyperbolic flux to ensure that the hydrostatic balance is maintained to machine precision.

  • Xing, Y., Shu, C.-W., "High order finite difference WENO schemes with the exact conservation property for the shallow water equations", Journal of Computational Physics, 208, 2005, pp. 206-227. http://dx.doi.org/10.1016/j.jcp.2005.02.006
Parameters
fComputed source function (array size and layout same as u)
uSolution (conserved variables)
xSpatial coordinates
sSolver object of type HyPar
mMPI object of type MPIVariables
tCurrent solution time

Definition at line 111 of file ShallowWater1DSource.c.

119 {
120  HyPar *solver = (HyPar* ) s;
121  ShallowWater1D *param = (ShallowWater1D*) solver->physics;
122 
123  int ghosts = solver->ghosts;
124  int *dim = solver->dim_local;
125  int ndims = solver->ndims;
126  int index[ndims], bounds[ndims], offset[ndims];
127 
128  /* set bounds for array index to include ghost points */
129  _ArrayCopy1D_(dim,bounds,ndims);
130  int i; for (i=0; i<ndims; i++) bounds[i] += 2*ghosts;
131 
132  /* set offset such that index is compatible with ghost point arrangement */
133  _ArraySetValue_(offset,ndims,-ghosts);
134 
135  int done = 0; _ArraySetValue_(index,ndims,0);
136  while (!done) {
137  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
138  (f+_MODEL_NVARS_*p)[0] = 0.0;
139  (f+_MODEL_NVARS_*p)[1] = 0.5 * param->g * param->b[p] * param->b[p];
140  _ArrayIncrementIndex_(ndims,bounds,index,done);
141  }
142 
143  return(0);
144 }
Structure containing variables and parameters specific to the 1D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 1D ShallowWater equations.
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
#define _ArrayIncrementIndex_(N, imax, i, done)
void * physics
Definition: hypar.h:266
int ghosts
Definition: hypar.h:52
#define _MODEL_NVARS_
Definition: euler1d.h:58
#define _ArrayCopy1D_(x, y, size)

◆ ShallowWater1DSourceFunction2()

int ShallowWater1DSourceFunction2 ( double *  f,
double *  u,
double *  x,
void *  s,
void *  m,
double  t 
)
static

Compute the second source function that is then "discretized" in a way similar to the hyperbolic flux function for the balanced formulation introduced in the reference below. The source term is reformulated and "discretized" in a similar fashion as the hyperbolic flux to ensure that the hydrostatic balance is maintained to machine precision.

  • Xing, Y., Shu, C.-W., "High order finite difference WENO schemes with the exact conservation property for the shallow water equations", Journal of Computational Physics, 208, 2005, pp. 206-227. http://dx.doi.org/10.1016/j.jcp.2005.02.006
Parameters
fComputed source function (array size and layout same as u)
uSolution (conserved variables)
xSpatial coordinates
sSolver object of type HyPar
mMPI object of type MPIVariables
tCurrent solution time

Definition at line 155 of file ShallowWater1DSource.c.

163 {
164  HyPar *solver = (HyPar* ) s;
165  ShallowWater1D *param = (ShallowWater1D*) solver->physics;
166 
167  int ghosts = solver->ghosts;
168  int *dim = solver->dim_local;
169  int ndims = solver->ndims;
170  int index[ndims], bounds[ndims], offset[ndims];
171 
172  /* set bounds for array index to include ghost points */
173  _ArrayCopy1D_(dim,bounds,ndims);
174  int i; for (i=0; i<ndims; i++) bounds[i] += 2*ghosts;
175 
176  /* set offset such that index is compatible with ghost point arrangement */
177  _ArraySetValue_(offset,ndims,-ghosts);
178 
179  int done = 0; _ArraySetValue_(index,ndims,0);
180  while (!done) {
181  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
182  (f+_MODEL_NVARS_*p)[0] = 0.0;
183  (f+_MODEL_NVARS_*p)[1] = param->b[p];
184  _ArrayIncrementIndex_(ndims,bounds,index,done);
185  }
186 
187  return(0);
188 }
Structure containing variables and parameters specific to the 1D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 1D ShallowWater equations.
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
#define _ArrayIncrementIndex_(N, imax, i, done)
void * physics
Definition: hypar.h:266
int ghosts
Definition: hypar.h:52
#define _MODEL_NVARS_
Definition: euler1d.h:58
#define _ArrayCopy1D_(x, y, size)

◆ ShallowWater1DSource()

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

Compute the source terms for the 1D shallow water equations. The source term is computed according to the balanced formulation introduced in the reference below. The source term is reformulated and "discretized" in a similar fashion as the hyperbolic flux to ensure that the hydrostatic balance is maintained to machine precision.

  • Xing, Y., Shu, C.-W., "High order finite difference WENO schemes with the exact conservation property for the shallow water equations", Journal of Computational Physics, 208, 2005, pp. 206-227. http://dx.doi.org/10.1016/j.jcp.2005.02.006
Parameters
sourceComputed source terms (array size & layout same as u)
uSolution (conserved variables)
sSolver object of type HyPar
mMPI object of type MPIVariables
tCurrent solution time

Definition at line 25 of file ShallowWater1DSource.c.

32 {
33  HyPar *solver = (HyPar* ) s;
34  MPIVariables *mpi = (MPIVariables*) m;
35  ShallowWater1D *param = (ShallowWater1D*) solver->physics;
36 
37  int v, done, p, p1, p2;
38  double *SourceI = solver->fluxI; /* interace source term */
39  double *SourceC = solver->fluxC; /* cell-centered source term */
40  double *SourceL = solver->fL;
41  double *SourceR = solver->fR;
42 
43  int ndims = solver->ndims;
44  int ghosts = solver->ghosts;
45  int *dim = solver->dim_local;
46  double *x = solver->x;
47  double *dxinv = solver->dxinv;
48  int index[ndims],index1[ndims],index2[ndims],dim_interface[ndims];
49 
50  /* set interface dimensions */
51  _ArrayCopy1D_(dim,dim_interface,ndims); dim_interface[_XDIR_]++;
52 
53  /* calculate the first source function */
54  IERR ShallowWater1DSourceFunction1(SourceC,u,x,solver,mpi,t); CHECKERR(ierr);
55  /* calculate the left and right interface source terms */
56  IERR solver->InterpolateInterfacesHyp(SourceL,SourceC,u,x, 1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
57  IERR solver->InterpolateInterfacesHyp(SourceR,SourceC,u,x,-1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
58  /* calculate the final interface source term */
59  IERR param->SourceUpwind(SourceI,SourceL,SourceR,u,_XDIR_,solver,t);
60  /* calculate the final cell-centered source term */
61  done = 0; _ArraySetValue_(index,ndims,0);
62  while (!done) {
63  _ArrayCopy1D_(index,index1,ndims);
64  _ArrayCopy1D_(index,index2,ndims); index2[_XDIR_]++;
65  _ArrayIndex1D_(ndims,dim ,index ,ghosts,p );
66  _ArrayIndex1D_(ndims,dim_interface,index1,0 ,p1);
67  _ArrayIndex1D_(ndims,dim_interface,index2,0 ,p2);
68  double dx_inverse; _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,dxinv,dx_inverse);
69  for (v=0; v<_MODEL_NVARS_; v++)
70  source[_MODEL_NVARS_*p+v] += (SourceI[_MODEL_NVARS_*p2+v]-SourceI[_MODEL_NVARS_*p1+v])*dx_inverse;
71  _ArrayIncrementIndex_(ndims,dim,index,done);
72  }
73 
74  /* calculate the second source function */
75  IERR ShallowWater1DSourceFunction2(SourceC,u,x,solver,mpi,t); CHECKERR(ierr);
76  /* calculate the left and right interface source terms */
77  IERR solver->InterpolateInterfacesHyp(SourceL,SourceC,u,x, 1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
78  IERR solver->InterpolateInterfacesHyp(SourceR,SourceC,u,x,-1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
79  /* calculate the final interface source term */
80  IERR param->SourceUpwind(SourceI,SourceL,SourceR,u,_XDIR_,solver,t);
81  /* calculate the final cell-centered source term */
82  done = 0; _ArraySetValue_(index,ndims,0);
83  while (!done) {
84  _ArrayCopy1D_(index,index1,ndims);
85  _ArrayCopy1D_(index,index2,ndims); index2[_XDIR_]++;
86  _ArrayIndex1D_(ndims,dim ,index ,ghosts,p );
87  _ArrayIndex1D_(ndims,dim_interface,index1,0 ,p1);
88  _ArrayIndex1D_(ndims,dim_interface,index2,0 ,p2);
89  double dx_inverse; _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,dxinv,dx_inverse);
90  double h, vel; _ShallowWater1DGetFlowVar_((u+_MODEL_NVARS_*p),h,vel);
91  double term[_MODEL_NVARS_] = { 0.0, -param->g * (h + param->b[p]) };
92  for (v=0; v<_MODEL_NVARS_; v++) {
93  source[_MODEL_NVARS_*p+v] += term[v]*(SourceI[_MODEL_NVARS_*p2+v]-SourceI[_MODEL_NVARS_*p1+v])*dx_inverse;
94  }
95  vel = h; /* useless statement to avoid compiler warning */
96  _ArrayIncrementIndex_(ndims,dim,index,done);
97  }
98 
99  return(0);
100 }
Structure containing variables and parameters specific to the 1D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 1D ShallowWater equations.
static int ShallowWater1DSourceFunction2(double *, double *, double *, void *, void *, double)
#define IERR
Definition: basic.h:16
#define CHECKERR(ierr)
Definition: basic.h:18
int(* SourceUpwind)(double *, double *, double *, double *, int, void *, double)
double * x
Definition: hypar.h:107
double * fluxI
Definition: hypar.h:136
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int(* InterpolateInterfacesHyp)(double *, double *, double *, double *, int, int, void *, void *, int)
Definition: hypar.h:224
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _GetCoordinate_(dir, i, dim, ghosts, x, coord)
Definition: basic.h:31
void * physics
Definition: hypar.h:266
#define _ShallowWater1DGetFlowVar_(u, h, v)
double * fR
Definition: hypar.h:139
double * fL
Definition: hypar.h:139
#define _XDIR_
Definition: euler1d.h:75
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
static int ShallowWater1DSourceFunction1(double *, double *, double *, void *, void *, double)
#define _MODEL_NVARS_
Definition: euler1d.h:58
#define _ArrayCopy1D_(x, y, size)
double * fluxC
Definition: hypar.h:128
double * dxinv
Definition: hypar.h:110