Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gardner48 committed May 12, 2024
1 parent 2427bba commit 5650b89
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 134 deletions.
8 changes: 7 additions & 1 deletion test/unit_tests/arkode/CXX_serial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@
set(unit_tests
"ark_test_analytic_sys_mri.cpp\;0"
"ark_test_analytic_sys_mri.cpp\;1"
"ark_test_dahlquist_ark.cpp\;0 -1"
"ark_test_dahlquist_ark.cpp\;1 -1"
"ark_test_dahlquist_ark.cpp\;2 -1"
"ark_test_dahlquist_ark.cpp\;0 0"
"ark_test_dahlquist_ark.cpp\;1 0"
"ark_test_dahlquist_ark.cpp\;2 0"
"ark_test_dahlquist_ark.cpp\;0 1"
"ark_test_dahlquist_ark.cpp\;1 1"
"ark_test_dahlquist_ark.cpp\;2 1"
"ark_test_dahlquist_erk.cpp\;-1"
"ark_test_dahlquist_erk.cpp\;0"
"ark_test_dahlquist_erk.cpp\;1"
"ark_test_dahlquist_mri.cpp\;"
"ark_test_dahlquist_mri.cpp\;-1"
"ark_test_dahlquist_mri.cpp\;0"
"ark_test_dahlquist_mri.cpp\;1"
"ark_test_butcher.cpp\;"
"ark_test_getjac.cpp\;"
"ark_test_getjac_mri.cpp\;"
Expand Down
40 changes: 33 additions & 7 deletions test/unit_tests/arkode/CXX_serial/ark_test_dahlquist_ark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum class rk_type

enum class interp_type
{
none = -1,
hermite,
lagrange
};
Expand Down Expand Up @@ -93,8 +94,9 @@ struct ProblemOptions
sunrealtype h = SUN_RCONST(0.01);

// Interpolant type
// 0 = Hermite
// 1 = Lagrange
// -1 = None
// 0 = Hermite
// 1 = Lagrange
interp_type i_type = interp_type::hermite;

// Predictor type
Expand Down Expand Up @@ -166,8 +168,20 @@ int main(int argc, char* argv[])

if (argc > 2)
{
if (std::stoi(argv[2]) == 1) { prob_opts.i_type = interp_type::lagrange; }
else { prob_opts.i_type = interp_type::hermite; }
if (std::stoi(argv[2]) == -1) { prob_opts.i_type = interp_type::none; }
else if (std::stoi(argv[2]) == 0)
{
prob_opts.i_type = interp_type::hermite;
}
else if (std::stoi(argv[2]) == 1)
{
prob_opts.i_type = interp_type::lagrange;
}
else
{
std::cerr << "ERROR: Invalid interpolation type option" << std::endl;
return 1;
}
}

if (argc > 3)
Expand Down Expand Up @@ -201,7 +215,11 @@ int main(int argc, char* argv[])
{
std::cout << " interp type = Hermite\n";
}
else { std::cout << " interp type = Lagrange\n"; }
else if (prob_opts.i_type == interp_type::lagrange)
{
std::cout << " interp type = Lagrange\n";
}
else { std::cout << " interp type = None\n"; }
if (prob_opts.p_type == 0) { std::cout << " pred type = Trivial (0)\n"; }
else { std::cout << " pred type = Max order (1)\n"; }

Expand Down Expand Up @@ -489,6 +507,11 @@ int run_tests(ARKodeButcherTable Be, ARKodeButcherTable Bi,
flag = ARKodeSetInterpolantType(arkstep_mem, ARK_INTERP_LAGRANGE);
if (check_flag(&flag, "ARKodeSetInterpolantType", 1)) { return 1; }
}
else if (prob_opts.i_type == interp_type::none)
{
flag = ARKodeSetInterpolantType(arkstep_mem, ARK_INTERP_NONE);
if (check_flag(&flag, "ARKodeSetInterpolantType", 1)) { return 1; }
}

// Create matrix and linear solver (if necessary)
SUNMatrix A = nullptr;
Expand Down Expand Up @@ -595,8 +618,11 @@ int run_tests(ARKodeButcherTable Be, ARKodeButcherTable Bi,
flag = ARKodeGetLastStep(arkstep_mem, &h_last);
if (check_flag(&flag, "ARKodeGetLastStep", 1)) { return 1; }

flag = ARKodeGetDky(arkstep_mem, t_ret - h_last / TWO, 0, y);
if (check_flag(&flag, "ARKodeGetDky", 1)) { return 1; }
if (prob_opts.i_type != interp_type::none)
{
flag = ARKodeGetDky(arkstep_mem, t_ret - h_last / TWO, 0, y);
if (check_flag(&flag, "ARKodeGetDky", 1)) { return 1; }
}

// Stiffly accurate (and FSAL) methods do not require an additional RHS
// evaluation to get the new RHS value at the end of a step for dense
Expand Down
40 changes: 33 additions & 7 deletions test/unit_tests/arkode/CXX_serial/ark_test_dahlquist_erk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

enum class interp_type
{
none = -1,
hermite,
lagrange
};
Expand All @@ -71,8 +72,9 @@ struct ProblemOptions
sunrealtype h = SUN_RCONST(0.01);

// Interpolant type
// 0 = Hermite
// 1 = Lagrange
// -1 = None
// 0 = Hermite
// 1 = Lagrange
interp_type i_type = interp_type::hermite;
};

Expand Down Expand Up @@ -109,8 +111,20 @@ int main(int argc, char* argv[])
// Check for inputs
if (argc > 1)
{
if (std::stoi(argv[1]) == 0) { prob_opts.i_type = interp_type::hermite; }
else { prob_opts.i_type = interp_type::lagrange; }
if (std::stoi(argv[1]) == -1) { prob_opts.i_type = interp_type::none; }
else if (std::stoi(argv[1]) == 0)
{
prob_opts.i_type = interp_type::hermite;
}
else if (std::stoi(argv[1]) == 1)
{
prob_opts.i_type = interp_type::lagrange;
}
else
{
std::cerr << "ERROR: Invalid interpolation type option" << std::endl;
return 1;
}
}

// Output problem setup
Expand All @@ -123,7 +137,11 @@ int main(int argc, char* argv[])
{
std::cout << " interp type = Hermite\n";
}
else { std::cout << " interp type = Lagrange\n"; }
else if (prob_opts.i_type == interp_type::lagrange)
{
std::cout << " interp type = Lagrange\n";
}
else { std::cout << " interp type = None\n"; }

// Create SUNDIALS context
sundials::Context sunctx;
Expand Down Expand Up @@ -251,6 +269,11 @@ int run_tests(ARKodeButcherTable Be, ProblemData& prob_data,
flag = ARKodeSetInterpolantType(erkstep_mem, ARK_INTERP_LAGRANGE);
if (check_flag(&flag, "ARKodeSetInterpolantType", 1)) { return 1; }
}
else if (prob_opts.i_type == interp_type::none)
{
flag = ARKodeSetInterpolantType(erkstep_mem, ARK_INTERP_NONE);
if (check_flag(&flag, "ERKodeSetInterpolantType", 1)) { return 1; }
}

// Attach Butcher tables
flag = ERKStepSetTable(erkstep_mem, Be);
Expand Down Expand Up @@ -305,8 +328,11 @@ int run_tests(ARKodeButcherTable Be, ProblemData& prob_data,
flag = ARKodeGetLastStep(erkstep_mem, &h_last);
if (check_flag(&flag, "ARKodeGetLastStep", 1)) { return 1; }

flag = ARKodeGetDky(erkstep_mem, t_ret - h_last / TWO, 0, y);
if (check_flag(&flag, "ARKodeGetDky", 1)) { return 1; }
if (prob_opts.i_type != interp_type::none)
{
flag = ARKodeGetDky(erkstep_mem, t_ret - h_last / TWO, 0, y);
if (check_flag(&flag, "ARKodeGetDky", 1)) { return 1; }
}

// Stiffly accurate (and FSAL) methods do not require an additional RHS
// evaluation to get the new RHS value at the end of a step for dense
Expand Down
Loading

0 comments on commit 5650b89

Please sign in to comment.