Skip to content

Commit d5df79e

Browse files
authored
Replace Interpolation macros with type-safe functions (#169)
1 parent 0ce0255 commit d5df79e

File tree

6 files changed

+344
-344
lines changed

6 files changed

+344
-344
lines changed

src/Interpolation/extrapolated_prolongation.cpp

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,40 +46,37 @@
4646
*
4747
*/
4848

49-
#define FINE_NODE_EXTRAPOLATED_PROLONGATION() \
50-
do { \
51-
if (i_r & 1) { \
52-
if (i_theta & 1) { \
53-
/* (odd, odd) -> node in center of coarse cell */ \
54-
double value = \
55-
0.5 * (coarse_values[coarse_grid.index(i_r_coarse + 1, i_theta_coarse)] + /* Bottom right */ \
56-
coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse + 1)] /* Top left */ \
57-
); \
58-
fine_result[fine_grid.index(i_r, i_theta)] = value; \
59-
} \
60-
else { \
61-
/* (odd, even) -> between coarse nodes in radial direction */ \
62-
double value = 0.5 * (coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse)] + /* Left */ \
63-
coarse_values[coarse_grid.index(i_r_coarse + 1, i_theta_coarse)] /* Right */ \
64-
); \
65-
fine_result[fine_grid.index(i_r, i_theta)] = value; \
66-
} \
67-
} \
68-
else { \
69-
if (i_theta & 1) { \
70-
/* (even, odd) -> between coarse nodes in angular direction */ \
71-
double value = 0.5 * (coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse)] + /* Bottom */ \
72-
coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse + 1)] /* Top */ \
73-
); \
74-
fine_result[fine_grid.index(i_r, i_theta)] = value; \
75-
} \
76-
else { \
77-
/* (even, even) -> node lies exactly on coarse grid */ \
78-
fine_result[fine_grid.index(i_r, i_theta)] = \
79-
coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse)]; /* Center */ \
80-
} \
81-
} \
82-
} while (0)
49+
inline void fineNodeExtrapolatedProlongation(int i_r, int i_theta, int i_r_coarse, int i_theta_coarse,
50+
const PolarGrid& coarse_grid, const PolarGrid& fine_grid,
51+
Vector<double>& fine_result, ConstVector<double>& coarse_values)
52+
{
53+
if (i_r & 1) {
54+
if (i_theta & 1) { /* (odd, odd) -> node in center of coarse cell */
55+
double value = 0.5 * (coarse_values[coarse_grid.index(i_r_coarse + 1, i_theta_coarse)] + /* Bottom right */
56+
coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse + 1)] /* Top left */
57+
);
58+
fine_result[fine_grid.index(i_r, i_theta)] = value;
59+
}
60+
else { /* (odd, even) -> between coarse nodes in radial direction */
61+
double value = 0.5 * (coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse)] + /* Left */
62+
coarse_values[coarse_grid.index(i_r_coarse + 1, i_theta_coarse)] /* Right */
63+
);
64+
fine_result[fine_grid.index(i_r, i_theta)] = value;
65+
}
66+
}
67+
else {
68+
if (i_theta & 1) { /* (even, odd) -> between coarse nodes in angular direction */
69+
double value = 0.5 * (coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse)] + /* Bottom */
70+
coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse + 1)] /* Top */
71+
);
72+
fine_result[fine_grid.index(i_r, i_theta)] = value;
73+
}
74+
else { /* (even, even) -> node lies exactly on coarse grid */
75+
fine_result[fine_grid.index(i_r, i_theta)] =
76+
coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse)]; /* Center */
77+
}
78+
}
79+
}
8380

8481
void Interpolation::applyExtrapolatedProlongation(const PolarGrid& coarse_grid, const PolarGrid& fine_grid,
8582
Vector<double> fine_result, ConstVector<double> coarse_values) const
@@ -98,7 +95,8 @@ void Interpolation::applyExtrapolatedProlongation(const PolarGrid& coarse_grid,
9895
int i_r_coarse = i_r / 2;
9996
for (int i_theta = 0; i_theta < fine_grid.ntheta(); i_theta++) {
10097
int i_theta_coarse = i_theta / 2;
101-
FINE_NODE_EXTRAPOLATED_PROLONGATION();
98+
fineNodeExtrapolatedProlongation(i_r, i_theta, i_r_coarse, i_theta_coarse, coarse_grid, fine_grid,
99+
fine_result, coarse_values);
102100
}
103101
}
104102

@@ -108,7 +106,8 @@ void Interpolation::applyExtrapolatedProlongation(const PolarGrid& coarse_grid,
108106
int i_theta_coarse = i_theta / 2;
109107
for (int i_r = fine_grid.numberSmootherCircles(); i_r < fine_grid.nr(); i_r++) {
110108
int i_r_coarse = i_r / 2;
111-
FINE_NODE_EXTRAPOLATED_PROLONGATION();
109+
fineNodeExtrapolatedProlongation(i_r, i_theta, i_r_coarse, i_theta_coarse, coarse_grid, fine_grid,
110+
fine_result, coarse_values);
112111
}
113112
}
114113
}

src/Interpolation/extrapolated_restriction.cpp

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,31 @@
2121
* - Radial direction: check domain boundaries
2222
*/
2323

24-
#define COARSE_NODE_EXTRAPOLATED_RESTRICTION() \
25-
do { \
26-
int i_r = i_r_coarse * 2; \
27-
int i_theta = i_theta_coarse * 2; \
28-
\
29-
/* Center + Angular contributions (always present) */ \
30-
double value = fine_values[fine_grid.index(i_r, i_theta)] + \
31-
0.5 * fine_values[fine_grid.index(i_r, i_theta - 1)] + \
32-
0.5 * fine_values[fine_grid.index(i_r, i_theta + 1)]; \
33-
\
34-
/* Left contributions (if not at inner boundary) */ \
35-
if (i_r_coarse > 0) { \
36-
value += 0.5 * fine_values[fine_grid.index(i_r - 1, i_theta)] + \
37-
0.5 * fine_values[fine_grid.index(i_r - 1, i_theta + 1)]; /* Top-Left diagonal */ \
38-
} \
39-
\
40-
/* Right contributions (if not at outer boundary) */ \
41-
if (i_r_coarse < coarse_grid.nr() - 1) { \
42-
value += 0.5 * fine_values[fine_grid.index(i_r + 1, i_theta)] + \
43-
0.5 * fine_values[fine_grid.index(i_r + 1, i_theta - 1)]; /* Bottom-Right diagonal */ \
44-
} \
45-
\
46-
coarse_result[coarse_grid.index(i_r_coarse, i_theta_coarse)] = value; \
47-
} while (0)
24+
inline void coarseNodeExtrapolatedRestriction(int i_r_coarse, int i_theta_coarse, const PolarGrid& fine_grid,
25+
const PolarGrid& coarse_grid, Vector<double>& coarse_result,
26+
ConstVector<double>& fine_values)
27+
{
28+
int i_r = i_r_coarse * 2;
29+
int i_theta = i_theta_coarse * 2;
30+
31+
/* Center + Angular contributions (always present) */
32+
double value = fine_values[fine_grid.index(i_r, i_theta)] + 0.5 * fine_values[fine_grid.index(i_r, i_theta - 1)] +
33+
0.5 * fine_values[fine_grid.index(i_r, i_theta + 1)];
34+
35+
/* Left contributions (if not at inner boundary) */
36+
if (i_r_coarse > 0) {
37+
value += 0.5 * fine_values[fine_grid.index(i_r - 1, i_theta)] +
38+
0.5 * fine_values[fine_grid.index(i_r - 1, i_theta + 1)]; /* Top-Left diagonal */
39+
}
40+
41+
/* Right contributions (if not at outer boundary) */
42+
if (i_r_coarse < coarse_grid.nr() - 1) {
43+
value += 0.5 * fine_values[fine_grid.index(i_r + 1, i_theta)] +
44+
0.5 * fine_values[fine_grid.index(i_r + 1, i_theta - 1)]; /* Bottom-Right diagonal */
45+
}
46+
47+
coarse_result[coarse_grid.index(i_r_coarse, i_theta_coarse)] = value;
48+
}
4849

4950
void Interpolation::applyExtrapolatedRestriction(const PolarGrid& fine_grid, const PolarGrid& coarse_grid,
5051
Vector<double> coarse_result, ConstVector<double> fine_values) const
@@ -61,15 +62,17 @@ void Interpolation::applyExtrapolatedRestriction(const PolarGrid& fine_grid, con
6162
#pragma omp for nowait
6263
for (int i_r_coarse = 0; i_r_coarse < coarse_grid.numberSmootherCircles(); i_r_coarse++) {
6364
for (int i_theta_coarse = 0; i_theta_coarse < coarse_grid.ntheta(); i_theta_coarse++) {
64-
COARSE_NODE_EXTRAPOLATED_RESTRICTION();
65+
coarseNodeExtrapolatedRestriction(i_r_coarse, i_theta_coarse, fine_grid, coarse_grid, coarse_result,
66+
fine_values);
6567
}
6668
}
6769

6870
/* Radial Indexing Section */
6971
#pragma omp for nowait
7072
for (int i_theta_coarse = 0; i_theta_coarse < coarse_grid.ntheta(); i_theta_coarse++) {
7173
for (int i_r_coarse = coarse_grid.numberSmootherCircles(); i_r_coarse < coarse_grid.nr(); i_r_coarse++) {
72-
COARSE_NODE_EXTRAPOLATED_RESTRICTION();
74+
coarseNodeExtrapolatedRestriction(i_r_coarse, i_theta_coarse, fine_grid, coarse_grid, coarse_result,
75+
fine_values);
7376
}
7477
}
7578
}

0 commit comments

Comments
 (0)