12 for(
int iType = 0;iType < (int)
NUMBCTYPE;iType++){
13 const std::string &bcName(
bcNames[iType]);
14 if(inName == bcName)
return(iType);
21 if(inType >= 0 && inType < (
int)
NUMBCTYPE)
22 return(std::string(
bcNames[inType]));
23 return(std::string(
bcNames[(
int)NUMBCTYPE]));
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){
38 int numDim = bufferSizes.size();
39 double spongeAmp = bcParams[0];
40 double spongePower = bcParams[1];
42 int opDir = normalDir;
43 if(opDir < 0) opDir *= -1;
46 size_t spongeStart = 0;
48 size_t spongeSize = 0;
49 size_t sponge_end1 = spongeRegion[
opDir].first;
50 size_t sponge_end2 = spongeRegion[
opDir].second;
53 spongeStart = sponge_end2;
54 spongeEnd = sponge_end1;
55 spongeSize = spongeStart - spongeEnd;
57 spongeStart = sponge_end1;
58 spongeEnd = sponge_end2;
59 spongeSize = spongeEnd - spongeStart;
61 assert(spongeSize > 0);
62 double spongeScale = 1.0/((double)spongeSize);
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;
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;
80 size_t nPlane = bufferSizes[0]*bufferSizes[1];
81 size_t kBufferIndex,jBufferIndex,iBufferIndex;
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);
102 for(
int iEquation = 0;iEquation < numEquations;iEquation++){
103 rhsBuffers[iEquation][bufferIndex] = rhsBuffers[iEquation][bufferIndex] -
104 spongeFac*(stateBuffers[iEquation][bufferIndex] -
105 targetBuffers[iEquation][bufferIndex]);
110 }
else if(numDim == 2){
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;
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;
122 size_t jBufferIndex,iBufferIndex;
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);
140 for(
int iEquation = 0;iEquation < numEquations;iEquation++){
141 rhsBuffers[iEquation][bufferIndex] = rhsBuffers[iEquation][bufferIndex] -
142 spongeFac*(stateBuffers[iEquation][bufferIndex] -
143 targetBuffers[iEquation][bufferIndex]);
147 }
else if(numDim == 1){
149 size_t iPartStart = partitionOpInterval[0].first;
150 size_t iPartEnd = partitionOpInterval[0].second;
152 size_t iBufferStart = opBufferInterval[0].first;
153 size_t iBufferEnd = opBufferInterval[0].second;
157 for(
size_t partIndex = iPartStart,iBufferIndex = iBufferStart;
158 partIndex <= iPartEnd;
159 partIndex++,iBufferIndex++){
161 double spongeDistance = std::abs(
double(partIndex) -
double(spongeStart));
162 double eta = spongeDistance*spongeScale;
163 double spongeFac = spongeAmp*std::pow(eta,spongePower);
166 for(
int iEquation = 0;iEquation < numEquations;iEquation++){
168 rhsBuffers[iEquation][iBufferIndex] = rhsBuffers[iEquation][iBufferIndex] -
169 spongeFac*(stateBuffers[iEquation][iBufferIndex] -
170 targetBuffers[iEquation][iBufferIndex]);
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){
189 int numDim = bufferSizes.size();
190 double spongeAmp = bcParams[0];
191 double spongeWidth = bcParams[1];
192 double spongeScale = 1.0/spongeWidth;
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)
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
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;
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;
226 size_t nPlane = bufferSizes[0]*bufferSizes[1];
227 size_t kBufferIndex,jBufferIndex,iBufferIndex;
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;
249 if(iMask[bufferIndex]&disabledMask)
252 double spongeDistanceX = double(partIndex[0])-spongeCenter[0];
253 double spongeDistanceX2 = spongeDistanceX*spongeDistanceX;
255 double spongeDistance = spongeDistanceX2+
259 double spongeDistance2 = -1.0*spongeDistance*spongeScale;
260 double spongeFac = spongeAmp*std::exp(spongeDistance2);
263 for(
int iEquation = 0;iEquation < numEquations;iEquation++){
264 rhsBuffers[iEquation][bufferIndex] = rhsBuffers[iEquation][bufferIndex] -
265 spongeFac*(stateBuffers[iEquation][bufferIndex] -
266 targetBuffers[iEquation][bufferIndex]);
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)
277 spongeSize[0] = bcFlags[1];
280 spongeSize[1] = bcFlags[3];
282 double spongeCenter[] = {
283 double(spongeRegion[0].first)+(spongeSize[0]-1)/2.0,
284 double(spongeRegion[1].first)+(spongeSize[1]-1)/2.0
287 spongeCenter[0] = bcFlags[0] - 1;
289 spongeCenter[1] = bcFlags[2] - 1;
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;
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;
305 size_t jBufferIndex,iBufferIndex;
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;
320 if(iMask[bufferIndex]&disabledMask)
323 double spongeDistanceX = double(partIndex[0])-spongeCenter[0];
324 double spongeDistanceX2 = spongeDistanceX*spongeDistanceX;
325 double spongeDistance = spongeDistanceX2 +
327 double spongeDistance2 = -1.0*spongeDistance*spongeScale;
328 double spongeFac = spongeAmp*std::exp(spongeDistance2);
329 spongeDistance = std::sqrt(spongeDistance);
331 for(
int iEquation = 0;iEquation < numEquations;iEquation++){
332 rhsBuffers[iEquation][bufferIndex] = rhsBuffers[iEquation][bufferIndex] -
333 spongeFac*(stateBuffers[iEquation][bufferIndex] -
334 targetBuffers[iEquation][bufferIndex]);
339 }
else if(numDim == 1){
341 double spongeSize[] = {
342 (double(spongeRegion[0].second)-double(spongeRegion[0].first)+1),
345 double spongeCenter[] = {
346 (double(spongeRegion[0].first)+(spongeSize[0]-1))/2.0,
349 size_t iPartStart = partitionOpInterval[0].first;
350 size_t iPartEnd = partitionOpInterval[0].second;
352 size_t iBufferStart = opBufferInterval[0].first;
353 size_t iBufferEnd = opBufferInterval[0].second;
357 for(
size_t partIndex = iPartStart,iBufferIndex = iBufferStart;
358 partIndex <= iPartEnd;
359 partIndex++,iBufferIndex++){
362 if(iMask[iBufferIndex]&disabledMask)
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);
372 for(
int iEquation = 0;iEquation < numEquations;iEquation++){
373 rhsBuffers[iEquation][iBufferIndex] = rhsBuffers[iEquation][iBufferIndex] -
374 spongeFac*(stateBuffers[iEquation][iBufferIndex] -
375 targetBuffers[iEquation][iBufferIndex]);
void size_t int size_t int * opDir
static const char * bcNames[]
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
Simple Block Structured Mesh object.
int ResolveBCName(const std::string &inName)
std::string ResolveBCType(int inType)
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