HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
Interp1PrimFirstOrderUpwindChar.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 <matmult_native.h>
11 #include <mathfunctions.h>
12 #include <interpolation.h>
13 #include <mpivars.h>
14 #include <hypar.h>
15 
16 #ifdef with_omp
17 #include <omp.h>
18 #endif
19 
20 #undef _MINIMUM_GHOSTS_
21 
25 #define _MINIMUM_GHOSTS_ 1
26 
78  double *fI,
79  double *fC,
80  double *u,
81  double *x,
82  int upw,
83  int dir,
84  void *s,
85  void *m,
86  int uflag
87  )
88 {
89  HyPar *solver = (HyPar*) s;
90  int i, k, v;
92 
93  int ghosts = solver->ghosts;
94  int ndims = solver->ndims;
95  int nvars = solver->nvars;
96  int *dim = solver->dim_local;
97 
98  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
99  dimension "dir" */
100  int indexC[ndims], indexI[ndims], index_outer[ndims], bounds_outer[ndims], bounds_inter[ndims];
101  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
102  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
103  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
104 
105  /* allocate arrays for the averaged state, eigenvectors and characteristic interpolated f */
106  double R[nvars*nvars], L[nvars*nvars], uavg[nvars], fchar[nvars];
107 
108 #pragma omp parallel for schedule(auto) default(shared) private(i,k,v,R,L,uavg,fchar,index_outer,indexC,indexI)
109  for (i=0; i<N_outer; i++) {
110  _ArrayIndexnD_(ndims,i,bounds_outer,index_outer,0);
111  _ArrayCopy1D_(index_outer,indexC,ndims);
112  _ArrayCopy1D_(index_outer,indexI,ndims);
113 
114  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
115 
116  int pL, pR; /* 1D index of the left and right cells */
117  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,pL);
118  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,pR);
119  int p; /* 1D index of the interface */
120  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
121 
122  /* find averaged state at this interface */
123  IERR solver->AveragingFunction(uavg,&u[nvars*pL],&u[nvars*pR],solver->physics); CHECKERR(ierr);
124 
125  /* Get the left and right eigenvectors */
126  IERR solver->GetLeftEigenvectors (uavg,L,solver->physics,dir); CHECKERR(ierr);
127  IERR solver->GetRightEigenvectors (uavg,R,solver->physics,dir); CHECKERR(ierr);
128 
129  /* For each characteristic field */
130  for (v = 0; v < nvars; v++) {
131 
132  /* calculate the characteristic flux components along this characteristic */
133  double fcL = 0, fcR = 0;
134  for (k = 0; k < nvars; k++) {
135  fcL += L[v*nvars+k] * fC[pL*nvars+k];
136  fcR += L[v*nvars+k] * fC[pR*nvars+k];
137  }
138 
139  /* first order upwind approximation of the characteristic flux */
140  fchar[v] = (upw > 0 ? fcL : fcR);
141 
142  }
143 
144  /* calculate the interface u from the characteristic u */
145  IERR MatVecMult(nvars,(fI+nvars*p),R,fchar); CHECKERR(ierr);
146 
147  }
148  }
149 
150  return(0);
151 }
int nvars
Definition: hypar.h:29
#define IERR
Definition: basic.h:16
MPI related function definitions.
#define CHECKERR(ierr)
Definition: basic.h:18
Contains function definitions for common mathematical functions.
int(* AveragingFunction)(double *, double *, double *, void *)
Definition: hypar.h:354
Some basic definitions and macros.
#define _ArrayIndexnD_(N, index, imax, i, ghost)
int ndims
Definition: hypar.h:26
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
void * physics
Definition: hypar.h:266
int ghosts
Definition: hypar.h:52
Contains macros and function definitions for common matrix multiplication.
Definitions for the functions computing the interpolated value of the primitive at the cell interface...
#define MatVecMult(N, y, A, x)
#define _DECLARE_IERR_
Definition: basic.h:17
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
int(* GetRightEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:359
#define _ArrayProduct1D_(x, size, p)
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357
int Interp1PrimFirstOrderUpwindChar(double *fI, double *fC, double *u, double *x, int upw, int dir, void *s, void *m, int uflag)
1st order upwind reconstruction (characteristic-based) on a uniform grid