HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
VlasovUpwind.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/vlasov.h>
12 #include <hypar.h>
13 
14 double VlasovAdvectionCoeff(int*, int, void*);
15 
17 int VlasovUpwind( double* fI,
18  double* fL,
19  double* fR,
20  double* uL,
21  double* uR,
22  double* u,
23  int dir,
24  void* s,
25  double t
26  )
27 {
28  HyPar *solver = (HyPar*) s;
29  Vlasov *param = (Vlasov*) solver->physics;
30  int done;
31 
32  int ndims = solver->ndims;
33  int *dim = solver->dim_local;
34  int ghosts = solver->ghosts;
35 
36  int index_outer[ndims],
37  index_inter[ndims],
38  bounds_outer[ndims],
39  bounds_inter[ndims];
40  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
41  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
42 
43  done = 0; _ArraySetValue_(index_outer,ndims,0);
44  while (!done) {
45  _ArrayCopy1D_(index_outer,index_inter,ndims);
46  for (index_inter[dir] = 0; index_inter[dir] < bounds_inter[dir]; index_inter[dir]++) {
47 
48  int p; _ArrayIndex1D_(ndims,bounds_inter,index_inter,0,p);
49  int indexL[ndims]; _ArrayCopy1D_(index_inter,indexL,ndims); indexL[dir]--;
50  int indexR[ndims]; _ArrayCopy1D_(index_inter,indexR,ndims);
51  int idxL[ndims], idxR[ndims];
52 
53  int neig = 2+4*(ndims-1);
54  double eig[neig];
55  int count = 0;
56  eig[count] = VlasovAdvectionCoeff(indexL, dir, solver); count++;
57  eig[count] = VlasovAdvectionCoeff(indexR, dir, solver); count++;
58  for (int tdir = 0; tdir < ndims; tdir++ ) {
59  if (tdir != dir) {
60  _ArrayCopy1D_(indexL, idxL, ndims); idxL[tdir]--;
61  _ArrayCopy1D_(indexR, idxR, ndims); idxR[tdir]--;
62  eig[count] = VlasovAdvectionCoeff(idxL, dir, solver); count++;
63  eig[count] = VlasovAdvectionCoeff(idxR, dir, solver); count++;
64  _ArrayCopy1D_(indexL, idxL, ndims); idxL[tdir]++;
65  _ArrayCopy1D_(indexR, idxR, ndims); idxR[tdir]++;
66  eig[count] = VlasovAdvectionCoeff(idxL, dir, solver); count++;
67  eig[count] = VlasovAdvectionCoeff(idxR, dir, solver); count++;
68  }
69  }
70  if (count != neig) {
71  fprintf(stderr, "Error in VlasovUpwind(): count != neig for dir=%d\n",dir);
72  return 1;
73  }
74 
75  int all_positive = 1, all_negative = 1;
76  double maxabs_eig = 0.0;
77  for (int n = 0; n<neig; n++) {
78  if (eig[n] <= 0) all_positive = 0;
79  if (eig[n] >= 0) all_negative = 0;
80  if (absolute(eig[n]) > maxabs_eig) {
81  maxabs_eig = absolute(eig[n]);
82  }
83  }
84 
85  if (all_positive) {
86  fI[p] = fL[p];
87  } else if (all_negative) {
88  fI[p] = fR[p];
89  } else {
90  fI[p] = 0.5 * (fL[p] + fR[p] - maxabs_eig * (uR[p] - uL[p]));
91  }
92 
93  }
94  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
95 
96  }
97 
98  return 0;
99 }
Definition: vlasov.h:57
#define absolute(a)
Definition: math_ops.h:32
int VlasovUpwind(double *fI, double *fL, double *fR, double *uL, double *uR, double *u, int dir, void *s, double t)
Definition: VlasovUpwind.c:17
Contains function definitions for common mathematical functions.
Some basic definitions and macros.
int ndims
Definition: hypar.h:26
Vlasov Equation.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Contains structure definition for hypar.
#define _ArrayIndex1D_(N, imax, i, 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
double VlasovAdvectionCoeff(int *, int, void *)
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.