diff --git a/src/solver/simulation/hydro-remix-new.cpp b/src/solver/simulation/hydro-remix-new.cpp index 80c7530b73..7c78b20703 100644 --- a/src/solver/simulation/hydro-remix-new.cpp +++ b/src/solver/simulation/hydro-remix-new.cpp @@ -85,6 +85,23 @@ static void checkInputCorrectness(const std::vector& G, { throw std::invalid_argument(msg_prefix + "all arrays of sizes 0"); } + + // Hydro production < Pmax + for (int h = 0; h < H.size(); h++) + { + if (H[h] > P_max[h]) + { + throw std::invalid_argument(msg_prefix + "H not smaller than Pmax everywhere"); + } + } + + for (int h = 0; h < H.size(); h++) + { + if (H[h] < P_min[h]) + { + throw std::invalid_argument(msg_prefix + "H not greater than Pmin everywhere"); + } + } } std::pair, std::vector> new_remix_hydro( diff --git a/src/tests/src/solver/simulation/test-hydro-remix.cpp b/src/tests/src/solver/simulation/test-hydro-remix.cpp index d29577e627..0ebb2075db 100644 --- a/src/tests/src/solver/simulation/test-hydro-remix.cpp +++ b/src/tests/src/solver/simulation/test-hydro-remix.cpp @@ -74,103 +74,104 @@ BOOST_AUTO_TEST_CASE(all_input_arrays_of_size_0__exception_raised) checkMessage("Remix hydro input : all arrays of sizes 0")); } -BOOST_AUTO_TEST_CASE(input_is_acceptable__no_exception_raised) +BOOST_AUTO_TEST_CASE(H_not_smaller_than_pmax__exception_raised) { - std::vector G = {0.}, H = {0.}, D = {0.}, P_max = {0.}, P_min = {0.}, inflows = {0.}; + std::vector G(5, 0.), D(5, 0.), P_min(5, 0.), inflows(5, 0.); + std::vector H = {1., 2., 3., 4., 5.}; + std::vector P_max = {2., 2., 2., 4., 5.}; double initial_level = 0.; double capa = 1.; - BOOST_CHECK_NO_THROW(new_remix_hydro(G, H, D, P_max, P_min, initial_level, capa, inflows)); + BOOST_CHECK_EXCEPTION(new_remix_hydro(G, H, D, P_max, P_min, initial_level, capa, inflows), + std::invalid_argument, + checkMessage("Remix hydro input : H not smaller than Pmax everywhere")); } -BOOST_AUTO_TEST_CASE(hydro_increases_but_pmax_only_10mwh___10mwh_are_moved_from_last_to_first_hour) +BOOST_AUTO_TEST_CASE(H_not_greater_than_pmin__exception_raised) { - std::vector G(5, 100.); - std::vector H = {0., 20., 40., 60., 80.}; - std::vector D = {80.0, 60., 40., 20., 0.}; - std::vector P_max(5, 10.); - std::vector P_min(5, 0.); - double initial_level = 500.; - double capa = 1000.; - std::vector inflows(5, 0.); - - auto [new_H, new_D] = new_remix_hydro(G, H, D, P_max, P_min, initial_level, capa, inflows); + std::vector G(5, 0.), D(5, 0.), P_max(5, 1000.), inflows(5, 0.); + std::vector H = {1., 2., 3., 4., 5.}; + std::vector P_min = {0., 0., 4., 0., 0.}; + double initial_level = 0.; + double capa = 1.; - std::vector expected_H = {10., 20., 40., 60., 70.}; - std::vector expected_D = {70., 60., 40., 20., 10.}; - BOOST_CHECK(new_H == expected_H); - BOOST_CHECK(new_D == expected_D); + BOOST_CHECK_EXCEPTION(new_remix_hydro(G, H, D, P_max, P_min, initial_level, capa, inflows), + std::invalid_argument, + checkMessage("Remix hydro input : H not greater than Pmin everywhere")); } -BOOST_AUTO_TEST_CASE(hydro_increases_but_pmax_only_20mwh___20mwh_are_moved_from_last_to_first_hour) +BOOST_AUTO_TEST_CASE(input_is_acceptable__no_exception_raised) { - std::vector G(5, 100.); - std::vector H = {0., 20., 40., 60., 80.}; - std::vector D = {80.0, 60., 40., 20., 0.}; - std::vector P_max(5, 20.); - std::vector P_min(5, 0.); - double initial_level = 500.; - double capa = 1000.; - std::vector inflows(5, 0.); - - auto [new_H, new_D] = new_remix_hydro(G, H, D, P_max, P_min, initial_level, capa, inflows); + std::vector G = {0.}, H = {0.}, D = {0.}, P_max = {0.}, P_min = {0.}, inflows = {0.}; + double initial_level = 0.; + double capa = 1.; - std::vector expected_H = {20., 20., 40., 60., 60.}; - BOOST_CHECK(new_H == expected_H); + BOOST_CHECK_NO_THROW(new_remix_hydro(G, H, D, P_max, P_min, initial_level, capa, inflows)); } -BOOST_AUTO_TEST_CASE(hydro_increases_but_pmax_only_30mwh___30mwh_are_moved_from_last_to_first_hour) +BOOST_AUTO_TEST_CASE(hydro_increases_and_pmax_40mwh___H_is_smoothed_to_mean_H_20mwh) { + std::vector P_max(5, 40.); + std::vector P_min(5, 0.); std::vector G(5, 100.); - std::vector H = {0., 20., 40., 60., 80.}; + std::vector H = {0., 10., 20., 30., 40.}; // H <= Pmax everywhere std::vector D = {80.0, 60., 40., 20., 0.}; - std::vector P_max(5, 30.); - std::vector P_min(5, 0.); double initial_level = 500.; double capa = 1000.; std::vector inflows(5, 0.); auto [new_H, new_D] = new_remix_hydro(G, H, D, P_max, P_min, initial_level, capa, inflows); - std::vector expected_H = {30., 30., 40., 50., 50.}; + std::vector expected_H = {20., 20., 20., 20., 20.}; + // D such as G + H + D remains constant at each hour + std::vector expected_D = {60., 50., 40., 30., 20.}; BOOST_CHECK(new_H == expected_H); + BOOST_CHECK(new_D == expected_D); } -BOOST_AUTO_TEST_CASE(hydro_increases_and_pmax_40mwh___final_hydro_is_flat_and_limited_by_pmax) +BOOST_AUTO_TEST_CASE(Pmax_does_not_influence_results_when_greater_than_40mwh) { + std::vector P_max(5, 50.); + std::vector P_min(5, 0.); std::vector G(5, 100.); - std::vector H = {0., 20., 40., 60., 80.}; + std::vector H = {0., 10., 20., 30., 40.}; // H <= Pmax everywhere std::vector D = {80.0, 60., 40., 20., 0.}; - std::vector P_max(5, 40.); - std::vector P_min(5, 0.); double initial_level = 500.; double capa = 1000.; std::vector inflows(5, 0.); auto [new_H, new_D] = new_remix_hydro(G, H, D, P_max, P_min, initial_level, capa, inflows); - std::vector expected_H = {40., 40., 40., 40., 40.}; + std::vector expected_H = {20., 20., 20., 20., 20.}; + // D such as G + H + D remains constant at each hour + std::vector expected_D = {60., 50., 40., 30., 20.}; BOOST_CHECK(new_H == expected_H); + BOOST_CHECK(new_D == expected_D); } -BOOST_AUTO_TEST_CASE(hydro_increases_and_pmax_50mwh___final_hydro_is_flat_and_limited_by_pmax) +BOOST_AUTO_TEST_CASE(hydro_decreases_and_pmax_40mwh___H_is_smoothed_to_mean_H_20mwh) { - std::vector G(5, 100.); - std::vector H = {0., 20., 40., 60., 80.}; - std::vector D = {80.0, 60., 40., 20., 0.}; - std::vector P_max(5, 50.); + std::vector P_max(5, 40.); std::vector P_min(5, 0.); + std::vector G(5, 100.); + std::vector H = {40., 30., 20., 10., 0.}; // H <= Pmax everywhere + // std::vector D = {80.0, 60., 40., 20., 0.}; + std::vector D = {0., 20., 40., 60., 80.}; double initial_level = 500.; double capa = 1000.; std::vector inflows(5, 0.); auto [new_H, new_D] = new_remix_hydro(G, H, D, P_max, P_min, initial_level, capa, inflows); - std::vector expected_H = {40., 40., 40., 40., 40.}; + std::vector expected_H = {20., 20., 20., 20., 20.}; + // D such as G + H + D remains constant at each hour + std::vector expected_D = {20., 30., 40., 50., 60.}; BOOST_CHECK(new_H == expected_H); + BOOST_CHECK(new_D == expected_D); } // Comment for further tests : // - Remix hydro algorithm seems symetrical (if we have input vectors and corresponding output // vectors, run the algo on reversed vectors gives reversed output result vectors) // - After running remix hydro algo, sum(H), sum(H + D) must remain the same. +// - influence of D : low values of G + H are searched where D > 0 (not where D >= 0)