PlasCom2  1.0
XPACC Multi-physics simluation application
WENO.C
Go to the documentation of this file.
1 // Functions for WENO schemes
2 //
3 // Source for basic scheme is:
4 // Jiang and Shu, J. Comput. Phys. 126 (1996) 202
5 // Deviations noted individually
6 
7 #include "WENO.H"
8 
9 namespace WENO {
10 
11  void ReconstPointVal(double vals[], CoeffsWENO& coeffs, int group, double& pVal) {
12  // Computes point value reconstructions for an array of values on all
13  // stencils for a given group
14  //
15  // Inputs/Outputs
16  // vals -- Field/flux values, index 0 corresponds to low offset for this group
17  // coeffs -- WENO coefficients
18  // group -- WENO stencil group to use
19  // pVal -- Reconstructed value
20 
21  int nSten = coeffs.NSten(group);
22  double pValSten[nSten];
23  double siSten[nSten];
24  for (int s=0; s<nSten; s++) {
25  int i = coeffs.Lo(group, s) - coeffs.LoGroup(group);
26  ReconstPointValSten(&vals[i], coeffs, group, s, pValSten[s]);
27  SmoothInd(&vals[i], coeffs, group, s, siSten[s]);
28  }
29 
30  double nlWeights[nSten];
31  double nlWeightsSum = 0;
32  for (int s=0; s<nSten; s++) {
33  nlWeights[s] = coeffs.LinWeight(group, s)/std::pow(coeffs.epsW + siSten[s], coeffs.pW);
34  nlWeightsSum += nlWeights[s];
35  }
36 
37  pVal = 0;
38  for (int s=0; s<nSten; s++) {
39  pVal += nlWeights[s]*pValSten[s]/nlWeightsSum;
40  }
41  }
42 
43  void ReconstPointValSten(double vals[], CoeffsWENO& coeffs, int group, int sten, double& pVal) {
44  // Computes point value reconstructions for an array of values on a single stencil
45  //
46  // Inputs/Outputs
47  // vals -- Field/flux values, index 0 corresponds to low offset for this stencil
48  // coeffs -- WENO coefficients
49  // group -- WENO stencil group to use
50  // sten -- Stencil to use within the group
51  // pVal -- Reconstructed value
52 
53  StencilSet reconst = coeffs.Reconst(group);
54  int lo = coeffs.Lo(group, sten);
55 
56  pVal = 0;
57  for (int j=reconst.stencilStarts[sten]; j<reconst.stencilStarts[sten]+reconst.stencilSizes[sten]; j++) {
58  pVal = pVal + reconst.stencilWeights[j]*vals[reconst.stencilOffsets[j]-lo];
59  }
60  }
61 
62  void SmoothInd(double vals[], CoeffsWENO& coeffs, int group, int sten, double& si) {
63  // Computes smoothness indicator for an array of values on a single stencil
64  //
65  // Inputs/Outputs
66  // vals -- Field/flux values, index 0 corresponds to low offset for this stencil
67  // coeffs -- WENO coefficients
68  // group -- WENO stencil group to use
69  // sten -- Stencil to use within the group
70  // si -- Smoothness indicator
71 
72  int lo = coeffs.Lo(group, sten);
73 
74  StencilSet si1 = coeffs.SmIndFirst(group);
75  double comb = 0;
76  for (int j=si1.stencilStarts[sten]; j<si1.stencilStarts[sten]+si1.stencilSizes[sten]; j++) {
77  comb = comb + si1.stencilWeights[j]*vals[si1.stencilOffsets[j]-lo];
78  }
79  si = coeffs.siFirst*comb*comb;
80 
81  StencilSet si2 = coeffs.SmIndSecond(group);
82  comb = 0;
83  for (int j=si2.stencilStarts[sten]; j<si2.stencilStarts[sten]+si2.stencilSizes[sten]; j++) {
84  comb = comb + si2.stencilWeights[j]*vals[si2.stencilOffsets[j]-lo];
85  }
86  si = si + coeffs.siSecond*comb*comb;
87  }
88 
89  void Project(int n, int m, double T[], double vals[], double res[]) {
90  // Computes characteristic projection for a given set of values
91  // with a given rotation matrix
92  //
93  // Inputs/Outputs
94  // n -- size of rotation matrix
95  // m -- number of columns in field/flux value matrix
96  // T -- n x n rotation matrix (column-major ordering)
97  // vals -- n x m matrix of field/flux values (row-major ordering)
98  // res -- n x m result matrix (row-major ordering)
99 
100  for (int i=0; i<n; i++) {
101  for (int j=0; j<m; j++) {
102  int rIndex = i*m + j; // (i,j) row-major
103  res[rIndex] = 0;
104  for (int k=0; k<n; k++) {
105  int tIndex = i + k*n; // (i,k) col-major
106  int vIndex = k*m + j; // (k,j) row-major
107  res[rIndex] += T[tIndex]*vals[vIndex];
108  }
109  }
110  }
111  }
112 
113  double EntropyFixEta(int n, double lambdaL[], double lambdaR[]) {
114  // Computes entropy fix threshold eta
115  //
116  // Inputs
117  // n -- number of eigenvalues in problem
118  // lambdaL -- eigenvalues of left state (n x n diagonal matrix)
119  // lambdaR -- eigenvalues of right state (n x n diagonal matrix)
120 
121  double eta = 0;
122  for (int i=0; i<n; i++) {
123  int diag = i*(n+1);
124  eta = std::max(eta, std::abs(lambdaR[diag] - lambdaL[diag]));
125  }
126  eta *= 0.5;
127 
128  return eta;
129  }
130 }
double pW
Definition: WENO.H:37
int * stencilSizes
The number of weights for each stencil.
Definition: Stencil.H:102
int LoGroup(int group)
Definition: WENO.H:268
double epsW
Definition: WENO.H:36
void ReconstPointVal(double vals[], CoeffsWENO &coeffs, int group, double &pVal)
Definition: WENO.C:11
double EntropyFixEta(int n, double lambdaL[], double lambdaR[])
Definition: WENO.C:113
int * stencilStarts
The starting index into the stencilWeight and stencilOffset arrays for each stencil.
Definition: Stencil.H:104
int * stencilOffsets
The offsets wrt the grid point at which the stencil is being applied.
Definition: Stencil.H:106
Definition: WENO.H:10
StencilSet SmIndSecond(int group)
Definition: WENO.H:292
double siSecond
Definition: WENO.H:35
void ReconstPointValSten(double vals[], CoeffsWENO &coeffs, int group, int sten, double &pVal)
Definition: WENO.C:43
StencilSet SmIndFirst(int group)
Definition: WENO.H:286
void Project(int n, int m, double T[], double vals[], double res[])
Definition: WENO.C:89
Encapsulation for a collection of operator stencils.
Definition: Stencil.H:26
int Lo(int group, int sten)
Definition: WENO.H:272
int NSten(int group)
Definition: WENO.H:264
StencilSet Reconst(int group)
Definition: WENO.H:280
double * stencilWeights
The stencil weights.
Definition: Stencil.H:108
void SmoothInd(double vals[], CoeffsWENO &coeffs, int group, int sten, double &si)
Definition: WENO.C:62
double LinWeight(int group, int sten)
Definition: WENO.H:276
double siFirst
Definition: WENO.H:34