HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
FirstDerivativeFirstOrder.c
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <basic.h>
9 #include <mathfunctions.h>
10 #include <arrayfunctions.h>
11 #include <firstderivative.h>
12 
13 #include <mpivars.h>
14 #include <hypar.h>
17 
18 #ifdef with_omp
19 #include <omp.h>
20 #endif
21 
38  double *Df,
39  double *f,
41  int dir,
42  int bias,
44  void *s,
45  void *m
46  )
47 {
48  SolverContext *solver = (SolverContext*) s;
49  int i, j, v;
50 
51  int ghosts = solver->ghosts;
52  int ndims = solver->ndims;
53  int nvars = solver->nvars;
54  int *dim = solver->dim_local;
55 
56 
57  if ((!Df) || (!f)) {
58  fprintf(stderr, "Error in FirstDerivativeSecondOrder(): input arrays not allocated.\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  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
67 
68 #pragma omp parallel for schedule(auto) default(shared) private(i,j,v,index_outer,indexC)
69  for (j=0; j<N_outer; j++) {
70  _ArrayIndexnD_(ndims,j,bounds_outer,index_outer,0);
71  _ArrayCopy1D_(index_outer,indexC,ndims);
72  /* left boundary */
73  for (i = -ghosts; i < -ghosts+1; i++) {
74  int qC, qR;
75  indexC[dir] = i ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qC );
76  indexC[dir] = i+1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qR );
77  for (v=0; v<nvars; v++) Df[qC*nvars+v] = f[qR*nvars+v]-f[qC*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] = max(bias,0)*f[qR*nvars+v]-bias*f[qC*nvars+v]+min(bias,0)*f[qL*nvars+v];
86  }
87  /* right boundary */
88  for (i = dim[dir]+ghosts-1; i < dim[dir]+ghosts; i++) {
89  int qL, qC;
90  indexC[dir] = i-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qL );
91  indexC[dir] = i ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qC );
92  for (v=0; v<nvars; v++) Df[qC*nvars+v] = f[qC*nvars+v]-f[qL*nvars+v];
93  }
94  }
95 
96  return(0);
97 }
int nvars
Definition: hypar.h:29
MPI related function definitions.
Contains function definitions for common mathematical functions.
#define min(a, b)
Definition: math_ops.h:14
MPIVariables MPIContext
Some basic definitions and macros.
int FirstDerivativeFirstOrder(double *Df, double *f, int dir, int bias, void *s, void *m)
#define _ArrayIndexnD_(N, index, imax, i, ghost)
int ndims
Definition: hypar.h:26
HyPar SolverContext
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Contains structure definition for hypar.
#define _ArrayIndex1D_(N, imax, i, ghost, index)
int * dim_local
Definition: hypar.h:37
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
#define _ArrayCopy1D_(x, y, size)
#define max(a, b)
Definition: math_ops.h:18
Contains macros and function definitions for common array operations.
Definitions for the functions computing the first derivative.
#define _ArrayProduct1D_(x, size, p)