Skip to content

Commit

Permalink
Fix fcompare's --abs_tol (AMReX-Codes#2504)
Browse files Browse the repository at this point in the history
There is a bug that ignores the absolute errors of components that do not
have the biggest relative error when --abs_tol is used.  It results in
something like below

    fcompare.gnu.ex --abs_tol 1.e-12 plt00010 plt00002

                variable name            absolute error            relative error
                                            (||A - B||)         (||A - B||/||A||)
     ----------------------------------------------------------------------------
     level = 0
     density                                          0                         0
     pressure                                         0                         0
     theta                                            0                         0
     x_velocity                          4.39990436e-05           2.749038203e-06
     y_velocity                         4.818762188e-05           9.964503154e-06
     z_velocity                          4.70120484e-19              0.7986458289
     PLOTFILE AGREE to specified tolerances: absolute = 1e-12 relative = 0

In this commit, this is fixed by applying the test to each component
separately.  A component passes if its relative error or absolute error
satisfies the respective tolerance.  The whole comparison passes if all
components pass.
  • Loading branch information
WeiqunZhang authored Nov 30, 2021
1 parent d62f0d2 commit 062a071
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions Tools/Plotfile/fcompare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ int main_main()
const int narg = amrex::command_argument_count();

Real global_error = 0.0;
Real global_rerror = 0.0;
Real abserr_for_global_rerror = 0.0;
bool any_nans = false;
ErrZone err_zone;
bool all_variables_found = true;
bool all_variables_passed = true;

// defaults
int norm = 0;
Expand Down Expand Up @@ -316,13 +315,10 @@ int main_main()
*(std::max_element(aerror.begin(),
aerror.end())));

const auto max_rerr = std::max_element(rerror.begin(), rerror.end());
global_rerror = std::max(global_rerror, *max_rerr);
const auto idx = std::distance(rerror.begin(), max_rerr);
abserr_for_global_rerror = std::max(
abserr_for_global_rerror, aerror[idx]);
for (int icomp_a = 0; icomp_a < ncomp_a; ++icomp_a) {
any_nans = any_nans || has_nan_a[icomp_a] || has_nan_b[icomp_a];
all_variables_passed = all_variables_passed &&
(aerror[icomp_a] <= atol || rerror[icomp_a] <= rtol);
}
}

Expand Down Expand Up @@ -373,11 +369,12 @@ int main_main()
if (abort_if_not_all_found) return EXIT_FAILURE;
}

if (global_error == 0.0 && !any_nans) {
if (any_nans) {
return EXIT_FAILURE;
} else if (global_error == 0.0) {
amrex::Print() << " PLOTFILE AGREE" << std::endl;
return EXIT_SUCCESS;
} else if ((abserr_for_global_rerror <= atol) ||
(global_rerror <= rtol)) {
} else if (all_variables_passed) {
amrex::Print() << " PLOTFILE AGREE to specified tolerances: "
<< "absolute = " << atol
<< " relative = " << rtol << std::endl;
Expand Down

0 comments on commit 062a071

Please sign in to comment.