Skip to content

Commit

Permalink
update stat comparison to use tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
gardner48 committed Nov 5, 2023
1 parent dd83c27 commit 396fcff
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions test/unit_tests/arkode/CXX_serial/ark_test_analytic_sys_mri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ static int dense_MM(SUNMatrix A, SUNMatrix B, SUNMatrix C);
// Private function to check function return values
static int check_flag(void *flagvalue, const string funcname, int opt);

// check if relative difference is within tolerance
static bool Compare(long int a, long int b, sunrealtype tol);

// SUNContext for the simulation
static SUNContext sunctx = NULL;

Expand Down Expand Up @@ -312,11 +315,11 @@ int main(int argc, char* argv[])
numfails += 1;
cout << " Internal solver steps error: " << ark_nst << " vs " << mri_nst << "\n";
}
if (ark_nfi != mri_nfsi) {
if (!Compare(ark_nfi, mri_nfsi, ONE)) {
numfails += 1;
cout << " RHS evals error: " << ark_nfi << " vs " << mri_nfsi << "\n";
}
if (ark_nni != mri_nni) {
if (!Compare(ark_nni, mri_nni, ONE)) {
numfails += 1;
cout << " Nonlinear iterations error: " << ark_nni << " vs " << mri_nni << "\n";
}
Expand Down Expand Up @@ -535,6 +538,13 @@ static int check_flag(void *flagvalue, const string funcname, int opt)
return 0;
}

// Check if relative difference of a and b is less than tolerance
static bool Compare(long int a, long int b, sunrealtype tol)
{
sunrealtype rel_diff = SUN_RCONST(100.0) *
abs(static_cast<sunrealtype>(a - b) / static_cast<sunrealtype>(a));

return (rel_diff > tol) ? false : true;
}

//---- end of file ----

0 comments on commit 396fcff

Please sign in to comment.