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

Function to evaluate the advection term in the linear advection-diffusion-reaction model. More...

#include <stdlib.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <physicalmodels/linearadr.h>
#include <hypar.h>

Go to the source code of this file.

Functions

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

Detailed Description

Function to evaluate the advection term in the linear advection-diffusion-reaction model.

Author
Debojyoti Ghosh

Definition in file LinearADRAdvection.c.

Function Documentation

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

Evaluate the advection term in the linear advection-diffusion-reaction model:
Compute

\begin{equation} a_d u \end{equation}

given \(u\) and \(d\) in the hyperbolic term

\begin{equation} \sum_d \frac {\partial} {\partial x_d} \left( a_d u \right) \end{equation}

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

Definition at line 37 of file LinearADRAdvection.c.

43 {
44  HyPar *solver = (HyPar*) s;
45  LinearADR *param = (LinearADR*) solver->physics;
46  double *adv = param->a;
47  int i, v;
48 
49  int *dim = solver->dim_local;
50  int ghosts = solver->ghosts;
51  int ndims = solver->ndims;
52  int nvars = solver->nvars;
53 
54  int index[ndims],
55  bounds[ndims],
56  offset[ndims];
57 
58  /* set bounds for array index to include ghost points */
59  _ArrayCopy1D_(dim,bounds,ndims);
60  for (i=0; i<ndims; i++) bounds[i] += 2*ghosts;
61 
62  /* set offset such that index is compatible with ghost point arrangement */
63  _ArraySetValue_(offset,ndims,-ghosts);
64 
65  int done = 0; _ArraySetValue_(index,ndims,0);
66  if (param->constant_advection == 1) {
67  while (!done) {
68  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
69  for (v = 0; v < nvars; v++) {
70  f[nvars*p+v] = param->a[nvars*dir+v] * u[nvars*p+v];
71  }
72  _ArrayIncrementIndex_(ndims,bounds,index,done);
73  }
74  } else if (param->constant_advection == 0) {
75  while (!done) {
76  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
77  for (v = 0; v < nvars; v++) {
78  double a = adv[nvars*ndims*p+nvars*dir+v];
79  f[nvars*p+v] = a * u[nvars*p+v];
80  }
81  _ArrayIncrementIndex_(ndims,bounds,index,done);
82  }
83  } else {
84  while (!done) {
85  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
86  for (v = 0; v < nvars; v++) {
87  f[nvars*p+v] = 0.0;
88  }
89  _ArrayIncrementIndex_(ndims,bounds,index,done);
90  }
91  }
92 
93  return(0);
94 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
void * physics
Definition: hypar.h:266
Structure containing variables and parameters specific to the linear advection-diffusion-reaction mod...
Definition: linearadr.h:37
int * dim_local
Definition: hypar.h:37
double * a
Definition: linearadr.h:50
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
#define _ArrayCopy1D_(x, y, size)
int nvars
Definition: hypar.h:29
int constant_advection
Definition: linearadr.h:40
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23