PlasCom2  1.0
XPACC Multi-physics simluation application
WENO.H
Go to the documentation of this file.
1 #ifndef __WENO_H__
2 #define __WENO_H__
3 
4 #include "Stencil.H"
5 
6 #include <cmath>
7 #include <algorithm>
8 #include <vector>
9 
10 namespace WENO {
11 
13 
14  class CoeffsWENO {
15 
16  // Private data
17  std::vector<StencilSet> reconstCoeffs; // StencilSets with reconstruction coefficients
18  std::vector<StencilSet> siCoeffsFirst; // StencilSets with first set of smoothness indicator coefficients
19  std::vector<StencilSet> siCoeffsSecond; // StencilSets with second set of smoothness indicator coefficients
20  std::vector<std::vector<double> > linWeights; // linear weights for non-linear combination step
21 
22  std::vector<int> nSten; // number of stencils in each group
23  std::vector<int> loGroup; // smallest offset from center point in group
24  std::vector<std::vector<int> > loOffset; // smallest offset from center point in each stencil
25 
26  public:
27 
28  // Public data
29  int loAll; // smallest offset from center point in group of stencils
30  int hiAll; // largest offset from center point in group of stencils
31  int nGroup; // number of groups
32 
33  // coefficients for WENO combination
34  double siFirst;
35  double siSecond;
36  double epsW;
37  double pW;
38 
39  // Constructor
41 
42  nGroup = 2;
43  // Group 0 = negative upwinding
44  // Group 1 = positive upwinding
45 
46  loOffset.resize(nGroup);
47 
48  // Smoothness indicator constant coefficients
49  siFirst = 13/12.0;
50  siSecond = 1/4.0;
51 
52  // Non-linear combination coefficients
53  epsW = 1e-6;
54  pW = 2;
55  linWeights.resize(nGroup);
56 
57  // fill vectors with blank stencilsets
58  for (int g=0; g<nGroup; g++) {
59  StencilSet ss;
60  reconstCoeffs.push_back(ss);
61  }
62  for (int g=0; g<nGroup; g++) {
63  StencilSet ss;
64  siCoeffsFirst.push_back(ss);
65  }
66  for (int g=0; g<nGroup; g++) {
67  StencilSet ss;
68  siCoeffsSecond.push_back(ss);
69  }
70 
71  StencilSet temp; // temporary StencilSet for adding values
72  temp.ownData = true;
73 
74  // Reconstruction coefficients -- group 0
75  temp.numStencils = 3;
76  temp.numValues = 9;
77  temp.stencilSizes = new int[temp.numStencils];
78  temp.stencilStarts = new int[temp.numStencils];
79  temp.stencilOffsets = new int[temp.numValues];
80  temp.stencilWeights = new double[temp.numValues];
81 
82  temp.stencilSizes[0] = 3;
83  temp.stencilSizes[1] = 3;
84  temp.stencilSizes[2] = 3;
85 
86  temp.stencilStarts[0] = 0;
87  for (int i=1; i<temp.numStencils; i++)
88  temp.stencilStarts[i] = temp.stencilStarts[i-1] + temp.stencilSizes[i-1];
89 
90  temp.stencilOffsets = new int[temp.numValues];
91  temp.stencilOffsets[0] = 3;
92  temp.stencilOffsets[1] = 2;
93  temp.stencilOffsets[2] = 1;
94  temp.stencilOffsets[3] = 2;
95  temp.stencilOffsets[4] = 1;
96  temp.stencilOffsets[5] = 0;
97  temp.stencilOffsets[6] = 1;
98  temp.stencilOffsets[7] = 0;
99  temp.stencilOffsets[8] = -1;
100 
101  loAll = temp.stencilOffsets[0];
102  hiAll = temp.stencilOffsets[0];
103  loGroup.push_back(temp.stencilOffsets[0]);
104  for (int i=0; i<temp.numValues; i++) {
105  if (loGroup[0] > temp.stencilOffsets[i]) loGroup[0] = temp.stencilOffsets[i];
106  if (loAll > temp.stencilOffsets[i]) loAll = temp.stencilOffsets[i];
107  if (hiAll < temp.stencilOffsets[i]) hiAll = temp.stencilOffsets[i];
108  }
109  for (int s=0; s<temp.numStencils; s++) {
110  loOffset[0].push_back(temp.stencilOffsets[temp.stencilStarts[s]]);
111  for (int i=temp.stencilStarts[s]+1; i<temp.stencilStarts[s]+temp.stencilSizes[s]; i++) {
112  if (loOffset[0][s] > temp.stencilOffsets[i]) loOffset[0][s] = temp.stencilOffsets[i];
113  }
114  }
115 
116  temp.stencilWeights[0] = 1/3.0;
117  temp.stencilWeights[1] = -7/6.0;
118  temp.stencilWeights[2] = 11/6.0;
119  temp.stencilWeights[3] = -1/6.0;
120  temp.stencilWeights[4] = 5/6.0;
121  temp.stencilWeights[5] = 1/3.0;
122  temp.stencilWeights[6] = 1/3.0;
123  temp.stencilWeights[7] = 5/6.0;
124  temp.stencilWeights[8] = -1/6.0;
125 
126  reconstCoeffs[0].Copy(temp);
127  nSten.push_back(temp.numStencils);
128  linWeights[0].push_back(0.1);
129  linWeights[0].push_back(0.6);
130  linWeights[0].push_back(0.3);
131 
132  // Reconstruction coefficients -- group 1
133  // Note that group 1 is symmetric to group 0 about i+1/2, so
134  // sizes/starts/weights do not change
135  temp.stencilOffsets[0] = -2;
136  temp.stencilOffsets[1] = -1;
137  temp.stencilOffsets[2] = 0;
138  temp.stencilOffsets[3] = -1;
139  temp.stencilOffsets[4] = 0;
140  temp.stencilOffsets[5] = 1;
141  temp.stencilOffsets[6] = 0;
142  temp.stencilOffsets[7] = 1;
143  temp.stencilOffsets[8] = 2;
144 
145  loGroup.push_back(temp.stencilOffsets[0]);
146  for (int i=0; i<temp.numValues; i++) {
147  if (loGroup[1] > temp.stencilOffsets[i]) loGroup[1] = temp.stencilOffsets[i];
148  if (loAll > temp.stencilOffsets[i]) loAll = temp.stencilOffsets[i];
149  if (hiAll < temp.stencilOffsets[i]) hiAll = temp.stencilOffsets[i];
150  }
151  for (int s=0; s<temp.numStencils; s++) {
152  loOffset[1].push_back(temp.stencilOffsets[temp.stencilStarts[s]]);
153  for (int i=temp.stencilStarts[s]+1; i<temp.stencilStarts[s]+temp.stencilSizes[s]; i++) {
154  if (loOffset[1][s] > temp.stencilOffsets[i]) loOffset[1][s] = temp.stencilOffsets[i];
155  }
156  }
157 
158  reconstCoeffs[1].Copy(temp);
159  nSten.push_back(temp.numStencils);
160  linWeights[1].push_back(0.1);
161  linWeights[1].push_back(0.6);
162  linWeights[1].push_back(0.3);
163 
164  // First set of smoothness indicator coefficients -- group 0
165  // Same sizes as reconstruction coefficients, but since we just did
166  // group 1, need to enter the offsets again
167  temp.stencilOffsets[0] = 3;
168  temp.stencilOffsets[1] = 2;
169  temp.stencilOffsets[2] = 1;
170  temp.stencilOffsets[3] = 2;
171  temp.stencilOffsets[4] = 1;
172  temp.stencilOffsets[5] = 0;
173  temp.stencilOffsets[6] = 1;
174  temp.stencilOffsets[7] = 0;
175  temp.stencilOffsets[8] = -1;
176 
177  temp.stencilWeights[0] = 1;
178  temp.stencilWeights[1] = -2;
179  temp.stencilWeights[2] = 1;
180  temp.stencilWeights[3] = 1;
181  temp.stencilWeights[4] = -2;
182  temp.stencilWeights[5] = 1;
183  temp.stencilWeights[6] = 1;
184  temp.stencilWeights[7] = -2;
185  temp.stencilWeights[8] = 1;
186 
187  siCoeffsFirst[0].Copy(temp);
188 
189  // First set of smoothness indicator coefficients -- group 1
190  // Note that group 1 is symmetric to group 0 about i+1/2, so
191  // sizes/starts/weights do not change
192  temp.stencilOffsets[0] = -2;
193  temp.stencilOffsets[1] = -1;
194  temp.stencilOffsets[2] = 0;
195  temp.stencilOffsets[3] = -1;
196  temp.stencilOffsets[4] = 0;
197  temp.stencilOffsets[5] = 1;
198  temp.stencilOffsets[6] = 0;
199  temp.stencilOffsets[7] = 1;
200  temp.stencilOffsets[8] = 2;
201 
202  siCoeffsFirst[1].Copy(temp);
203 
204  // Second set of smoothness indicator coefficients -- group 0
205  temp.numStencils = 3;
206  temp.numValues = 8;
207  temp.stencilSizes = new int[temp.numStencils];
208  temp.stencilStarts = new int[temp.numStencils];
209  temp.stencilOffsets = new int[temp.numValues];
210  temp.stencilWeights = new double[temp.numValues];
211 
212  temp.stencilSizes[0] = 3;
213  temp.stencilSizes[1] = 2;
214  temp.stencilSizes[2] = 3;
215 
216  temp.stencilStarts[0] = 0;
217  for (int i=1; i<temp.numStencils; i++)
218  temp.stencilStarts[i] = temp.stencilStarts[i-1] + temp.stencilSizes[i-1];
219 
220  temp.stencilOffsets = new int[temp.numValues];
221  temp.stencilOffsets[0] = 3;
222  temp.stencilOffsets[1] = 2;
223  temp.stencilOffsets[2] = 1;
224  temp.stencilOffsets[3] = 2;
225  temp.stencilOffsets[4] = 0;
226  temp.stencilOffsets[5] = 1;
227  temp.stencilOffsets[6] = 0;
228  temp.stencilOffsets[7] = -1;
229 
230  temp.stencilWeights[0] = 1;
231  temp.stencilWeights[1] = -4;
232  temp.stencilWeights[2] = 3;
233  temp.stencilWeights[3] = 1;
234  temp.stencilWeights[4] = -1;
235  temp.stencilWeights[5] = 3;
236  temp.stencilWeights[6] = -4;
237  temp.stencilWeights[7] = 1;
238 
239  siCoeffsSecond[0].Copy(temp);
240 
241  // Second set of smoothness indicator coefficients -- group 1
242  // Note that group 1 is symmetric to group 0 about i+1/2, so
243  // sizes/starts/weights do not change
244  temp.stencilOffsets[0] = -2;
245  temp.stencilOffsets[1] = -1;
246  temp.stencilOffsets[2] = 0;
247  temp.stencilOffsets[3] = -1;
248  temp.stencilOffsets[4] = 1;
249  temp.stencilOffsets[5] = 0;
250  temp.stencilOffsets[6] = 1;
251  temp.stencilOffsets[7] = 2;
252 
253  siCoeffsSecond[1].Copy(temp);
254  }
255 
256  // Get necessary width of halo region
257  int HaloWidth() {
258  // WENO computes results at face i+1/2 for stencils centered on cell i,
259  // so the +1 below handles the case where WENO needs to compute the
260  // left face of the leftmost cell
261  return std::max(std::abs(loAll)+1, std::abs(hiAll));
262  }
263 
264  int NSten(int group) {
265  return nSten[group];
266  }
267 
268  int LoGroup(int group) {
269  return loGroup[group];
270  }
271 
272  int Lo(int group, int sten) {
273  return loOffset[group][sten];
274  }
275 
276  double LinWeight(int group, int sten) {
277  return linWeights[group][sten];
278  }
279 
280  StencilSet Reconst(int group) {
281  StencilSet res;
282  res.Copy(reconstCoeffs[group]);
283  return res;
284  }
285 
286  StencilSet SmIndFirst(int group) {
287  StencilSet res;
288  res.Copy(siCoeffsFirst[group]);
289  return res;
290  }
291 
292  StencilSet SmIndSecond(int group) {
293  StencilSet res;
294  res.Copy(siCoeffsSecond[group]);
295  return res;
296  }
297  };
298 
299  void ReconstPointVal(double vals[], CoeffsWENO& coeffs, int group, double& pVal);
300  void ReconstPointValSten(double vals[], CoeffsWENO& coeffs, int group, int sten, double& pVal);
301  void SmoothInd(double vals[], CoeffsWENO& coeffs, int group, int sten, double& si);
302  void Project(int n, int m, double T[], double vals[], double res[]);
303  double EntropyFixEta(int n, double lambdaL[], double lambdaR[]);
304 }
305 
306 #endif
std::vector< int > loGroup
Definition: WENO.H:23
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
std::vector< StencilSet > siCoeffsSecond
Definition: WENO.H:19
void ReconstPointVal(double vals[], CoeffsWENO &coeffs, int group, double &pVal)
Definition: WENO.C:11
std::vector< StencilSet > siCoeffsFirst
Definition: WENO.H:18
double EntropyFixEta(int n, double lambdaL[], double lambdaR[])
Definition: WENO.C:113
void Copy(const stencilset &inStencilSet)
Copy a stencil.
Definition: Stencil.H:34
std::vector< StencilSet > reconstCoeffs
Definition: WENO.H:17
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
std::vector< std::vector< int > > loOffset
Definition: WENO.H:24
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
int HaloWidth()
Definition: WENO.H:257
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 numValues
The total number of weights for all stencils (reqd for Fortran)
Definition: Stencil.H:98
std::vector< std::vector< double > > linWeights
Definition: WENO.H:20
plascom2::operators::stencilset StencilSet
Definition: WENO.H:12
int Lo(int group, int sten)
Definition: WENO.H:272
int NSten(int group)
Definition: WENO.H:264
bool ownData
Indicates whether this data structure owns the stencil memory.
Definition: Stencil.H:100
StencilSet Reconst(int group)
Definition: WENO.H:280
double * stencilWeights
The stencil weights.
Definition: Stencil.H:108
int nGroup
Definition: WENO.H:31
int numStencils
The number of stencils (e.g. interior + boundary)
Definition: Stencil.H:93
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
std::vector< int > nSten
Definition: WENO.H:22