HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
VlasovUpwind.c File Reference

Contains functions to compute the upwind flux at grid interfaces for the Vlasov equations. More...

#include <stdlib.h>
#include <math.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <mathfunctions.h>
#include <physicalmodels/vlasov.h>
#include <hypar.h>

Go to the source code of this file.

Functions

double VlasovAdvectionCoeff (int *, int, void *)
 
int VlasovUpwind (double *fI, double *fL, double *fR, double *uL, double *uR, double *u, int dir, void *s, double t)
 

Detailed Description

Contains functions to compute the upwind flux at grid interfaces for the Vlasov equations.

Author
John Loffeld

Definition in file VlasovUpwind.c.

Function Documentation

double VlasovAdvectionCoeff ( int *  idx,
int  dir,
void *  s 
)

Returns the advection coefficient at a given grid index \(c\), where

\begin{equation} c = v_i, \end{equation}

if dir < Vlasov::ndims_x ( \(i = {\rm dir}\)), and

\begin{equation} c = E_i, \end{equation}

the electric field if dir >= Vlasov::ndims_x ( \(i = \) dir-Vlasov::ndims_x).

Note: this function assumes that the electric field has already been set.

Parameters
idxgrid index
dirSpatial dimension
sSolver object of type HyPar

Definition at line 28 of file VlasovAdvectionCoeff.c.

32 {
33 
34  HyPar *solver = (HyPar*) s;
35  Vlasov *param = (Vlasov*) solver->physics;
36 
37  int* dim = solver->dim_local;
38  int ghosts = solver->ghosts;
39 
40  double retval = DBL_MAX;
41 
42  if (dir < param->ndims_x) {
43 
44  int veldim = dir + param->ndims_x;
45  _GetCoordinate_(veldim,idx[veldim],dim,ghosts,solver->x,retval);
46 
47  } else {
48 
49  int ndims_x = param->ndims_x;
50  int dim_x[ndims_x]; _ArrayCopy1D_(dim, dim_x, ndims_x);
51 
52  int idx_x[ndims_x];
53  _ArrayCopy1D_(idx, idx_x, ndims_x);
54  int p; _ArrayIndex1D_(ndims_x, dim_x, idx_x, ghosts, p);
55  retval = param->e_field[ndims_x*p+(dir-ndims_x)];
56 
57  }
58 
59  return retval;
60 
61 }
int ndims_x
Definition: vlasov.h:63
double * e_field
Definition: vlasov.h:81
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
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
Definition: vlasov.h:57
#define _ArrayCopy1D_(x, y, size)
double * x
Definition: hypar.h:107
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int VlasovUpwind ( double *  fI,
double *  fL,
double *  fR,
double *  uL,
double *  uR,
double *  u,
int  dir,
void *  s,
double  t 
)

Upwinding scheme for the Vlasov equations

Parameters
fIComputed upwind interface flux
fLLeft-biased reconstructed interface flux
fRRight-biased reconstructed interface flux
uLLeft-biased reconstructed interface solution
uRRight-biased reconstructed interface solution
uCell-centered solution
dirSpatial dimension
sSolver object of type HyPar
tCurrent solution time

Definition at line 17 of file VlasovUpwind.c.

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 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
double VlasovAdvectionCoeff(int *, int, void *)
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
Definition: vlasov.h:57
#define _ArrayCopy1D_(x, y, size)
int ndims
Definition: hypar.h:26
#define absolute(a)
Definition: math_ops.h:32
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23