HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Interp1PrimFifthOrderUpwindChar.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <basic.h>
8 #include <arrayfunctions.h>
9 #include <matmult_native.h>
10 #include <mathfunctions.h>
11 #include <interpolation.h>
12 #include <mpivars.h>
13 #include <hypar.h>
14 
15 #ifdef with_omp
16 #include <omp.h>
17 #endif
18 
19 #undef _MINIMUM_GHOSTS_
20 
24 #define _MINIMUM_GHOSTS_ 3
25 
85  double *fI,
86  double *fC,
87  double *u,
88  double *x,
89  int upw,
90  int dir,
91  void *s,
92  void *m,
93  int uflag
94  )
95 {
96  HyPar *solver = (HyPar*) s;
97  int i, k, v;
99 
100  int ghosts = solver->ghosts;
101  int ndims = solver->ndims;
102  int nvars = solver->nvars;
103  int *dim = solver->dim_local;
104 
105  /* define some constants */
106  static const double one_by_thirty = 1.0/30.0,
107  thirteen_by_sixty = 13.0/60.0,
108  fortyseven_by_sixty = 47.0/60.0,
109  twentyseven_by_sixty = 27.0/60.0,
110  one_by_twenty = 1.0/20.0;
111 
112  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
113  dimension "dir" */
114  int indexC[ndims], indexI[ndims], index_outer[ndims], bounds_outer[ndims], bounds_inter[ndims];
115  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
116  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
117  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
118 
119  /* allocate arrays for the averaged state, eigenvectors and characteristic interpolated f */
120  double R[nvars*nvars], L[nvars*nvars], uavg[nvars], fchar[nvars];
121 
122 #pragma omp parallel for schedule(auto) default(shared) private(i,k,v,R,L,uavg,fchar,index_outer,indexC,indexI)
123  for (i=0; i<N_outer; i++) {
124  _ArrayIndexnD_(ndims,i,bounds_outer,index_outer,0);
125  _ArrayCopy1D_(index_outer,indexC,ndims);
126  _ArrayCopy1D_(index_outer,indexI,ndims);
127 
128  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
129 
130  /* 1D indices of the stencil grid points */
131  int qm1,qm2,qm3,qp1,qp2;
132  if (upw > 0) {
133  indexC[dir] = indexI[dir]-3; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm3);
134  indexC[dir] = indexI[dir]-2; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm2);
135  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1);
136  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qp1);
137  indexC[dir] = indexI[dir]+1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qp2);
138  } else {
139  indexC[dir] = indexI[dir]+2; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm3);
140  indexC[dir] = indexI[dir]+1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm2);
141  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qm1);
142  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qp1);
143  indexC[dir] = indexI[dir]-2; _ArrayIndex1D_(ndims,dim,indexC,ghosts,qp2);
144  }
145 
146  int p; /* 1D index of the interface */
147  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
148 
149  /* find averaged state at this interface */
150  IERR solver->AveragingFunction(uavg,&u[nvars*qm1],&u[nvars*qp1],solver->physics); CHECKERR(ierr);
151 
152  /* Get the left and right eigenvectors */
153  IERR solver->GetLeftEigenvectors (uavg,L,solver->physics,dir); CHECKERR(ierr);
154  IERR solver->GetRightEigenvectors (uavg,R,solver->physics,dir); CHECKERR(ierr);
155 
156  /* For each characteristic field */
157  for (v = 0; v < nvars; v++) {
158 
159  /* calculate the characteristic flux components along this characteristic */
160  double fm3, fm2, fm1, fp1, fp2;
161  fm3 = fm2 = fm1 = fp1 = fp2 = 0;
162  for (k = 0; k < nvars; k++) {
163  fm3 += L[v*nvars+k] * fC[qm3*nvars+k];
164  fm2 += L[v*nvars+k] * fC[qm2*nvars+k];
165  fm1 += L[v*nvars+k] * fC[qm1*nvars+k];
166  fp1 += L[v*nvars+k] * fC[qp1*nvars+k];
167  fp2 += L[v*nvars+k] * fC[qp2*nvars+k];
168  }
169 
170  /* fifth order upwind approximation of the characteristic flux */
171  fchar[v] = one_by_thirty * fm3
172  - thirteen_by_sixty * fm2
173  + fortyseven_by_sixty * fm1
174  + twentyseven_by_sixty * fp1
175  - one_by_twenty * fp2;
176  }
177 
178  /* calculate the interface u from the characteristic u */
179  IERR MatVecMult(nvars,(fI+nvars*p),R,fchar); CHECKERR(ierr);
180 
181  }
182  }
183 
184  return(0);
185 }
Definitions for the functions computing the interpolated value of the primitive at the cell interface...
#define _ArrayIndexnD_(N, index, imax, i, ghost)
void * physics
Definition: hypar.h:266
int(* GetRightEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:359
int * dim_local
Definition: hypar.h:37
MPI related function definitions.
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
int(* AveragingFunction)(double *, double *, double *, void *)
Definition: hypar.h:354
#define MatVecMult(N, y, A, x)
Contains function definitions for common mathematical functions.
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357
#define _ArrayCopy1D_(x, y, size)
int nvars
Definition: hypar.h:29
#define CHECKERR(ierr)
Definition: basic.h:18
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 IERR
Definition: basic.h:16
#define _ArrayProduct1D_(x, size, p)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Contains macros and function definitions for common matrix multiplication.
#define _DECLARE_IERR_
Definition: basic.h:17
int Interp1PrimFifthOrderUpwindChar(double *, double *, double *, double *, int, int, void *, void *, int)
5th order upwind reconstruction (characteristic-based) on a uniform grid