Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 35 additions & 36 deletions src/Interpolation/extrapolated_prolongation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,37 @@
*
*/

#define FINE_NODE_EXTRAPOLATED_PROLONGATION() \
do { \
if (i_r & 1) { \
if (i_theta & 1) { \
/* (odd, odd) -> node in center of coarse cell */ \
double value = \
0.5 * (coarse_values[coarse_grid.index(i_r_coarse + 1, i_theta_coarse)] + /* Bottom right */ \
coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse + 1)] /* Top left */ \
); \
fine_result[fine_grid.index(i_r, i_theta)] = value; \
} \
else { \
/* (odd, even) -> between coarse nodes in radial direction */ \
double value = 0.5 * (coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse)] + /* Left */ \
coarse_values[coarse_grid.index(i_r_coarse + 1, i_theta_coarse)] /* Right */ \
); \
fine_result[fine_grid.index(i_r, i_theta)] = value; \
} \
} \
else { \
if (i_theta & 1) { \
/* (even, odd) -> between coarse nodes in angular direction */ \
double value = 0.5 * (coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse)] + /* Bottom */ \
coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse + 1)] /* Top */ \
); \
fine_result[fine_grid.index(i_r, i_theta)] = value; \
} \
else { \
/* (even, even) -> node lies exactly on coarse grid */ \
fine_result[fine_grid.index(i_r, i_theta)] = \
coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse)]; /* Center */ \
} \
} \
} while (0)
inline void fineNodeExtrapolatedProlongation(int i_r, int i_theta, int i_r_coarse, int i_theta_coarse,
const PolarGrid& coarse_grid, const PolarGrid& fine_grid,
Vector<double>& fine_result, ConstVector<double>& coarse_values)
{
if (i_r & 1) {
if (i_theta & 1) { /* (odd, odd) -> node in center of coarse cell */
double value = 0.5 * (coarse_values[coarse_grid.index(i_r_coarse + 1, i_theta_coarse)] + /* Bottom right */
coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse + 1)] /* Top left */
);
fine_result[fine_grid.index(i_r, i_theta)] = value;
}
else { /* (odd, even) -> between coarse nodes in radial direction */
double value = 0.5 * (coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse)] + /* Left */
coarse_values[coarse_grid.index(i_r_coarse + 1, i_theta_coarse)] /* Right */
);
fine_result[fine_grid.index(i_r, i_theta)] = value;
}
}
else {
if (i_theta & 1) { /* (even, odd) -> between coarse nodes in angular direction */
double value = 0.5 * (coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse)] + /* Bottom */
coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse + 1)] /* Top */
);
fine_result[fine_grid.index(i_r, i_theta)] = value;
}
else { /* (even, even) -> node lies exactly on coarse grid */
fine_result[fine_grid.index(i_r, i_theta)] =
coarse_values[coarse_grid.index(i_r_coarse, i_theta_coarse)]; /* Center */
}
}
}

void Interpolation::applyExtrapolatedProlongation(const PolarGrid& coarse_grid, const PolarGrid& fine_grid,
Vector<double> fine_result, ConstVector<double> coarse_values) const
Expand All @@ -98,7 +95,8 @@ void Interpolation::applyExtrapolatedProlongation(const PolarGrid& coarse_grid,
int i_r_coarse = i_r / 2;
for (int i_theta = 0; i_theta < fine_grid.ntheta(); i_theta++) {
int i_theta_coarse = i_theta / 2;
FINE_NODE_EXTRAPOLATED_PROLONGATION();
fineNodeExtrapolatedProlongation(i_r, i_theta, i_r_coarse, i_theta_coarse, coarse_grid, fine_grid,
fine_result, coarse_values);
}
}

Expand All @@ -108,7 +106,8 @@ void Interpolation::applyExtrapolatedProlongation(const PolarGrid& coarse_grid,
int i_theta_coarse = i_theta / 2;
for (int i_r = fine_grid.numberSmootherCircles(); i_r < fine_grid.nr(); i_r++) {
int i_r_coarse = i_r / 2;
FINE_NODE_EXTRAPOLATED_PROLONGATION();
fineNodeExtrapolatedProlongation(i_r, i_theta, i_r_coarse, i_theta_coarse, coarse_grid, fine_grid,
fine_result, coarse_values);
}
}
}
Expand Down
55 changes: 29 additions & 26 deletions src/Interpolation/extrapolated_restriction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,31 @@
* - Radial direction: check domain boundaries
*/

#define COARSE_NODE_EXTRAPOLATED_RESTRICTION() \
do { \
int i_r = i_r_coarse * 2; \
int i_theta = i_theta_coarse * 2; \
\
/* Center + Angular contributions (always present) */ \
double value = fine_values[fine_grid.index(i_r, i_theta)] + \
0.5 * fine_values[fine_grid.index(i_r, i_theta - 1)] + \
0.5 * fine_values[fine_grid.index(i_r, i_theta + 1)]; \
\
/* Left contributions (if not at inner boundary) */ \
if (i_r_coarse > 0) { \
value += 0.5 * fine_values[fine_grid.index(i_r - 1, i_theta)] + \
0.5 * fine_values[fine_grid.index(i_r - 1, i_theta + 1)]; /* Top-Left diagonal */ \
} \
\
/* Right contributions (if not at outer boundary) */ \
if (i_r_coarse < coarse_grid.nr() - 1) { \
value += 0.5 * fine_values[fine_grid.index(i_r + 1, i_theta)] + \
0.5 * fine_values[fine_grid.index(i_r + 1, i_theta - 1)]; /* Bottom-Right diagonal */ \
} \
\
coarse_result[coarse_grid.index(i_r_coarse, i_theta_coarse)] = value; \
} while (0)
inline void coarseNodeExtrapolatedRestriction(int i_r_coarse, int i_theta_coarse, const PolarGrid& fine_grid,
const PolarGrid& coarse_grid, Vector<double>& coarse_result,
ConstVector<double>& fine_values)
{
int i_r = i_r_coarse * 2;
int i_theta = i_theta_coarse * 2;

/* Center + Angular contributions (always present) */
double value = fine_values[fine_grid.index(i_r, i_theta)] + 0.5 * fine_values[fine_grid.index(i_r, i_theta - 1)] +
0.5 * fine_values[fine_grid.index(i_r, i_theta + 1)];

/* Left contributions (if not at inner boundary) */
if (i_r_coarse > 0) {
value += 0.5 * fine_values[fine_grid.index(i_r - 1, i_theta)] +
0.5 * fine_values[fine_grid.index(i_r - 1, i_theta + 1)]; /* Top-Left diagonal */
}

/* Right contributions (if not at outer boundary) */
if (i_r_coarse < coarse_grid.nr() - 1) {
value += 0.5 * fine_values[fine_grid.index(i_r + 1, i_theta)] +
0.5 * fine_values[fine_grid.index(i_r + 1, i_theta - 1)]; /* Bottom-Right diagonal */
}

coarse_result[coarse_grid.index(i_r_coarse, i_theta_coarse)] = value;
}

void Interpolation::applyExtrapolatedRestriction(const PolarGrid& fine_grid, const PolarGrid& coarse_grid,
Vector<double> coarse_result, ConstVector<double> fine_values) const
Expand All @@ -61,15 +62,17 @@ void Interpolation::applyExtrapolatedRestriction(const PolarGrid& fine_grid, con
#pragma omp for nowait
for (int i_r_coarse = 0; i_r_coarse < coarse_grid.numberSmootherCircles(); i_r_coarse++) {
for (int i_theta_coarse = 0; i_theta_coarse < coarse_grid.ntheta(); i_theta_coarse++) {
COARSE_NODE_EXTRAPOLATED_RESTRICTION();
coarseNodeExtrapolatedRestriction(i_r_coarse, i_theta_coarse, fine_grid, coarse_grid, coarse_result,
fine_values);
}
}

/* Radial Indexing Section */
#pragma omp for nowait
for (int i_theta_coarse = 0; i_theta_coarse < coarse_grid.ntheta(); i_theta_coarse++) {
for (int i_r_coarse = coarse_grid.numberSmootherCircles(); i_r_coarse < coarse_grid.nr(); i_r_coarse++) {
COARSE_NODE_EXTRAPOLATED_RESTRICTION();
coarseNodeExtrapolatedRestriction(i_r_coarse, i_theta_coarse, fine_grid, coarse_grid, coarse_result,
fine_values);
}
}
}
Expand Down
Loading