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

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

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

Go to the source code of this file.

Functions

int LinearADRDiffusionG (double *f, double *u, int dir, void *s, double t)
 
int LinearADRDiffusionH (double *f, double *u, int dir1, int dir2, void *s, double t)
 

Detailed Description

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

Author
Debojyoti Ghosh

Definition in file LinearADRDiffusion.c.

Function Documentation

◆ LinearADRDiffusionG()

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

Evaluate the diffusion term in the linear advection-diffusion-reaction model for a "pure Laplacian" type operator (no cross derivatives):
Compute

\begin{equation} \nu_d u \end{equation}

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

\begin{equation} \sum_d \frac {\partial^2} {\partial x_d^2} \left( \nu_d u \right) \end{equation}

Parameters
fArray to hold the computed diffusion term (same size and layout as u)
uArray containing the solution
dirSpatial dimension (unused since this is a 1D system)
sSolver object of type HyPar
tCurrent time

Definition at line 26 of file LinearADRDiffusion.c.

32 {
33  HyPar *solver = (HyPar*) s;
34  LinearADR *param = (LinearADR*) solver->physics;
35  int i, v;
36 
37  int *dim = solver->dim_local;
38  int ghosts = solver->ghosts;
39  int ndims = solver->ndims;
40  int nvars = solver->nvars;
41  int index[ndims], bounds[ndims], offset[ndims];
42 
43  /* set bounds for array index to include ghost points */
44  _ArrayCopy1D_(dim,bounds,ndims);
45  for (i=0; i<ndims; i++) bounds[i] += 2*ghosts;
46 
47  /* set offset such that index is compatible with ghost point arrangement */
48  _ArraySetValue_(offset,ndims,-ghosts);
49 
50  int done = 0; _ArraySetValue_(index,ndims,0);
51  while (!done) {
52  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
53  for (v = 0; v < nvars; v++) f[nvars*p+v] = param->d[nvars*dir+v] * u[nvars*p+v];
54  _ArrayIncrementIndex_(ndims,bounds,index,done);
55  }
56 
57  return(0);
58 }
int nvars
Definition: hypar.h:29
int ndims
Definition: hypar.h:26
Structure containing variables and parameters specific to the linear advection-diffusion-reaction mod...
Definition: linearadr.h:37
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 * d
Definition: linearadr.h:53

◆ LinearADRDiffusionH()

int LinearADRDiffusionH ( double *  f,
double *  u,
int  dir1,
int  dir2,
void *  s,
double  t 
)

Evaluate the diffusion term in the linear advection-diffusion-reaction model for a parabolic operator with no cross derivatives:
Compute

\begin{equation} \nu_d u \end{equation}

given \(u\) and \(d_1,d_2\) in the parabolic term

\begin{equation} \sum_{d_1}\sum_{d_2} \frac {\partial^2} {\partial x_{d_1} \partial x_{d_2}} \left( \nu_d u \right) \end{equation}

Note: it's not correctly implemented. Will implement when necessary.

Parameters
fArray to hold the computed diffusion term (same size and layout as u)
uArray containing the solution
dir1First spatial dimension of the double derivative \(d_1\)
dir2Second spatial dimension of the double derivative \(d_2\)
sSolver object of type HyPar
tCurrent time

Definition at line 74 of file LinearADRDiffusion.c.

81 {
82  HyPar *solver = (HyPar*) s;
83  LinearADR *param = (LinearADR*) solver->physics;
84  int i, v;
85 
86  int *dim = solver->dim_local;
87  int ghosts = solver->ghosts;
88  int ndims = solver->ndims;
89  int nvars = solver->nvars;
90  int index[ndims], bounds[ndims], offset[ndims];
91 
92  if (dir1 == dir2) {
93 
94  int dir = dir1;
95 
96  /* set bounds for array index to include ghost points */
97  _ArrayCopy1D_(dim,bounds,ndims);
98  for (i=0; i<ndims; i++) bounds[i] += 2*ghosts;
99 
100  /* set offset such that index is compatible with ghost point arrangement */
101  _ArraySetValue_(offset,ndims,-ghosts);
102 
103  int done = 0; _ArraySetValue_(index,ndims,0);
104  while (!done) {
105  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
106  for (v = 0; v < nvars; v++) f[nvars*p+v] = param->d[nvars*dir+v] * u[nvars*p+v];
107  _ArrayIncrementIndex_(ndims,bounds,index,done);
108  }
109 
110  } else _ArraySetValue_(f,solver->npoints_local_wghosts*nvars,0.0);
111 
112 
113  return(0);
114 }
int nvars
Definition: hypar.h:29
int ndims
Definition: hypar.h:26
Structure containing variables and parameters specific to the linear advection-diffusion-reaction mod...
Definition: linearadr.h:37
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
int npoints_local_wghosts
Definition: hypar.h:42
#define _ArrayCopy1D_(x, y, size)
double * d
Definition: linearadr.h:53