From adb89a75c068019a146d07c35e24d6008a2797bf Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 19 Dec 2024 16:09:08 +0100 Subject: [PATCH] New hydro remix : adding a unit test on getting a sub optimal solution for H --- .../solver/simulation/test-hydro-remix.cpp | 69 ++++++++++++++++++- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/src/tests/src/solver/simulation/test-hydro-remix.cpp b/src/tests/src/solver/simulation/test-hydro-remix.cpp index 4fbf8cef27..2ed37a3799 100644 --- a/src/tests/src/solver/simulation/test-hydro-remix.cpp +++ b/src/tests/src/solver/simulation/test-hydro-remix.cpp @@ -388,7 +388,7 @@ BOOST_AUTO_TEST_CASE(input_leads_to_levels_less_than_zero___exception_raised) "Remix hydro input : levels computed from input don't respect reservoir bounds")); } -BOOST_AUTO_TEST_CASE(influence_of_reservoir_capacity_on_hydro_production, +BOOST_AUTO_TEST_CASE(influence_of_capacity_on_hydro_prod___case_where_no_influence, *boost::unit_test::tolerance(0.001)) { // Not important for this test @@ -426,8 +426,9 @@ BOOST_AUTO_TEST_CASE(influence_of_reservoir_capacity_on_hydro_production, BOOST_TEST(new_H == expected_H, boost::test_tools::per_element()); BOOST_TEST(L == expected_L, boost::test_tools::per_element()); - // Now, if we limit to capacity to sup(input_levels) = 155, we should have same H and L - // as previously + // Case 2 : now, if we lower capacity to sup(input_levels) = 155, we should + // have same computed H and L as previously : this value of capacity should + // not have an influence on H and levels as results of the algorithm. capacity = 155.; auto [new_H2, new_D2, L2] = new_remix_hydro(G, H, @@ -446,6 +447,68 @@ BOOST_AUTO_TEST_CASE(influence_of_reservoir_capacity_on_hydro_production, BOOST_TEST(L2 == expected_L, boost::test_tools::per_element()); } +BOOST_AUTO_TEST_CASE(lowering_capacity_too_much_leads_to_suboptimal_solution_for_GplusH, + *boost::unit_test::tolerance(0.001)) +{ + // Not important for this test + std::vector P_max(10, std::numeric_limits::max()); + std::vector P_min(10, 0.); + std::vector G(10, 0.), pump(10, 0.), ovf(10, 0.), S(10, 0.), DTG_MRG(10, 0.); + std::vector D(10, 20.); + + // H oscillates between 10 and 20 (new H will be flattened to 15 everywhere) + std::vector H = {20., 10., 20., 10., 20., 10., 20., 10., 20., 10.}; + // First inflows > H, then inflows < H. Consequence : levels first increase, then decrease. + std::vector inflows = {25., 25., 25., 25., 25., 5., 5., 5., 5., 5.}; + double init_level = 100.; + // H and inflows result in : input_levels = {105, 120, 125, 140, 145, 140, 125, 120, 105, 100} + // Note sup(input_levels) = 145 + + // Case 1 : capacity unlimited + double capacity = std::numeric_limits::max(); + auto [new_H, new_D, L] = new_remix_hydro(G, + H, + D, + P_max, + P_min, + init_level, + capacity, + inflows, + ovf, + pump, + S, + DTG_MRG); + + std::vector expected_H(10, 15.); // H is flat and is 15. (means of initial H) + // Levels associated to new H are such as sup(L) = 150. > sup(input_levels) = 145 + std::vector expected_L = {110., 120., 130., 140., 150., 140., 130., 120., 110., 100.}; + BOOST_TEST(new_H == expected_H, boost::test_tools::per_element()); + BOOST_TEST(L == expected_L, boost::test_tools::per_element()); + + // Case 2 : now we lower capacity to sup(input_levels) = 145. + // This makes input acceptable for algo : levels computed from input have an + // up bound <= capacity + // But this time levels can not increase up to sup(L) = 150., as it would if capacity + // was infinite. So we expect to get an output H flat by interval, not on the whole domain. + capacity = 145.; + auto [new_H2, new_D2, L2] = new_remix_hydro(G, + H, + D, + P_max, + P_min, + init_level, + capacity, + inflows, + ovf, + pump, + S, + DTG_MRG); + + // new_H2 is flat by interval + std::vector expected_H2 = {16., 16., 16., 16., 16., 14., 14., 14., 14., 14.}; + BOOST_TEST(new_H2 == expected_H2, boost::test_tools::per_element()); +} + // Ideas for building further tests : // ================================ // - Remix hydro algorithm seems symmetrical (if we have input vectors and corresponding output