HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
VlasovAdvection.c File Reference

Contains the function to compute the hyperbolic flux for the Vlasov equations over the domain. More...

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

Go to the source code of this file.

Functions

double VlasovAdvectionCoeff (int *, int, void *)
 
int VlasovAdvection (double *f, double *u, int dir, void *s, double t)
 

Detailed Description

Contains the function to compute the hyperbolic flux for the Vlasov equations over the domain.

Author
John Loffeld

Definition in file VlasovAdvection.c.

Function Documentation

◆ VlasovAdvectionCoeff()

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 }
Definition: vlasov.h:57
double * x
Definition: hypar.h:107
double * e_field
Definition: vlasov.h:81
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _ArrayIndex1D_(N, imax, i, ghost, index)
int * dim_local
Definition: hypar.h:37
#define _GetCoordinate_(dir, i, dim, ghosts, x, coord)
Definition: basic.h:31
void * physics
Definition: hypar.h:266
int ghosts
Definition: hypar.h:52
#define _ArrayCopy1D_(x, y, size)
int ndims_x
Definition: vlasov.h:63

◆ VlasovAdvection()

int VlasovAdvection ( double *  f,
double *  u,
int  dir,
void *  s,
double  t 
)

Compute the hyperbolic flux over the local domain.

\begin{equation} {\bf F}\left({\bf u}(x,v)\right) = c {\bf u}(x,v), \end{equation}

where the advection coefficient \(c\) is computed by VlasovAdvectionCoeff().

Parameters
fArray to hold the computed flux (same size and layout as u)
uArray containing the conserved solution
dirSpatial dimension
sSolver object of type HyPar
tCurrent time

Definition at line 22 of file VlasovAdvection.c.

28 {
29 
30  HyPar *solver = (HyPar*) s;
31  Vlasov *param = (Vlasov*) solver->physics;
32 
33  int* dim = solver->dim_local;
34  int ghosts = solver->ghosts;
35  int ndims = solver->ndims;
36 
37  // set bounds for array index to include ghost points
38  int bounds[ndims];
39  _ArrayCopy1D_(dim,bounds,ndims);
40  for (int i=0; i<ndims; i++) bounds[i] += 2*ghosts;
41 
42  // set offset such that index is compatible with ghost point arrangement
43  int offset[ndims];
44  _ArraySetValue_(offset,ndims,-ghosts);
45 
46  int done = 0;
47  int index_wog[ndims];
48  int index[ndims]; _ArraySetValue_(index,ndims,0);
49  while (!done) {
50 
51  _ArrayCopy1D_(index, index_wog, ndims);
52  for (int i = 0; i < ndims; i++) index_wog[i] -= ghosts;
53  double adv_coeff = VlasovAdvectionCoeff(index_wog, dir, solver);
54 
55  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
56  f[p] = adv_coeff * u[p];
57  _ArrayIncrementIndex_(ndims,bounds,index,done);
58 
59  }
60 
61  return 0;
62 }
Definition: vlasov.h:57
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _ArrayIndex1DWO_(N, imax, i, offset, 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
#define _ArrayCopy1D_(x, y, size)
double VlasovAdvectionCoeff(int *, int, void *)