HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Interp1PrimSecondOrderCentralChar.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 
80  double *fI,
81  double *fC,
82  double *u,
83  double *x,
84  int upw,
85  int dir,
86  void *s,
87  void *m,
88  int uflag
89  )
90 {
91  HyPar *solver = (HyPar*) s;
92  int i, k, v;
94 
95  int ghosts = solver->ghosts;
96  int ndims = solver->ndims;
97  int nvars = solver->nvars;
98  int *dim = solver->dim_local;
99 
100  /* create index and bounds for the outer loop, i.e., to loop over all 1D lines along
101  dimension "dir" */
102  int indexC[ndims], indexI[ndims], index_outer[ndims], bounds_outer[ndims], bounds_inter[ndims];
103  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
104  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
105  int N_outer; _ArrayProduct1D_(bounds_outer,ndims,N_outer);
106 
107  /* allocate arrays for the averaged state, eigenvectors and characteristic interpolated f */
108  double R[nvars*nvars], L[nvars*nvars], uavg[nvars], fchar[nvars];
109 
110 #pragma omp parallel for schedule(auto) default(shared) private(i,k,v,R,L,uavg,fchar,index_outer,indexC,indexI)
111  for (i=0; i<N_outer; i++) {
112  _ArrayIndexnD_(ndims,i,bounds_outer,index_outer,0);
113  _ArrayCopy1D_(index_outer,indexC,ndims);
114  _ArrayCopy1D_(index_outer,indexI,ndims);
115 
116  for (indexI[dir] = 0; indexI[dir] < dim[dir]+1; indexI[dir]++) {
117 
118  int pL, pR; /* 1D index of the left and right cells */
119  indexC[dir] = indexI[dir]-1; _ArrayIndex1D_(ndims,dim,indexC,ghosts,pL);
120  indexC[dir] = indexI[dir] ; _ArrayIndex1D_(ndims,dim,indexC,ghosts,pR);
121  int p; /* 1D index of the interface */
122  _ArrayIndex1D_(ndims,bounds_inter,indexI,0,p);
123 
124  /* find averaged state at this interface */
125  IERR solver->AveragingFunction(uavg,&u[nvars*pL],&u[nvars*pR],solver->physics); CHECKERR(ierr);
126 
127  /* Get the left and right eigenvectors */
128  IERR solver->GetLeftEigenvectors (uavg,L,solver->physics,dir); CHECKERR(ierr);
129  IERR solver->GetRightEigenvectors (uavg,R,solver->physics,dir); CHECKERR(ierr);
130 
131  /* For each characteristic field */
132  for (v = 0; v < nvars; v++) {
133 
134  /* calculate the characteristic flux components along this characteristic */
135  double fcL = 0, fcR = 0;
136  for (k = 0; k < nvars; k++) {
137  fcL += L[v*nvars+k] * fC[pL*nvars+k];
138  fcR += L[v*nvars+k] * fC[pR*nvars+k];
139  }
140 
141  /* first order upwind approximation of the characteristic flux */
142  fchar[v] = 0.5 * (fcL + fcR);
143 
144  }
145 
146  /* calculate the interface u from the characteristic u */
147  IERR MatVecMult(nvars,(fI+nvars*p),R,fchar); CHECKERR(ierr);
148 
149  }
150  }
151 
152  return(0);
153 }
Definitions for the functions computing the interpolated value of the primitive at the cell interface...
int Interp1PrimSecondOrderCentralChar(double *, double *, double *, double *, int, int, void *, void *, int)
2nd order central reconstruction (characteristic-based) on a uniform grid
#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