From acc072f5ef624c90a7528bc5d93f7051e72b5399 Mon Sep 17 00:00:00 2001 From: julianlitz Date: Mon, 27 Jul 2026 22:01:50 +0200 Subject: [PATCH 1/2] Extrapolation fallback --- include/GMGPolar/gmgpolar.h | 2 +- include/GMGPolar/setup.h | 52 +++++++++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/include/GMGPolar/gmgpolar.h b/include/GMGPolar/gmgpolar.h index daed475a..3e481f2c 100644 --- a/include/GMGPolar/gmgpolar.h +++ b/include/GMGPolar/gmgpolar.h @@ -159,7 +159,7 @@ class GMGPolar : public IGMGPolar /* --------------- */ /* Setup Functions */ int chooseNumberOfLevels(const PolarGrid& finest_grid); - bool checkUniformRefinement(const PolarGrid& grid, double tolerance) const; + bool checkUniformRefinement(const PolarGrid& grid, double tolerance, bool print = true) const; /* --------------- */ /* Solve Functions */ diff --git a/include/GMGPolar/setup.h b/include/GMGPolar/setup.h index abcdcb14..2b8180c9 100644 --- a/include/GMGPolar/setup.h +++ b/include/GMGPolar/setup.h @@ -26,10 +26,32 @@ void GMGPolar::setup() writeToVTK("output_finest_grid", grid_); if (extrapolation_ != ExtrapolationType::NONE) { - const double precision = 1e-12; - if (!checkUniformRefinement(grid_, precision)) { - std::cerr << "[Extrapolation Warning] Finest PolarGrid is not from a single uniform " - "refinement.\n"; + // Three-tier tolerance strategy: + // - strict_tol: within this -> do nothing + // - warn_tol: within this but not strict -> warn (if verbose_>0) + // - otherwise: disable extrapolation and warn (always) + const double strict_tol = 1e-12; + const double warn_tol = 1e-05; + + // Reuse existing checkUniformRefinement with a "print" flag: do quiet checks first + if (checkUniformRefinement(grid_, strict_tol, false)) { + // within strict tolerance: nothing to do + } + else if (checkUniformRefinement(grid_, warn_tol, false)) { + // within warning tolerance: print advisory message for users that enabled verbosity + if (verbose_ > 0) { + std::cerr << "[Extrapolation Warning] Finest PolarGrid deviates from uniform refinement (\"warning\" " + "threshold: " + << warn_tol << "). Extrapolation may be slightly inaccurate.\n"; + } + } + else { + // worse than warning tolerance: call checkUniformRefinement once more with printing enabled to show details, + // then disable extrapolation and notify (important change -> always print) + checkUniformRefinement(grid_, warn_tol, true); + std::cerr << "[Extrapolation Warning] Finest PolarGrid is not from a single uniform refinement; disabling " + "extrapolation.\n"; + extrapolation_ = ExtrapolationType::NONE; } } @@ -588,7 +610,7 @@ void GMGPolar::printSettings(const P template bool GMGPolar::checkUniformRefinement(const PolarGrid& grid, - double tolerance) const + double tolerance, bool print) const { HostConstVector h_radius = grid.host_radii(); HostConstVector h_theta = grid.host_theta(); @@ -601,10 +623,12 @@ bool GMGPolar::checkUniformRefinemen double diff = std::abs(expected_mid - actual_mid); if (diff > tolerance) { - std::cerr << "[Extrapolation Warning] Radial mismatch at i_r = " << i_r << "\n" - << " left = " << left << ", right = " << right << "\n" - << " expected = " << expected_mid << ", actual = " << actual_mid << "\n" - << " diff = " << diff << " (tol = " << tolerance << ")\n"; + if (print) { + std::cerr << "[Extrapolation Warning] Radial mismatch at i_r = " << i_r << "\n" + << " left = " << left << ", right = " << right << "\n" + << " expected = " << expected_mid << ", actual = " << actual_mid << "\n" + << " diff = " << diff << " (tol = " << tolerance << ")\n"; + } return false; } } @@ -618,10 +642,12 @@ bool GMGPolar::checkUniformRefinemen double diff = std::abs(expected_mid - actual_mid); if (diff > tolerance) { - std::cerr << "[Extrapolation Warning] Angular mismatch at i_theta = " << i_theta << "\n" - << " left = " << left << ", right = " << right << "\n" - << " expected = " << expected_mid << ", actual = " << actual_mid << "\n" - << " diff = " << diff << " (tol = " << tolerance << ")\n"; + if (print) { + std::cerr << "[Extrapolation Warning] Angular mismatch at i_theta = " << i_theta << "\n" + << " left = " << left << ", right = " << right << "\n" + << " expected = " << expected_mid << ", actual = " << actual_mid << "\n" + << " diff = " << diff << " (tol = " << tolerance << ")\n"; + } return false; } } From 3d957510f9347cb91c7bc8c8a0066a1121e777d7 Mon Sep 17 00:00:00 2001 From: julianlitz Date: Mon, 27 Jul 2026 22:17:46 +0200 Subject: [PATCH 2/2] Reduce output if no verbose --- include/GMGPolar/gmgpolar.h | 2 +- include/GMGPolar/setup.h | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/GMGPolar/gmgpolar.h b/include/GMGPolar/gmgpolar.h index 3e481f2c..6bb7f306 100644 --- a/include/GMGPolar/gmgpolar.h +++ b/include/GMGPolar/gmgpolar.h @@ -159,7 +159,7 @@ class GMGPolar : public IGMGPolar /* --------------- */ /* Setup Functions */ int chooseNumberOfLevels(const PolarGrid& finest_grid); - bool checkUniformRefinement(const PolarGrid& grid, double tolerance, bool print = true) const; + bool checkUniformRefinement(const PolarGrid& grid, double tolerance, bool print) const; /* --------------- */ /* Solve Functions */ diff --git a/include/GMGPolar/setup.h b/include/GMGPolar/setup.h index 2b8180c9..3d976ea1 100644 --- a/include/GMGPolar/setup.h +++ b/include/GMGPolar/setup.h @@ -29,11 +29,10 @@ void GMGPolar::setup() // Three-tier tolerance strategy: // - strict_tol: within this -> do nothing // - warn_tol: within this but not strict -> warn (if verbose_>0) - // - otherwise: disable extrapolation and warn (always) + // - otherwise: disable extrapolation -> warn (if verbose_>0) const double strict_tol = 1e-12; const double warn_tol = 1e-05; - // Reuse existing checkUniformRefinement with a "print" flag: do quiet checks first if (checkUniformRefinement(grid_, strict_tol, false)) { // within strict tolerance: nothing to do } @@ -46,11 +45,12 @@ void GMGPolar::setup() } } else { - // worse than warning tolerance: call checkUniformRefinement once more with printing enabled to show details, - // then disable extrapolation and notify (important change -> always print) - checkUniformRefinement(grid_, warn_tol, true); - std::cerr << "[Extrapolation Warning] Finest PolarGrid is not from a single uniform refinement; disabling " - "extrapolation.\n"; + // worse than warning tolerance: disable extrapolation + if (verbose_ > 0) { + std::cerr + << "[Extrapolation Warning] Finest PolarGrid is not from a single uniform refinement; disabling " + "extrapolation.\n"; + } extrapolation_ = ExtrapolationType::NONE; } }