HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ShallowWater2DComputeCFL.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <basic.h>
8 #include <math.h>
9 #include <arrayfunctions.h>
10 #include <mathfunctions.h>
12 #include <hypar.h>
13 
18  void *s,
19  void *m,
20  double dt,
21  double t
22  )
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)
2D Shallow Water Equations
Contains function definitions for common mathematical functions.
double ShallowWater2DComputeCFL(void *s, void *m, double dt, double t)
#define _ShallowWater2DGetFlowVar_(u, h, uvel, vvel)
Contains structure definition for hypar.
double * dxinv
Definition: hypar.h:110
Some basic definitions and macros.
int ndims
Definition: hypar.h:26
Contains macros and function definitions for common array operations.
#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