Skip to content
Draft
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
12 changes: 6 additions & 6 deletions include/GMGPolar/igmgpolar.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,14 @@ class IGMGPolar

/* ------------------- */
/* Multigrid Functions */
void multigrid_V_Cycle(int level_depth, Vector<double> solution, Vector<double> rhs, Vector<double> residual);
void multigrid_W_Cycle(int level_depth, Vector<double> solution, Vector<double> rhs, Vector<double> residual);
void multigrid_F_Cycle(int level_depth, Vector<double> solution, Vector<double> rhs, Vector<double> residual);
void extrapolated_multigrid_V_Cycle(int level_depth, Vector<double> solution, Vector<double> rhs,
void multigrid_V_Cycle(int level_depth, Vector<double> solution, ConstVector<double> rhs, Vector<double> residual);
void multigrid_W_Cycle(int level_depth, Vector<double> solution, ConstVector<double> rhs, Vector<double> residual);
void multigrid_F_Cycle(int level_depth, Vector<double> solution, ConstVector<double> rhs, Vector<double> residual);
void extrapolated_multigrid_V_Cycle(int level_depth, Vector<double> solution, ConstVector<double> rhs,
Vector<double> residual);
void extrapolated_multigrid_W_Cycle(int level_depth, Vector<double> solution, Vector<double> rhs,
void extrapolated_multigrid_W_Cycle(int level_depth, Vector<double> solution, ConstVector<double> rhs,
Vector<double> residual);
void extrapolated_multigrid_F_Cycle(int level_depth, Vector<double> solution, Vector<double> rhs,
void extrapolated_multigrid_F_Cycle(int level_depth, Vector<double> solution, ConstVector<double> rhs,
Vector<double> residual);

/* ----------------------- */
Expand Down
138 changes: 61 additions & 77 deletions include/GMGPolar/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,22 @@ void GMGPolar<DomainGeometry, DensityProfileCoefficients>::setup()
}

if (!is_uniform_refinement) {
throw std::runtime_error(
"Extrapolation Error: Finest PolarGrid does not originate from a single uniform refinement.");
Comment on lines -45 to -46
Copy link
Collaborator Author

@julianlitz julianlitz Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abort immediately may not be a good idea. Better replace by a warning?

std::cerr << "Warning: Finest PolarGrid does not originate from a single uniform refinement.\n";
}
}

// ---------------------------------------------------------- //
// Building PolarGrid and LevelCache for all multigrid levels //
// ---------------------------------------------------------- //
number_of_levels_ = chooseNumberOfLevels(*finest_grid); /* Implementation below */
number_of_levels_ = chooseNumberOfLevels(*finest_grid);
levels_.clear();
levels_.reserve(number_of_levels_);

int level_depth = 0;
auto finest_levelCache = std::make_unique<LevelCache>(*finest_grid, density_profile_coefficients_, domain_geometry_,
cache_density_profile_coefficients_, cache_domain_geometry_);
levels_.emplace_back(level_depth, std::move(finest_grid), std::move(finest_levelCache), extrapolation_, FMG_);
Comment on lines -57 to -60
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid variable shadowing in later loops.

levels_.emplace_back(0, std::move(finest_grid), std::move(finest_levelCache), extrapolation_, FMG_);

for (level_depth = 1; level_depth < number_of_levels_; level_depth++) {
for (int level_depth = 1; level_depth < number_of_levels_; level_depth++) {
auto current_grid = std::make_unique<PolarGrid>(coarseningGrid(levels_[level_depth - 1].grid()));
auto current_levelCache =
std::make_unique<LevelCache>(*current_grid, density_profile_coefficients_, domain_geometry_,
Expand All @@ -81,84 +79,70 @@ void GMGPolar<DomainGeometry, DensityProfileCoefficients>::setup()
if (verbose_ > 0)
printSettings();

// -------------------------------------------------------
// Initializing various operators based on the level index
// ------------------------------------------------ //
// Define residual operator on all multigrid levels //
// ------------------------------------------------ //
for (int level_depth = 0; level_depth < number_of_levels_; level_depth++) {
// ---------------------- //
// Level 0 (finest Level) //
// ---------------------- //
if (level_depth == 0) {
auto start_setup_smoother = std::chrono::high_resolution_clock::now();
switch (extrapolation_) {
case ExtrapolationType::NONE:
full_grid_smoothing_ = true;
levels_[level_depth].initializeSmoothing(domain_geometry_, density_profile_coefficients_,
DirBC_Interior_, max_omp_threads_,
stencil_distribution_method_);
break;
case ExtrapolationType::IMPLICIT_EXTRAPOLATION:
full_grid_smoothing_ = false;
levels_[level_depth].initializeExtrapolatedSmoothing(domain_geometry_, density_profile_coefficients_,
DirBC_Interior_, max_omp_threads_,
stencil_distribution_method_);
break;
case ExtrapolationType::IMPLICIT_FULL_GRID_SMOOTHING:
full_grid_smoothing_ = true;
levels_[level_depth].initializeSmoothing(domain_geometry_, density_profile_coefficients_,
DirBC_Interior_, max_omp_threads_,
stencil_distribution_method_);
break;
case ExtrapolationType::COMBINED:
full_grid_smoothing_ = true;
levels_[level_depth].initializeSmoothing(domain_geometry_, density_profile_coefficients_,
DirBC_Interior_, max_omp_threads_,
stencil_distribution_method_);
levels_[level_depth].initializeExtrapolatedSmoothing(domain_geometry_, density_profile_coefficients_,
DirBC_Interior_, max_omp_threads_,
stencil_distribution_method_);
break;
default:
full_grid_smoothing_ = false;
levels_[level_depth].initializeSmoothing(domain_geometry_, density_profile_coefficients_,
DirBC_Interior_, max_omp_threads_,
stencil_distribution_method_);
levels_[level_depth].initializeExtrapolatedSmoothing(domain_geometry_, density_profile_coefficients_,
DirBC_Interior_, max_omp_threads_,
stencil_distribution_method_);
break;
}
auto end_setup_smoother = std::chrono::high_resolution_clock::now();
t_setup_smoother_ += std::chrono::duration<double>(end_setup_smoother - start_setup_smoother).count();
levels_[level_depth].initializeResidual(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
max_omp_threads_, stencil_distribution_method_);
levels_[level_depth].initializeResidual(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
max_omp_threads_, stencil_distribution_method_);
}
Comment on lines +82 to +88
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract Residual initialization


// ----------------------------------------- //
// Build direct solver on the coarsest level //
// ----------------------------------------- //
auto start_setup_directSolver = std::chrono::high_resolution_clock::now();
levels_[number_of_levels_ - 1].initializeDirectSolver(domain_geometry_, density_profile_coefficients_,
DirBC_Interior_, max_omp_threads_,
stencil_distribution_method_);
auto end_setup_directSolver = std::chrono::high_resolution_clock::now();
t_setup_directSolver_ += std::chrono::duration<double>(end_setup_directSolver - start_setup_directSolver).count();
Comment on lines +90 to +98
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract DirectSolver initialization


// ---------------------------------------------------------- //
// Build the full-grid smoother and the extrapolated smoother //
// ---------------------------------------------------------- //
auto start_setup_smoother = std::chrono::high_resolution_clock::now();

bool do_full_grid_smoothing = false;
bool do_extrapolated_smoothing = false;

switch (extrapolation_) {

case ExtrapolationType::NONE:
do_full_grid_smoothing = true;
break;

case ExtrapolationType::IMPLICIT_EXTRAPOLATION:
do_extrapolated_smoothing = true;
break;

case ExtrapolationType::IMPLICIT_FULL_GRID_SMOOTHING:
do_full_grid_smoothing = true;
break;

case ExtrapolationType::COMBINED:
do_full_grid_smoothing = true;
do_extrapolated_smoothing = true;
break;
}

full_grid_smoothing_ = do_full_grid_smoothing;

if (number_of_levels_ > 1) {
if (do_full_grid_smoothing) {
levels_[0].initializeSmoothing(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
max_omp_threads_, stencil_distribution_method_);
}
// -------------------------- //
// Level n-1 (coarsest Level) //
// -------------------------- //
else if (level_depth == number_of_levels_ - 1) {
auto start_setup_directSolver = std::chrono::high_resolution_clock::now();
levels_[level_depth].initializeDirectSolver(domain_geometry_, density_profile_coefficients_,
DirBC_Interior_, max_omp_threads_,
stencil_distribution_method_);
auto end_setup_directSolver = std::chrono::high_resolution_clock::now();
t_setup_directSolver_ +=
std::chrono::duration<double>(end_setup_directSolver - start_setup_directSolver).count();
levels_[level_depth].initializeResidual(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
max_omp_threads_, stencil_distribution_method_);
if (do_extrapolated_smoothing) {
levels_[0].initializeExtrapolatedSmoothing(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
max_omp_threads_, stencil_distribution_method_);
}
// ------------------- //
// Intermediate levels //
// ------------------- //
else {
auto start_setup_smoother = std::chrono::high_resolution_clock::now();
for (int level_depth = 1; level_depth < number_of_levels_ - 1; level_depth++) {
levels_[level_depth].initializeSmoothing(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
max_omp_threads_, stencil_distribution_method_);
auto end_setup_smoother = std::chrono::high_resolution_clock::now();
t_setup_smoother_ += std::chrono::duration<double>(end_setup_smoother - start_setup_smoother).count();
levels_[level_depth].initializeResidual(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
max_omp_threads_, stencil_distribution_method_);
}
}
Comment on lines +100 to 143
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract Smoother initialization. Simpler to read.

auto end_setup_smoother = std::chrono::high_resolution_clock::now();
t_setup_smoother_ += std::chrono::duration<double>(end_setup_smoother - start_setup_smoother).count();

auto end_setup = std::chrono::high_resolution_clock::now();
t_setup_total_ = std::chrono::duration<double>(end_setup - start_setup).count();
Expand Down
12 changes: 9 additions & 3 deletions src/GMGPolar/MultigridMethods/extrapolated_multigrid_F_Cycle.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../../../include/GMGPolar/gmgpolar.h"

void IGMGPolar::extrapolated_multigrid_F_Cycle(int level_depth, Vector<double> solution, Vector<double> rhs,
void IGMGPolar::extrapolated_multigrid_F_Cycle(int level_depth, Vector<double> solution, ConstVector<double> rhs,
Vector<double> residual)
{
assert(0 <= level_depth && level_depth < number_of_levels_ - 1);
Expand Down Expand Up @@ -93,8 +93,14 @@ void IGMGPolar::extrapolated_multigrid_F_Cycle(int level_depth, Vector<double> s
assign(next_level.residual(), 0.0);

/* Step 3: Solve for the error by recursively calling the multigrid cycle. */
multigrid_F_Cycle(level_depth + 1, next_level.residual(), next_level.error_correction(), next_level.solution());
multigrid_V_Cycle(level_depth + 1, next_level.residual(), next_level.error_correction(), next_level.solution());
multigrid_F_Cycle(level_depth + 1,
next_level.residual(), // error (solution)
next_level.error_correction(), // coarse residual (rhs)
next_level.solution()); // workspace
multigrid_V_Cycle(level_depth + 1,
next_level.residual(), // error (solution)
next_level.error_correction(), // coarse residual (rhs)
next_level.solution()); // workspace
}

/* Interpolate the correction */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../../../include/GMGPolar/gmgpolar.h"

void IGMGPolar::extrapolated_multigrid_V_Cycle(int level_depth, Vector<double> solution, Vector<double> rhs,
void IGMGPolar::extrapolated_multigrid_V_Cycle(int level_depth, Vector<double> solution, ConstVector<double> rhs,
Vector<double> residual)
{
assert(0 <= level_depth && level_depth < number_of_levels_ - 1);
Expand Down Expand Up @@ -93,7 +93,10 @@ void IGMGPolar::extrapolated_multigrid_V_Cycle(int level_depth, Vector<double> s
assign(next_level.residual(), 0.0);

/* Step 3: Solve for the error by recursively calling the multigrid cycle. */
multigrid_V_Cycle(level_depth + 1, next_level.residual(), next_level.error_correction(), next_level.solution());
multigrid_V_Cycle(level_depth + 1,
next_level.residual(), // error (solution)
next_level.error_correction(), // coarse residual (rhs)
next_level.solution()); // workspace
}

/* Interpolate the correction */
Expand Down
12 changes: 9 additions & 3 deletions src/GMGPolar/MultigridMethods/extrapolated_multigrid_W_Cycle.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../../../include/GMGPolar/gmgpolar.h"

void IGMGPolar::extrapolated_multigrid_W_Cycle(int level_depth, Vector<double> solution, Vector<double> rhs,
void IGMGPolar::extrapolated_multigrid_W_Cycle(int level_depth, Vector<double> solution, ConstVector<double> rhs,
Vector<double> residual)
{
assert(0 <= level_depth && level_depth < number_of_levels_ - 1);
Expand Down Expand Up @@ -93,8 +93,14 @@ void IGMGPolar::extrapolated_multigrid_W_Cycle(int level_depth, Vector<double> s
assign(next_level.residual(), 0.0);

/* Step 3: Solve for the error by recursively calling the multigrid cycle. */
multigrid_W_Cycle(level_depth + 1, next_level.residual(), next_level.error_correction(), next_level.solution());
multigrid_W_Cycle(level_depth + 1, next_level.residual(), next_level.error_correction(), next_level.solution());
multigrid_W_Cycle(level_depth + 1,
next_level.residual(), // error (solution)
next_level.error_correction(), // coarse residual (rhs)
next_level.solution()); // workspace
multigrid_W_Cycle(level_depth + 1,
next_level.residual(), // error (solution)
next_level.error_correction(), // coarse residual (rhs)
next_level.solution()); // workspace
}

/* Interpolate the correction */
Expand Down
Loading