HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
Numa3DComputeCFL.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <math.h>
3 #include <basic.h>
4 #include <arrayfunctions.h>
5 #include <mathfunctions.h>
7 #include <hypar.h>
8 
9 double Numa3DComputeCFL(void *s,void *m,double dt,double t)
10 {
11  HyPar *solver = (HyPar*) s;
12  Numa3D *param = (Numa3D*) solver->physics;
13 
14  int *dim = solver->dim_local;
15  int ghosts = solver->ghosts;
16  int ndims = solver->ndims;
17  double *u = solver->u;
18  int index[ndims];
19 
20  double max_cfl = 0;
21  int done = 0; _ArraySetValue_(index,ndims,0);
22  while (!done) {
23  int p; _ArrayIndex1D_(ndims,dim,index,ghosts,p);
24  double drho,uvel,vvel,wvel,dT,rho0,T0,P0,EP,c,zcoord;
25 
26  _GetCoordinate_(_ZDIR_,index[_ZDIR_],dim,ghosts,solver->x,zcoord);
27  param->StandardAtmosphere(param,zcoord,&EP,&P0,&rho0,&T0);
28  _Numa3DGetFlowVars_ ((u+_MODEL_NVARS_*p),drho,uvel,vvel,wvel,dT,rho0);
29  _Numa3DComputeSpeedofSound_ (param->gamma,param->R,T0,dT,rho0,drho,EP,c);
30 
31  double dxinv, dyinv, dzinv;
32  _GetCoordinate_(_XDIR_,index[_XDIR_],dim,ghosts,solver->dxinv,dxinv); /* 1/dx */
33  _GetCoordinate_(_YDIR_,index[_YDIR_],dim,ghosts,solver->dxinv,dyinv); /* 1/dy */
34  _GetCoordinate_(_ZDIR_,index[_ZDIR_],dim,ghosts,solver->dxinv,dzinv); /* 1/dz */
35 
36  double local_cfl[3];
37  local_cfl[_XDIR_] = (absolute(uvel)+c)*dt*dxinv; /* local cfl for this grid point (x) */
38  local_cfl[_YDIR_] = (absolute(vvel)+c)*dt*dyinv; /* local cfl for this grid point (y) */
39  local_cfl[_ZDIR_] = (absolute(wvel)+c)*dt*dzinv; /* local cfl for this grid point (z) */
40  if (local_cfl[_XDIR_] > max_cfl) max_cfl = local_cfl[_XDIR_];
41  if (local_cfl[_YDIR_] > max_cfl) max_cfl = local_cfl[_YDIR_];
42  if (local_cfl[_ZDIR_] > max_cfl) max_cfl = local_cfl[_ZDIR_];
43 
44  _ArrayIncrementIndex_(ndims,dim,index,done);
45  }
46 
47  return(max_cfl);
48 }
#define absolute(a)
Definition: math_ops.h:32
Contains function definitions for common mathematical functions.
#define _ZDIR_
#define _Numa3DGetFlowVars_(u, drho, uvel, vvel, wvel, dT, rho0)
Definition: numa3d.h:39
double * u
Definition: hypar.h:116
Some basic definitions and macros.
double * x
Definition: hypar.h:107
Definition: numa3d.h:128
double Numa3DComputeCFL(void *s, void *m, double dt, double t)
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _YDIR_
Definition: euler2d.h:41
Contains structure definition for hypar.
#define _ArrayIndex1D_(N, imax, i, ghost, index)
double R
Definition: numa3d.h:130
#define _Numa3DComputeSpeedofSound_(gamma, R, T0, dT, rho0, drho, EP, c)
Definition: numa3d.h:118
double gamma
Definition: numa3d.h:129
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
void(* StandardAtmosphere)(void *, double, double *, double *, double *, double *)
Definition: numa3d.h:139
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _GetCoordinate_(dir, i, dim, ghosts, x, coord)
Definition: basic.h:31
void * physics
Definition: hypar.h:266
#define _XDIR_
Definition: euler1d.h:75
int ghosts
Definition: hypar.h:52
#define _MODEL_NVARS_
Definition: euler1d.h:58
Contains macros and function definitions for common array operations.
double * dxinv
Definition: hypar.h:110