HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
FirstDerivativeSecondOrder.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>
13 #include <hypar.h>
16 
17 #ifdef with_omp
18 #include <omp.h>
19 #endif
20 
37  double *Df,
38  double *f,
40  int dir,
41  int bias,
43  void *s,
44  void *m
45  )
46 {
47  SolverContext *solver = (SolverContext*) s;
48  int i, j, v;
49 
50  int ghosts = solver->ghosts;
51  int ndims = solver->ndims;
52  int nvars = solver->nvars;
53  int *dim = solver->dim_local;
54 
55 
56  if ((!Df) || (!f)) {
57  fprintf(stderr, "Error in FirstDerivativeSecondOrder(): input arrays not allocated.\n");
58  return(1);
59  }
60 
61  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
62  dimension "dir" */
63  int indexC[ndims], index_outer[ndims], bounds_outer[ndims];
64  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
65  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
66 
67 #pragma omp parallel for schedule(auto) default(shared) private(i,j,v,index_outer,indexC)
68  for (j=0; j<N_outer; j++) {
69  _ArrayIndexnD_(ndims,j,bounds_outer,index_outer,0);
70  _ArrayCopy1D_(index_outer,indexC,ndims);
71  /* left boundary */
72  for (i = -ghosts; i < -ghosts+1; i++) {
73  int qC, qR, qRR;
74  indexC[dir] = i ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qC );
75  indexC[dir] = i+1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qR );
76  indexC[dir] = i+2; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qRR);
77  for (v=0; v<nvars; v++) Df[qC*nvars+v] = 0.5 * (-3*f[qC*nvars+v]+4*f[qR*nvars+v]-f[qRR*nvars+v]);
78  }
79  /* interior */
80  for (i = -ghosts+1; i < dim[dir]+ghosts-1; i++) {
81  int qC, qL, qR;
82  indexC[dir] = i ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qC );
83  indexC[dir] = i-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qL);
84  indexC[dir] = i+1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qR);
85  for (v=0; v<nvars; v++) Df[qC*nvars+v] = 0.5 * (f[qR*nvars+v]-f[qL*nvars+v]);
86  }
87  /* right boundary */
88  for (i = dim[dir]+ghosts-1; i < dim[dir]+ghosts; i++) {
89  int qLL, qL, qC;
90  indexC[dir] = i-2; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qLL);
91  indexC[dir] = i-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qL );
92  indexC[dir] = i ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qC );
93  for (v=0; v<nvars; v++) Df[qC*nvars+v] = 0.5 * (3*f[qC*nvars+v]-4*f[qL*nvars+v]+f[qLL*nvars+v]);
94  }
95  }
96 
97  return(0);
98 }
HyPar SolverContext
Definitions for the functions computing the first derivative.
#define _ArrayIndexnD_(N, index, imax, i, ghost)
int * dim_local
Definition: hypar.h:37
MPI related function definitions.
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArrayCopy1D_(x, y, size)
int nvars
Definition: hypar.h:29
Contains structure definition for hypar.
Some basic definitions and macros.
int ndims
Definition: hypar.h:26
Contains macros and function definitions for common array operations.
#define _ArrayProduct1D_(x, size, p)
int FirstDerivativeSecondOrderCentral(double *, double *, int, int, void *, void *)
Structure of MPI-related variables.
MPIVariables MPIContext
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23