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
2 changes: 1 addition & 1 deletion include/GMGPolar/gmgpolar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) const;

/* --------------- */
/* Solve Functions */
Expand Down
52 changes: 39 additions & 13 deletions include/GMGPolar/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,32 @@ void GMGPolar<DomainGeometry, DensityProfileCoefficients>::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 -> warn (if verbose_>0)
const double strict_tol = 1e-12;
const double warn_tol = 1e-05;

if (checkUniformRefinement(grid_, strict_tol, false)) {
// within strict tolerance: nothing to do
}
else if (checkUniformRefinement(grid_, warn_tol, false)) {
Comment on lines +36 to +39

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (checkUniformRefinement(grid_, strict_tol, false)) {
// within strict tolerance: nothing to do
}
else if (checkUniformRefinement(grid_, warn_tol, false)) {
if (checkUniformRefinement(grid_, strict_tol, false)) {
// within strict tolerance: nothing to do
}
else if (checkUniformRefinement(grid_, warn_tol, false)) {

Maybe you should pass something like verbose_ > 1 instead of 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: disable extrapolation
if (verbose_ > 0) {
std::cerr
<< "[Extrapolation Warning] Finest PolarGrid is not from a single uniform refinement; disabling "
"extrapolation.\n";
}
extrapolation_ = ExtrapolationType::NONE;
}
}

Expand Down Expand Up @@ -588,7 +610,7 @@ void GMGPolar<DomainGeometry, DensityProfileCoefficients>::printSettings(const P

template <concepts::DomainGeometry DomainGeometry, concepts::DensityProfileCoefficients DensityProfileCoefficients>
bool GMGPolar<DomainGeometry, DensityProfileCoefficients>::checkUniformRefinement(const PolarGrid& grid,
double tolerance) const
double tolerance, bool print) const
{
HostConstVector<double> h_radius = grid.host_radii();
HostConstVector<double> h_theta = grid.host_theta();
Expand All @@ -601,10 +623,12 @@ bool GMGPolar<DomainGeometry, DensityProfileCoefficients>::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;
}
}
Expand All @@ -618,10 +642,12 @@ bool GMGPolar<DomainGeometry, DensityProfileCoefficients>::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";
}
Comment on lines +645 to +650

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How would I get this message to be displayed given that all calls pass print=false and that checkUniformRefinement is private?

return false;
}
}
Expand Down
Loading