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

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

#include <stdio.h>
#include <stdlib.h>
#include <string.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

double ShallowWater1DComputeCFL (void *, void *, double, double)
 
int ShallowWater1DFlux (double *, double *, int, void *, double)
 
int ShallowWater1DSource (double *, double *, void *, void *, double)
 
int ShallowWater1DUpwindRoe (double *, double *, double *, double *, double *, double *, int, void *, double)
 
int ShallowWater1DUpwindLLF (double *, double *, double *, double *, double *, double *, int, void *, double)
 
int ShallowWater1DJacobian (double *, double *, void *, int, int, int)
 
int ShallowWater1DRoeAverage (double *, double *, double *, void *)
 
int ShallowWater1DLeftEigenvectors (double *, double *, void *, int)
 
int ShallowWater1DRightEigenvectors (double *, double *, void *, int)
 
int ShallowWater1DTopography (void *, void *, int, int, int *)
 
int ShallowWater1DSourceUpwindLLF (double *, double *, double *, double *, int, void *, double)
 
int ShallowWater1DSourceUpwindRoe (double *, double *, double *, double *, int, void *, double)
 
int ShallowWater1DModifiedSolution (double *, double *, int, void *, void *, double)
 
int ShallowWater1DWriteTopography (void *, void *, double)
 
int ShallowWater1DInitialize (void *s, void *m)
 

Detailed Description

Initialize the 1D shallow water equations module.

Author
Debojyoti Ghosh

Definition in file ShallowWater1DInitialize.c.

Function Documentation

double ShallowWater1DComputeCFL ( 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 ShallowWater1DComputeCFL.c.

23 {
24  HyPar *solver = (HyPar*) s;
25  ShallowWater1D *param = (ShallowWater1D*) 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, v, c, dxinv, local_cfl;
39  _GetCoordinate_(0,index[0],dim,ghosts,solver->dxinv,dxinv); /* 1/dx */
40  c = sqrt(param->g*h); /* speed of gravity waves */
41  local_cfl = (absolute(v)+c)*dt*dxinv; /* local cfl for this grid point */
42  if (local_cfl > max_cfl) max_cfl = local_cfl;
43  _ArrayIncrementIndex_(ndims,dim,index,done);
44  }
45 
46  return(max_cfl);
47 }
#define _ArraySetValue_(x, size, value)
double * u
Definition: hypar.h:116
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.
#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
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
double * dxinv
Definition: hypar.h:110
int ndims
Definition: hypar.h:26
#define absolute(a)
Definition: math_ops.h:32
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _ShallowWater1DGetFlowVar_(u, h, v)
int ShallowWater1DFlux ( 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}{c} hu \\ hu^2 + \frac{1}{2} gh^2 \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 (unused since this is a 1D system)
sSolver object of type HyPar
tCurrent time

Definition at line 16 of file ShallowWater1DFlux.c.

23 {
24  HyPar *solver = (HyPar*) s;
25  ShallowWater1D *param = (ShallowWater1D*) solver->physics;
26  int *dim = solver->dim_local;
27  int ghosts = solver->ghosts;
28  static const int ndims = _MODEL_NDIMS_;
29  static const int nvars = _MODEL_NVARS_;
30  static int index[_MODEL_NDIMS_], bounds[_MODEL_NDIMS_], offset[_MODEL_NDIMS_];
31 
32  /* set bounds for array index to include ghost points */
33  _ArrayAddCopy1D_(dim,(2*ghosts),bounds,ndims);
34  /* set offset such that index is compatible with ghost point arrangement */
35  _ArraySetValue_(offset,ndims,-ghosts);
36 
37  int done = 0; _ArraySetValue_(index,ndims,0);
38  while (!done) {
39  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
40  double h, v;
41  _ShallowWater1DGetFlowVar_((u+nvars*p),h,v);
42  _ShallowWater1DSetFlux_((f+nvars*p),h,v,param->g);
43  _ArrayIncrementIndex_(ndims,bounds,index,done);
44  }
45 
46  return(0);
47 }
#define _ArraySetValue_(x, size, value)
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.
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _MODEL_NVARS_
Definition: euler1d.h:58
#define _ShallowWater1DSetFlux_(f, h, v, g)
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 _ArrayAddCopy1D_(x, a, y, size)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _ShallowWater1DGetFlowVar_(u, h, v)
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 }
#define _ArraySetValue_(x, size, value)
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.
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _MODEL_NVARS_
Definition: euler1d.h:58
static int ShallowWater1DSourceFunction2(double *, double *, double *, void *, void *, double)
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
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
static int ShallowWater1DSourceFunction1(double *, double *, double *, void *, void *, double)
double * fluxI
Definition: hypar.h:136
#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
double * dxinv
Definition: hypar.h:110
int ndims
Definition: hypar.h:26
#define IERR
Definition: basic.h:16
Structure of MPI-related variables.
double * x
Definition: hypar.h:107
int(* SourceUpwind)(double *, double *, double *, double *, int, void *, double)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _XDIR_
Definition: euler1d.h:75
double * fR
Definition: hypar.h:139
#define _ShallowWater1DGetFlowVar_(u, h, v)
int ShallowWater1DUpwindRoe ( 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 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 (unused since this is a 1D system)
sSolver object of type HyPar
tCurrent solution time

Definition at line 31 of file ShallowWater1DUpwind.c.

42 {
43  HyPar *solver = (HyPar*) s;
44  ShallowWater1D *param = (ShallowWater1D*) 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 
73  _ShallowWater1DRoeAverage_ (uavg,(u+_MODEL_NVARS_*pL),(u+_MODEL_NVARS_*pR),param);
74  _ShallowWater1DEigenvalues_ (uavg,D,param,0);
75  _ShallowWater1DLeftEigenvectors_ (uavg,L,param,0);
76  _ShallowWater1DRightEigenvectors_ (uavg,R,param,0);
77 
78  k = 0; D[k] = absolute(D[k]);
79  k = 3; D[k] = absolute(D[k]);
80 
81  MatMult2(2,DL,D,L);
82  MatMult2(2,modA,R,DL);
83 
84  udiss[0] = modA[0*_MODEL_NVARS_+0]*udiff[0] + modA[0*_MODEL_NVARS_+1]*udiff[1];
85  udiss[1] = modA[1*_MODEL_NVARS_+0]*udiff[0] + modA[1*_MODEL_NVARS_+1]*udiff[1];
86 
87  fI[_MODEL_NVARS_*p+0] = 0.5 * (fL[_MODEL_NVARS_*p+0]+fR[_MODEL_NVARS_*p+0]) - udiss[0];
88  fI[_MODEL_NVARS_*p+1] = 0.5 * (fL[_MODEL_NVARS_*p+1]+fR[_MODEL_NVARS_*p+1]) - udiss[1];
89  }
90  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
91  }
92 
93  return(0);
94 }
#define _ArraySetValue_(x, size, value)
#define _ShallowWater1DRoeAverage_(uavg, uL, uR, p)
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.
#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 MatMult2(N, A, X, Y)
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ShallowWater1DLeftEigenvectors_(u, L, p, dir)
#define _ShallowWater1DEigenvalues_(u, D, p, dir)
#define _ShallowWater1DRightEigenvectors_(u, R, p, dir)
#define _ArrayCopy1D_(x, y, size)
int ndims
Definition: hypar.h:26
#define absolute(a)
Definition: math_ops.h:32
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int ShallowWater1DUpwindLLF ( 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 (unused since this is a 1D system)
sSolver object of type HyPar
tCurrent solution time

Definition at line 114 of file ShallowWater1DUpwind.c.

125 {
126  HyPar *solver = (HyPar*) s;
127  ShallowWater1D *param = (ShallowWater1D*) solver->physics;
128  int done,k;
129 
130  int ndims = solver->ndims;
131  int *dim = solver->dim_local;
132  int ghosts = solver->ghosts;
133 
134  int index_outer[ndims], index_inter[ndims], bounds_outer[ndims], bounds_inter[ndims];
135  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
136  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
138 
139  done = 0; _ArraySetValue_(index_outer,ndims,0);
140  while (!done) {
141  _ArrayCopy1D_(index_outer,index_inter,ndims);
142  for (index_inter[dir] = 0; index_inter[dir] < bounds_inter[dir]; index_inter[dir]++) {
143  int p; _ArrayIndex1D_(ndims,bounds_inter,index_inter,0,p);
144  int indexL[ndims]; _ArrayCopy1D_(index_inter,indexL,ndims); indexL[dir]--;
145  int indexR[ndims]; _ArrayCopy1D_(index_inter,indexR,ndims);
146  int pL; _ArrayIndex1D_(ndims,dim,indexL,ghosts,pL);
147  int pR; _ArrayIndex1D_(ndims,dim,indexR,ghosts,pR);
148  double uavg[_MODEL_NVARS_], fcL[_MODEL_NVARS_], fcR[_MODEL_NVARS_],
149  ucL[_MODEL_NVARS_], ucR[_MODEL_NVARS_], fc[_MODEL_NVARS_];
150 
151  /* Local Lax-Friedrich upwinding scheme */
152 
153  _ShallowWater1DRoeAverage_ (uavg,(u+_MODEL_NVARS_*pL),(u+_MODEL_NVARS_*pR),param);
154  _ShallowWater1DEigenvalues_ (uavg,D,param,0);
155  _ShallowWater1DLeftEigenvectors_ (uavg,L,param,0);
156  _ShallowWater1DRightEigenvectors_(uavg,R,param,0);
157 
158  /* calculate characteristic fluxes and variables */
163 
164  for (k = 0; k < _MODEL_NVARS_; k++) {
165  double eigL,eigC,eigR;
166  _ShallowWater1DEigenvalues_((u+_MODEL_NVARS_*pL),D,param,0);
167  eigL = D[k*_MODEL_NVARS_+k];
168  _ShallowWater1DEigenvalues_((u+_MODEL_NVARS_*pR),D,param,0);
169  eigR = D[k*_MODEL_NVARS_+k];
170  _ShallowWater1DEigenvalues_(uavg,D,param,0);
171  eigC = D[k*_MODEL_NVARS_+k];
172 
173  double alpha = max3(absolute(eigL),absolute(eigC),absolute(eigR));
174  fc[k] = 0.5 * (fcL[k] + fcR[k] + alpha * (ucL[k]-ucR[k]));
175  }
176 
177  /* calculate the interface flux from the characteristic flux */
178  MatVecMult2(_MODEL_NVARS_,(fI+_MODEL_NVARS_*p),R,fc);
179  }
180  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
181  }
182 
183  return(0);
184 }
#define _ArraySetValue_(x, size, value)
#define _ShallowWater1DRoeAverage_(uavg, uL, uR, p)
#define max3(a, b, c)
Definition: math_ops.h:27
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.
#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 _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ShallowWater1DLeftEigenvectors_(u, L, p, dir)
#define _ShallowWater1DEigenvalues_(u, D, p, dir)
#define _ShallowWater1DRightEigenvectors_(u, R, p, dir)
#define _ArrayCopy1D_(x, y, size)
#define MatVecMult2(N, y, A, x)
int ndims
Definition: hypar.h:26
#define absolute(a)
Definition: math_ops.h:32
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int ShallowWater1DJacobian ( double *  Jac,
double *  u,
void *  p,
int  dir,
int  nvars,
int  upw 
)

Function to compute the flux Jacobian of the 1D 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 = 4
usolution at a grid point (array of size nvar = 2)
pobject containing the physics-related parameters
dirdimension (x/y/z) (not used, since this is 1D system)
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 ShallowWater1DJacobian.c.

24 {
25  ShallowWater1D *param = (ShallowWater1D*) p;
28 
29  /* get the eigenvalues and left,right eigenvectors */
30  _ShallowWater1DEigenvalues_ (u,D,param,0);
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 = 3; 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 
38  MatMult2(2,DL,D,L);
39  MatMult2(2,Jac,R,DL);
40 
41  return(0);
42 }
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.
#define _MODEL_NVARS_
Definition: euler1d.h:58
#define MatMult2(N, A, X, Y)
#define _ShallowWater1DLeftEigenvectors_(u, L, p, dir)
#define _ShallowWater1DEigenvalues_(u, D, p, dir)
#define _ShallowWater1DRightEigenvectors_(u, R, p, dir)
#define absolute(a)
Definition: math_ops.h:32
#define max(a, b)
Definition: math_ops.h:18
#define min(a, b)
Definition: math_ops.h:14
int ShallowWater1DRoeAverage ( double *  uavg,
double *  uL,
double *  uR,
void *  p 
)

Compute the Roe-averaged state for the 1D shallow water equations. This function just calls the macro _ShallowWater1DRoeAverage_ and is not used by any functions within the 1D 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 ShallowWater1D with physics-related variables

Definition at line 16 of file ShallowWater1DFunctions.c.

22 {
23  ShallowWater1D *param = (ShallowWater1D*) p;
24  _ShallowWater1DRoeAverage_(uavg,uL,uR,param);
25  return(0);
26 }
#define _ShallowWater1DRoeAverage_(uavg, uL, uR, p)
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 ShallowWater1DLeftEigenvectors ( double *  u,
double *  L,
void *  p,
int  dir 
)

Compute the left eigenvections for the 1D shallow water equations. This function just calls the macro _ShallowWater1DLeftEigenvectors_ and is not used by any functions within the 1D 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 = 2^2 to save the matrix of left eigenvectors in (row-major format).
pObject of type ShallowWater1D with physics-related variables
dirSpatial dimension (not used, since this is a 1D system)

Definition at line 19 of file ShallowWater1DEigen.c.

26 {
27  ShallowWater1D *param = (ShallowWater1D*) p;
28  _ShallowWater1DLeftEigenvectors_(u,L,param,dir);
29  return(0);
30 }
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.
#define _ShallowWater1DLeftEigenvectors_(u, L, p, dir)
int ShallowWater1DRightEigenvectors ( double *  u,
double *  R,
void *  p,
int  dir 
)

Compute the right eigenvections for the 1D shallow water equations. This function just calls the macro _ShallowWater1DRightEigenvectors_ and is not used by any functions within the 1D 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 = 2^2 to save the matrix of right eigenvectors in (row-major format).
pObject of type ShallowWater1D with physics-related variables
dirSpatial dimension (not used, since this is a 1D system)

Definition at line 38 of file ShallowWater1DEigen.c.

45 {
46  ShallowWater1D *param = (ShallowWater1D*) p;
47  _ShallowWater1DRightEigenvectors_(u,R,param,dir);
48  return(0);
49 }
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.
#define _ShallowWater1DRightEigenvectors_(u, R, p, dir)
int ShallowWater1DTopography ( 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 ShallowWater1DTopography.c.

27 {
28  HyPar *solver = (HyPar*) s;
29  MPIVariables *mpi = (MPIVariables*) m;
30  ShallowWater1D *param = (ShallowWater1D*) 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 ShallowWater1DTopography()\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 ShallowWater1DTopography()\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
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.
#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 all solver-specific variables and functions.
Definition: hypar.h:23
#define _DECLARE_IERR_
Definition: basic.h:17
int ShallowWater1DSourceUpwindLLF ( 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 (unused since this is a 1D case)
sSolver object of type HyPar
tCurrent solution time

Definition at line 22 of file ShallowWater1DSourceUpwind.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 ShallowWater1DSourceUpwindRoe ( 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 (unused since this is a 1D case)
sSolver object of type HyPar
tCurrent solution time

Definition at line 64 of file ShallowWater1DSourceUpwind.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 ShallowWater1DModifiedSolution ( 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 1D 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 (unused since this is a 1D system)
sSolver object of type HyPar
mMPI object of type MPIVariables
waqtCurrent solution time

Definition at line 21 of file ShallowWater1DModifiedSolution.c.

29 {
30  HyPar *solver = (HyPar*) s;
31  ShallowWater1D *param = (ShallowWater1D*) 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,v;
50  uC[_MODEL_NVARS_*p+0] = h + param->b[p];
51  uC[_MODEL_NVARS_*p+1] = h * v;
52  _ArrayIncrementIndex_(ndims,bounds,index,done);
53  }
54  return(0);
55 }
#define _ArraySetValue_(x, size, value)
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.
#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)
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _ShallowWater1DGetFlowVar_(u, h, v)
int ShallowWater1DWriteTopography ( 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 ShallowWater1DWriteTopography.c.

20 {
21  HyPar *solver = (HyPar*) s;
22  MPIVariables *mpi = (MPIVariables*) m;
23  ShallowWater1D *params = (ShallowWater1D*) 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,mpi,
58  fname_root );
59  }
60 
61 
62  }
63 
64  return(0);
65 }
int * dim_global
Definition: hypar.h:33
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.
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 all solver-specific variables and functions.
Definition: hypar.h:23
#define _DECLARE_IERR_
Definition: basic.h:17
int ShallowWater1DInitialize ( void *  s,
void *  m 
)

Function to initialize the 1D shallow water equations (ShallowWater1D) 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 ShallowWater1DInitialize.c.

41 {
42  HyPar *solver = (HyPar*) s;
43  MPIVariables *mpi = (MPIVariables*) m;
44  ShallowWater1D *physics = (ShallowWater1D*) solver->physics;
45  int ferr, d;
46 
47  static int count = 0;
48 
49  if (solver->nvars != _MODEL_NVARS_) {
50  fprintf(stderr,"Error in ShallowWater1DInitialize(): nvars has to be %d.\n",_MODEL_NVARS_);
51  return(1);
52  }
53  if (solver->ndims != _MODEL_NDIMS_) {
54  fprintf(stderr,"Error in ShallowWater1DInitialize(): 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  strcpy(physics->upw_choice,"roe");
62 
63  /* reading physical model specific inputs */
64  if (!mpi->rank) {
65  FILE *in;
66  if (!count) printf("Reading physical model inputs from file \"physics.inp\".\n");
67  in = fopen("physics.inp","r");
68  if (!in) printf("Warning: File \"physics.inp\" not found. Using default values.\n");
69  else {
70  char word[_MAX_STRING_SIZE_];
71  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
72  if (!strcmp(word, "begin")){
73  while (strcmp(word, "end")){
74  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
75  if (!strcmp(word, "gravity")) {
76  ferr = fscanf(in,"%lf",&physics->g);
77  if (ferr != 1) return(1);
78  } else if (!strcmp(word, "topography_type")) {
79  ferr = fscanf(in,"%d",&physics->bt_type);
80  if (ferr != 1) return(1);
81  } else if (!strcmp(word,"upwinding")) {
82  ferr = fscanf(in,"%s",physics->upw_choice);
83  if (ferr != 1) return(1);
84  } else if (strcmp(word,"end")) {
85  char useless[_MAX_STRING_SIZE_];
86  ferr = fscanf(in,"%s",useless); if (ferr != 1) return(ferr);
87  printf("Warning: keyword %s in file \"physics.inp\" with value %s not ",word,useless);
88  printf("recognized or extraneous. Ignoring.\n");
89  }
90  }
91  } else {
92  fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
93  return(1);
94  }
95  }
96  fclose(in);
97  }
98 
99 #ifndef serial
100  IERR MPIBroadcast_double (&physics->g ,1,0,&mpi->world); CHECKERR(ierr);
101  IERR MPIBroadcast_integer (&physics->bt_type ,1,0,&mpi->world); CHECKERR(ierr);
103 #endif
104 
105  /* initializing physical model-specific functions */
107  solver->FFunction = ShallowWater1DFlux;
111  if (!strcmp(physics->upw_choice,_ROE_ )) solver->Upwind = ShallowWater1DUpwindRoe;
112  else if (!strcmp(physics->upw_choice,_LLF_ )) solver->Upwind = ShallowWater1DUpwindLLF;
113  else {
114  if (!mpi->rank) fprintf(stderr,"Error in ShallowWater1DInitialize(): %s is not a valid upwinding scheme.\n",
115  physics->upw_choice);
116  return(1);
117  }
122 
123  if (!strcmp(physics->upw_choice,_LLF_ )) physics->SourceUpwind = ShallowWater1DSourceUpwindLLF;
124  else if (!strcmp(physics->upw_choice,_ROE_ )) physics->SourceUpwind = ShallowWater1DSourceUpwindRoe;
125 
126  /* allocate array to hold the bottom topography field */
127  physics->b = (double*) calloc (solver->npoints_local_wghosts, sizeof(double));
128  /* set function pointer to read this topography */
130 
131  count++;
132  return(0);
133 }
int ShallowWater1DUpwindRoe(double *, double *, double *, double *, double *, double *, int, void *, double)
int ShallowWater1DFlux(double *f, double *u, int dir, void *s, double t)
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
int ShallowWater1DModifiedSolution(double *, double *, int, void *, void *, double)
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.
#define _MODEL_NVARS_
Definition: euler1d.h:58
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(* 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 ShallowWater1DSource(double *, double *, void *, void *, double)
MPI_Comm world
#define _MAX_STRING_SIZE_
Definition: basic.h:14
int ShallowWater1DTopography(void *, void *, int, int, int *)
int ShallowWater1DRightEigenvectors(double *u, double *R, void *p, int dir)
int(* AveragingFunction)(double *, double *, double *, void *)
Definition: hypar.h:354
int ShallowWater1DUpwindLLF(double *, double *, double *, double *, double *, double *, int, void *, double)
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357
#define _ROE_
Definition: euler1d.h:62
int ShallowWater1DJacobian(double *, double *, void *, int, int, int)
int(* SFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:317
int nvars
Definition: hypar.h:29
#define CHECKERR(ierr)
Definition: basic.h:18
double ShallowWater1DComputeCFL(void *s, void *m, double dt, double t)
char upw_choice[_MAX_STRING_SIZE_]
int ShallowWater1DSourceUpwindLLF(double *, double *, double *, double *, int, void *, double)
int(* UFunction)(double *, double *, int, void *, void *, double)
Definition: hypar.h:321
int MPIBroadcast_character(char *, int, int, void *)
Definition: MPIBroadcast.c:37
int ShallowWater1DSourceUpwindRoe(double *, double *, double *, double *, int, void *, double)
int ndims
Definition: hypar.h:26
#define IERR
Definition: basic.h:16
int ShallowWater1DRoeAverage(double *uavg, double *uL, double *uR, void *p)
Structure of MPI-related variables.
int(* SourceUpwind)(double *, double *, double *, double *, int, void *, double)
int ShallowWater1DLeftEigenvectors(double *u, double *L, void *p, int dir)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int ShallowWater1DWriteTopography(void *, void *, double)
int MPIBroadcast_integer(int *, int, int, void *)
Definition: MPIBroadcast.c:23