HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
FirstDerivativeSecondOrderNoGhosts.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 <firstderivative.h>
11 
12 #include <mpivars.h>
14 
15 #undef _MINIMUM_GHOSTS_
16 
19 #define _MINIMUM_GHOSTS_ 1
20 
21 #ifdef with_omp
22 #include <omp.h>
23 #endif
24 
43  double *f,
45  int dir,
46  int bias,
48  int ndims,
49  int *dim,
50  int ghosts,
51  int nvars,
52  void* m )
53 {
54  MPIContext* mpi = (MPIContext*) m;
55  int i, j, v;
56 
57  if ((!Df) || (!f)) {
58  fprintf(stderr, "Error in FirstDerivativeSecondOrder(): input arrays not allocated.\n");
59  return(1);
60  }
61  if (ghosts < _MINIMUM_GHOSTS_) {
62  fprintf(stderr, "Error in FirstDerivativeSecondOrderCentralNoGhosts(): insufficient number of ghosts.\n");
63  return(1);
64  }
65 
66  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
67  dimension "dir" */
68  int indexC[ndims], index_outer[ndims], bounds_outer[ndims];
69  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
70  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
71 
72 #pragma omp parallel for schedule(auto) default(shared) private(i,j,v,index_outer,indexC)
73  for (j=0; j<N_outer; j++) {
74  _ArrayIndexnD_(ndims,j,bounds_outer,index_outer,0);
75  _ArrayCopy1D_(index_outer,indexC,ndims);
76  for (i = 0; i < dim[dir]; i++) {
77  int qC, qL, qR;
78  indexC[dir] = i-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qL);
79  indexC[dir] = i ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qC );
80  indexC[dir] = i+1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qR);
81  for (v=0; v<nvars; v++) Df[qC*nvars+v] = 0.5 * (f[qR*nvars+v]-f[qL*nvars+v]);
82  }
83  }
84 
85  if (mpi->ip[dir] == 0) {
86  /* left physical boundary: overwrite the leftmost value with biased finite-difference */
87 #pragma omp parallel for schedule(auto) default(shared) private(i,j,v,index_outer,indexC)
88  for (j=0; j<N_outer; j++) {
89  _ArrayIndexnD_(ndims,j,bounds_outer,index_outer,0);
90  _ArrayCopy1D_(index_outer,indexC,ndims);
91  i = 0;
92  int qC, qR, qR2;
93  indexC[dir] = i ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qC );
94  indexC[dir] = i+1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qR);
95  indexC[dir] = i+2; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qR2);
96  for (v=0; v<nvars; v++) Df[qC*nvars+v] = (-0.5*f[qR2*nvars+v]+2*f[qR*nvars+v]-1.5*f[qC*nvars+v]);
97  }
98  }
99 
100  if (mpi->ip[dir] == (mpi->iproc[dir]-1)) {
101  /* right physical boundary: overwrite the rightmost value with biased finite-difference */
102 #pragma omp parallel for schedule(auto) default(shared) private(i,j,v,index_outer,indexC)
103  for (j=0; j<N_outer; j++) {
104  _ArrayIndexnD_(ndims,j,bounds_outer,index_outer,0);
105  _ArrayCopy1D_(index_outer,indexC,ndims);
106  i = dim[dir] - 1;
107  int qC, qL, qL2;
108  indexC[dir] = i-2; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qL2);
109  indexC[dir] = i-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qL);
110  indexC[dir] = i ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qC );
111  for (v=0; v<nvars; v++) Df[qC*nvars+v] = (0.5*f[qL2*nvars+v]-2*f[qL*nvars+v]+1.5*f[qC*nvars+v]);
112  }
113  }
114 
115  return 0;
116 }
MPI related function definitions.
Some basic definitions and macros.
#define _ArrayIndexnD_(N, index, imax, i, ghost)
MPIVariables MPIContext
#define _ArrayIndex1D_(N, imax, i, ghost, index)
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 first derivative.
#define _ArrayProduct1D_(x, size, p)
int FirstDerivativeSecondOrderCentralNoGhosts(double *Df, double *f, int dir, int bias, int ndims, int *dim, int ghosts, int nvars, void *m)