Skip to content

Commit

Permalink
Applied suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
drreynolds committed Oct 23, 2024
1 parent eb2e79a commit ff1cd67
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 38 deletions.
36 changes: 16 additions & 20 deletions test/unit_tests/arkode/CXX_serial/ark_test_brusselator_mriadapt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,16 +675,13 @@ int main(int argc, char* argv[])
printf(" %10.6" FSYM " %10.6" FSYM " %10.6" FSYM " %10.6" FSYM " %.1" ESYM
" %.1" ESYM " %.1" ESYM "\n",
t, ydata[0], ydata[1], ydata[2], uerr, verr, werr);
int Nout = 0;
while (Tf - t > 1.0e-8)
while (Tf - t > SUN_RCONST(1.0e-8))
{
// reset reference solver so that it begins with identical state
retval = ARKodeReset(arkode_ref, t, y);

// evolve solution in one-step mode
retval = ARKodeSetStopTime(arkode_mem, tout);
if (check_flag(retval, "ARKodeSetStopTime")) return 1;
retval = ARKodeEvolve(arkode_mem, tout, y, &t, ARK_ONE_STEP);
retval = ARKodeEvolve(arkode_mem, Tf, y, &t, ARK_ONE_STEP);
if (retval < 0)
{
printf("ARKodeEvolve error (%i)\n", retval);
Expand All @@ -694,7 +691,7 @@ int main(int argc, char* argv[])
// evolve reference solver to same time in "normal" mode
retval = ARKodeSetStopTime(arkode_ref, t);
if (check_flag(retval, "ARKodeSetStopTime")) return 1;
retval = ARKodeEvolve(arkode_ref, t, yref, &t2, ARK_NORMAL);
retval = ARKodeEvolve(arkode_ref, Tf, yref, &t2, ARK_NORMAL);
if (retval < 0)
{
printf("ARKodeEvolve reference solution error (%i)\n", retval);
Expand All @@ -705,20 +702,19 @@ int main(int argc, char* argv[])
u = ydata[0];
v = ydata[1];
w = ydata[2];
uerr = SUNRabs(yrefdata[0] - u);
verr = SUNRabs(yrefdata[1] - v);
werr = SUNRabs(yrefdata[2] - w);
uerr = std::abs(yrefdata[0] - u);
verr = std::abs(yrefdata[1] - v);
werr = std::abs(yrefdata[2] - w);
uerrtot += uerr * uerr;
verrtot += verr * verr;
werrtot += werr * werr;
errtot += uerr * uerr + verr * verr + werr * werr;
accuracy = std::max(accuracy, uerr / SUNRabs(opts.atol +
opts.rtol * yrefdata[0]));
accuracy = std::max(accuracy, verr / SUNRabs(opts.atol +
opts.rtol * yrefdata[1]));
accuracy = std::max(accuracy, werr / SUNRabs(opts.atol +
opts.rtol * yrefdata[2]));
Nout++;
accuracy = std::max(accuracy, uerr / std::abs(opts.atol +
opts.rtol * yrefdata[0]));
accuracy = std::max(accuracy, verr / std::abs(opts.atol +
opts.rtol * yrefdata[1]));
accuracy = std::max(accuracy, werr / std::abs(opts.atol +
opts.rtol * yrefdata[2]));

// Periodically output current results to screen
if (t >= tout)
Expand All @@ -730,10 +726,6 @@ int main(int argc, char* argv[])
t, u, v, w, uerr, verr, werr);
}
}
uerrtot = SUNRsqrt(uerrtot / Nt);
verrtot = SUNRsqrt(verrtot / Nt);
werrtot = SUNRsqrt(werrtot / Nt);
errtot = SUNRsqrt(errtot / Nt / 3);
printf(" "
"---------------------------------------------------------------------"
"----\n");
Expand Down Expand Up @@ -767,6 +759,10 @@ int main(int argc, char* argv[])
check_flag(retval, "ARKodeGetNumRhsEvals");

// Print some final statistics
uerrtot = std::sqrt(uerrtot / (sunrealtype)nsts);
verrtot = std::sqrt(verrtot / (sunrealtype)nsts);
werrtot = std::sqrt(werrtot / (sunrealtype)nsts);
errtot = std::sqrt(errtot / SUN_RCONST(3.0) / (sunrealtype)nsts);
std::cout << "\nFinal Solver Statistics:\n";
std::cout << " Slow steps = " << nsts << " (attempts = " << natts
<< ", fails = " << netfs << ")\n";
Expand Down
32 changes: 14 additions & 18 deletions test/unit_tests/arkode/CXX_serial/ark_test_kpr_mriadapt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,16 +682,13 @@ int main(int argc, char* argv[])
printf(" ------------------------------------------------------\n");
printf(" %10.6" FSYM " %10.6" FSYM " %10.6" FSYM " %.2" ESYM " %.2" ESYM
"\n", t, ydata[0], ydata[1], uerr, verr);
int Nout = 0;
while (Tf - t > 1.0e-8)
while (Tf - t > SUN_RCONST(1.0e-8))
{
// reset reference solver so that it begins with identical state
retval = ARKodeReset(arkode_ref, t, y);

// evolve solution in one-step mode
retval = ARKodeSetStopTime(arkode_mem, tout);
if (check_flag(retval, "ARKodeSetStopTime")) return 1;
retval = ARKodeEvolve(arkode_mem, tout, y, &t, ARK_ONE_STEP);
retval = ARKodeEvolve(arkode_mem, Tf, y, &t, ARK_ONE_STEP);
if (retval < 0)
{
printf("ARKodeEvolve error (%i)\n", retval);
Expand All @@ -701,7 +698,7 @@ int main(int argc, char* argv[])
// evolve reference solver to same time in "normal" mode
retval = ARKodeSetStopTime(arkode_ref, t);
if (check_flag(retval, "ARKodeSetStopTime")) return 1;
retval = ARKodeEvolve(arkode_ref, t, yref, &t2, ARK_NORMAL);
retval = ARKodeEvolve(arkode_ref, Tf, yref, &t2, ARK_NORMAL);
if (retval < 0)
{
printf("ARKodeEvolve reference solution error (%i)\n", retval);
Expand All @@ -711,16 +708,15 @@ int main(int argc, char* argv[])
// access/print solution and error
u = ydata[0];
v = ydata[1];
uerr = SUNRabs(yrefdata[0] - u);
verr = SUNRabs(yrefdata[1] - v);
uerr = std::abs(yrefdata[0] - u);
verr = std::abs(yrefdata[1] - v);
uerrtot += uerr * uerr;
verrtot += verr * verr;
errtot += uerr * uerr + verr * verr;
accuracy = std::max(accuracy, uerr / SUNRabs(opts.atol +
opts.rtol * yrefdata[0]));
accuracy = std::max(accuracy, verr / SUNRabs(opts.atol +
opts.rtol * yrefdata[1]));
Nout++;
accuracy = std::max(accuracy, uerr / std::abs(opts.atol +
opts.rtol * yrefdata[0]));
accuracy = std::max(accuracy, verr / std::abs(opts.atol +
opts.rtol * yrefdata[1]));

// Periodically output current results to screen
if (t >= tout)
Expand All @@ -732,9 +728,6 @@ int main(int argc, char* argv[])
t, u, v, uerr, verr);
}
}
uerrtot = SUNRsqrt(uerrtot / Nt);
verrtot = SUNRsqrt(verrtot / Nt);
errtot = SUNRsqrt(errtot / Nt / 2);
printf(" ------------------------------------------------------\n");

//
Expand Down Expand Up @@ -766,6 +759,9 @@ int main(int argc, char* argv[])
check_flag(retval, "ARKodeGetNumRhsEvals");

// Print some final statistics
uerrtot = std::sqrt(uerrtot / (sunrealtype)nsts);
verrtot = std::sqrt(verrtot / (sunrealtype)nsts);
errtot = std::sqrt(errtot / SUN_RCONST(2.0) / (sunrealtype)nsts);
std::cout << "\nFinal Solver Statistics:\n";
std::cout << " Slow steps = " << nsts << " (attempts = " << natts
<< ", fails = " << netfs << ")\n";
Expand Down Expand Up @@ -1015,12 +1011,12 @@ static sunrealtype sdot(sunrealtype t, Options* opts)

static sunrealtype utrue(sunrealtype t, Options* opts)
{
return (SUNRsqrt(TWO + r(t, opts)));
return (std::sqrt(TWO + r(t, opts)));
}

static sunrealtype vtrue(sunrealtype t, Options* opts)
{
return (SUNRsqrt(TWO + s(t, opts)));
return (std::sqrt(TWO + s(t, opts)));
}

static int Ytrue(sunrealtype t, N_Vector y, Options* opts)
Expand Down

0 comments on commit ff1cd67

Please sign in to comment.