-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapplyAscOrtho.inl
More file actions
482 lines (421 loc) · 21.1 KB
/
applyAscOrtho.inl
File metadata and controls
482 lines (421 loc) · 21.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
#pragma once
namespace smoother_give
{
static inline void nodeApplyAscOrthoCircleGive(int i_r, int i_theta, const PolarGrid& grid, bool DirBC_Interior,
SmootherColor smoother_color, ConstVector<double>& x,
ConstVector<double>& rhs, Vector<double>& result, double arr, double att,
double art, double detDF, double coeff_beta)
{
assert(i_r >= 0 && i_r <= grid.numberSmootherCircles());
bool isOddNumberSmootherCircles = (grid.numberSmootherCircles() & 1);
bool isOddRadialIndex = (i_r & 1);
SmootherColor node_color =
(isOddNumberSmootherCircles == isOddRadialIndex) ? SmootherColor::White : SmootherColor::Black;
/* -------------------- */
/* Node in the interior */
/* -------------------- */
if (i_r > 0 && i_r < grid.numberSmootherCircles()) {
double h1 = grid.radialSpacing(i_r - 1);
double h2 = grid.radialSpacing(i_r);
double k1 = grid.angularSpacing(i_theta - 1);
double k2 = grid.angularSpacing(i_theta);
double coeff1 = 0.5 * (k1 + k2) / h1;
double coeff2 = 0.5 * (k1 + k2) / h2;
double coeff3 = 0.5 * (h1 + h2) / k1;
double coeff4 = 0.5 * (h1 + h2) / k2;
int i_theta_M1 = grid.wrapThetaIndex(i_theta - 1);
int i_theta_P1 = grid.wrapThetaIndex(i_theta + 1);
int center = grid.index(i_r, i_theta);
int left = grid.index(i_r - 1, i_theta);
int right = grid.index(i_r + 1, i_theta);
int bottom = grid.index(i_r, i_theta_M1);
int top = grid.index(i_r, i_theta_P1);
/* -------------------- */
/* Inside Section Parts */
if (node_color == smoother_color) {
/* Fill result(i,j) */
result[center] -= (-coeff1 * arr * x[left] /* Left */
- coeff2 * arr * x[right]); /* Right */
/* Fill result(i,j-1) */
result[bottom] -= (-0.25 * art * x[right] /* Top Right */
+ 0.25 * art * x[left]); /* Top Left */
/* Fill result(i,j+1) */
result[top] -= (+0.25 * art * x[right] /* Bottom Right */
- 0.25 * art * x[left]); /* Bottom Left */
}
/* --------------------- */
/* Outside Section Parts */
else if (node_color != smoother_color) {
/* Fill result(i-1,j) */
if (i_r > 1 || !DirBC_Interior) {
result[left] -= (-coeff1 * arr * x[center] /* Right */
- 0.25 * art * x[top] /* Top Right */
+ 0.25 * art * x[bottom]); /* Bottom Right */
}
/* Fill result(i+1,j) */
if (i_r < grid.numberSmootherCircles() - 1) {
result[right] -= (-coeff2 * arr * x[center] /* Left */
+ 0.25 * art * x[top] /* Top Left */
- 0.25 * art * x[bottom]); /* Bottom Left */
}
}
}
/* -------------------- */
/* Node on the boundary */
/* -------------------- */
else if (i_r == 0) {
/* ------------------------------------------------ */
/* Case 1: Dirichlet boundary on the inner boundary */
/* ------------------------------------------------ */
if (DirBC_Interior) {
double h2 = grid.radialSpacing(i_r);
double k1 = grid.angularSpacing(i_theta - 1);
double k2 = grid.angularSpacing(i_theta);
double coeff2 = 0.5 * (k1 + k2) / h2;
int i_theta_M1 = grid.wrapThetaIndex(i_theta - 1);
int i_theta_P1 = grid.wrapThetaIndex(i_theta + 1);
int center = grid.index(i_r, i_theta);
int right = grid.index(i_r + 1, i_theta);
int bottom = grid.index(i_r, i_theta_M1);
int top = grid.index(i_r, i_theta_P1);
/* -------------------- */
/* Inside Section Parts */
if (node_color == smoother_color) {
/* Nothing to be done here */
}
/* --------------------- */
/* Outside Section Parts */
else if (node_color != smoother_color) {
/* Fill result(i+1,j) */
result[right] -= (-coeff2 * arr * x[center] /* Left */
+ 0.25 * art * x[top] /* Top Left */
- 0.25 * art * x[bottom]); /* Bottom Left */
}
}
else {
/* ------------------------------------------------------------- */
/* Case 2: Across origin discretization on the interior boundary */
/* ------------------------------------------------------------- */
// h1 gets replaced with 2 * R0.
// (i_r-1,i_theta) gets replaced with (i_r, i_theta + (grid.ntheta()/2)).
// Some more adjustments from the changing the 9-point stencil to the artifical 7-point stencil.
double h1 = 2.0 * grid.radius(0);
double h2 = grid.radialSpacing(i_r);
double k1 = grid.angularSpacing(i_theta - 1);
double k2 = grid.angularSpacing(i_theta);
double coeff1 = 0.5 * (k1 + k2) / h1;
double coeff2 = 0.5 * (k1 + k2) / h2;
double coeff3 = 0.5 * (h1 + h2) / k1;
double coeff4 = 0.5 * (h1 + h2) / k2;
const int i_theta_M1 = grid.wrapThetaIndex(i_theta - 1);
const int i_theta_P1 = grid.wrapThetaIndex(i_theta + 1);
const int i_theta_Across = grid.wrapThetaIndex(i_theta + grid.ntheta() / 2);
const int left = grid.index(i_r, i_theta_Across);
const int bottom = grid.index(i_r, i_theta_M1);
const int center = grid.index(i_r, i_theta);
const int top = grid.index(i_r, i_theta_P1);
const int right = grid.index(i_r + 1, i_theta);
/* -------------------- */
/* Inside Section Parts */
if (node_color == smoother_color) {
/* Fill result(i,j) */
result[center] -= (
/* - coeff1 * arr * x[left] // Left: Not in Asc_ortho */
-coeff2 * arr * x[right]); /* Right */
/* Fill result(i,j-1) */
result[bottom] -= (-0.25 * art * x[right]); /* Top Right */
/* + 0.25 * art * x[left]; // Top Left: REMOVED DUE TO ARTIFICAL 7 POINT STENCIL */
/* Fill result(i,j+1) */
result[top] -= (+0.25 * art * x[right]); /* Bottom Right */
/* - 0.25 * art * x[left]; // Bottom Left: REMOVED DUE TO ARTIFICAL 7 POINT STENCIL */
}
/* --------------------- */
/* Outside Section Parts */
else if (node_color != smoother_color) {
/* Fill result(i+1,j) */
result[right] -= (-coeff2 * arr * x[center] /* Left */
+ 0.25 * art * x[top] /* Top Left */
- 0.25 * art * x[bottom]); /* Bottom Left */
}
}
}
/* ----------------------------- */
/* Node next to circular section */
/* ----------------------------- */
else if (i_r == grid.numberSmootherCircles()) {
assert(node_color == SmootherColor::White);
if (smoother_color == SmootherColor::Black) {
double h1 = grid.radialSpacing(i_r - 1);
double k1 = grid.angularSpacing(i_theta - 1);
double k2 = grid.angularSpacing(i_theta);
double coeff1 = 0.5 * (k1 + k2) / h1;
int i_theta_M1 = grid.wrapThetaIndex(i_theta - 1);
int i_theta_P1 = grid.wrapThetaIndex(i_theta + 1);
int center = grid.index(i_r, i_theta);
int left = grid.index(i_r - 1, i_theta);
int bottom = grid.index(i_r, i_theta_M1);
int top = grid.index(i_r, i_theta_P1);
/* --------------------- */
/* Outside Section Parts */
/* Fill result(i-1,j) */
result[left] -= (-coeff1 * arr * x[center] /* Right */
- 0.25 * art * x[top] /* Top Right */
+ 0.25 * art * x[bottom]); /* Bottom Right */
}
}
}
static inline void nodeApplyAscOrthoRadialGive(int i_r, int i_theta, const PolarGrid& grid, bool DirBC_Interior,
SmootherColor smoother_color, ConstVector<double>& x,
ConstVector<double>& rhs, Vector<double>& result, double arr, double att,
double art, double detDF, double coeff_beta)
{
assert(i_r >= grid.numberSmootherCircles() - 1 && i_r < grid.nr());
SmootherColor node_color = (i_theta & 1) ? SmootherColor::White : SmootherColor::Black;
/* -------------------- */
/* Node in the interior */
/* -------------------- */
if (i_r > grid.numberSmootherCircles() && i_r < grid.nr() - 2) {
double h1 = grid.radialSpacing(i_r - 1);
double h2 = grid.radialSpacing(i_r);
double k1 = grid.angularSpacing(i_theta - 1);
double k2 = grid.angularSpacing(i_theta);
double coeff1 = 0.5 * (k1 + k2) / h1;
double coeff2 = 0.5 * (k1 + k2) / h2;
double coeff3 = 0.5 * (h1 + h2) / k1;
double coeff4 = 0.5 * (h1 + h2) / k2;
int i_theta_M1 = grid.wrapThetaIndex(i_theta - 1);
int i_theta_P1 = grid.wrapThetaIndex(i_theta + 1);
int center = grid.index(i_r, i_theta);
int left = grid.index(i_r - 1, i_theta);
int right = grid.index(i_r + 1, i_theta);
int bottom = grid.index(i_r, i_theta_M1);
int top = grid.index(i_r, i_theta_P1);
/* -------------------- */
/* Inside Section Parts */
if (node_color == smoother_color) {
/* Fill result(i,j) */
result[center] -= (-coeff3 * att * x[bottom] /* Bottom */
- coeff4 * att * x[top] /* Top */
); /* Fill result(i-1,j) */
result[left] -= (-0.25 * art * x[top] /* Top Right */
+ 0.25 * art * x[bottom]); /* Bottom Right */
/* Fill result(i+1,j) */
result[right] -= (+0.25 * art * x[top] /* Top Left */
- 0.25 * art * x[bottom]); /* Bottom Left */
}
/* --------------------- */
/* Outside Section Parts */
else if (node_color != smoother_color) {
/* Fill result(i,j-1) */
result[bottom] -= (-coeff3 * att * x[center] /* Top */
- 0.25 * art * x[right] /* Top Right */
+ 0.25 * art * x[left]); /* Top Left */
/* Fill result(i,j+1) */
result[top] -= (-coeff4 * att * x[center] /* Bottom */
+ 0.25 * art * x[right] /* Bottom Right */
- 0.25 * art * x[left]); /* Bottom Left */
}
}
/* -------------------------------- */
/* Node left next to radial section */
/* -------------------------------- */
else if (i_r == grid.numberSmootherCircles() - 1) {
double h1 = grid.radialSpacing(i_r - 1);
double h2 = grid.radialSpacing(i_r);
double k1 = grid.angularSpacing(i_theta - 1);
double k2 = grid.angularSpacing(i_theta);
double coeff1 = 0.5 * (k1 + k2) / h1;
double coeff2 = 0.5 * (k1 + k2) / h2;
double coeff3 = 0.5 * (h1 + h2) / k1;
double coeff4 = 0.5 * (h1 + h2) / k2;
int i_theta_M1 = grid.wrapThetaIndex(i_theta - 1);
int i_theta_P1 = grid.wrapThetaIndex(i_theta + 1);
int center = grid.index(i_r, i_theta);
int right = grid.index(i_r + 1, i_theta);
int bottom = grid.index(i_r, i_theta_M1);
int top = grid.index(i_r, i_theta_P1);
/* -------------------- */
/* Inside Section Parts */
if (node_color == smoother_color) {
/* Fill result(i+1,j) */
result[right] -= (-coeff2 * arr * x[center] /* Left */
+ 0.25 * art * x[top] /* Top Left */
- 0.25 * art * x[bottom]); /* Bottom Left */
}
/* --------------------- */
/* Outside Section Parts */
else if (node_color != smoother_color) {
/* Nothing to be done here */
}
}
/* --------------------------- */
/* Node next to circle section */
/* --------------------------- */
else if (i_r == grid.numberSmootherCircles()) {
double h1 = grid.radialSpacing(i_r - 1);
double h2 = grid.radialSpacing(i_r);
double k1 = grid.angularSpacing(i_theta - 1);
double k2 = grid.angularSpacing(i_theta);
double coeff1 = 0.5 * (k1 + k2) / h1;
double coeff2 = 0.5 * (k1 + k2) / h2;
double coeff3 = 0.5 * (h1 + h2) / k1;
double coeff4 = 0.5 * (h1 + h2) / k2;
int i_theta_M1 = grid.wrapThetaIndex(i_theta - 1);
int i_theta_P1 = grid.wrapThetaIndex(i_theta + 1);
int center = grid.index(i_r, i_theta);
int left = grid.index(i_r - 1, i_theta);
int right = grid.index(i_r + 1, i_theta);
int bottom = grid.index(i_r, i_theta_M1);
int top = grid.index(i_r, i_theta_P1);
/* -------------------- */
/* Inside Section Parts */
if (node_color == smoother_color) {
/* Fill result(i,j) */
result[center] -= (-coeff1 * arr * x[left] /* Left */
- coeff3 * att * x[bottom] /* Bottom */
- coeff4 * att * x[top] /* Top */
);
/* Fill result(i+1,j) */
result[right] -= (+0.25 * art * x[top] /* Top Left */
- 0.25 * art * x[bottom]); /* Bottom Left */
}
/* --------------------- */
/* Outside Section Parts */
else if (node_color != smoother_color) {
/* Fill result(i,j-1) */
result[bottom] -= (-coeff3 * att * x[center] /* Top */
- 0.25 * art * x[right] /* Top Right */
+ 0.25 * art * x[left]); /* Top Left */
/* Fill result(i,j+1) */
result[top] -= (-coeff4 * att * x[center] /* Bottom */
+ 0.25 * art * x[right] /* Bottom Right */
- 0.25 * art * x[left]); /* Bottom Left */
}
}
/* ------------------------------- */
/* Node next to dirichlet boundary */
/* ------------------------------- */
else if (i_r == grid.nr() - 2) {
double h1 = grid.radialSpacing(i_r - 1);
double h2 = grid.radialSpacing(i_r);
double k1 = grid.angularSpacing(i_theta - 1);
double k2 = grid.angularSpacing(i_theta);
double coeff1 = 0.5 * (k1 + k2) / h1;
double coeff2 = 0.5 * (k1 + k2) / h2;
double coeff3 = 0.5 * (h1 + h2) / k1;
double coeff4 = 0.5 * (h1 + h2) / k2;
int i_theta_M1 = grid.wrapThetaIndex(i_theta - 1);
int i_theta_P1 = grid.wrapThetaIndex(i_theta + 1);
int center = grid.index(i_r, i_theta);
int left = grid.index(i_r - 1, i_theta);
int right = grid.index(i_r + 1, i_theta);
int bottom = grid.index(i_r, i_theta_M1);
int top = grid.index(i_r, i_theta_P1);
/* -------------------- */
/* Inside Section Parts */
if (node_color == smoother_color) {
/* Fill result(i,j) */
result[center] -= (-coeff3 * att * x[bottom] /* Bottom */
- coeff4 * att * x[top] /* Top */
);
/* Fill result(i-1,j) */
result[left] -= (-0.25 * art * x[top] /* Top Right */
+ 0.25 * art * x[bottom]); /* Bottom Right */
// "Right" is part of the radial Asc smoother matrices,
// but is shifted over to the rhs to make the radial Asc smoother matrices symmetric.
// Note that the circle Asc smoother matrices are symmetric by default.
// Note that rhs[right] contains the correct boundary value of u_D.
result[center] -= -coeff2 * arr * rhs[right]; /* Right: Symmetry shift! */
}
/* --------------------- */
/* Outside Section Parts */
else if (node_color != smoother_color) {
/* Fill result(i,j-1) */
result[bottom] -= (-coeff3 * att * x[center] /* Top */
- 0.25 * art * x[right] /* Top Right */
+ 0.25 * art * x[left]); /* Top Left */
/* Fill result(i,j+1) */
result[top] -= (-coeff4 * att * x[center] /* Bottom */
+ 0.25 * art * x[right] /* Bottom Right */
- 0.25 * art * x[left]); /* Bottom Left */
}
}
/* ------------------------------ */
/* Node on the dirichlet boundary */
/* ------------------------------ */
else if (i_r == grid.nr() - 1) {
double h1 = grid.radialSpacing(i_r - 1);
double k1 = grid.angularSpacing(i_theta - 1);
double k2 = grid.angularSpacing(i_theta);
double coeff1 = 0.5 * (k1 + k2) / h1;
int i_theta_M1 = grid.wrapThetaIndex(i_theta - 1);
int i_theta_P1 = grid.wrapThetaIndex(i_theta + 1);
int center = grid.index(i_r, i_theta);
int left = grid.index(i_r - 1, i_theta);
int bottom = grid.index(i_r, i_theta_M1);
int top = grid.index(i_r, i_theta_P1);
/* -------------------- */
/* Inside Section Parts */
if (node_color == smoother_color) {
/* Fill result(i-1,j) */
result[left] -= (-0.25 * art * x[top] /* Top Right */
+ 0.25 * art * x[bottom] /* Bottom Right */
);
// "Right" is part of the radial Asc smoother matrices,
// but is shifted over to the rhs to make the radial Asc smoother matrices symmetric.
// Note that the circle Asc smoother matrices are symmetric by default.
// Note that rhs[center] contains the correct boundary value of u_D.
result[left] -= (-coeff1 * arr * rhs[center] /* Right */
);
}
/* --------------------- */
/* Outside Section Parts */
else if (node_color != smoother_color) {
/* Nothing to be done here */
}
}
}
} // namespace smoother_give
template <concepts::DomainGeometry DomainGeometry>
void SmootherGive<DomainGeometry>::applyAscOrthoCircleSection(const int i_r, const SmootherColor smoother_color,
ConstVector<double> x, ConstVector<double> rhs,
Vector<double> temp)
{
using smoother_give::nodeApplyAscOrthoCircleGive;
const PolarGrid& grid = Smoother<DomainGeometry>::grid_;
const LevelCache<DomainGeometry>& level_cache = Smoother<DomainGeometry>::level_cache_;
const bool DirBC_Interior = Smoother<DomainGeometry>::DirBC_Interior_;
assert(i_r >= 0 && i_r < grid.numberSmootherCircles() + 1);
const double r = grid.radius(i_r);
for (int i_theta = 0; i_theta < grid.ntheta(); i_theta++) {
const double theta = grid.theta(i_theta);
const int index = grid.index(i_r, i_theta);
double coeff_beta, arr, att, art, detDF;
level_cache.obtainValues(i_r, i_theta, index, r, theta, coeff_beta, arr, att, art, detDF);
// Apply Asc Ortho at the current node
nodeApplyAscOrthoCircleGive(i_r, i_theta, grid, DirBC_Interior, smoother_color, x, rhs, temp, arr, att, art,
detDF, coeff_beta);
}
}
template <concepts::DomainGeometry DomainGeometry>
void SmootherGive<DomainGeometry>::applyAscOrthoRadialSection(const int i_theta, const SmootherColor smoother_color,
ConstVector<double> x, ConstVector<double> rhs,
Vector<double> temp)
{
using smoother_give::nodeApplyAscOrthoRadialGive;
const PolarGrid& grid = Smoother<DomainGeometry>::grid_;
const LevelCache<DomainGeometry>& level_cache = Smoother<DomainGeometry>::level_cache_;
const bool DirBC_Interior = Smoother<DomainGeometry>::DirBC_Interior_;
const double theta = grid.theta(i_theta);
/* We need to obtain left contributions from the circular section for AscOrtho. */
/* !!! i_r = grid.numberSmootherCircles()-1 !!! */
for (int i_r = grid.numberSmootherCircles() - 1; i_r < grid.nr(); i_r++) {
const double r = grid.radius(i_r);
const int index = grid.index(i_r, i_theta);
double coeff_beta, arr, att, art, detDF;
level_cache.obtainValues(i_r, i_theta, index, r, theta, coeff_beta, arr, att, art, detDF);
// Apply Asc Ortho at the current node
nodeApplyAscOrthoRadialGive(i_r, i_theta, grid, DirBC_Interior, smoother_color, x, rhs, temp, arr, att, art,
detDF, coeff_beta);
}
}