PlasCom2  1.0
XPACC Multi-physics simluation application
NavierStokesBC.C
Go to the documentation of this file.
1 #include "NavierStokesBC.H"
2 #include <cmath>
3 
4 namespace simulation {
5  namespace domain {
6  namespace boundary {
7  namespace bc {
8  namespace navierstokes {
9 
10  int ResolveBCName(const std::string &inName)
11  {
12  for(int iType = 0;iType < (int)NUMBCTYPE;iType++){
13  const std::string &bcName(bcNames[iType]);
14  if(inName == bcName) return(iType);
15  }
16  return((int)NUMBCTYPE);
17  }
18 
19  std::string ResolveBCType(int inType)
20  {
21  if(inType >= 0 && inType < (int)NUMBCTYPE)
22  return(std::string(bcNames[inType]));
23  return(std::string(bcNames[(int)NUMBCTYPE]));
24 
25  }
26 
27 
28  void LinearSponge(const std::vector<size_t> &bufferSizes,int normalDir,
29  const pcpp::IndexIntervalType &spongeRegion,
30  const pcpp::IndexIntervalType &partitionOpInterval,
31  const pcpp::IndexIntervalType &opBufferInterval,
32  const double *bcParams,const int *bcFlags,
33  const int numEquations,
34  const std::vector<double *> &stateBuffers,
35  const std::vector<double *> &targetBuffers,
36  std::vector<double *> &rhsBuffers){
37 
38  int numDim = bufferSizes.size();
39  double spongeAmp = bcParams[0];
40  double spongePower = bcParams[1];
41 
42  int opDir = normalDir;
43  if(opDir < 0) opDir *= -1;
44  opDir -= 1;
45 
46  size_t spongeStart = 0;
47  size_t spongeEnd = 0;
48  size_t spongeSize = 0;
49  size_t sponge_end1 = spongeRegion[opDir].first;
50  size_t sponge_end2 = spongeRegion[opDir].second;
51 
52  if(normalDir > 0){
53  spongeStart = sponge_end2;
54  spongeEnd = sponge_end1;
55  spongeSize = spongeStart - spongeEnd;
56  } else {
57  spongeStart = sponge_end1;
58  spongeEnd = sponge_end2;
59  spongeSize = spongeEnd - spongeStart;
60  }
61  assert(spongeSize > 0);
62  double spongeScale = 1.0/((double)spongeSize);
63 
64  if(numDim == 3){
65 
66  size_t kPartStart = partitionOpInterval[2].first;
67  size_t kPartEnd = partitionOpInterval[2].second;
68  size_t jPartStart = partitionOpInterval[1].first;
69  size_t jPartEnd = partitionOpInterval[1].second;
70  size_t iPartStart = partitionOpInterval[0].first;
71  size_t iPartEnd = partitionOpInterval[0].second;
72 
73  size_t kBufferStart = opBufferInterval[2].first;
74  size_t kBufferEnd = opBufferInterval[2].second;
75  size_t jBufferStart = opBufferInterval[1].first;
76  size_t jBufferEnd = opBufferInterval[1].second;
77  size_t iBufferStart = opBufferInterval[0].first;
78  size_t iBufferEnd = opBufferInterval[0].second;
79 
80  size_t nPlane = bufferSizes[0]*bufferSizes[1];
81  size_t kBufferIndex,jBufferIndex,iBufferIndex;
82 
83  size_t partIndex[] = {0,0,0};
84  for(partIndex[2] = kPartStart,kBufferIndex = kBufferStart;
85  partIndex[2] <= kPartEnd;
86  partIndex[2]++,kBufferIndex++){
87  size_t zIndex = kBufferIndex*nPlane;
88  for(partIndex[1] = jPartStart,jBufferIndex = jBufferStart;
89  partIndex[1] <= jPartEnd;
90  partIndex[1]++,jBufferIndex++){
91  size_t yzIndex = jBufferIndex*bufferSizes[0] + zIndex;
92  for(partIndex[0] = iPartStart,iBufferIndex = iBufferStart;
93  partIndex[0] <= iPartEnd;
94  partIndex[0]++,iBufferIndex++){
95  size_t bufferIndex = yzIndex + iBufferIndex;
96  double spongeDistance = std::abs(double(partIndex[opDir])
97  - double(spongeStart));
98  double eta = spongeDistance*spongeScale;
99  double spongeFac = spongeAmp*std::pow(eta,spongePower);
100 
101  // rhs = rhs - spongeFac*(state - target)
102  for(int iEquation = 0;iEquation < numEquations;iEquation++){
103  rhsBuffers[iEquation][bufferIndex] = rhsBuffers[iEquation][bufferIndex] -
104  spongeFac*(stateBuffers[iEquation][bufferIndex] -
105  targetBuffers[iEquation][bufferIndex]);
106  }
107  }
108  }
109  }
110  } else if(numDim == 2){
111 
112  size_t jPartStart = partitionOpInterval[1].first;
113  size_t jPartEnd = partitionOpInterval[1].second;
114  size_t iPartStart = partitionOpInterval[0].first;
115  size_t iPartEnd = partitionOpInterval[0].second;
116 
117  size_t jBufferStart = opBufferInterval[1].first;
118  size_t jBufferEnd = opBufferInterval[1].second;
119  size_t iBufferStart = opBufferInterval[0].first;
120  size_t iBufferEnd = opBufferInterval[0].second;
121 
122  size_t jBufferIndex,iBufferIndex;
123 
124  size_t partIndex[] = {0,0};
125  for(partIndex[1] = jPartStart,jBufferIndex = jBufferStart;
126  partIndex[1] <= jPartEnd;
127  partIndex[1]++,jBufferIndex++){
128  size_t yIndex = jBufferIndex*bufferSizes[0];
129  for(partIndex[0] = iPartStart,iBufferIndex = iBufferStart;
130  partIndex[0] <= iPartEnd;
131  partIndex[0]++,iBufferIndex++){
132  size_t bufferIndex = yIndex + iBufferIndex;
133  double spongeDistance = std::abs(double(partIndex[opDir]) -
134  double(spongeStart));
135  double eta = spongeDistance*spongeScale;
136  double spongeFac = spongeAmp*std::pow(eta,spongePower);
137 
138  // rhs = rhs - spongeFac*(state - target)
140  for(int iEquation = 0;iEquation < numEquations;iEquation++){
141  rhsBuffers[iEquation][bufferIndex] = rhsBuffers[iEquation][bufferIndex] -
142  spongeFac*(stateBuffers[iEquation][bufferIndex] -
143  targetBuffers[iEquation][bufferIndex]);
144  }
145  }
146  }
147  } else if(numDim == 1){
148 
149  size_t iPartStart = partitionOpInterval[0].first;
150  size_t iPartEnd = partitionOpInterval[0].second;
151 
152  size_t iBufferStart = opBufferInterval[0].first;
153  size_t iBufferEnd = opBufferInterval[0].second;
154 
155  size_t iBufferIndex;
156 
157  for(size_t partIndex = iPartStart,iBufferIndex = iBufferStart;
158  partIndex <= iPartEnd;
159  partIndex++,iBufferIndex++){
160 
161  double spongeDistance = std::abs(double(partIndex) - double(spongeStart));
162  double eta = spongeDistance*spongeScale;
163  double spongeFac = spongeAmp*std::pow(eta,spongePower);
164 
165  // rhs = rhs - spongeFac*(state - target)
166  for(int iEquation = 0;iEquation < numEquations;iEquation++){
167 
168  rhsBuffers[iEquation][iBufferIndex] = rhsBuffers[iEquation][iBufferIndex] -
169  spongeFac*(stateBuffers[iEquation][iBufferIndex] -
170  targetBuffers[iEquation][iBufferIndex]);
171  }
172  }
173  }
174  return;
175  } // LinearSponge BC
176 
177 
178  void SpongeZone(const std::vector<size_t> &bufferSizes,int normalDir,
179  const pcpp::IndexIntervalType &spongeRegion,
180  const pcpp::IndexIntervalType &partitionOpInterval,
181  const pcpp::IndexIntervalType &opBufferInterval,
182  const double *bcParams,const int *bcFlags,
183  const int *iMask,const int disabledMask,
184  const int numEquations,
185  const std::vector<double *> &stateBuffers,
186  const std::vector<double *> &targetBuffers,
187  std::vector<double *> &rhsBuffers){
188 
189  int numDim = bufferSizes.size();
190  double spongeAmp = bcParams[0];
191  double spongeWidth = bcParams[1];
192  double spongeScale = 1.0/spongeWidth;
193 
194 // std::cout << "SpongeAmp = " << spongeAmp << std::endl
195 // << "SpongeWidth = " << spongeWidth << std::endl;
196 
197 // std::cout << "In sponge zone " << std::endl;
198  if(numDim == 3){
199 
200  double spongeSize[] = {
201  (double(spongeRegion[0].second)-double(spongeRegion[0].first)+1),
202  (double(spongeRegion[1].second)-double(spongeRegion[1].first)+1),
203  (double(spongeRegion[2].second)-double(spongeRegion[2].first)+1)
204  };
205 
206  double spongeCenter[] = {
207  double(spongeRegion[0].first)+(spongeSize[0]-1)/2.0,
208  double(spongeRegion[1].first)+(spongeSize[1]-1)/2.0,
209  double(spongeRegion[2].first)+(spongeSize[2]-1)/2.0
210  };
211 
212  size_t kPartStart = partitionOpInterval[2].first;
213  size_t kPartEnd = partitionOpInterval[2].second;
214  size_t jPartStart = partitionOpInterval[1].first;
215  size_t jPartEnd = partitionOpInterval[1].second;
216  size_t iPartStart = partitionOpInterval[0].first;
217  size_t iPartEnd = partitionOpInterval[0].second;
218 
219  size_t kBufferStart = opBufferInterval[2].first;
220  size_t kBufferEnd = opBufferInterval[2].second;
221  size_t jBufferStart = opBufferInterval[1].first;
222  size_t jBufferEnd = opBufferInterval[1].second;
223  size_t iBufferStart = opBufferInterval[0].first;
224  size_t iBufferEnd = opBufferInterval[0].second;
225 
226  size_t nPlane = bufferSizes[0]*bufferSizes[1];
227  size_t kBufferIndex,jBufferIndex,iBufferIndex;
228 
229  size_t partIndex[] = {0,0,0};
230  for(partIndex[2] = kPartStart,kBufferIndex = kBufferStart;
231  partIndex[2] <= kPartEnd;
232  partIndex[2]++,kBufferIndex++){
233  size_t zIndex = kBufferIndex*nPlane;
234  double spongeDistanceZ = double(partIndex[2])-spongeCenter[2];
235  double spongeDistanceZ2 = spongeDistanceZ*spongeDistanceZ;
236  spongeDistanceZ = std::sqrt(spongeDistanceZ2);
237  for(partIndex[1] = jPartStart,jBufferIndex = jBufferStart;
238  partIndex[1] <= jPartEnd;
239  partIndex[1]++,jBufferIndex++){
240  size_t yzIndex = jBufferIndex*bufferSizes[0] + zIndex;
241  double spongeDistanceY = double(partIndex[1])-spongeCenter[1];
242  double spongeDistanceY2 = spongeDistanceY*spongeDistanceY;
243  spongeDistanceY = std::sqrt(spongeDistanceY2);
244  for(partIndex[0] = iPartStart,iBufferIndex = iBufferStart;
245  partIndex[0] <= iPartEnd;
246  partIndex[0]++,iBufferIndex++){
247  size_t bufferIndex = yzIndex + iBufferIndex;
248 
249  if(iMask[bufferIndex]&disabledMask)
250  continue;
251 
252  double spongeDistanceX = double(partIndex[0])-spongeCenter[0];
253  double spongeDistanceX2 = spongeDistanceX*spongeDistanceX;
254 
255  double spongeDistance = spongeDistanceX2+
256  spongeDistanceY2+
257  spongeDistanceZ2;
258 
259  double spongeDistance2 = -1.0*spongeDistance*spongeScale;
260  double spongeFac = spongeAmp*std::exp(spongeDistance2);
261 
262  // rhs = rhs - spongeFac*(state - target)
263  for(int iEquation = 0;iEquation < numEquations;iEquation++){
264  rhsBuffers[iEquation][bufferIndex] = rhsBuffers[iEquation][bufferIndex] -
265  spongeFac*(stateBuffers[iEquation][bufferIndex] -
266  targetBuffers[iEquation][bufferIndex]);
267  }
268  }
269  }
270  }
271  } else if(numDim == 2){
272  double spongeSize[] = {
273  (double(spongeRegion[0].second)-double(spongeRegion[0].first)+1),
274  (double(spongeRegion[1].second)-double(spongeRegion[1].first)+1)
275  };
276  if(bcFlags[1] > 0){
277  spongeSize[0] = bcFlags[1];
278  }
279  if(bcFlags[3] > 0){
280  spongeSize[1] = bcFlags[3];
281  }
282  double spongeCenter[] = {
283  double(spongeRegion[0].first)+(spongeSize[0]-1)/2.0,
284  double(spongeRegion[1].first)+(spongeSize[1]-1)/2.0
285  };
286  if(bcFlags[0] > 0)
287  spongeCenter[0] = bcFlags[0] - 1;
288  if(bcFlags[2] > 0)
289  spongeCenter[1] = bcFlags[2] - 1;
290 
291 // std::cout << "Sponge: (" << spongeCenter[0] << ","
292 // << spongeCenter[1] << ") (" << spongeSize[0] << ","
293 // << spongeSize[1] << ")" << std::endl;
294 
295  size_t jPartStart = partitionOpInterval[1].first;
296  size_t jPartEnd = partitionOpInterval[1].second;
297  size_t iPartStart = partitionOpInterval[0].first;
298  size_t iPartEnd = partitionOpInterval[0].second;
299 
300  size_t jBufferStart = opBufferInterval[1].first;
301  size_t jBufferEnd = opBufferInterval[1].second;
302  size_t iBufferStart = opBufferInterval[0].first;
303  size_t iBufferEnd = opBufferInterval[0].second;
304 
305  size_t jBufferIndex,iBufferIndex;
306 
307  size_t partIndex[] = {0,0};
308  for(partIndex[1] = jPartStart, jBufferIndex = jBufferStart;
309  partIndex[1] <= jPartEnd;
310  partIndex[1]++,jBufferIndex++){
311  size_t yIndex = jBufferIndex*bufferSizes[0];
312  double spongeDistanceY = double(partIndex[1])-spongeCenter[1];
313  double spongeDistanceY2 = spongeDistanceY*spongeDistanceY;
314  spongeDistanceY = std::sqrt(spongeDistanceY2);
315  for(partIndex[0] = iPartStart,iBufferIndex = iBufferStart;
316  partIndex[0] <= iPartEnd;
317  partIndex[0]++,iBufferIndex++){
318  size_t bufferIndex = yIndex + iBufferIndex;
319 
320  if(iMask[bufferIndex]&disabledMask)
321  continue;
322 
323  double spongeDistanceX = double(partIndex[0])-spongeCenter[0];
324  double spongeDistanceX2 = spongeDistanceX*spongeDistanceX;
325  double spongeDistance = spongeDistanceX2 +
326  spongeDistanceY2;
327  double spongeDistance2 = -1.0*spongeDistance*spongeScale;
328  double spongeFac = spongeAmp*std::exp(spongeDistance2);
329  spongeDistance = std::sqrt(spongeDistance);
330 
331  for(int iEquation = 0;iEquation < numEquations;iEquation++){
332  rhsBuffers[iEquation][bufferIndex] = rhsBuffers[iEquation][bufferIndex] -
333  spongeFac*(stateBuffers[iEquation][bufferIndex] -
334  targetBuffers[iEquation][bufferIndex]);
335 
336  }
337  }
338  }
339  } else if(numDim == 1){
340 
341  double spongeSize[] = {
342  (double(spongeRegion[0].second)-double(spongeRegion[0].first)+1),
343  };
344 
345  double spongeCenter[] = {
346  (double(spongeRegion[0].first)+(spongeSize[0]-1))/2.0,
347  };
348 
349  size_t iPartStart = partitionOpInterval[0].first;
350  size_t iPartEnd = partitionOpInterval[0].second;
351 
352  size_t iBufferStart = opBufferInterval[0].first;
353  size_t iBufferEnd = opBufferInterval[0].second;
354 
355  size_t iBufferIndex;
356 
357  for(size_t partIndex = iPartStart,iBufferIndex = iBufferStart;
358  partIndex <= iPartEnd;
359  partIndex++,iBufferIndex++){
360 
361 
362  if(iMask[iBufferIndex]&disabledMask)
363  continue;
364 
365  double spongeDistanceX = double(partIndex)-spongeCenter[0];
366  double spongeDistanceX2 = spongeDistanceX*spongeDistanceX;
367  double spongeDistance = std::sqrt(spongeDistanceX2);
368  double spongeDistance2 = -1.0*spongeDistance*spongeDistance*spongeScale;
369  double spongeFac = spongeAmp*std::exp(spongeDistance2);
370 
371  // rhs = rhs - spongeFac*(state - target)
372  for(int iEquation = 0;iEquation < numEquations;iEquation++){
373  rhsBuffers[iEquation][iBufferIndex] = rhsBuffers[iEquation][iBufferIndex] -
374  spongeFac*(stateBuffers[iEquation][iBufferIndex] -
375  targetBuffers[iEquation][iBufferIndex]);
376  }
377  }
378  }
379  return;
380  } // SpongeZone BC
381 
382  // Namespaces close
383  }
384  }
385  }
386  }
387 }
void size_t int size_t int * opDir
void SpongeZone(const std::vector< size_t > &bufferSizes, int normalDir, const pcpp::IndexIntervalType &spongeRegion, const pcpp::IndexIntervalType &partitionOpInterval, const pcpp::IndexIntervalType &opBufferInterval, const double *bcParams, const int *bcFlags, const int *iMask, const int disabledMask, const int numEquations, const std::vector< double *> &stateBuffers, const std::vector< double *> &targetBuffers, std::vector< double *> &rhsBuffers)
void LinearSponge(const std::vector< size_t > &bufferSizes, int normalDir, const pcpp::IndexIntervalType &spongeRegion, const pcpp::IndexIntervalType &partitionOpInterval, const pcpp::IndexIntervalType &opBufferInterval, const double *bcParams, const int *bcFlags, const int numEquations, const std::vector< double *> &stateBuffers, const std::vector< double *> &targetBuffers, std::vector< double *> &rhsBuffers)
void const size_t const size_t * bufferSizes
Definition: MetricKernels.H:19
Simple Block Structured Mesh object.
Definition: IndexUtil.H:21
int ResolveBCName(const std::string &inName)
void const size_t const size_t const int const size_t const size_t const size_t const size_t const int const double const double const double * bcParams
Definition: SATKernels.H:10