HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
ShallowWater1DTopography.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <math.h>
8 #include <string.h>
9 #include <basic.h>
10 #include <common.h>
11 #include <arrayfunctions.h>
12 #include <io.h>
14 #include <hypar.h>
15 #include <mpivars.h>
16 
21  void *s,
22  void *m,
23  int idx,
24  int nsims,
25  int *dim_topo
26  )
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 }
Some common functions used here and there.
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 ShallowWater1DTopography(void *s, void *m, int idx, int nsims, int *dim_topo)
1D Shallow Water Equations
#define IERR
Definition: basic.h:16
MPI related function definitions.
#define CHECKERR(ierr)
Definition: basic.h:18
int MPIExchangeBoundariesnD(int, int, int *, int, void *, double *)
Some basic definitions and macros.
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _MAX_STRING_SIZE_
Definition: basic.h:14
#define _MODEL_NDIMS_
Definition: euler1d.h:56
Contains structure definition for hypar.
void GetStringFromInteger(int, char *, int)
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
#define _ArrayIncrementIndex_(N, imax, i, done)
void * physics
Definition: hypar.h:266
int ghosts
Definition: hypar.h:52
int ReadArray(int, int, int *, int *, int, void *, void *, double *, double *, char *, int *)
Definition: ReadArray.c:25
Structure of MPI-related variables.
int npoints_local_wghosts
Definition: hypar.h:42
#define _DECLARE_IERR_
Definition: basic.h:17
Function declarations for file I/O functions.
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
int * dim_global
Definition: hypar.h:33
int ReadArraywInterp(int, int, int *, int *, int *, int, void *, void *, double *, double *, char *, int *)