From 91445aca2039bb2d850fad1671e14cb43279d6d3 Mon Sep 17 00:00:00 2001 From: julianlitz Date: Fri, 19 Jun 2026 19:26:10 +0200 Subject: [PATCH 01/13] Improve enum class names --- include/Definitions/global_definitions.h | 11 ++------- include/GMGPolar/setup.h | 4 ++-- include/Level/level.inl | 16 ++++++------- src/ConfigParser/config_parser.cpp | 6 ++--- src/GMGPolar/gmgpolar.cpp | 2 +- src/convergence_order.cpp | 2 +- src/strong_scaling.cpp | 6 ++--- src/weak_scaling.cpp | 6 ++--- tests/GMGPolar/convergence_order.cpp | 2 +- tests/GMGPolar/pcg_tests.cpp | 24 +++++++++---------- tests/GMGPolar/solve_tests.cpp | 30 ++++++++++++------------ 11 files changed, 51 insertions(+), 58 deletions(-) diff --git a/include/Definitions/global_definitions.h b/include/Definitions/global_definitions.h index d90ae9a6d..379b32166 100644 --- a/include/Definitions/global_definitions.h +++ b/include/Definitions/global_definitions.h @@ -6,8 +6,8 @@ enum class StencilDistributionMethod { - CPU_TAKE = 0, - CPU_GIVE = 1 + TAKE = 0, + GIVE = 1 }; /* Multigrid Cycle Types */ @@ -34,13 +34,6 @@ enum class ExtrapolationType COMBINED = 3, }; -/* Smoother Colors */ -enum class SmootherColor -{ - Black = 0, - White = 1, -}; - /* -----------*/ /* Test Cases */ /* -----------*/ diff --git a/include/GMGPolar/setup.h b/include/GMGPolar/setup.h index f4e031b9a..be0766c0a 100644 --- a/include/GMGPolar/setup.h +++ b/include/GMGPolar/setup.h @@ -10,7 +10,7 @@ void GMGPolar::setup() auto start_setup_createLevels = std::chrono::high_resolution_clock::now(); - if (stencil_distribution_method_ == StencilDistributionMethod::CPU_TAKE) { + if (stencil_distribution_method_ == StencilDistributionMethod::TAKE) { if (!cache_density_profile_coefficients_ || !cache_domain_geometry_) { throw std::runtime_error("Error: Caching must be enabled for both density profile coefficients and domain " "geometry in 'Take' implementation strategy."); @@ -424,7 +424,7 @@ void GMGPolar::printSettings(const P std::cout << "Across the origin (Interior boundary condition)\n"; } - if (stencil_distribution_method_ == StencilDistributionMethod::CPU_TAKE) { + if (stencil_distribution_method_ == StencilDistributionMethod::TAKE) { std::cout << "A-Take (Stencil Distribution)\n"; } else { diff --git a/include/Level/level.inl b/include/Level/level.inl index 4b2832ac0..451487609 100644 --- a/include/Level/level.inl +++ b/include/Level/level.inl @@ -94,10 +94,10 @@ template ::initializeResidual( const bool DirBC_Interior, const StencilDistributionMethod stencil_distribution_method) { - if (stencil_distribution_method == StencilDistributionMethod::CPU_TAKE) { + if (stencil_distribution_method == StencilDistributionMethod::TAKE) { op_residual_ = std::make_unique>(*grid_, *level_cache_, DirBC_Interior); } - else if (stencil_distribution_method == StencilDistributionMethod::CPU_GIVE) { + else if (stencil_distribution_method == StencilDistributionMethod::GIVE) { op_residual_ = std::make_unique>(*grid_, *level_cache_, DirBC_Interior); } if (!op_residual_) @@ -127,10 +127,10 @@ template ::initializeDirectSolver( const bool DirBC_Interior, const StencilDistributionMethod stencil_distribution_method) { - if (stencil_distribution_method == StencilDistributionMethod::CPU_TAKE) { + if (stencil_distribution_method == StencilDistributionMethod::TAKE) { op_directSolver_ = std::make_unique>(*grid_, *level_cache_, DirBC_Interior); } - else if (stencil_distribution_method == StencilDistributionMethod::CPU_GIVE) { + else if (stencil_distribution_method == StencilDistributionMethod::GIVE) { op_directSolver_ = std::make_unique>(*grid_, *level_cache_, DirBC_Interior); } @@ -152,10 +152,10 @@ template ::initializeSmoothing( const bool DirBC_Interior, const StencilDistributionMethod stencil_distribution_method) { - if (stencil_distribution_method == StencilDistributionMethod::CPU_TAKE) { + if (stencil_distribution_method == StencilDistributionMethod::TAKE) { op_smoother_ = std::make_unique>(*grid_, *level_cache_, DirBC_Interior); } - else if (stencil_distribution_method == StencilDistributionMethod::CPU_GIVE) { + else if (stencil_distribution_method == StencilDistributionMethod::GIVE) { op_smoother_ = std::make_unique>(*grid_, *level_cache_, DirBC_Interior); } if (!op_smoother_) @@ -177,11 +177,11 @@ template ::initializeExtrapolatedSmoothing( const bool DirBC_Interior, const StencilDistributionMethod stencil_distribution_method) { - if (stencil_distribution_method == StencilDistributionMethod::CPU_TAKE) { + if (stencil_distribution_method == StencilDistributionMethod::TAKE) { op_extrapolated_smoother_ = std::make_unique>(*grid_, *level_cache_, DirBC_Interior); } - else if (stencil_distribution_method == StencilDistributionMethod::CPU_GIVE) { + else if (stencil_distribution_method == StencilDistributionMethod::GIVE) { op_extrapolated_smoother_ = std::make_unique>(*grid_, *level_cache_, DirBC_Interior); } diff --git a/src/ConfigParser/config_parser.cpp b/src/ConfigParser/config_parser.cpp index f1cd7f6af..57b14e9b5 100644 --- a/src/ConfigParser/config_parser.cpp +++ b/src/ConfigParser/config_parser.cpp @@ -8,7 +8,7 @@ ConfigParser::ConfigParser() parser_.add("paraview", '\0', "Generate ParaView output (0/1).", OPTIONAL, 0); parser_.add("DirBC_Interior", '\0', "Interior BC type (0=Across-origin, 1=Dirichlet).", OPTIONAL, 0, cmdline::oneof(0, 1)); - parser_.add("stencilDistributionMethod", '\0', "Stencil distribution (0=CPU_Take,1=CPU_Give)", OPTIONAL, 0, + parser_.add("stencilDistributionMethod", '\0', "Stencil distribution (0=TAKE,1=GIVE)", OPTIONAL, 0, cmdline::oneof(0, 1)); parser_.add("cacheDensityProfileCoefficients", '\0', "Cache density coefficients (0/1).", OPTIONAL, 1, cmdline::oneof(0, 1)); @@ -97,8 +97,8 @@ bool ConfigParser::parse(int argc, char* argv[]) paraview_ = parser_.get("paraview") != 0; DirBC_Interior_ = parser_.get("DirBC_Interior") != 0; const int methodValue = parser_.get("stencilDistributionMethod"); - if (methodValue == static_cast(StencilDistributionMethod::CPU_TAKE) || - methodValue == static_cast(StencilDistributionMethod::CPU_GIVE)) { + if (methodValue == static_cast(StencilDistributionMethod::TAKE) || + methodValue == static_cast(StencilDistributionMethod::GIVE)) { stencil_distribution_method_ = static_cast(methodValue); } else { diff --git a/src/GMGPolar/gmgpolar.cpp b/src/GMGPolar/gmgpolar.cpp index d237e7d48..2b3d61458 100644 --- a/src/GMGPolar/gmgpolar.cpp +++ b/src/GMGPolar/gmgpolar.cpp @@ -11,7 +11,7 @@ IGMGPolar::IGMGPolar(const PolarGrid& grid) , paraview_(false) // Numerical method setup , DirBC_Interior_(true) - , stencil_distribution_method_(StencilDistributionMethod::CPU_GIVE) + , stencil_distribution_method_(StencilDistributionMethod::GIVE) , cache_density_profile_coefficients_(true) , cache_domain_geometry_(false) // Multigrid settings diff --git a/src/convergence_order.cpp b/src/convergence_order.cpp index 99cec9e37..e63d68b12 100644 --- a/src/convergence_order.cpp +++ b/src/convergence_order.cpp @@ -16,7 +16,7 @@ int main(int argc, char* argv[]) const int verbose = 0; const bool paraview = false; - const StencilDistributionMethod stencilDistributionMethod = StencilDistributionMethod::CPU_TAKE; + const StencilDistributionMethod stencilDistributionMethod = StencilDistributionMethod::TAKE; const bool cacheDensityProfileCoefficients = true; const bool cacheDomainGeometry = true; diff --git a/src/strong_scaling.cpp b/src/strong_scaling.cpp index fbe390d39..f5ed1f7ef 100644 --- a/src/strong_scaling.cpp +++ b/src/strong_scaling.cpp @@ -56,7 +56,7 @@ void runTest(int divideBy2, std::ostream& outfile) const int verbose = 1; const bool paraview = false; - const StencilDistributionMethod stencilDistributionMethod = StencilDistributionMethod::CPU_GIVE; + const StencilDistributionMethod stencilDistributionMethod = StencilDistributionMethod::GIVE; const bool cacheDensityProfileCoefficients = true; const bool cacheDomainGeometry = false; @@ -121,10 +121,10 @@ void runTest(int divideBy2, std::ostream& outfile) solver.printTimings(); std::string stencil_string = ""; - if (solver.stencilDistributionMethod() == StencilDistributionMethod::CPU_TAKE) { + if (solver.stencilDistributionMethod() == StencilDistributionMethod::TAKE) { stencil_string = "Take"; } - else if (solver.stencilDistributionMethod() == StencilDistributionMethod::CPU_GIVE) { + else if (solver.stencilDistributionMethod() == StencilDistributionMethod::GIVE) { stencil_string = "Give"; } diff --git a/src/weak_scaling.cpp b/src/weak_scaling.cpp index 52279cfeb..9f07e6044 100644 --- a/src/weak_scaling.cpp +++ b/src/weak_scaling.cpp @@ -56,7 +56,7 @@ void runTest(int divideBy2, std::ostream& outfile) const int verbose = 1; const bool paraview = false; - const StencilDistributionMethod stencilDistributionMethod = StencilDistributionMethod::CPU_GIVE; + const StencilDistributionMethod stencilDistributionMethod = StencilDistributionMethod::GIVE; const bool cacheDensityProfileCoefficients = true; const bool cacheDomainGeometry = false; @@ -119,10 +119,10 @@ void runTest(int divideBy2, std::ostream& outfile) solver.solve(boundary_conditions, source_term); std::string stencil_string = ""; - if (solver.stencilDistributionMethod() == StencilDistributionMethod::CPU_TAKE) { + if (solver.stencilDistributionMethod() == StencilDistributionMethod::TAKE) { stencil_string = "Take"; } - else if (solver.stencilDistributionMethod() == StencilDistributionMethod::CPU_GIVE) { + else if (solver.stencilDistributionMethod() == StencilDistributionMethod::GIVE) { stencil_string = "Give"; } diff --git a/tests/GMGPolar/convergence_order.cpp b/tests/GMGPolar/convergence_order.cpp index b9e8c3ea2..c2c6a77f6 100644 --- a/tests/GMGPolar/convergence_order.cpp +++ b/tests/GMGPolar/convergence_order.cpp @@ -173,7 +173,7 @@ get_gmgpolar_error(PolarGrid const& grid, CzarnyGeometry const& domain_geometry, // --- Discretization and method settings --- // gmgpolar.DirBC_Interior(false); // Use across-origin calculation - gmgpolar.stencilDistributionMethod(StencilDistributionMethod::CPU_TAKE); + gmgpolar.stencilDistributionMethod(StencilDistributionMethod::TAKE); gmgpolar.cacheDensityProfileCoefficients(true); gmgpolar.cacheDomainGeometry(true); diff --git a/tests/GMGPolar/pcg_tests.cpp b/tests/GMGPolar/pcg_tests.cpp index 2c3a0ccfa..df7becd50 100644 --- a/tests/GMGPolar/pcg_tests.cpp +++ b/tests/GMGPolar/pcg_tests.cpp @@ -156,7 +156,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -198,7 +198,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -240,7 +240,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -282,7 +282,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -322,7 +322,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -362,7 +362,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -402,7 +402,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -442,7 +442,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -481,7 +481,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -520,7 +520,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -559,7 +559,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -598,7 +598,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation diff --git a/tests/GMGPolar/solve_tests.cpp b/tests/GMGPolar/solve_tests.cpp index 074bb3405..9d1460ba5 100644 --- a/tests/GMGPolar/solve_tests.cpp +++ b/tests/GMGPolar/solve_tests.cpp @@ -138,7 +138,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -174,7 +174,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -210,7 +210,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -246,7 +246,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -280,7 +280,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -314,7 +314,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -348,7 +348,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -382,7 +382,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -415,7 +415,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -448,7 +448,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -481,7 +481,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -514,7 +514,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -547,7 +547,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -580,7 +580,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation @@ -613,7 +613,7 @@ using gmgpolar_test_suite = testing::Types< std::integral_constant, // divideBy2 std::integral_constant, // verbose std::integral_constant, // DirBC_Interior - std::integral_constant, // StencilDistributionMethod + std::integral_constant, // StencilDistributionMethod std::integral_constant, // cacheDensityProfileCoefficient std::integral_constant, // cacheDomainGeometry std::integral_constant, // extrapolation From a7c4c01f7c941dd908a75068ecb098b66d53e5a1 Mon Sep 17 00:00:00 2001 From: Julian Litz <91479202+julianlitz@users.noreply.github.com> Date: Fri, 19 Jun 2026 22:03:13 +0200 Subject: [PATCH 02/13] Prefer auto over LevelCache< > --- include/GMGPolar/solver.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/GMGPolar/solver.h b/include/GMGPolar/solver.h index b7e9bdc28..0d9bbafe1 100644 --- a/include/GMGPolar/solver.h +++ b/include/GMGPolar/solver.h @@ -25,7 +25,7 @@ void GMGPolar::solve(const BoundaryC Level& current_level = levels_[level_depth]; // Inject rhs if there is a next level if (level_depth + 1 < initial_rhs_f_levels) { - Level& next_level = levels_[level_depth + 1]; + auto& next_level = levels_[level_depth + 1]; injection(level_depth, next_level.rhs(), current_level.rhs()); } // Discretize the rhs for the current level @@ -202,7 +202,7 @@ void GMGPolar::fullMultigridApproxim { // Start from the coarsest level int coarsest_depth = number_of_levels_ - 1; - Level& coarsest_level = levels_[coarsest_depth]; + auto& coarsest_level = levels_[coarsest_depth]; // Solve directly on the coarsest level Kokkos::deep_copy(coarsest_level.solution(), coarsest_level.rhs()); @@ -233,7 +233,7 @@ void GMGPolar::solveMultigrid(double double& current_residual_norm, double& current_relative_residual_norm) { - Level& level = levels_[0]; + auto& level = levels_[0]; while (number_of_iterations_ < max_iterations_) { /* ----------------------- */ @@ -308,7 +308,7 @@ void GMGPolar::solvePCG(double& init double& current_residual_norm, double& current_relative_residual_norm) { - Level& level = levels_[0]; + auto& level = levels_[0]; // x = initial guess Kokkos::deep_copy(pcg_solution_, level.solution()); @@ -475,7 +475,7 @@ void GMGPolar::updateResidualNorms( { level.computeResidual(level.residual(), level.rhs(), level.solution()); if (extrapolation_ != ExtrapolationType::NONE) { - Level& next_level = levels_[level.level_depth() + 1]; + auto& next_level = levels_[level.level_depth() + 1]; injection(level.level_depth(), next_level.solution(), level.solution()); next_level.computeResidual(next_level.residual(), next_level.rhs(), next_level.solution()); applyExtrapolation(level.level_depth(), level.residual(), next_level.residual()); @@ -579,8 +579,8 @@ template ::initRhsHierarchy() { for (int level_depth = 0; level_depth < number_of_levels_ - 1; ++level_depth) { - Level& current_level = levels_[level_depth]; - Level& next_level = levels_[level_depth + 1]; + auto& current_level = levels_[level_depth]; + auto& next_level = levels_[level_depth + 1]; restriction(level_depth, next_level.rhs(), current_level.rhs()); } } From 0ecb5f95f7a8a2f55ec15e2da35dd2d8429e9062 Mon Sep 17 00:00:00 2001 From: Julian Litz <91479202+julianlitz@users.noreply.github.com> Date: Fri, 19 Jun 2026 22:04:49 +0200 Subject: [PATCH 03/13] auto --- include/GMGPolar/solver.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/GMGPolar/solver.h b/include/GMGPolar/solver.h index 0d9bbafe1..89644e460 100644 --- a/include/GMGPolar/solver.h +++ b/include/GMGPolar/solver.h @@ -22,7 +22,7 @@ void GMGPolar::solve(const BoundaryC int initial_rhs_f_levels = FMG_ ? number_of_levels_ : (extrapolation_ == ExtrapolationType::NONE ? 1 : 2); // Loop through the levels, injecting and discretizing rhs for (int level_depth = 0; level_depth < initial_rhs_f_levels; ++level_depth) { - Level& current_level = levels_[level_depth]; + auto& current_level = levels_[level_depth]; // Inject rhs if there is a next level if (level_depth + 1 < initial_rhs_f_levels) { auto& next_level = levels_[level_depth + 1]; @@ -210,8 +210,8 @@ void GMGPolar::fullMultigridApproxim // Prolongate the solution from the coarsest level up to the finest, while applying Multigrid Cycles on each level for (int depth = coarsest_depth; depth > 0; --depth) { - Level& coarse_level = levels_[depth]; // Current coarse level - Level& fine_level = levels_[depth - 1]; // Next finer level + auto& coarse_level = levels_[depth]; // Current coarse level + auto& fine_level = levels_[depth - 1]; // Next finer level // The bi-cubic FMG interpolation is of higher order FMGInterpolation(coarse_level.level_depth(), fine_level.solution(), coarse_level.solution()); From ded54b03c65bb6496fa7afe09352717f615ef865 Mon Sep 17 00:00:00 2001 From: Julian Litz <91479202+julianlitz@users.noreply.github.com> Date: Fri, 19 Jun 2026 22:05:46 +0200 Subject: [PATCH 04/13] Update extrapolated_multigrid_F_Cycle.h --- .../MultigridMethods/extrapolated_multigrid_F_Cycle.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/GMGPolar/MultigridMethods/extrapolated_multigrid_F_Cycle.h b/include/GMGPolar/MultigridMethods/extrapolated_multigrid_F_Cycle.h index b36e98a41..adfced8a9 100644 --- a/include/GMGPolar/MultigridMethods/extrapolated_multigrid_F_Cycle.h +++ b/include/GMGPolar/MultigridMethods/extrapolated_multigrid_F_Cycle.h @@ -17,8 +17,8 @@ void GMGPolar::extrapolated_multigri /* ------------------------------ */ /* Extrapolated multigrid F-cycle */ /* ------------------------------ */ - Level& level = levels_[level_depth]; - Level& next_level = levels_[level_depth + 1]; + auto& level = levels_[level_depth]; + auto& next_level = levels_[level_depth + 1]; /* ------------ */ /* Presmoothing */ From e11fd9079f07316a153616ed0ac2d0b38ab6bdbc Mon Sep 17 00:00:00 2001 From: Julian Litz <91479202+julianlitz@users.noreply.github.com> Date: Fri, 19 Jun 2026 22:06:12 +0200 Subject: [PATCH 05/13] Update extrapolated_multigrid_V_Cycle.h --- .../MultigridMethods/extrapolated_multigrid_V_Cycle.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/GMGPolar/MultigridMethods/extrapolated_multigrid_V_Cycle.h b/include/GMGPolar/MultigridMethods/extrapolated_multigrid_V_Cycle.h index 36e6c67eb..a9002b303 100644 --- a/include/GMGPolar/MultigridMethods/extrapolated_multigrid_V_Cycle.h +++ b/include/GMGPolar/MultigridMethods/extrapolated_multigrid_V_Cycle.h @@ -17,8 +17,8 @@ void GMGPolar::extrapolated_multigri /* ------------------------------ */ /* Extrapolated multigrid V-cycle */ /* ------------------------------ */ - Level& level = levels_[level_depth]; - Level& next_level = levels_[level_depth + 1]; + auto& level = levels_[level_depth]; + auto& next_level = levels_[level_depth + 1]; /* ------------ */ /* Presmoothing */ From 0be9e335b283e778f77f533513fa18ece5e98f47 Mon Sep 17 00:00:00 2001 From: Julian Litz <91479202+julianlitz@users.noreply.github.com> Date: Fri, 19 Jun 2026 22:06:31 +0200 Subject: [PATCH 06/13] Update extrapolated_multigrid_W_Cycle.h --- .../MultigridMethods/extrapolated_multigrid_W_Cycle.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/GMGPolar/MultigridMethods/extrapolated_multigrid_W_Cycle.h b/include/GMGPolar/MultigridMethods/extrapolated_multigrid_W_Cycle.h index 0b1577352..43c367c4f 100644 --- a/include/GMGPolar/MultigridMethods/extrapolated_multigrid_W_Cycle.h +++ b/include/GMGPolar/MultigridMethods/extrapolated_multigrid_W_Cycle.h @@ -17,8 +17,8 @@ void GMGPolar::extrapolated_multigri /* ------------------------------ */ /* Extrapolated multigrid W-cycle */ /* ------------------------------ */ - Level& level = levels_[level_depth]; - Level& next_level = levels_[level_depth + 1]; + auto& level = levels_[level_depth]; + auto& next_level = levels_[level_depth + 1]; /* ------------ */ /* Presmoothing */ From 3a7c8bca8b1de67515e6eb86e7be8d84aabfdd9f Mon Sep 17 00:00:00 2001 From: Julian Litz <91479202+julianlitz@users.noreply.github.com> Date: Fri, 19 Jun 2026 22:07:05 +0200 Subject: [PATCH 07/13] Update multigrid_F_Cycle.h --- include/GMGPolar/MultigridMethods/multigrid_F_Cycle.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/GMGPolar/MultigridMethods/multigrid_F_Cycle.h b/include/GMGPolar/MultigridMethods/multigrid_F_Cycle.h index abeede937..aca4b642e 100644 --- a/include/GMGPolar/MultigridMethods/multigrid_F_Cycle.h +++ b/include/GMGPolar/MultigridMethods/multigrid_F_Cycle.h @@ -16,7 +16,7 @@ void GMGPolar::multigrid_F_Cycle(int /* ---------------------------------------------------- */ /* Coarsest level: solve A * x = rhs using DirectSolver */ /* ---------------------------------------------------- */ - Level& coarsest_level = levels_[level_depth]; + auto& coarsest_level = levels_[level_depth]; /* Step 1: Copy rhs in solution */ Kokkos::deep_copy(solution, rhs); @@ -33,8 +33,8 @@ void GMGPolar::multigrid_F_Cycle(int /* ----------------- */ /* Multigrid F-cycle */ /* ----------------- */ - Level& level = levels_[level_depth]; - Level& next_level = levels_[level_depth + 1]; + auto& level = levels_[level_depth]; + auto& next_level = levels_[level_depth + 1]; /* ------------ */ /* Presmoothing */ From 4c6bf2c1180feedb3053d3be8d182f923021e533 Mon Sep 17 00:00:00 2001 From: Julian Litz <91479202+julianlitz@users.noreply.github.com> Date: Fri, 19 Jun 2026 22:07:33 +0200 Subject: [PATCH 08/13] Update multigrid_V_Cycle.h --- include/GMGPolar/MultigridMethods/multigrid_V_Cycle.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/GMGPolar/MultigridMethods/multigrid_V_Cycle.h b/include/GMGPolar/MultigridMethods/multigrid_V_Cycle.h index f8d6e1287..c027f6a82 100644 --- a/include/GMGPolar/MultigridMethods/multigrid_V_Cycle.h +++ b/include/GMGPolar/MultigridMethods/multigrid_V_Cycle.h @@ -16,7 +16,7 @@ void GMGPolar::multigrid_V_Cycle(int /* ---------------------------------------------------- */ /* Coarsest level: solve A * x = rhs using DirectSolver */ /* ---------------------------------------------------- */ - Level& coarsest_level = levels_[level_depth]; + auto& coarsest_level = levels_[level_depth]; /* Step 1: Copy rhs in solution */ Kokkos::deep_copy(solution, rhs); @@ -33,8 +33,8 @@ void GMGPolar::multigrid_V_Cycle(int /* ----------------- */ /* Multigrid V-cycle */ /* ----------------- */ - Level& level = levels_[level_depth]; - Level& next_level = levels_[level_depth + 1]; + auto& level = levels_[level_depth]; + auto& next_level = levels_[level_depth + 1]; /* ------------ */ /* Presmoothing */ From ad5d74b8723f5e23303bd587d9ed03636e758b6e Mon Sep 17 00:00:00 2001 From: Julian Litz <91479202+julianlitz@users.noreply.github.com> Date: Fri, 19 Jun 2026 22:08:00 +0200 Subject: [PATCH 09/13] Update multigrid_W_Cycle.h --- include/GMGPolar/MultigridMethods/multigrid_W_Cycle.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/GMGPolar/MultigridMethods/multigrid_W_Cycle.h b/include/GMGPolar/MultigridMethods/multigrid_W_Cycle.h index cf59b1209..b5a3067e4 100644 --- a/include/GMGPolar/MultigridMethods/multigrid_W_Cycle.h +++ b/include/GMGPolar/MultigridMethods/multigrid_W_Cycle.h @@ -16,7 +16,7 @@ void GMGPolar::multigrid_W_Cycle(int /* ---------------------------------------------------- */ /* Coarsest level: solve A * x = rhs using DirectSolver */ /* ---------------------------------------------------- */ - Level& coarsest_level = levels_[level_depth]; + auto& coarsest_level = levels_[level_depth]; /* Step 1: Copy rhs in solution */ Kokkos::deep_copy(solution, rhs); @@ -33,8 +33,8 @@ void GMGPolar::multigrid_W_Cycle(int /* ----------------- */ /* Multigrid W-cycle */ /* ----------------- */ - Level& level = levels_[level_depth]; - Level& next_level = levels_[level_depth + 1]; + auto& level = levels_[level_depth]; + auto& next_level = levels_[level_depth + 1]; /* ------------ */ /* Presmoothing */ From 41265c4a11e8a5e25ea270a3133ae5c928d2fe47 Mon Sep 17 00:00:00 2001 From: julianlitz Date: Fri, 19 Jun 2026 22:20:18 +0200 Subject: [PATCH 10/13] Introduce LevelType --- .../extrapolated_multigrid_F_Cycle.h | 4 +- .../extrapolated_multigrid_V_Cycle.h | 4 +- .../extrapolated_multigrid_W_Cycle.h | 4 +- .../MultigridMethods/multigrid_F_Cycle.h | 6 +-- .../MultigridMethods/multigrid_V_Cycle.h | 6 +-- .../MultigridMethods/multigrid_W_Cycle.h | 6 +-- include/GMGPolar/gmgpolar.h | 31 ++++++------- include/GMGPolar/setup.h | 10 ++-- include/GMGPolar/solver.h | 46 ++++++++++--------- include/GMGPolar/utils.h | 6 +-- 10 files changed, 60 insertions(+), 63 deletions(-) diff --git a/include/GMGPolar/MultigridMethods/extrapolated_multigrid_F_Cycle.h b/include/GMGPolar/MultigridMethods/extrapolated_multigrid_F_Cycle.h index adfced8a9..f20524608 100644 --- a/include/GMGPolar/MultigridMethods/extrapolated_multigrid_F_Cycle.h +++ b/include/GMGPolar/MultigridMethods/extrapolated_multigrid_F_Cycle.h @@ -17,8 +17,8 @@ void GMGPolar::extrapolated_multigri /* ------------------------------ */ /* Extrapolated multigrid F-cycle */ /* ------------------------------ */ - auto& level = levels_[level_depth]; - auto& next_level = levels_[level_depth + 1]; + LevelType& level = levels_[level_depth]; + LevelType& next_level = levels_[level_depth + 1]; /* ------------ */ /* Presmoothing */ diff --git a/include/GMGPolar/MultigridMethods/extrapolated_multigrid_V_Cycle.h b/include/GMGPolar/MultigridMethods/extrapolated_multigrid_V_Cycle.h index a9002b303..d7d12b165 100644 --- a/include/GMGPolar/MultigridMethods/extrapolated_multigrid_V_Cycle.h +++ b/include/GMGPolar/MultigridMethods/extrapolated_multigrid_V_Cycle.h @@ -17,8 +17,8 @@ void GMGPolar::extrapolated_multigri /* ------------------------------ */ /* Extrapolated multigrid V-cycle */ /* ------------------------------ */ - auto& level = levels_[level_depth]; - auto& next_level = levels_[level_depth + 1]; + LevelType& level = levels_[level_depth]; + LevelType& next_level = levels_[level_depth + 1]; /* ------------ */ /* Presmoothing */ diff --git a/include/GMGPolar/MultigridMethods/extrapolated_multigrid_W_Cycle.h b/include/GMGPolar/MultigridMethods/extrapolated_multigrid_W_Cycle.h index 43c367c4f..9a07efa3b 100644 --- a/include/GMGPolar/MultigridMethods/extrapolated_multigrid_W_Cycle.h +++ b/include/GMGPolar/MultigridMethods/extrapolated_multigrid_W_Cycle.h @@ -17,8 +17,8 @@ void GMGPolar::extrapolated_multigri /* ------------------------------ */ /* Extrapolated multigrid W-cycle */ /* ------------------------------ */ - auto& level = levels_[level_depth]; - auto& next_level = levels_[level_depth + 1]; + LevelType& level = levels_[level_depth]; + LevelType& next_level = levels_[level_depth + 1]; /* ------------ */ /* Presmoothing */ diff --git a/include/GMGPolar/MultigridMethods/multigrid_F_Cycle.h b/include/GMGPolar/MultigridMethods/multigrid_F_Cycle.h index aca4b642e..304a6de9d 100644 --- a/include/GMGPolar/MultigridMethods/multigrid_F_Cycle.h +++ b/include/GMGPolar/MultigridMethods/multigrid_F_Cycle.h @@ -16,7 +16,7 @@ void GMGPolar::multigrid_F_Cycle(int /* ---------------------------------------------------- */ /* Coarsest level: solve A * x = rhs using DirectSolver */ /* ---------------------------------------------------- */ - auto& coarsest_level = levels_[level_depth]; + LevelType& coarsest_level = levels_[level_depth]; /* Step 1: Copy rhs in solution */ Kokkos::deep_copy(solution, rhs); @@ -33,8 +33,8 @@ void GMGPolar::multigrid_F_Cycle(int /* ----------------- */ /* Multigrid F-cycle */ /* ----------------- */ - auto& level = levels_[level_depth]; - auto& next_level = levels_[level_depth + 1]; + LevelType& level = levels_[level_depth]; + LevelType& next_level = levels_[level_depth + 1]; /* ------------ */ /* Presmoothing */ diff --git a/include/GMGPolar/MultigridMethods/multigrid_V_Cycle.h b/include/GMGPolar/MultigridMethods/multigrid_V_Cycle.h index c027f6a82..69c2ccbdf 100644 --- a/include/GMGPolar/MultigridMethods/multigrid_V_Cycle.h +++ b/include/GMGPolar/MultigridMethods/multigrid_V_Cycle.h @@ -16,7 +16,7 @@ void GMGPolar::multigrid_V_Cycle(int /* ---------------------------------------------------- */ /* Coarsest level: solve A * x = rhs using DirectSolver */ /* ---------------------------------------------------- */ - auto& coarsest_level = levels_[level_depth]; + LevelType& coarsest_level = levels_[level_depth]; /* Step 1: Copy rhs in solution */ Kokkos::deep_copy(solution, rhs); @@ -33,8 +33,8 @@ void GMGPolar::multigrid_V_Cycle(int /* ----------------- */ /* Multigrid V-cycle */ /* ----------------- */ - auto& level = levels_[level_depth]; - auto& next_level = levels_[level_depth + 1]; + LevelType& level = levels_[level_depth]; + LevelType& next_level = levels_[level_depth + 1]; /* ------------ */ /* Presmoothing */ diff --git a/include/GMGPolar/MultigridMethods/multigrid_W_Cycle.h b/include/GMGPolar/MultigridMethods/multigrid_W_Cycle.h index b5a3067e4..4dc233cfe 100644 --- a/include/GMGPolar/MultigridMethods/multigrid_W_Cycle.h +++ b/include/GMGPolar/MultigridMethods/multigrid_W_Cycle.h @@ -16,7 +16,7 @@ void GMGPolar::multigrid_W_Cycle(int /* ---------------------------------------------------- */ /* Coarsest level: solve A * x = rhs using DirectSolver */ /* ---------------------------------------------------- */ - auto& coarsest_level = levels_[level_depth]; + LevelType& coarsest_level = levels_[level_depth]; /* Step 1: Copy rhs in solution */ Kokkos::deep_copy(solution, rhs); @@ -33,8 +33,8 @@ void GMGPolar::multigrid_W_Cycle(int /* ----------------- */ /* Multigrid W-cycle */ /* ----------------- */ - auto& level = levels_[level_depth]; - auto& next_level = levels_[level_depth + 1]; + LevelType& level = levels_[level_depth]; + LevelType& next_level = levels_[level_depth + 1]; /* ------------ */ /* Presmoothing */ diff --git a/include/GMGPolar/gmgpolar.h b/include/GMGPolar/gmgpolar.h index dc80f18ec..daed475ac 100644 --- a/include/GMGPolar/gmgpolar.h +++ b/include/GMGPolar/gmgpolar.h @@ -18,6 +18,8 @@ template ; + /* ---------------------------------------------------------------------- */ /* Constructor & Initialization */ /* ---------------------------------------------------------------------- */ @@ -94,7 +96,7 @@ class GMGPolar : public IGMGPolar /* ---------------- */ /* Multigrid levels */ int number_of_levels_; - std::vector> levels_; + std::vector levels_; /* ---------------------- */ /* Interpolation operator */ @@ -145,9 +147,9 @@ class GMGPolar : public IGMGPolar /* --------------- */ /* Setup Functions */ template - void build_rhs_f(const Level& level, Vector rhs_f, - const BoundaryConditions& boundary_conditions, const SourceTerm& source_term); - void discretize_rhs_f(const Level& level, Vector rhs_f); + void build_rhs_f(const LevelType& level, Vector rhs_f, const BoundaryConditions& boundary_conditions, + const SourceTerm& source_term); + void discretize_rhs_f(const LevelType& level, Vector rhs_f); /* --------------- */ /* Solve Functions */ @@ -165,19 +167,13 @@ class GMGPolar : public IGMGPolar void solveMultigrid(double& initial_residual_norm, double& current_residual_norm, double& current_relative_residual_norm); void solvePCG(double& initial_residual_norm, double& current_residual_norm, double& current_relative_residual_norm); - double residualNorm(const ResidualNormType& norm_type, - const Level& level, - ConstVector residual) const; - void evaluateExactError(Level& level, - HostConstVector exact_solution); - void updateResidualNorms(Level& level, int iteration, - double& initial_residual_norm, double& current_residual_norm, - double& current_relative_residual_norm); + double residualNorm(const ResidualNormType& norm_type, const LevelType& level, ConstVector residual) const; + void evaluateExactError(LevelType& level, HostConstVector exact_solution); + void updateResidualNorms(LevelType& level, int iteration, double& initial_residual_norm, + double& current_residual_norm, double& current_relative_residual_norm); void initRhsHierarchy(); - void applyMultigridIterations(Level& level, MultigridCycleType cycle, - int iterations); - void applyExtrapolatedMultigridIterations(Level& level, - MultigridCycleType cycle, int iterations); + void applyMultigridIterations(LevelType& level, MultigridCycleType cycle, int iterations); + void applyExtrapolatedMultigridIterations(LevelType& level, MultigridCycleType cycle, int iterations); /* ----------------- */ /* Print information */ @@ -213,8 +209,7 @@ class GMGPolar : public IGMGPolar void writeToVTK(const std::filesystem::path& file_path, const PolarGrid& grid); private: - void writeToVTK(const std::filesystem::path& file_path, - const Level& level, + void writeToVTK(const std::filesystem::path& file_path, const LevelType& level, HostConstVector grid_function); }; diff --git a/include/GMGPolar/setup.h b/include/GMGPolar/setup.h index be0766c0a..abcdcb144 100644 --- a/include/GMGPolar/setup.h +++ b/include/GMGPolar/setup.h @@ -190,8 +190,8 @@ int GMGPolar::chooseNumberOfLevels(c } template -void GMGPolar::discretize_rhs_f( - const Level& level, Vector rhs_f) +void GMGPolar::discretize_rhs_f(const LevelType& level, + Vector rhs_f) { const PolarGrid& grid = level.grid(); assert(std::ssize(rhs_f) == grid.numberOfNodes()); @@ -331,9 +331,9 @@ void GMGPolar::discretize_rhs_f( template template -void GMGPolar::build_rhs_f( - const Level& level, Vector rhs_f, - const BoundaryConditions& boundary_conditions, const SourceTerm& source_term) +void GMGPolar::build_rhs_f(const LevelType& level, Vector rhs_f, + const BoundaryConditions& boundary_conditions, + const SourceTerm& source_term) { const PolarGrid& grid(level.grid()); assert(std::ssize(rhs_f) == grid.numberOfNodes()); diff --git a/include/GMGPolar/solver.h b/include/GMGPolar/solver.h index 89644e460..63c708541 100644 --- a/include/GMGPolar/solver.h +++ b/include/GMGPolar/solver.h @@ -22,10 +22,10 @@ void GMGPolar::solve(const BoundaryC int initial_rhs_f_levels = FMG_ ? number_of_levels_ : (extrapolation_ == ExtrapolationType::NONE ? 1 : 2); // Loop through the levels, injecting and discretizing rhs for (int level_depth = 0; level_depth < initial_rhs_f_levels; ++level_depth) { - auto& current_level = levels_[level_depth]; + LevelType& current_level = levels_[level_depth]; // Inject rhs if there is a next level if (level_depth + 1 < initial_rhs_f_levels) { - auto& next_level = levels_[level_depth + 1]; + LevelType& next_level = levels_[level_depth + 1]; injection(level_depth, next_level.rhs(), current_level.rhs()); } // Discretize the rhs for the current level @@ -82,7 +82,7 @@ void GMGPolar::solve(const BoundaryC /* --------------------------------------- */ /* Start Solver at finest level (depth 0) */ /* --------------------------------------- */ - Level& level = levels_[0]; + LevelType& level = levels_[0]; number_of_iterations_ = 0; double initial_residual_norm = 1.0; @@ -201,8 +201,8 @@ void GMGPolar::fullMultigridApproxim int FMG_iterations) { // Start from the coarsest level - int coarsest_depth = number_of_levels_ - 1; - auto& coarsest_level = levels_[coarsest_depth]; + int coarsest_depth = number_of_levels_ - 1; + LevelType& coarsest_level = levels_[coarsest_depth]; // Solve directly on the coarsest level Kokkos::deep_copy(coarsest_level.solution(), coarsest_level.rhs()); @@ -210,8 +210,8 @@ void GMGPolar::fullMultigridApproxim // Prolongate the solution from the coarsest level up to the finest, while applying Multigrid Cycles on each level for (int depth = coarsest_depth; depth > 0; --depth) { - auto& coarse_level = levels_[depth]; // Current coarse level - auto& fine_level = levels_[depth - 1]; // Next finer level + LevelType& coarse_level = levels_[depth]; // Current coarse level + LevelType& fine_level = levels_[depth - 1]; // Next finer level // The bi-cubic FMG interpolation is of higher order FMGInterpolation(coarse_level.level_depth(), fine_level.solution(), coarse_level.solution()); @@ -233,7 +233,7 @@ void GMGPolar::solveMultigrid(double double& current_residual_norm, double& current_relative_residual_norm) { - auto& level = levels_[0]; + LevelType& level = levels_[0]; while (number_of_iterations_ < max_iterations_) { /* ----------------------- */ @@ -308,7 +308,7 @@ void GMGPolar::solvePCG(double& init double& current_residual_norm, double& current_relative_residual_norm) { - auto& level = levels_[0]; + LevelType& level = levels_[0]; // x = initial guess Kokkos::deep_copy(pcg_solution_, level.solution()); @@ -338,7 +338,7 @@ void GMGPolar::solvePCG(double& init level.applySystemOperator(level.residual(), pcg_search_direction_); if (extrapolation_ != ExtrapolationType::NONE) { assert(number_of_levels_ > 1); - Level& next_level = levels_[level.level_depth() + 1]; + LevelType& next_level = levels_[level.level_depth() + 1]; injection(0, next_level.solution(), pcg_search_direction_); next_level.applySystemOperator(next_level.residual(), next_level.solution()); applyExtrapolation(0, level.residual(), next_level.residual()); @@ -421,8 +421,9 @@ void GMGPolar::solvePCG(double& init // ============================================================================= template -void GMGPolar::applyMultigridIterations( - Level& level, MultigridCycleType cycle, int iterations) +void GMGPolar::applyMultigridIterations(LevelType& level, + MultigridCycleType cycle, + int iterations) { for (int i = 0; i < iterations; i++) { switch (cycle) { @@ -444,7 +445,7 @@ void GMGPolar::applyMultigridIterati template void GMGPolar::applyExtrapolatedMultigridIterations( - Level& level, MultigridCycleType cycle, int iterations) + LevelType& level, MultigridCycleType cycle, int iterations) { for (int i = 0; i < iterations; i++) { switch (cycle) { @@ -469,13 +470,14 @@ void GMGPolar::applyExtrapolatedMult // ============================================================================= template -void GMGPolar::updateResidualNorms( - Level& level, int iteration, double& initial_residual_norm, - double& current_residual_norm, double& current_relative_residual_norm) +void GMGPolar::updateResidualNorms(LevelType& level, int iteration, + double& initial_residual_norm, + double& current_residual_norm, + double& current_relative_residual_norm) { level.computeResidual(level.residual(), level.rhs(), level.solution()); if (extrapolation_ != ExtrapolationType::NONE) { - auto& next_level = levels_[level.level_depth() + 1]; + LevelType& next_level = levels_[level.level_depth() + 1]; injection(level.level_depth(), next_level.solution(), level.solution()); next_level.computeResidual(next_level.residual(), next_level.rhs(), next_level.solution()); applyExtrapolation(level.level_depth(), level.residual(), next_level.residual()); @@ -504,9 +506,9 @@ void GMGPolar::updateResidualNorms( } template -double GMGPolar::residualNorm( - const ResidualNormType& norm_type, const Level& level, - ConstVector residual) const +double GMGPolar::residualNorm(const ResidualNormType& norm_type, + const LevelType& level, + ConstVector residual) const { switch (norm_type) { case ResidualNormType::EUCLIDEAN: @@ -579,8 +581,8 @@ template ::initRhsHierarchy() { for (int level_depth = 0; level_depth < number_of_levels_ - 1; ++level_depth) { - auto& current_level = levels_[level_depth]; - auto& next_level = levels_[level_depth + 1]; + LevelType& current_level = levels_[level_depth]; + LevelType& next_level = levels_[level_depth + 1]; restriction(level_depth, next_level.rhs(), current_level.rhs()); } } diff --git a/include/GMGPolar/utils.h b/include/GMGPolar/utils.h index df76f2973..1b0b5c60e 100644 --- a/include/GMGPolar/utils.h +++ b/include/GMGPolar/utils.h @@ -256,9 +256,9 @@ void GMGPolar::writeToVTK(const std: } template -void GMGPolar::writeToVTK( - const std::filesystem::path& file_path, const Level& level, - HostConstVector grid_function) +void GMGPolar::writeToVTK(const std::filesystem::path& file_path, + const LevelType& level, + HostConstVector grid_function) { const PolarGrid& grid = level.grid(); From b136bf7f8476d55fec94bcd2d0bf4bf7742ba1e9 Mon Sep 17 00:00:00 2001 From: julianlitz Date: Fri, 19 Jun 2026 22:40:46 +0200 Subject: [PATCH 11/13] Correct Level getters --- include/Level/level.h | 12 ++++-------- include/Level/level.inl | 32 ++++---------------------------- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/include/Level/level.h b/include/Level/level.h index 7b8a8d8a0..7c7616e44 100644 --- a/include/Level/level.h +++ b/include/Level/level.h @@ -82,14 +82,10 @@ class Level const PolarGrid& grid() const; const LevelCacheType& levelCache() const; - Vector rhs(); - ConstVector rhs() const; - Vector solution(); - ConstVector solution() const; - Vector residual(); - ConstVector residual() const; - Vector error_correction(); - ConstVector error_correction() const; + Vector rhs() const; + Vector solution() const; + Vector residual() const; + Vector error_correction() const; // -------------- // // Apply Residual // diff --git a/include/Level/level.inl b/include/Level/level.inl index 451487609..c0a42664a 100644 --- a/include/Level/level.inl +++ b/include/Level/level.inl @@ -41,49 +41,25 @@ Level::levelCache() const } template -Vector Level::rhs() +Vector Level::rhs() const { return rhs_; } template -ConstVector Level::rhs() const -{ - return rhs_; -} - -template -Vector Level::solution() -{ - return solution_; -} - -template -ConstVector Level::solution() const +Vector Level::solution() const { return solution_; } template -Vector Level::residual() +Vector Level::residual() const { return residual_; } template -ConstVector Level::residual() const -{ - return residual_; -} - -template -Vector Level::error_correction() -{ - return error_correction_; -} - -template -ConstVector Level::error_correction() const +Vector Level::error_correction() const { return error_correction_; } From 56ad3be649daba46de971c394223cbfa74d9a946 Mon Sep 17 00:00:00 2001 From: Julian Litz <91479202+julianlitz@users.noreply.github.com> Date: Mon, 22 Jun 2026 18:08:25 +0200 Subject: [PATCH 12/13] Overload vector methods for level class --- include/Level/level.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/Level/level.h b/include/Level/level.h index 7c7616e44..7b8a8d8a0 100644 --- a/include/Level/level.h +++ b/include/Level/level.h @@ -82,10 +82,14 @@ class Level const PolarGrid& grid() const; const LevelCacheType& levelCache() const; - Vector rhs() const; - Vector solution() const; - Vector residual() const; - Vector error_correction() const; + Vector rhs(); + ConstVector rhs() const; + Vector solution(); + ConstVector solution() const; + Vector residual(); + ConstVector residual() const; + Vector error_correction(); + ConstVector error_correction() const; // -------------- // // Apply Residual // From 8560f668c1b74d4d2e4e99a95257f1cdf8463eac Mon Sep 17 00:00:00 2001 From: Julian Litz <91479202+julianlitz@users.noreply.github.com> Date: Mon, 22 Jun 2026 18:10:12 +0200 Subject: [PATCH 13/13] Refactor Level class methods to return ConstVector --- include/Level/level.inl | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/include/Level/level.inl b/include/Level/level.inl index c0a42664a..451487609 100644 --- a/include/Level/level.inl +++ b/include/Level/level.inl @@ -41,25 +41,49 @@ Level::levelCache() const } template -Vector Level::rhs() const +Vector Level::rhs() { return rhs_; } template -Vector Level::solution() const +ConstVector Level::rhs() const +{ + return rhs_; +} + +template +Vector Level::solution() +{ + return solution_; +} + +template +ConstVector Level::solution() const { return solution_; } template -Vector Level::residual() const +Vector Level::residual() { return residual_; } template -Vector Level::error_correction() const +ConstVector Level::residual() const +{ + return residual_; +} + +template +Vector Level::error_correction() +{ + return error_correction_; +} + +template +ConstVector Level::error_correction() const { return error_correction_; }