HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
LinearADRAdvection.c
Go to the documentation of this file.
1 
7 #include <stdlib.h>
8 #include <basic.h>
9 #include <arrayfunctions.h>
11 #include <hypar.h>
12 
37 int LinearADRAdvection( double *f,
38  double *u,
39  int dir,
40  void *s,
41  double t
42  )
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 }
int constant_advection
Definition: linearadr.h:40
int nvars
Definition: hypar.h:29
Some basic definitions and macros.
int LinearADRAdvection(double *f, double *u, int dir, void *s, double t)
int ndims
Definition: hypar.h:26
Structure containing variables and parameters specific to the linear advection-diffusion-reaction mod...
Definition: linearadr.h:37
double * a
Definition: linearadr.h:50
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Contains structure definition for hypar.
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
Linear Advection-Diffusion-Reaction model.
#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)
Contains macros and function definitions for common array operations.