HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
BurgersUpwind.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <math.h>
8 #include <basic.h>
9 #include <arrayfunctions.h>
10 #include <mathfunctions.h>
11 #include <physicalmodels/burgers.h>
12 #include <hypar.h>
13 
15 int BurgersUpwind( double* fI,
16  double* fL,
17  double* fR,
18  double* uL,
19  double* uR,
20  double* u,
21  int dir,
22  void* s,
23  double t
24  )
25 {
26  HyPar *solver = (HyPar*) s;
27  Burgers *param = (Burgers*) solver->physics;
28  int done,v;
29 
30  int ndims = solver->ndims;
31  int nvars = solver->nvars;
32  int *dim = solver->dim_local;
33  int ghosts = solver->ghosts;
34 
35  int index_outer[ndims], index_inter[ndims], bounds_outer[ndims], bounds_inter[ndims];
36  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
37  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
38 
39  done = 0; _ArraySetValue_(index_outer,ndims,0);
40  while (!done) {
41  _ArrayCopy1D_(index_outer,index_inter,ndims);
42  for (index_inter[dir] = 0; index_inter[dir] < bounds_inter[dir]; index_inter[dir]++) {
43 
44  int p; _ArrayIndex1D_(ndims,bounds_inter,index_inter,0,p);
45  int indexL[ndims]; _ArrayCopy1D_(index_inter,indexL,ndims); indexL[dir]--;
46  int indexR[ndims]; _ArrayCopy1D_(index_inter,indexR,ndims);
47  int pL; _ArrayIndex1D_(ndims,dim,indexL,ghosts,pL);
48  int pR; _ArrayIndex1D_(ndims,dim,indexR,ghosts,pR);
49 
50  for (v = 0; v < nvars; v++) {
51  double eigL = u[nvars*pL+v],
52  eigR = u[nvars*pR+v];
53 
54  if ((eigL > 0) && (eigR > 0)) {
55  fI[nvars*p+v] = fL[nvars*p+v];
56  } else if ((eigL < 0) && (eigR < 0)) {
57  fI[nvars*p+v] = fR[nvars*p+v];
58  } else {
59  double alpha = max(absolute(eigL), absolute(eigR));
60  fI[nvars*p+v] = 0.5 * (fL[nvars*p+v] + fR[nvars*p+v] - alpha * (uR[nvars*p+v] - uL[nvars*p+v]));
61  }
62  }
63 
64  }
65  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
66 
67  }
68 
69  return(0);
70 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
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)
Contains function definitions for common mathematical functions.
#define _ArrayCopy1D_(x, y, size)
int nvars
Definition: hypar.h:29
Contains structure definition for hypar.
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
int BurgersUpwind(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: BurgersUpwind.c:15
#define max(a, b)
Definition: math_ops.h:18
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23