From cfde3ba434fdafb694567250f91eba9071b58376 Mon Sep 17 00:00:00 2001 From: Felix Albrecht <mail@felixalbrecht.de> Date: Mon, 7 Oct 2013 11:20:59 +0200 Subject: [PATCH] [common.convergence-study] added rel/abs switch --- dune/stuff/common/convergence-study.hh | 44 +++++++++++++++++++------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/dune/stuff/common/convergence-study.hh b/dune/stuff/common/convergence-study.hh index 1602d2e2b..9c6cf68db 100644 --- a/dune/stuff/common/convergence-study.hh +++ b/dune/stuff/common/convergence-study.hh @@ -46,7 +46,7 @@ public: virtual void refine() = 0; - std::map<std::string, std::vector<double>> run(std::ostream& out = std::cout) + std::map<std::string, std::vector<double>> run(const bool relative = true, std::ostream& out = std::cout) { if (provided_norms().size() == 0) DUNE_THROW(Dune::InvalidStateException, "You have to provide at least one norm!"); @@ -68,14 +68,31 @@ public: out << " grid "; for (const auto& norm : provided_norms()) { std::string relative_norm_str = ""; - if (norm.empty()) - relative_norm_str = "??? (relative)"; - else if (norm.size() <= 8) - relative_norm_str = norm + " (relative)"; - else if (norm.size() <= 12) - relative_norm_str = norm + " (rel.)"; - else - relative_norm_str = norm.substr(0, 11) + ". (rel.)"; + if (norm.empty()) { + relative_norm_str = "???"; + if (relative) + relative_norm_str += " (relative)"; + else + relative_norm_str += " (absolute)"; + } else if (norm.size() <= 8) { + relative_norm_str = norm; + if (relative) + relative_norm_str += " (relative)"; + else + relative_norm_str += " (absolute)"; + } else if (norm.size() <= 12) { + relative_norm_str = norm; + if (relative) + relative_norm_str += " (rel.)"; + else + relative_norm_str += " (abs.)"; + } else { + relative_norm_str = norm.substr(0, 11); + if (relative) + relative_norm_str += " (rel.)"; + else + relative_norm_str += " (abs.)"; + } const double missing = (19.0 - relative_norm_str.size()) / 2.0; for (size_t ii = 0; ii < missing; ++ii) relative_norm_str += " "; @@ -103,7 +120,10 @@ public: std::map<std::string, double> reference_norm; std::map<std::string, double> last_relative_error; for (const auto& norm : provided_norms()) { - reference_norm[norm] = norm_reference_solution(norm); + if (relative) + reference_norm[norm] = norm_reference_solution(norm); + else + reference_norm[norm] = 0.0; last_relative_error[norm] = 0.0; } double last_grid_width = current_grid_width(); @@ -126,7 +146,9 @@ public: // loop over all norms/columns for (const auto& norm : provided_norms()) { // compute and print relative error - const double relative_error = current_error_norm(norm) / reference_norm[norm]; + double relative_error = current_error_norm(norm); + if (relative) + relative_error /= reference_norm[norm]; ret[norm].push_back(relative_error); out << " | " << std::setw(8) << std::setprecision(2) << std::scientific << relative_error << std::flush; // print eoc -- GitLab