Skip to content

Commit

Permalink
ODE: fixing debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
lucbv committed Apr 5, 2023
1 parent c0a5dc8 commit 49c889f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
22 changes: 13 additions & 9 deletions ode/unit_test/Test_ODE_RK.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,28 +144,32 @@ void test_method(const std::string label, ode_type& my_ode,

EXPECT_EQ(solver_type::order(), order);
EXPECT_EQ(solver_type::num_stages(), num_stages);
#if (KOKKOSKERNELS_DEBUG_LEVEL > 0)
#if defined(HAVE_KOKKOSKERNELS_DEBUG)
std::cout << "\n" << label << std::endl;
std::cout << " order: " << solver_type::order() << std::endl;
std::cout << " number of stages: " << solver_type::num_stages() << std::endl;
#else
(void)label;
#endif
for (int stageIdx = 0; stageIdx < solver_type::num_stages(); ++stageIdx) {
EXPECT_NEAR_KK(ks(0, stageIdx), kstack_h(0, stageIdx), 1e-8);
EXPECT_NEAR_KK(ks(1, stageIdx), kstack_h(1, stageIdx), 1e-8);
#if (KOKKOSKERNELS_DEBUG_LEVEL > 0)
#if defined(HAVE_KOKKOSKERNELS_DEBUG)
std::cout << " k" << stageIdx << "={" << kstack_h(0, stageIdx) << ", "
<< kstack_h(1, stageIdx) << "}" << std::endl;
#endif
}
EXPECT_NEAR_KK(sol(0), y_new_h(0), 1e-8);
EXPECT_NEAR_KK(sol(1), y_new_h(1), 1e-8);
#if (KOKKOSKERNELS_DEBUG_LEVEL > 0)
#if defined(HAVE_KOKKOSKERNELS_DEBUG)
std::cout << " y={" << y_new_h(0) << ", " << y_new_h(1) << "}" << std::endl;
std::cout << " error={"
<< Kokkos::abs(y_new_h(0) - y_ref_h(0)) / Kokkos::abs(y_ref_h(0))
<< ", "
<< Kokkos::abs(y_new_h(1) - y_ref_h(1)) / Kokkos::abs(y_ref_h(1))
<< "}" << std::endl;
#else
(void)y_ref_h;
#endif

} // test_method
Expand Down Expand Up @@ -209,7 +213,7 @@ void test_RK() {
Kokkos::parallel_for(my_policy, wrapper);

Kokkos::deep_copy(y_ref_h, y_ref);
#if (KOKKOSKERNELS_DEBUG_LEVEL > 0)
#if defined(HAVE_KOKKOSKERNELS_DEBUG)
std::cout << "\nAnalytical solution" << std::endl;
std::cout << " y={" << y_ref_h(0) << ", " << y_ref_h(1) << "}"
<< std::endl;
Expand Down Expand Up @@ -336,7 +340,7 @@ void test_rate(ode_type& my_ode, const scalar_type& tstart,
Kokkos::deep_copy(y_new_h, y_new);
error(idx) = Kokkos::abs(y_new_h(0) - y_ref_h(0)) / Kokkos::abs(y_ref_h(0));

#if (KOKKOSKERNELS_DEBUG_LEVEL > 0)
#if defined(HAVE_KOKKOSKERNELS_DEBUG)
scalar_type dt = (tend - tstart) / num_steps(idx);
std::cout << "dt=" << dt << ", error=" << error(idx) << ", solution: {"
<< y_new_h(0) << ", " << y_new_h(1) << "}" << std::endl;
Expand Down Expand Up @@ -391,7 +395,7 @@ void test_convergence_rate() {
Kokkos::parallel_for(my_policy, wrapper);

Kokkos::deep_copy(y_ref_h, y_ref);
#if (KOKKOSKERNELS_DEBUG_LEVEL > 0)
#if defined(HAVE_KOKKOSKERNELS_DEBUG)
std::cout << "\nAnalytical solution" << std::endl;
std::cout << " y={" << y_ref_h(0) << ", " << y_ref_h(1) << "}"
<< std::endl;
Expand All @@ -409,7 +413,7 @@ void test_convergence_rate() {
double actual_ratio = error(idx + 1) / error(idx);
EXPECT_NEAR_KK_REL(actual_ratio, expected_ratio, 0.15);

#if (KOKKOSKERNELS_DEBUG_LEVEL > 0)
#if defined(HAVE_KOKKOSKERNELS_DEBUG)
double rel_ratio_diff = Kokkos::abs(actual_ratio - expected_ratio) /
Kokkos::abs(expected_ratio);
std::cout << "error ratio: " << actual_ratio
Expand All @@ -429,7 +433,7 @@ void test_convergence_rate() {
double actual_ratio = error(idx + 1) / error(idx);
EXPECT_NEAR_KK_REL(actual_ratio, expected_ratio, 0.05);

#if (KOKKOSKERNELS_DEBUG_LEVEL > 0)
#if defined(HAVE_KOKKOSKERNELS_DEBUG)
double rel_ratio_diff = Kokkos::abs(actual_ratio - expected_ratio) /
Kokkos::abs(expected_ratio);
std::cout << "error ratio: " << actual_ratio
Expand All @@ -449,7 +453,7 @@ void test_convergence_rate() {
double actual_ratio = error(idx + 1) / error(idx);
EXPECT_NEAR_KK_REL(actual_ratio, expected_ratio, 0.05);

#if (KOKKOSKERNELS_DEBUG_LEVEL > 0)
#if defined(HAVE_KOKKOSKERNELS_DEBUG)
double rel_ratio_diff = Kokkos::abs(actual_ratio - expected_ratio) /
Kokkos::abs(expected_ratio);
std::cout << "error ratio: " << actual_ratio
Expand Down
8 changes: 4 additions & 4 deletions ode/unit_test/Test_ODE_RK_chem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ void test_chem() {
chem_model_1 chem_model;
const int neqs = chem_model.neqs;
const int num_steps = 15000;
const double dt = 0.1;

KokkosODE::Experimental::ODE_params params(num_steps);
vec_type tmp("tmp vector", neqs);
Expand All @@ -123,7 +122,8 @@ void test_chem() {

auto y_new_h = Kokkos::create_mirror(y_new);
Kokkos::deep_copy(y_new_h, y_new);
#if (KOKKOSKERNELS_DEBUG_LEVEL > 0)
#if defined(HAVE_KOKKOSKERNELS_DEBUG)
const double dt = (chem_model.tend - chem_model.tstart) / params.num_steps;
std::cout << "\nChem model 1" << std::endl;
std::cout << " t0=" << chem_model.tstart << ", tn=" << chem_model.tend
<< std::endl;
Expand All @@ -141,7 +141,6 @@ void test_chem() {
chem_model_2 chem_model;
const int neqs = chem_model.neqs;
const int num_steps = 1500;
const double dt = 1;

KokkosODE::Experimental::ODE_params params(num_steps);
vec_type tmp("tmp vector", neqs);
Expand Down Expand Up @@ -169,7 +168,8 @@ void test_chem() {

auto y_new_h = Kokkos::create_mirror(y_new);
Kokkos::deep_copy(y_new_h, y_new);
#if (KOKKOSKERNELS_DEBUG_LEVEL > 0)
#if defined(HAVE_KOKKOSKERNELS_DEBUG)
const double dt = (chem_model.tend - chem_model.tstart) / params.num_steps;
std::cout << "\nChem model 2" << std::endl;
std::cout << " t0=" << chem_model.tstart << ", tn=" << chem_model.tend
<< std::endl;
Expand Down

0 comments on commit 49c889f

Please sign in to comment.