HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SecondDerivativeSecondOrder.c
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <basic.h>
9 #include <arrayfunctions.h>
10 #include <secondderivative.h>
11 #include <mpivars.h>
12 #include <hypar.h>
13 
14 #undef _MINIMUM_GHOSTS_
15 
18 #define _MINIMUM_GHOSTS_ 1
19 
35  double *D2f,
37  double *f,
39  int dir,
40  void *s,
41  void *m
42  )
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 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
int * dim_local
Definition: hypar.h:37
MPI related function definitions.
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
Definitions for the functions computing the second derivative.
int SecondDerivativeSecondOrderCentral(double *, double *, int, void *, void *)
#define _ArrayCopy1D_(x, y, size)
int nvars
Definition: hypar.h:29
Contains structure definition for hypar.
Some basic definitions and macros.
#define _MINIMUM_GHOSTS_
int ndims
Definition: hypar.h:26
Contains macros and function definitions for common array operations.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23