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

2nd order discretization of the second derivative. More...

#include <stdio.h>
#include <stdlib.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <secondderivative.h>
#include <mpivars.h>
#include <hypar.h>

Go to the source code of this file.

Macros

#define _MINIMUM_GHOSTS_   1
 

Functions

int SecondDerivativeSecondOrderCentral (double *D2f, double *f, int dir, void *s, void *m)
 

Detailed Description

2nd order discretization of the second derivative.

Author
Debojyoti Ghosh

Definition in file SecondDerivativeSecondOrder.c.

Macro Definition Documentation

◆ _MINIMUM_GHOSTS_

#define _MINIMUM_GHOSTS_   1

Minimum number of ghost points required.

Definition at line 18 of file SecondDerivativeSecondOrder.c.

Function Documentation

◆ SecondDerivativeSecondOrderCentral()

int SecondDerivativeSecondOrderCentral ( double *  D2f,
double *  f,
int  dir,
void *  s,
void *  m 
)

Computes the second-order finite-difference approximation to the second derivative (Note: not divided by the grid spacing):

\begin{equation} \left(\partial^2 f\right)_i = f_{i-1} - 2f_i + f_{i+1} \end{equation}

where \(i\) is the grid index along the spatial dimension of the derivative.

Notes:

  • The second derivative is computed at the grid points or the cell centers.
  • Though the array D2f includes ghost points, the second derivative is not computed at these locations. Thus, array elements corresponding to the ghost points contain undefined values.
  • D2f and f are 1D arrays containing the function and its computed derivatives on a multi- dimensional grid. The derivative along the specified dimension dir is computed by looping through all grid lines along dir.
Parameters
D2fArray to hold the computed second derivative (with ghost points) (same size and layout as f)
fArray containing the grid point function values whose first derivative is to be computed (with ghost points)
dirThe spatial dimension along which the derivative is computed
sSolver object of type HyPar
mMPI object of type MPIVariables

Definition at line 34 of file SecondDerivativeSecondOrder.c.

43 {
44  HyPar *solver = (HyPar*) s;
45  int i, v;
46 
47  int ghosts = solver->ghosts;
48  int ndims = solver->ndims;
49  int nvars = solver->nvars;
50  int *dim = solver->dim_local;
51 
52 
53  if ((!D2f) || (!f)) {
54  fprintf(stderr, "Error in SecondDerivativeSecondOrder(): input arrays not allocated.\n");
55  return(1);
56  }
57  if (ghosts < _MINIMUM_GHOSTS_) {
58  fprintf(stderr, "Error in SecondDerivativeSecondOrder(): insufficient number of ghosts.\n");
59  return(1);
60  }
61 
62  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
63  dimension "dir" */
64  int indexC[ndims], index_outer[ndims], bounds_outer[ndims];
65  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
66 
67  int done = 0; _ArraySetValue_(index_outer,ndims,0);
68  while (!done) {
69  _ArrayCopy1D_(index_outer,indexC,ndims);
70  for (i = 0; i < dim[dir]; i++) {
71  int qL, qC, qR;
72  indexC[dir] = i-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qL);
73  indexC[dir] = i ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qC);
74  indexC[dir] = i+1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qR);
75  for (v=0; v<nvars; v++) D2f[qC*nvars+v] = f[qL*nvars+v]-2*f[qC*nvars+v]+f[qR*nvars+v];
76  }
77  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
78  }
79 
80  return(0);
81 }
int nvars
Definition: hypar.h:29
int ndims
Definition: hypar.h:26
#define _MINIMUM_GHOSTS_
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
#define _ArrayIncrementIndex_(N, imax, i, done)
int ghosts
Definition: hypar.h:52
#define _ArrayCopy1D_(x, y, size)