HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
SecondDerivativeFourthOrder.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_ 2
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  static double one_twelve = 1.0/12.0;
53 
54  if ((!D2f) || (!f)) {
55  fprintf(stderr, "Error in SecondDerivativeFourthOrder(): input arrays not allocated.\n");
56  return(1);
57  }
58  if (ghosts < _MINIMUM_GHOSTS_) {
59  fprintf(stderr, "Error in SecondDerivativeFourthOrder(): insufficient number of ghosts.\n");
60  return(1);
61  }
62 
63  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
64  dimension "dir" */
65  int indexC[ndims], index_outer[ndims], bounds_outer[ndims];
66  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
67 
68  int done = 0; _ArraySetValue_(index_outer,ndims,0);
69  while (!done) {
70  _ArrayCopy1D_(index_outer,indexC,ndims);
71  for (i = 0; i < dim[dir]; i++) {
72  int qm2, qm1, qC, qp1, qp2;
73  indexC[dir] = i-2; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm2);
74  indexC[dir] = i-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1);
75  indexC[dir] = i ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qC );
76  indexC[dir] = i+1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qp1);
77  indexC[dir] = i+2; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qp2);
78  for (v=0; v<nvars; v++)
79  D2f[qC*nvars+v] = (-f[qm2*nvars+v]+16*f[qm1*nvars+v]-30*f[qC*nvars+v]+16*f[qp1*nvars+v]-f[qp2*nvars+v])*one_twelve;
80  }
81  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
82  }
83 
84  return(0);
85 }
int nvars
Definition: hypar.h:29
MPI related function definitions.
#define _MINIMUM_GHOSTS_
Some basic definitions and macros.
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Contains structure definition for hypar.
#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
int SecondDerivativeFourthOrderCentral(double *D2f, double *f, int dir, void *s, void *m)
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
Definitions for the functions computing the second derivative.