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

Initialize the 2D shallow water equations module. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <physicalmodels/shallowwater2d.h>
#include <mpivars.h>
#include <hypar.h>

Go to the source code of this file.

Functions

double ShallowWater2DComputeCFL (void *, void *, double, double)
 
int ShallowWater2DFlux (double *, double *, int, void *, double)
 
int ShallowWater2DSource (double *, double *, void *, void *, double)
 
int ShallowWater2DUpwindRoe (double *, double *, double *, double *, double *, double *, int, void *, double)
 
int ShallowWater2DUpwindLLF (double *, double *, double *, double *, double *, double *, int, void *, double)
 
int ShallowWater2DJacobian (double *, double *, void *, int, int, int)
 
int ShallowWater2DRoeAverage (double *, double *, double *, void *)
 
int ShallowWater2DLeftEigenvectors (double *, double *, void *, int)
 
int ShallowWater2DRightEigenvectors (double *, double *, void *, int)
 
int ShallowWater2DTopography (void *, void *, int, int, int *)
 
int ShallowWater2DSourceUpwindLLF (double *, double *, double *, double *, int, void *, double)
 
int ShallowWater2DSourceUpwindRoe (double *, double *, double *, double *, int, void *, double)
 
int ShallowWater2DModifiedSolution (double *, double *, int, void *, void *, double)
 
int ShallowWater2DWriteTopography (void *, void *, double)
 
int ShallowWater2DInitialize (void *s, void *m)
 

Detailed Description

Initialize the 2D shallow water equations module.

Author
Debojyoti Ghosh

Definition in file ShallowWater2DInitialize.c.

Function Documentation

double ShallowWater2DComputeCFL ( void *  s,
void *  m,
double  dt,
double  t 
)

Computes the maximum CFL number over the domain. Note that the CFL is computed over the local domain on this processor only.

Parameters
sSolver object of type HyPar
mMPI object of type MPIVariables
dtTime step size for which to compute the CFL
tTime

Definition at line 17 of file ShallowWater2DComputeCFL.c.

23 {
24  HyPar *solver = (HyPar*) s;
25  ShallowWater2D *param = (ShallowWater2D*) solver->physics;
26 
27  int *dim = solver->dim_local;
28  int ghosts = solver->ghosts;
29  int ndims = solver->ndims;
30  int index[ndims];
31  double *u = solver->u;
32 
33  double max_cfl = 0;
34  int done = 0; _ArraySetValue_(index,ndims,0);
35  while (!done) {
36  int p; _ArrayIndex1D_(ndims,dim,index,ghosts,p);
37  double h, uvel, vvel, c, dxinv, dyinv, local_cfl[_MODEL_NDIMS_];
38  _ShallowWater2DGetFlowVar_((u+_MODEL_NVARS_*p),h,uvel,vvel);
39 
40  _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,solver->dxinv,dxinv); /* 1/dx */
41  _GetCoordinate_(_YDIR_,index[_YDIR_],dim,ghosts,solver->dxinv,dyinv); /* 1/dy */
42  c = sqrt(param->g*h); /* speed of gravity waves */
43  local_cfl[_XDIR_]=(absolute(uvel)+c)*dt*dxinv;/* local cfl for this grid point (x) */
44  local_cfl[_YDIR_]=(absolute(vvel)+c)*dt*dyinv;/* local cfl for this grid point (y) */
45  if (local_cfl[_XDIR_] > max_cfl) max_cfl = local_cfl[_XDIR_];
46  if (local_cfl[_YDIR_] > max_cfl) max_cfl = local_cfl[_YDIR_];
47 
48  _ArrayIncrementIndex_(ndims,dim,index,done);
49  }
50 
51  return(max_cfl);
52 }
#define _YDIR_
Definition: euler2d.h:41
#define _ArraySetValue_(x, size, value)
double * u
Definition: hypar.h:116
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _MODEL_NVARS_
Definition: euler1d.h:58
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
#define _GetCoordinate_(dir, i, dim, ghosts, x, coord)
Definition: basic.h:31
#define _MODEL_NDIMS_
Definition: euler1d.h:56
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ShallowWater2DGetFlowVar_(u, h, uvel, vvel)
double * dxinv
Definition: hypar.h:110
int ndims
Definition: hypar.h:26
#define absolute(a)
Definition: math_ops.h:32
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _XDIR_
Definition: euler1d.h:75
int ShallowWater2DFlux ( double *  f,
double *  u,
int  dir,
void *  s,
double  t 
)

Compute the hyperbolic flux over the local domain.

\begin{equation} {\bf F}\left({\bf u}\right) = \left\{\begin{array}{cc} \left[\begin{array}{c} hu \\ hu^2 + \frac{1}{2} gh^2 \\ huv \end{array}\right] & {\rm dir} = x \\ \left[\begin{array}{c} hv \\ huv \\ hv^2 + \frac{1}{2} gh^2 \end{array}\right] & {\rm dir} = y \\ \end{array}\right. \end{equation}

Parameters
fArray to hold the computed flux (same size and layout as u)
uArray containing the conserved solution
dirSpatial dimension
sSolver object of type HyPar
tCurrent time

Definition at line 20 of file ShallowWater2DFlux.c.

27 {
28  HyPar *solver = (HyPar*) s;
29  ShallowWater2D *param = (ShallowWater2D*) solver->physics;
30  int *dim = solver->dim_local;
31  int ghosts = solver->ghosts;
32  static const int ndims = _MODEL_NDIMS_;
33  static const int nvars = _MODEL_NVARS_;
34  static int index[_MODEL_NDIMS_], bounds[_MODEL_NDIMS_], offset[_MODEL_NDIMS_];
35 
36  /* set bounds for array index to include ghost points */
37  _ArrayAddCopy1D_(dim,(2*ghosts),bounds,ndims);
38  /* set offset such that index is compatible with ghost point arrangement */
39  _ArraySetValue_(offset,ndims,-ghosts);
40 
41  int done = 0; _ArraySetValue_(index,ndims,0);
42  while (!done) {
43  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
44  double h, uvel, vvel;
45  _ShallowWater2DGetFlowVar_((u+nvars*p),h,uvel,vvel);
46  _ShallowWater2DSetFlux_((f+nvars*p),h,uvel,vvel,param->g,dir);
47  _ArrayIncrementIndex_(ndims,bounds,index,done);
48  }
49 
50  return(0);
51 }
#define _ShallowWater2DSetFlux_(f, h, uvel, vvel, g, dir)
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _MODEL_NVARS_
Definition: euler1d.h:58
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
#define _MODEL_NDIMS_
Definition: euler1d.h:56
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
#define _ShallowWater2DGetFlowVar_(u, h, uvel, vvel)
#define _ArrayAddCopy1D_(x, a, y, size)
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int ShallowWater2DSource ( double *  source,
double *  u,
void *  s,
void *  m,
double  t 
)

Compute the source terms for the 2D shallow water equations.

  • The topography gradient 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
  • The Coriolis source term is added in a naive way – a balanced formulation may be needed. The Coriolis source term is implemented as described in:
    Zhu, Et. al., "Variational Data Assimilation with a Variable Resolution Finite-Element Shallow-Water Equations Model", Monthly Weather Review, 122, 1994, pp. 946–965 http://dx.doi.org/10.1175/1520-0493(1994)122%3C0946:VDAWAV%3E2.0.CO;2
    Eqns. (2.1)-(2.3), (2.4)
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 33 of file ShallowWater2DSource.c.

40 {
41  HyPar *solver = (HyPar* ) s;
42  MPIVariables *mpi = (MPIVariables*) m;
43  ShallowWater2D *param = (ShallowWater2D*) solver->physics;
44 
45  int v, done, p, p1, p2;
46  double *SourceI = solver->fluxI; /* interace source term */
47  double *SourceC = solver->fluxC; /* cell-centered source term */
48  double *SourceL = solver->fL;
49  double *SourceR = solver->fR;
50 
51  int ndims = solver->ndims;
52  int ghosts = solver->ghosts;
53  int *dim = solver->dim_local;
54  double *x = solver->x;
55  double *dxinv = solver->dxinv;
56  int index[ndims],index1[ndims],index2[ndims],dim_interface[ndims];
57 
58  /* Along X */
59 
60  /* set interface dimensions */
61  _ArrayCopy1D_(dim,dim_interface,ndims); dim_interface[_XDIR_]++;
62 
63  /* calculate the first source function */
64  IERR ShallowWater2DSourceFunction1(SourceC,u,x,solver,mpi,t,_XDIR_); CHECKERR(ierr);
65  /* calculate the left and right interface source terms */
66  IERR solver->InterpolateInterfacesHyp(SourceL,SourceC,u,x, 1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
67  IERR solver->InterpolateInterfacesHyp(SourceR,SourceC,u,x,-1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
68  /* calculate the final interface source term */
69  IERR param->SourceUpwind(SourceI,SourceL,SourceR,u,_XDIR_,solver,t);
70  /* calculate the final cell-centered source term */
71  done = 0; _ArraySetValue_(index,ndims,0);
72  while (!done) {
73  _ArrayCopy1D_(index,index1,ndims);
74  _ArrayCopy1D_(index,index2,ndims); index2[_XDIR_]++;
75  _ArrayIndex1D_(ndims,dim ,index ,ghosts,p );
76  _ArrayIndex1D_(ndims,dim_interface,index1,0 ,p1);
77  _ArrayIndex1D_(ndims,dim_interface,index2,0 ,p2);
78  double dx_inverse; _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,dxinv,dx_inverse);
79  for (v=0; v<_MODEL_NVARS_; v++)
80  source[_MODEL_NVARS_*p+v] += (SourceI[_MODEL_NVARS_*p2+v]-SourceI[_MODEL_NVARS_*p1+v])*dx_inverse;
81  _ArrayIncrementIndex_(ndims,dim,index,done);
82  }
83  /* calculate the second source function */
84  IERR ShallowWater2DSourceFunction2(SourceC,u,x,solver,mpi,t,_XDIR_); CHECKERR(ierr);
85  /* calculate the left and right interface source terms */
86  IERR solver->InterpolateInterfacesHyp(SourceL,SourceC,u,x, 1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
87  IERR solver->InterpolateInterfacesHyp(SourceR,SourceC,u,x,-1,_XDIR_,solver,mpi,0); CHECKERR(ierr);
88  /* calculate the final interface source term */
89  IERR param->SourceUpwind(SourceI,SourceL,SourceR,u,_XDIR_,solver,t);
90  /* calculate the final cell-centered source term */
91  done = 0; _ArraySetValue_(index,ndims,0);
92  while (!done) {
93  _ArrayCopy1D_(index,index1,ndims);
94  _ArrayCopy1D_(index,index2,ndims); index2[_XDIR_]++;
95  _ArrayIndex1D_(ndims,dim ,index ,ghosts,p );
96  _ArrayIndex1D_(ndims,dim_interface,index1,0 ,p1);
97  _ArrayIndex1D_(ndims,dim_interface,index2,0 ,p2);
98  double dx_inverse; _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,dxinv,dx_inverse);
99  double h, uvel, vvel; _ShallowWater2DGetFlowVar_((u+_MODEL_NVARS_*p),h,uvel,vvel);
100  double term[_MODEL_NVARS_] = { 0.0, -param->g * (h + param->b[p]), 0.0 };
101  for (v=0; v<_MODEL_NVARS_; v++)
102  source[_MODEL_NVARS_*p+v] += term[v]*(SourceI[_MODEL_NVARS_*p2+v]-SourceI[_MODEL_NVARS_*p1+v])*dx_inverse;
103  uvel = vvel = h; /* useless statement to avoid compiler warning */
104  _ArrayIncrementIndex_(ndims,dim,index,done);
105  }
106 
107  /* Along Y */
108 
109  /* set interface dimensions */
110  _ArrayCopy1D_(dim,dim_interface,ndims); dim_interface[_YDIR_]++;
111 
112  /* calculate the first source function */
113  IERR ShallowWater2DSourceFunction1(SourceC,u,x,solver,mpi,t,_YDIR_); CHECKERR(ierr);
114  /* calculate the left and right interface source terms */
115  IERR solver->InterpolateInterfacesHyp(SourceL,SourceC,u,x, 1,_YDIR_,solver,mpi,0); CHECKERR(ierr);
116  IERR solver->InterpolateInterfacesHyp(SourceR,SourceC,u,x,-1,_YDIR_,solver,mpi,0); CHECKERR(ierr);
117  /* calculate the final interface source term */
118  IERR param->SourceUpwind(SourceI,SourceL,SourceR,u,_YDIR_,solver,t);
119  /* calculate the final cell-centered source term */
120  done = 0; _ArraySetValue_(index,ndims,0);
121  while (!done) {
122  _ArrayCopy1D_(index,index1,ndims);
123  _ArrayCopy1D_(index,index2,ndims); index2[_YDIR_]++;
124  _ArrayIndex1D_(ndims,dim ,index ,ghosts,p );
125  _ArrayIndex1D_(ndims,dim_interface,index1,0 ,p1);
126  _ArrayIndex1D_(ndims,dim_interface,index2,0 ,p2);
127  double dy_inverse; _GetCoordinate_(_YDIR_,index[_YDIR_],dim,ghosts,dxinv,dy_inverse);
128  for (v=0; v<_MODEL_NVARS_; v++)
129  source[_MODEL_NVARS_*p+v] += (SourceI[_MODEL_NVARS_*p2+v]-SourceI[_MODEL_NVARS_*p1+v])*dy_inverse;
130  _ArrayIncrementIndex_(ndims,dim,index,done);
131  }
132  /* calculate the second source function */
133  IERR ShallowWater2DSourceFunction2(SourceC,u,x,solver,mpi,t,_YDIR_); CHECKERR(ierr);
134  /* calculate the left and right interface source terms */
135  IERR solver->InterpolateInterfacesHyp(SourceL,SourceC,u,x, 1,_YDIR_,solver,mpi,0); CHECKERR(ierr);
136  IERR solver->InterpolateInterfacesHyp(SourceR,SourceC,u,x,-1,_YDIR_,solver,mpi,0); CHECKERR(ierr);
137  /* calculate the final interface source term */
138  IERR param->SourceUpwind(SourceI,SourceL,SourceR,u,_YDIR_,solver,t);
139  /* calculate the final cell-centered source term */
140  done = 0; _ArraySetValue_(index,ndims,0);
141  while (!done) {
142  _ArrayCopy1D_(index,index1,ndims);
143  _ArrayCopy1D_(index,index2,ndims); index2[_YDIR_]++;
144  _ArrayIndex1D_(ndims,dim ,index ,ghosts,p );
145  _ArrayIndex1D_(ndims,dim_interface,index1,0 ,p1);
146  _ArrayIndex1D_(ndims,dim_interface,index2,0 ,p2);
147  double dy_inverse; _GetCoordinate_(_YDIR_,index[_YDIR_],dim,ghosts,dxinv,dy_inverse);
148  double h, uvel, vvel; _ShallowWater2DGetFlowVar_((u+_MODEL_NVARS_*p),h,uvel,vvel);
149  double term[_MODEL_NVARS_] = { 0.0, 0.0, -param->g * (h + param->b[p]) };
150  for (v=0; v<_MODEL_NVARS_; v++)
151  source[_MODEL_NVARS_*p+v] += term[v]*(SourceI[_MODEL_NVARS_*p2+v]-SourceI[_MODEL_NVARS_*p1+v])*dy_inverse;
152  uvel = vvel = h; /* useless statement to avoid compiler warning */
153  _ArrayIncrementIndex_(ndims,dim,index,done);
154  }
155 
156  /* Naive addition of Coriolis force terms */
157  done = 0; _ArraySetValue_(index,ndims,0);
158  while (!done) {
159  _ArrayIndex1D_(ndims,dim,index ,ghosts,p);
160  double h, uvel, vvel;
161  _ShallowWater2DGetFlowVar_((u+_MODEL_NVARS_*p),h,uvel,vvel);
162  double ycoord; _GetCoordinate_(_YDIR_,index[_YDIR_],dim,ghosts,solver->x,ycoord);
163  double coeff = param->fhat + param->beta * (ycoord - 0.5*param->D);
164  double coriolis_x = coeff * vvel,
165  coriolis_y = -coeff * uvel;
166  source[_MODEL_NVARS_*p+1] += coriolis_x;
167  source[_MODEL_NVARS_*p+2] += coriolis_y;
168  _ArrayIncrementIndex_(ndims,dim,index,done);
169  }
170 
171  return(0);
172 }
#define _YDIR_
Definition: euler2d.h:41
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _MODEL_NVARS_
Definition: euler1d.h:58
double * fL
Definition: hypar.h:139
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
#define _GetCoordinate_(dir, i, dim, ghosts, x, coord)
Definition: basic.h:31
static int ShallowWater2DSourceFunction2(double *, double *, double *, void *, void *, double, int)
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
double * fluxI
Definition: hypar.h:136
int(* SourceUpwind)(double *, double *, double *, double *, int, void *, double)
#define _ArrayCopy1D_(x, y, size)
double * fluxC
Definition: hypar.h:128
int(* InterpolateInterfacesHyp)(double *, double *, double *, double *, int, int, void *, void *, int)
Definition: hypar.h:224
#define CHECKERR(ierr)
Definition: basic.h:18
#define _ShallowWater2DGetFlowVar_(u, h, uvel, vvel)
double * dxinv
Definition: hypar.h:110
static int ShallowWater2DSourceFunction1(double *, double *, double *, void *, void *, double, int)
int ndims
Definition: hypar.h:26
#define IERR
Definition: basic.h:16
Structure of MPI-related variables.
double * x
Definition: hypar.h:107
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _XDIR_
Definition: euler1d.h:75
double * fR
Definition: hypar.h:139
int ShallowWater2DUpwindRoe ( double *  fI,
double *  fL,
double *  fR,
double *  uL,
double *  uR,
double *  u,
int  dir,
void *  s,
double  t 
)

Roe's upwinding scheme.

\begin{equation} {\bf f}_{j+1/2} = \frac{1}{2}\left[ {\bf f}_{j+1/2}^L + {\bf f}_{j+1/2}^R - \left| A\left({\bf u}_{j+1/2}^L,{\bf u}_{j+1/2}^R\right) \right| \left( {\bf u}_{j+1/2}^R - {\bf u}_{j+1/2}^L \right)\right] \end{equation}

This upwinding scheme is modified for the balanced discretization of the 2D shallow water equations. See the following reference:

  • 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
fIComputed upwind interface flux
fLLeft-biased reconstructed interface flux
fRRight-biased reconstructed interface flux
uLLeft-biased reconstructed interface solution
uRRight-biased reconstructed interface solution
uCell-centered solution
dirSpatial dimension
sSolver object of type HyPar
tCurrent solution time

Definition at line 31 of file ShallowWater2DUpwind.c.

42 {
43  HyPar *solver = (HyPar*) s;
44  ShallowWater2D *param = (ShallowWater2D*) solver->physics;
45  int done,k;
46 
47  int ndims = solver->ndims;
48  int ghosts= solver->ghosts;
49  int *dim = solver->dim_local;
50 
51  int index_outer[ndims], index_inter[ndims], bounds_outer[ndims], bounds_inter[ndims];
52  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
53  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
56 
57  done = 0; _ArraySetValue_(index_outer,ndims,0);
58  while (!done) {
59  _ArrayCopy1D_(index_outer,index_inter,ndims);
60  for (index_inter[dir] = 0; index_inter[dir] < bounds_inter[dir]; index_inter[dir]++) {
61  int p; _ArrayIndex1D_(ndims,bounds_inter,index_inter,0,p);
62  int indexL[ndims]; _ArrayCopy1D_(index_inter,indexL,ndims); indexL[dir]--;
63  int indexR[ndims]; _ArrayCopy1D_(index_inter,indexR,ndims);
64  int pL; _ArrayIndex1D_(ndims,dim,indexL,ghosts,pL);
65  int pR; _ArrayIndex1D_(ndims,dim,indexR,ghosts,pR);
66  double udiff[_MODEL_NVARS_], uavg[_MODEL_NVARS_],udiss[_MODEL_NVARS_];
67 
68  /* Roe's upwinding scheme */
69 
70  udiff[0] = 0.5 * (uR[_MODEL_NVARS_*p+0] - uL[_MODEL_NVARS_*p+0]);
71  udiff[1] = 0.5 * (uR[_MODEL_NVARS_*p+1] - uL[_MODEL_NVARS_*p+1]);
72  udiff[2] = 0.5 * (uR[_MODEL_NVARS_*p+2] - uL[_MODEL_NVARS_*p+2]);
73 
74  _ShallowWater2DRoeAverage_ (uavg,(u+_MODEL_NVARS_*pL),(u+_MODEL_NVARS_*pR),param);
75  _ShallowWater2DEigenvalues_ (uavg,D,param,dir);
76  _ShallowWater2DLeftEigenvectors_ (uavg,L,param,dir);
77  _ShallowWater2DRightEigenvectors_ (uavg,R,param,dir);
78 
79  k = 0; D[k] = absolute(D[k]);
80  k = 4; D[k] = absolute(D[k]);
81  k = 8; D[k] = absolute(D[k]);
82 
83  MatMult3(_MODEL_NVARS_,DL,D,L);
84  MatMult3(_MODEL_NVARS_,modA,R,DL);
85 
86  udiss[0] = modA[0*_MODEL_NVARS_+0]*udiff[0] + modA[0*_MODEL_NVARS_+1]*udiff[1] + modA[0*_MODEL_NVARS_+2]*udiff[2];
87  udiss[1] = modA[1*_MODEL_NVARS_+0]*udiff[0] + modA[1*_MODEL_NVARS_+1]*udiff[1] + modA[1*_MODEL_NVARS_+2]*udiff[2];
88  udiss[2] = modA[2*_MODEL_NVARS_+0]*udiff[0] + modA[2*_MODEL_NVARS_+1]*udiff[1] + modA[2*_MODEL_NVARS_+2]*udiff[2];
89 
90  fI[_MODEL_NVARS_*p+0] = 0.5 * (fL[_MODEL_NVARS_*p+0]+fR[_MODEL_NVARS_*p+0]) - udiss[0];
91  fI[_MODEL_NVARS_*p+1] = 0.5 * (fL[_MODEL_NVARS_*p+1]+fR[_MODEL_NVARS_*p+1]) - udiss[1];
92  fI[_MODEL_NVARS_*p+2] = 0.5 * (fL[_MODEL_NVARS_*p+2]+fR[_MODEL_NVARS_*p+2]) - udiss[2];
93  }
94  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
95  }
96 
97  return(0);
98 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _MODEL_NVARS_
Definition: euler1d.h:58
#define MatMult3(N, A, X, Y)
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
#define _ShallowWater2DLeftEigenvectors_(u, L, p, dir)
#define _ShallowWater2DEigenvalues_(u, D, p, dir)
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ShallowWater2DRightEigenvectors_(u, R, p, dir)
#define _ArrayCopy1D_(x, y, size)
#define _ShallowWater2DRoeAverage_(uavg, uL, uR, p)
int ndims
Definition: hypar.h:26
#define absolute(a)
Definition: math_ops.h:32
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int ShallowWater2DUpwindLLF ( double *  fI,
double *  fL,
double *  fR,
double *  uL,
double *  uR,
double *  u,
int  dir,
void *  s,
double  t 
)

Characteristic-based local Lax-Friedrich upwinding scheme.

\begin{align} \alpha_{j+1/2}^{k,L} &= \sum_{k=1}^2 {\bf l}_{j+1/2}^k \cdot {\bf f}_{j+1/2}^{k,L}, \\ \alpha_{j+1/2}^{k,R} &= \sum_{k=1}^2 {\bf l}_{j+1/2}^k \cdot {\bf f}_{j+1/2}^{k,R}, \\ v_{j+1/2}^{k,L} &= \sum_{k=1}^2 {\bf l}_{j+1/2}^k \cdot {\bf u}_{j+1/2}^{k,L}, \\ v_{j+1/2}^{k,R} &= \sum_{k=1}^2 {\bf l}_{j+1/2}^k \cdot {\bf u}_{j+1/2}^{k,R}, \\ \alpha_{j+1/2}^k &= \frac{1}{2}\left[ \alpha_{j+1/2}^{k,L} + \alpha_{j+1/2}^{k,R} - \left(\max_{\left[j,j+1\right]} \lambda\right) \left( v_{j+1/2}^{k,R} - v_{j+1/2}^{k,L} \right) \right], \\ {\bf f}_{j+1/2} &= \sum_{k=1}^2 \alpha_{j+1/2}^k {\bf r}_{j+1/2}^k \end{align}

where \({\bf l}\), \({\bf r}\), and \(\lambda\) are the left-eigenvectors, right-eigenvectors and eigenvalues. The subscripts denote the grid locations.

This upwinding scheme is modified for the balanced discretization of the 1D shallow water equations. See the following reference:

  • 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
fIComputed upwind interface flux
fLLeft-biased reconstructed interface flux
fRRight-biased reconstructed interface flux
uLLeft-biased reconstructed interface solution
uRRight-biased reconstructed interface solution
uCell-centered solution
dirSpatial dimension
sSolver object of type HyPar
tCurrent solution time

Definition at line 118 of file ShallowWater2DUpwind.c.

129 {
130  HyPar *solver = (HyPar*) s;
131  ShallowWater2D *param = (ShallowWater2D*) solver->physics;
132  int done,k;
133 
134  int ndims = solver->ndims;
135  int *dim = solver->dim_local;
136  int ghosts = solver->ghosts;
137 
138  int index_outer[ndims], index_inter[ndims], bounds_outer[ndims], bounds_inter[ndims];
139  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
140  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
142 
143  done = 0; _ArraySetValue_(index_outer,ndims,0);
144  while (!done) {
145  _ArrayCopy1D_(index_outer,index_inter,ndims);
146  for (index_inter[dir] = 0; index_inter[dir] < bounds_inter[dir]; index_inter[dir]++) {
147  int p; _ArrayIndex1D_(ndims,bounds_inter,index_inter,0,p);
148  int indexL[ndims]; _ArrayCopy1D_(index_inter,indexL,ndims); indexL[dir]--;
149  int indexR[ndims]; _ArrayCopy1D_(index_inter,indexR,ndims);
150  int pL; _ArrayIndex1D_(ndims,dim,indexL,ghosts,pL);
151  int pR; _ArrayIndex1D_(ndims,dim,indexR,ghosts,pR);
152  double uavg[_MODEL_NVARS_], fcL[_MODEL_NVARS_], fcR[_MODEL_NVARS_],
153  ucL[_MODEL_NVARS_], ucR[_MODEL_NVARS_], fc[_MODEL_NVARS_];
154 
155  /* Local Lax-Friedrich upwinding scheme */
156 
157  _ShallowWater2DRoeAverage_ (uavg,(u+_MODEL_NVARS_*pL),(u+_MODEL_NVARS_*pR),param);
158  _ShallowWater2DEigenvalues_ (uavg,D,param,dir);
159  _ShallowWater2DLeftEigenvectors_ (uavg,L,param,dir);
160  _ShallowWater2DRightEigenvectors_(uavg,R,param,dir);
161 
162  /* calculate characteristic fluxes and variables */
167 
168  for (k = 0; k < _MODEL_NVARS_; k++) {
169  double eigL,eigC,eigR;
170  _ShallowWater2DEigenvalues_((u+_MODEL_NVARS_*pL),D,param,dir);
171  eigL = D[k*_MODEL_NVARS_+k];
172  _ShallowWater2DEigenvalues_((u+_MODEL_NVARS_*pR),D,param,dir);
173  eigR = D[k*_MODEL_NVARS_+k];
174  _ShallowWater2DEigenvalues_(uavg,D,param,dir);
175  eigC = D[k*_MODEL_NVARS_+k];
176 
177  double alpha = max3(absolute(eigL),absolute(eigC),absolute(eigR));
178  fc[k] = 0.5 * (fcL[k] + fcR[k] + alpha * (ucL[k]-ucR[k]));
179  }
180 
181  /* calculate the interface flux from the characteristic flux */
182  MatVecMult3(_MODEL_NVARS_,(fI+_MODEL_NVARS_*p),R,fc);
183  }
184  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
185  }
186 
187  return(0);
188 }
#define _ArraySetValue_(x, size, value)
#define max3(a, b, c)
Definition: math_ops.h:27
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _MODEL_NVARS_
Definition: euler1d.h:58
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
#define _ShallowWater2DLeftEigenvectors_(u, L, p, dir)
#define _ShallowWater2DEigenvalues_(u, D, p, dir)
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ShallowWater2DRightEigenvectors_(u, R, p, dir)
#define _ArrayCopy1D_(x, y, size)
#define _ShallowWater2DRoeAverage_(uavg, uL, uR, p)
int ndims
Definition: hypar.h:26
#define absolute(a)
Definition: math_ops.h:32
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define MatVecMult3(N, y, A, x)
int ShallowWater2DJacobian ( double *  Jac,
double *  u,
void *  p,
int  dir,
int  nvars,
int  upw 
)

Function to compute the flux Jacobian of the 2D shallow water equations, given the solution at a grid point. The Jacobian is square matrix of size nvar=2, and is returned as a 1D array (double) of 4 elements in row-major format.

Parameters
JacJacobian matrix: 1D array of size nvar^2 = 9
usolution at a grid point (array of size nvar = 3)
pobject containing the physics-related parameters
dirspatial dimension (x/y)
nvarsnumber of vector components
upw0 -> send back complete Jacobian, 1 -> send back Jacobian of right(+)-moving flux, -1 -> send back Jacobian of left(-)-moving flux

Definition at line 14 of file ShallowWater2DJacobian.c.

24 {
25  ShallowWater2D *param = (ShallowWater2D*) p;
28 
29  /* get the eigenvalues and left,right eigenvectors */
30  _ShallowWater2DEigenvalues_ (u,D,param,dir);
31  _ShallowWater2DLeftEigenvectors_ (u,L,param,dir);
32  _ShallowWater2DRightEigenvectors_(u,R,param,dir);
33 
34  int aupw = absolute(upw), k;
35  k = 0; D[k] = absolute( (1-aupw)*D[k] + 0.5*aupw*(1+upw)*max(0,D[k]) + 0.5*aupw*(1-upw)*min(0,D[k]) );
36  k = 4; D[k] = absolute( (1-aupw)*D[k] + 0.5*aupw*(1+upw)*max(0,D[k]) + 0.5*aupw*(1-upw)*min(0,D[k]) );
37  k = 8; D[k] = absolute( (1-aupw)*D[k] + 0.5*aupw*(1+upw)*max(0,D[k]) + 0.5*aupw*(1-upw)*min(0,D[k]) );
38 
39  MatMult3(_MODEL_NVARS_,DL,D,L);
40  MatMult3(_MODEL_NVARS_,Jac,R,DL);
41 
42  return(0);
43 }
#define _MODEL_NVARS_
Definition: euler1d.h:58
#define MatMult3(N, A, X, Y)
#define _ShallowWater2DLeftEigenvectors_(u, L, p, dir)
#define _ShallowWater2DEigenvalues_(u, D, p, dir)
#define _ShallowWater2DRightEigenvectors_(u, R, p, dir)
#define absolute(a)
Definition: math_ops.h:32
#define max(a, b)
Definition: math_ops.h:18
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
#define min(a, b)
Definition: math_ops.h:14
int ShallowWater2DRoeAverage ( double *  uavg,
double *  uL,
double *  uR,
void *  p 
)

Compute the Roe-averaged state for the 2D shallow water equations. This function just calls the macro _ShallowWater2DRoeAverage_ and is not used by any functions within the 2D shallow water module. However, it's necessary to define it and provide it to the the solver object (HyPar) so that it can then send it to interpolation functions for a characteristic-based reconstruction.

Parameters
uavgThe computed Roe-averaged state
uLLeft state (conserved variables)
uRRight state (conserved variables)
pObject of type ShallowWater2D with physics-related variables

Definition at line 16 of file ShallowWater2DFunctions.c.

22 {
23  ShallowWater2D *param = (ShallowWater2D*) p;
24  _ShallowWater2DRoeAverage_(uavg,uL,uR,param);
25  return(0);
26 }
#define _ShallowWater2DRoeAverage_(uavg, uL, uR, p)
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
int ShallowWater2DLeftEigenvectors ( double *  u,
double *  L,
void *  p,
int  dir 
)

Compute the left eigenvections for the 2D shallow water equations. This function just calls the macro _ShallowWater2DLeftEigenvectors_ and is not used by any functions within the 2D shallow water module. However, it's necessary to define it and provide it to the the solver object (HyPar) so that it can then send it to interpolation functions for a characteristic-based reconstruction.

Parameters
uConserved solution at a grid point
LArray of size nvar^2 = 3^2 to save the matrix of left eigenvectors in (row-major format).
pObject of type ShallowWater2D with physics-related variables
dirSpatial dimension

Definition at line 19 of file ShallowWater2DEigen.c.

26 {
27  ShallowWater2D *param = (ShallowWater2D*) p;
28  _ShallowWater2DLeftEigenvectors_(u,L,param,dir);
29  return(0);
30 }
#define _ShallowWater2DLeftEigenvectors_(u, L, p, dir)
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
int ShallowWater2DRightEigenvectors ( double *  u,
double *  R,
void *  p,
int  dir 
)

Compute the right eigenvections for the 2D shallow water equations. This function just calls the macro _ShallowWater2DRightEigenvectors_ and is not used by any functions within the 2D shallow water module. However, it's necessary to define it and provide it to the the solver object (HyPar) so that it can then send it to interpolation functions for a characteristic-based reconstruction.

Parameters
uConserved solution at a grid point
RArray of size nvar^2 = 3^2 to save the matrix of right eigenvectors in (row-major format).
pObject of type ShallowWater2D with physics-related variables
dirSpatial dimension

Definition at line 38 of file ShallowWater2DEigen.c.

45 {
46  ShallowWater2D *param = (ShallowWater2D*) p;
47  _ShallowWater2DRightEigenvectors_(u,R,param,dir);
48  return(0);
49 }
#define _ShallowWater2DRightEigenvectors_(u, R, p, dir)
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
int ShallowWater2DTopography ( void *  s,
void *  m,
int  idx,
int  nsims,
int *  dim_topo 
)

Set the bottom topography over the domain - reads the topography data from a file, if available, else sets it to a constant

Parameters
sSolver object of type HyPar
mMPI object of type MPIVariables
idxIndex of this simulation
nsimsTotal number of simulations
dim_topoGrid dimensions of the advection field stored in file

Definition at line 20 of file ShallowWater2DTopography.c.

27 {
28  HyPar *solver = (HyPar*) s;
29  MPIVariables *mpi = (MPIVariables*) m;
30  ShallowWater2D *param = (ShallowWater2D*) solver->physics;
31  double *S = param->b;
32  int d, done, *dim = solver->dim_local,
33  ghosts = solver->ghosts;
35 
36  char fname_root[_MAX_STRING_SIZE_] = "topography";
37  if (idx >= 0) {
38  if (nsims > 1) {
39  char index[_MAX_STRING_SIZE_];
40  GetStringFromInteger(idx, index, (int)log10(nsims)+1);
41  strcat(fname_root, "_");
42  strcat(fname_root, index);
43  }
44  }
45 
46  /* read topography from provided file, if available */
47  if (dim_topo == NULL) {
48  int ierr = ReadArray( solver->ndims,
49  1,
50  solver->dim_global,
51  solver->dim_local,
52  solver->ghosts,
53  solver,
54  mpi,
55  NULL,
56  S,
57  fname_root,
58  &param->topo_flag);
59  if (ierr) {
60  fprintf(stderr,"Error in ShallowWater2DTopography()\n");
61  fprintf(stderr," ReadArray() returned error!\n");
62  return ierr;
63  }
64  } else {
65  int ierr = ReadArraywInterp( solver->ndims,
66  1,
67  solver->dim_global,
68  solver->dim_local,
69  dim_topo,
70  solver->ghosts,
71  solver,
72  mpi,
73  NULL,
74  S,
75  fname_root,
76  &param->topo_flag);
77  if (ierr) {
78  fprintf(stderr,"Error in ShallowWater2DTopography()\n");
79  fprintf(stderr," ReadArraywInterp() returned error!\n");
80  return ierr;
81  }
82  }
83 
84  if (!param->topo_flag) {
85  /* if topography file not available, set it to zero */
87  }
88 
89  /* if parallel, exchange MPI-boundary ghost point data */
91  solver->ghosts,mpi,S); CHECKERR(ierr);
92 
93 
94  if (param->bt_type) {
95  /* if topography is periodic, then the overall problem must also be periodic
96  (i.e. boundary conditions will be specified as periodic). Hence,
97  MPIExchangeBoundariesnD() will take care of setting the ghosts points
98  for multi-processor simulations. For single processor, set the ghost
99  points accordingly. */
100  int indexb[_MODEL_NDIMS_], indexi[_MODEL_NDIMS_], bounds[_MODEL_NDIMS_],
101  offset[_MODEL_NDIMS_];
102  for (d = 0; d < _MODEL_NDIMS_; d++) {
103  if (mpi->iproc[d] == 1) {
104  _ArrayCopy1D_(dim,bounds,_MODEL_NDIMS_); bounds[d] = ghosts;
105  /* left boundary */
106  done = 0; _ArraySetValue_(indexb,_MODEL_NDIMS_,0);
107  _ArraySetValue_(offset,_MODEL_NDIMS_,0); offset[d] = -ghosts;
108  while (!done) {
109  _ArrayCopy1D_(indexb,indexi,_MODEL_NDIMS_); indexi[d] = indexb[d] + dim[d] - ghosts;
110  int p1; _ArrayIndex1DWO_(_MODEL_NDIMS_,dim,indexb,offset,ghosts,p1);
111  int p2; _ArrayIndex1D_ (_MODEL_NDIMS_,dim,indexi,ghosts,p2);
112  S[p1] = S[p2];
113  _ArrayIncrementIndex_(_MODEL_NDIMS_,bounds,indexb,done);
114  }
115  /* right boundary */
116  done = 0; _ArraySetValue_(indexb,_MODEL_NDIMS_,0);
117  _ArraySetValue_(offset,_MODEL_NDIMS_,0); offset[d] = dim[d];
118  while (!done) {
119  _ArrayCopy1D_(indexb,indexi,_MODEL_NDIMS_);
120  int p1; _ArrayIndex1DWO_(_MODEL_NDIMS_,dim,indexb,offset,ghosts,p1);
121  int p2; _ArrayIndex1D_ (_MODEL_NDIMS_,dim,indexi,ghosts,p2);
122  S[p1] = S[p2];
123  _ArrayIncrementIndex_(_MODEL_NDIMS_,bounds,indexb,done);
124  }
125  }
126  }
127  } else {
128  /* if topography is not periodic, extrapolate it at the boundaries */
129  int indexb[_MODEL_NDIMS_], indexi[_MODEL_NDIMS_], bounds[_MODEL_NDIMS_],
130  offset[_MODEL_NDIMS_];
131  for (d = 0; d < _MODEL_NDIMS_; d++) {
132  /* left boundary */
133  if (!mpi->ip[d]) {
134  _ArrayCopy1D_(dim,bounds,_MODEL_NDIMS_); bounds[d] = ghosts;
135  _ArraySetValue_(offset,_MODEL_NDIMS_,0); offset[d] = -ghosts;
136  done = 0; _ArraySetValue_(indexb,_MODEL_NDIMS_,0);
137  while (!done) {
138  _ArrayCopy1D_(indexb,indexi,_MODEL_NDIMS_); indexi[d] = ghosts-1-indexb[d];
139  int p1; _ArrayIndex1DWO_(_MODEL_NDIMS_,dim,indexb,offset,ghosts,p1);
140  int p2; _ArrayIndex1D_ (_MODEL_NDIMS_,dim,indexi,ghosts,p2);
141  S[p1] = S[p2];
142  _ArrayIncrementIndex_(_MODEL_NDIMS_,bounds,indexb,done);
143  }
144  }
145  /* right boundary */
146  if (mpi->ip[d] == mpi->iproc[d]-1) {
147  _ArrayCopy1D_(dim,bounds,_MODEL_NDIMS_); bounds[d] = ghosts;
148  _ArraySetValue_(offset,_MODEL_NDIMS_,0); offset[d] = dim[d];
149  done = 0; _ArraySetValue_(indexb,_MODEL_NDIMS_,0);
150  while (!done) {
151  _ArrayCopy1D_(indexb,indexi,_MODEL_NDIMS_); indexi[d] = dim[d]-1-indexb[d];
152  int p1; _ArrayIndex1DWO_(_MODEL_NDIMS_,dim,indexb,offset,ghosts,p1);
153  int p2; _ArrayIndex1D_ (_MODEL_NDIMS_,dim,indexi,ghosts,p2);
154  S[p1] = S[p2];
155  _ArrayIncrementIndex_(_MODEL_NDIMS_,bounds,indexb,done);
156  }
157  }
158  }
159  }
160 
161  return(0);
162 }
int npoints_local_wghosts
Definition: hypar.h:42
#define _ArraySetValue_(x, size, value)
int * dim_global
Definition: hypar.h:33
#define _ArrayIncrementIndex_(N, imax, i, done)
void GetStringFromInteger(int, char *, int)
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
#define _MODEL_NDIMS_
Definition: euler1d.h:56
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
int ReadArray(int, int, int *, int *, int, void *, void *, double *, double *, char *, int *)
Definition: ReadArray.c:25
#define _MAX_STRING_SIZE_
Definition: basic.h:14
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
#define _ArrayCopy1D_(x, y, size)
int ReadArraywInterp(int, int, int *, int *, int *, int, void *, void *, double *, double *, char *, int *)
#define CHECKERR(ierr)
Definition: basic.h:18
int ndims
Definition: hypar.h:26
#define IERR
Definition: basic.h:16
int MPIExchangeBoundariesnD(int, int, int *, int, void *, double *)
Structure of MPI-related variables.
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _DECLARE_IERR_
Definition: basic.h:17
int ShallowWater2DSourceUpwindLLF ( double *  fI,
double *  fL,
double *  fR,
double *  u,
int  dir,
void *  s,
double  t 
)

Compute the "upwind" source term in the balanced formulation introduced in the reference below. The "upwind" state is just the arithmetic average of the left and right states.

  • 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
fIComputed interface source term ("upwinded")
fLLeft-biased interface source term
fRRight-biased interface source term
uSolution (conserved variables)
dirSpatial dimension
sSolver object of type HyPar
tCurrent solution time

Definition at line 22 of file ShallowWater2DSourceUpwind.c.

31 {
32  HyPar *solver = (HyPar*) s;
33  int done,k;
34 
35  int ndims = solver->ndims;
36  int *dim = solver->dim_local;
37 
38  int index_outer[ndims], index_inter[ndims], bounds_outer[ndims], bounds_inter[ndims];
39  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
40  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
41 
42  done = 0; _ArraySetValue_(index_outer,ndims,0);
43  while (!done) {
44  _ArrayCopy1D_(index_outer,index_inter,ndims);
45  for (index_inter[dir] = 0; index_inter[dir] < bounds_inter[dir]; index_inter[dir]++) {
46  int p; _ArrayIndex1D_(ndims,bounds_inter,index_inter,0,p);
47  for (k = 0; k < _MODEL_NVARS_; k++)
48  (fI+_MODEL_NVARS_*p)[k] = 0.5 * ((fL+_MODEL_NVARS_*p)[k] + (fR+_MODEL_NVARS_*p)[k]);
49  }
50  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
51  }
52 
53  return(0);
54 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _MODEL_NVARS_
Definition: euler1d.h:58
int * dim_local
Definition: hypar.h:37
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArrayCopy1D_(x, y, size)
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int ShallowWater2DSourceUpwindRoe ( double *  fI,
double *  fL,
double *  fR,
double *  u,
int  dir,
void *  s,
double  t 
)

Compute the "upwind" source term in the balanced formulation introduced in the reference below. The "upwind" state is just the arithmetic average of the left and right states.

  • 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
fIComputed interface source term ("upwinded")
fLLeft-biased interface source term
fRRight-biased interface source term
uSolution (conserved variables)
dirSpatial dimension
sSolver object of type HyPar
tCurrent solution time

Definition at line 64 of file ShallowWater2DSourceUpwind.c.

73 {
74  HyPar *solver = (HyPar*) s;
75  int done,k;
76 
77  int ndims = solver->ndims;
78  int *dim = solver->dim_local;
79 
80  int index_outer[ndims], index_inter[ndims], bounds_outer[ndims], bounds_inter[ndims];
81  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
82  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
83 
84  done = 0; _ArraySetValue_(index_outer,ndims,0);
85  while (!done) {
86  _ArrayCopy1D_(index_outer,index_inter,ndims);
87  for (index_inter[dir] = 0; index_inter[dir] < bounds_inter[dir]; index_inter[dir]++) {
88  int p; _ArrayIndex1D_(ndims,bounds_inter,index_inter,0,p);
89  for (k = 0; k < _MODEL_NVARS_; k++)
90  (fI+_MODEL_NVARS_*p)[k] = 0.5 * ((fL+_MODEL_NVARS_*p)[k] + (fR+_MODEL_NVARS_*p)[k]);
91  }
92  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
93  }
94 
95  return(0);
96 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _MODEL_NVARS_
Definition: euler1d.h:58
int * dim_local
Definition: hypar.h:37
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArrayCopy1D_(x, y, size)
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int ShallowWater2DModifiedSolution ( double *  uC,
double *  u,
int  d,
void *  s,
void *  m,
double  waqt 
)

Compute the modified solution for the upwinding step in a balanced conservative finite-difference algorithm for the 2D shallow water equations.

Refer to:

  • 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
uCThe modified solution (same array size and layout as u)
uThe solution (conserved variables)
dSpatial dimension
sSolver object of type HyPar
mMPI object of type MPIVariables
waqtCurrent solution time

Definition at line 21 of file ShallowWater2DModifiedSolution.c.

29 {
30  HyPar *solver = (HyPar*) s;
31  ShallowWater2D *param = (ShallowWater2D*) solver->physics;
32 
33  int ghosts = solver->ghosts;
34  int *dim = solver->dim_local;
35  int ndims = solver->ndims;
36  int index[ndims], bounds[ndims], offset[ndims];
37 
38  /* set bounds for array index to include ghost points */
39  _ArrayCopy1D_(dim,bounds,ndims);
40  int i; for (i=0; i<ndims; i++) bounds[i] += 2*ghosts;
41 
42  /* set offset such that index is compatible with ghost point arrangement */
43  _ArraySetValue_(offset,ndims,-ghosts);
44 
45  int done = 0; _ArraySetValue_(index,ndims,0);
46  while (!done) {
47  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
48  double h,uvel,vvel;
49  _ShallowWater2DGetFlowVar_((u+_MODEL_NVARS_*p),h,uvel,vvel);
50  uC[_MODEL_NVARS_*p+0] = h + param->b[p];
51  uC[_MODEL_NVARS_*p+1] = h * uvel;
52  uC[_MODEL_NVARS_*p+2] = h * vvel;
53  _ArrayIncrementIndex_(ndims,bounds,index,done);
54  }
55  return(0);
56 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _MODEL_NVARS_
Definition: euler1d.h:58
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
#define _ArrayCopy1D_(x, y, size)
#define _ShallowWater2DGetFlowVar_(u, h, uvel, vvel)
int ndims
Definition: hypar.h:26
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int ShallowWater2DWriteTopography ( void *  s,
void *  m,
double  a_t 
)

Write out the topography data to file

Parameters
sSolver object of type HyPar
mMPI object of type MPIVariables
a_tCurrent simulation time

Definition at line 17 of file ShallowWater2DWriteTopography.c.

20 {
21  HyPar *solver = (HyPar*) s;
22  MPIVariables *mpi = (MPIVariables*) m;
23  ShallowWater2D *params = (ShallowWater2D*) solver->physics;
25 
26  if (params->topo_flag) {
27 
28  char fname_root[_MAX_STRING_SIZE_] = "topography";
29  if (solver->nsims > 1) {
30  char index[_MAX_STRING_SIZE_];
31  GetStringFromInteger(solver->my_idx, index, (int)log10(solver->nsims)+1);
32  strcat(fname_root, "_");
33  strcat(fname_root, index);
34  strcat(fname_root, "_");
35  }
36 
37  WriteArray( solver->ndims,
38  1,
39  solver->dim_global,
40  solver->dim_local,
41  solver->ghosts,
42  solver->x,
43  params->b,
44  solver,
45  mpi,
46  fname_root );
47 
48  if (!strcmp(solver->plot_solution, "yes")) {
49  PlotArray( solver->ndims,
50  1,
51  solver->dim_global,
52  solver->dim_local,
53  solver->ghosts,
54  solver->x,
55  params->b,
56  a_t,
57  solver,
58  mpi,
59  fname_root );
60  }
61 
62  }
63 
64  return(0);
65 }
int * dim_global
Definition: hypar.h:33
void GetStringFromInteger(int, char *, int)
void * physics
Definition: hypar.h:266
char plot_solution[_MAX_STRING_SIZE_]
Definition: hypar.h:194
int * dim_local
Definition: hypar.h:37
int ghosts
Definition: hypar.h:52
int nsims
Definition: hypar.h:64
int WriteArray(int, int, int *, int *, int, double *, double *, void *, void *, char *)
Definition: WriteArray.c:27
#define _MAX_STRING_SIZE_
Definition: basic.h:14
int PlotArray(int, int, int *, int *, int, double *, double *, double, void *, void *, char *)
Definition: PlotArray.c:31
int ndims
Definition: hypar.h:26
int my_idx
Definition: hypar.h:61
Structure of MPI-related variables.
double * x
Definition: hypar.h:107
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _DECLARE_IERR_
Definition: basic.h:17
int ShallowWater2DInitialize ( void *  s,
void *  m 
)

Function to initialize the 2D shallow water equations (ShallowWater2D) module: Sets the default parameters, read in and set physics-related parameters, and set the physics-related function pointers in HyPar.

Parameters
sSolver object of type HyPar
mObject of type MPIVariables containing MPI-related info

Definition at line 37 of file ShallowWater2DInitialize.c.

41 {
42  HyPar *solver = (HyPar*) s;
43  MPIVariables *mpi = (MPIVariables*) m;
44  ShallowWater2D *physics = (ShallowWater2D*) solver->physics;
45  int ferr, d;
46 
47  static int count = 0;
48 
49  if (solver->nvars != _MODEL_NVARS_) {
50  fprintf(stderr,"Error in ShallowWater2DInitialize(): nvars has to be %d.\n",_MODEL_NVARS_);
51  return(1);
52  }
53  if (solver->ndims != _MODEL_NDIMS_) {
54  fprintf(stderr,"Error in ShallowWater2DInitialize(): ndims has to be %d.\n",_MODEL_NDIMS_);
55  return(1);
56  }
57 
58  /* default values */
59  physics->g = 1.0;
60  physics->bt_type = 0;
61  physics->fhat = 0.0;
62  physics->beta = 0.0;
63  physics->D = 0.0;
64  strcpy(physics->upw_choice,"roe");
65 
66  /* reading physical model specific inputs */
67  if (!mpi->rank) {
68  FILE *in;
69  if (!count) printf("Reading physical model inputs from file \"physics.inp\".\n");
70  in = fopen("physics.inp","r");
71  if (!in) printf("Warning: File \"physics.inp\" not found. Using default values.\n");
72  else {
73  char word[_MAX_STRING_SIZE_];
74  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
75  if (!strcmp(word, "begin")){
76  while (strcmp(word, "end")){
77  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
78  if (!strcmp(word, "gravity")) {
79  ferr = fscanf(in,"%lf",&physics->g);
80  if (ferr != 1) return(1);
81  } else if (!strcmp(word, "topography_type")) {
82  ferr = fscanf(in,"%d",&physics->bt_type);
83  if (ferr != 1) return(1);
84  } else if (!strcmp(word, "coriolis_fhat")) {
85  ferr = fscanf(in,"%lf",&physics->fhat);
86  if (ferr != 1) return(1);
87  } else if (!strcmp(word, "coriolis_beta")) {
88  ferr = fscanf(in,"%lf",&physics->beta);
89  if (ferr != 1) return(1);
90  } else if (!strcmp(word, "coriolis_D")) {
91  ferr = fscanf(in,"%lf",&physics->D);
92  if (ferr != 1) return(1);
93  } else if (!strcmp(word,"upwinding")) {
94  ferr = fscanf(in,"%s",physics->upw_choice);
95  if (ferr != 1) return(1);
96  } else if (strcmp(word,"end")) {
97  char useless[_MAX_STRING_SIZE_];
98  ferr = fscanf(in,"%s",useless); if (ferr != 1) return(ferr);
99  printf("Warning: keyword %s in file \"physics.inp\" with value %s not ",word,useless);
100  printf("recognized or extraneous. Ignoring.\n");
101  }
102  }
103  } else {
104  fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
105  return(1);
106  }
107  }
108  fclose(in);
109  }
110 
111 #ifndef serial
112  IERR MPIBroadcast_double (&physics->g ,1,0,&mpi->world); CHECKERR(ierr);
113  IERR MPIBroadcast_integer (&physics->bt_type ,1,0,&mpi->world); CHECKERR(ierr);
114  IERR MPIBroadcast_double (&physics->fhat ,1,0,&mpi->world); CHECKERR(ierr);
115  IERR MPIBroadcast_double (&physics->beta ,1,0,&mpi->world); CHECKERR(ierr);
116  IERR MPIBroadcast_double (&physics->D ,1,0,&mpi->world); CHECKERR(ierr);
118 #endif
119 
120  /* initializing physical model-specific functions */
122  solver->FFunction = ShallowWater2DFlux;
126  if (!strcmp(physics->upw_choice,_ROE_ )) solver->Upwind = ShallowWater2DUpwindRoe;
127  else if (!strcmp(physics->upw_choice,_LLF_ )) solver->Upwind = ShallowWater2DUpwindLLF;
128  else {
129  if (!mpi->rank) fprintf(stderr,"Error in ShallowWater2DInitialize(): %s is not a valid upwinding scheme.\n",
130  physics->upw_choice);
131  return(1);
132  }
137 
138  if (!strcmp(physics->upw_choice,_LLF_ )) physics->SourceUpwind = ShallowWater2DSourceUpwindLLF;
139  else if (!strcmp(physics->upw_choice,_ROE_ )) physics->SourceUpwind = ShallowWater2DSourceUpwindRoe;
140 
141  /* allocate array to hold the bottom topography field */
142  physics->b = (double*) calloc (solver->npoints_local_wghosts, sizeof(double));
144 
145  count++;
146  return(0);
147 }
int ShallowWater2DLeftEigenvectors(double *u, double *L, void *p, int dir)
int npoints_local_wghosts
Definition: hypar.h:42
int(* JFunction)(double *, double *, void *, int, int, int)
Definition: hypar.h:326
double(* ComputeCFL)(void *, void *, double, double)
Definition: hypar.h:269
int MPIBroadcast_double(double *, int, int, void *)
Definition: MPIBroadcast.c:9
#define _MODEL_NVARS_
Definition: euler1d.h:58
int ShallowWater2DRoeAverage(double *uavg, double *uL, double *uR, void *p)
void * physics
Definition: hypar.h:266
int(* Upwind)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:295
int(* GetRightEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:359
#define _LLF_
Definition: euler1d.h:66
int(* PhysicsOutput)(void *, void *, double)
Definition: hypar.h:347
int ShallowWater2DWriteTopography(void *, void *, double)
int ShallowWater2DSource(double *, double *, void *, void *, double)
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
#define _MODEL_NDIMS_
Definition: euler1d.h:56
int(* PhysicsInput)(void *, void *, int, int, int *)
Definition: hypar.h:351
int ShallowWater2DUpwindRoe(double *, double *, double *, double *, double *, double *, int, void *, double)
int ShallowWater2DTopography(void *, void *, int, int, int *)
MPI_Comm world
#define _MAX_STRING_SIZE_
Definition: basic.h:14
char upw_choice[_MAX_STRING_SIZE_]
int(* AveragingFunction)(double *, double *, double *, void *)
Definition: hypar.h:354
int ShallowWater2DUpwindLLF(double *, double *, double *, double *, double *, double *, int, void *, double)
int(* SourceUpwind)(double *, double *, double *, double *, int, void *, double)
int ShallowWater2DRightEigenvectors(double *u, double *R, void *p, int dir)
double ShallowWater2DComputeCFL(void *s, void *m, double dt, double t)
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357
#define _ROE_
Definition: euler1d.h:62
int(* SFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:317
int nvars
Definition: hypar.h:29
int ShallowWater2DModifiedSolution(double *, double *, int, void *, void *, double)
int ShallowWater2DJacobian(double *, double *, void *, int, int, int)
#define CHECKERR(ierr)
Definition: basic.h:18
int(* UFunction)(double *, double *, int, void *, void *, double)
Definition: hypar.h:321
int MPIBroadcast_character(char *, int, int, void *)
Definition: MPIBroadcast.c:37
int ShallowWater2DSourceUpwindLLF(double *, double *, double *, double *, int, void *, double)
int ndims
Definition: hypar.h:26
int ShallowWater2DSourceUpwindRoe(double *, double *, double *, double *, int, void *, double)
#define IERR
Definition: basic.h:16
Structure of MPI-related variables.
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
int ShallowWater2DFlux(double *f, double *u, int dir, void *s, double t)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int MPIBroadcast_integer(int *, int, int, void *)
Definition: MPIBroadcast.c:23