HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
SecondDerivativeSecondOrderNoGhosts.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 
12 #include <mpivars.h>
14 
15 #undef _MINIMUM_GHOSTS_
16 
19 #define _MINIMUM_GHOSTS_ 1
20 
41  double* f,
43  int dir,
44  int ndims,
45  int* dim,
46  int ghosts,
47  int nvars,
48  void* m )
49 {
50  MPIContext* mpi = (MPIContext*) m;
51  int i, v;
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 SecondDerivativeSecondOrderNoGhosts(): 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  if (mpi->ip[dir] == 0) {
81  /* left physical boundary: overwrite the leftmost value with biased finite-difference */
82  int done = 0; _ArraySetValue_(index_outer,ndims,0);
83  while (!done) {
84  _ArrayCopy1D_(index_outer,indexC,ndims);
85  i = 0;
86  int qC, qR, qR2, qR3;
87  indexC[dir] = i ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qC);
88  indexC[dir] = i+1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qR);
89  indexC[dir] = i+2; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qR2);
90  indexC[dir] = i+3; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qR3);
91  for (v=0; v<nvars; v++) D2f[qC*nvars+v] = 2*f[qC*nvars+v]-5*f[qR*nvars+v]+4*f[qR2*nvars+v]-f[qR3*nvars+v];
92  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
93  }
94  }
95 
96  if (mpi->ip[dir] == (mpi->iproc[dir]-1)) {
97  /* right physical boundary: overwrite the rightmost value with biased finite-difference */
98  int done = 0; _ArraySetValue_(index_outer,ndims,0);
99  while (!done) {
100  _ArrayCopy1D_(index_outer,indexC,ndims);
101  i = dim[dir]-1;
102  int qL3, qL2, qL, qC;
103  indexC[dir] = i-3; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qL3);
104  indexC[dir] = i-2; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qL2);
105  indexC[dir] = i-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qL);
106  indexC[dir] = i ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qC);
107  for (v=0; v<nvars; v++) D2f[qC*nvars+v] = 2*f[qC*nvars+v]-5*f[qL*nvars+v]+4*f[qL2*nvars+v]-f[qL3*nvars+v];
108  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
109  }
110  }
111 
112 
113  return 0;
114 }
MPI related function definitions.
Some basic definitions and macros.
int SecondDerivativeSecondOrderCentralNoGhosts(double *D2f, double *f, int dir, int ndims, int *dim, int ghosts, int nvars, void *m)
#define _ArrayIndex1D_(N, imax, i, ghost, index)
MPIVariables MPIContext
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
Structure of MPI-related variables.
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
Definitions for the functions computing the second derivative.