diff --git a/src/solver/simulation/hydro-remix-new.cpp b/src/solver/simulation/hydro-remix-new.cpp index e44edd813b..76e9e9f90c 100644 --- a/src/solver/simulation/hydro-remix-new.cpp +++ b/src/solver/simulation/hydro-remix-new.cpp @@ -1,26 +1,14 @@ #include -#include -#include -#include -#include -#include #include -using namespace std; - namespace Antares::Solver::Simulation { -bool new_remix_hydro() -{ - return true; -} - -int find_min_index(const vector& G_plus_H, - const vector& new_D, - const vector& new_H, - const vector& tried_creux, - const vector& P_max, +int find_min_index(const std::vector& G_plus_H, + const std::vector& new_D, + const std::vector& new_H, + const std::vector& tried_creux, + const std::vector& P_max, double top) { double min_val = top; @@ -39,10 +27,10 @@ int find_min_index(const vector& G_plus_H, return min_idx; } -int find_max_index(const vector& G_plus_H, - const vector& new_H, - const vector& tried_pic, - const vector& P_min, +int find_max_index(const std::vector& G_plus_H, + const std::vector& new_H, + const std::vector& tried_pic, + const std::vector& P_min, double ref_value, double eps) { @@ -62,27 +50,28 @@ int find_max_index(const vector& G_plus_H, return max_idx; } -pair, vector> new_remix_hydro(const vector& G, - const vector& H, - const vector& D, - const vector& P_max, - const vector& P_min, - double initial_level, - double capa, - const vector& inflow) +std::pair, std::vector> new_remix_hydro( + const std::vector& G, + const std::vector& H, + const std::vector& D, + const std::vector& P_max, + const std::vector& P_min, + double initial_level, + double capa, + const std::vector& inflow) { - vector new_H = H; - vector new_D = D; + std::vector new_H = H; + std::vector new_D = D; int loop = 1000; double eps = 1e-2; double top = *max_element(G.begin(), G.end()) + *max_element(H.begin(), H.end()) + *max_element(D.begin(), D.end()) + 1; - vector G_plus_H(G.size()); - transform(G.begin(), G.end(), new_H.begin(), G_plus_H.begin(), plus<>()); + std::vector G_plus_H(G.size()); + transform(G.begin(), G.end(), new_H.begin(), G_plus_H.begin(), std::plus<>()); - vector level(G.size()); + std::vector level(G.size()); level[0] = initial_level + inflow[0] - new_H[0]; for (size_t i = 1; i < level.size(); ++i) { @@ -91,7 +80,7 @@ pair, vector> new_remix_hydro(const vector& G, while (loop-- > 0) { - vector tried_creux(G.size(), 0); + std::vector tried_creux(G.size(), 0); double delta = 0; while (true) @@ -102,7 +91,7 @@ pair, vector> new_remix_hydro(const vector& G, break; } - vector tried_pic(G.size(), 0); + std::vector tried_pic(G.size(), 0); while (true) { int idx_pic = find_max_index(G_plus_H, @@ -116,20 +105,21 @@ pair, vector> new_remix_hydro(const vector& G, break; } - vector intermediate_level(level.begin() + min(idx_creux, idx_pic), - level.begin() + max(idx_creux, idx_pic)); + std::vector intermediate_level(level.begin() + std::min(idx_creux, idx_pic), + level.begin() + + std::max(idx_creux, idx_pic)); - double max_pic = min(new_H[idx_pic] - P_min[idx_pic], - capa - - *max_element(intermediate_level.begin(), - intermediate_level.end())); - double max_creux = min( + double max_pic = std::min(new_H[idx_pic] - P_min[idx_pic], + capa + - *max_element(intermediate_level.begin(), + intermediate_level.end())); + double max_creux = std::min( {P_max[idx_creux] - new_H[idx_creux], new_D[idx_creux], *min_element(intermediate_level.begin(), intermediate_level.end())}); - double dif_pic_creux = max(G_plus_H[idx_pic] - G_plus_H[idx_creux], 0.0); + double dif_pic_creux = std::max(G_plus_H[idx_pic] - G_plus_H[idx_creux], 0.0); - delta = max(min({max_pic, max_creux, dif_pic_creux / 2.0}), 0.0); + delta = std::max(std::min({max_pic, max_creux, dif_pic_creux / 2.0}), 0.0); if (delta > 0) { @@ -157,7 +147,7 @@ pair, vector> new_remix_hydro(const vector& G, break; } - transform(G.begin(), G.end(), new_H.begin(), G_plus_H.begin(), plus<>()); + transform(G.begin(), G.end(), new_H.begin(), G_plus_H.begin(), std::plus<>()); level[0] = initial_level + inflow[0] - new_H[0]; for (size_t i = 1; i < level.size(); ++i) { diff --git a/src/tests/src/solver/simulation/test-hydro-remix.cpp b/src/tests/src/solver/simulation/test-hydro-remix.cpp index 4ca8773c4a..3f90756f0d 100644 --- a/src/tests/src/solver/simulation/test-hydro-remix.cpp +++ b/src/tests/src/solver/simulation/test-hydro-remix.cpp @@ -8,7 +8,6 @@ namespace Antares::Solver::Simulation { -bool new_remix_hydro(); std::pair, std::vector> new_remix_hydro( const std::vector& G, const std::vector& H, @@ -18,28 +17,21 @@ std::pair, std::vector> new_remix_hydro( double initial_level, double capa, const std::vector& inflow); -} // namespace Antares::Solver::Simulation +} using namespace Antares::Solver::Simulation; -using namespace std; BOOST_AUTO_TEST_CASE(my_first_unit_test) { - BOOST_CHECK(new_remix_hydro()); -} - -BOOST_AUTO_TEST_CASE(my_second_unit_test) -{ - vector G = {1.0, 2.0, 3.0, 4.0, 5.0}; - vector H = {2.0, 3.0, 4.0, 5.0, 6.0}; - vector D = {1.0, 1.5, 2.0, 2.5, 3.0}; - vector P_max = {10.0, 10.0, 10.0, 10.0, 10.0}; - vector P_min = {0.0, 0.0, 0.0, 0.0, 0.0}; + std::vector G = {1.0, 2.0, 3.0, 4.0, 5.0}; + std::vector H = {2.0, 3.0, 4.0, 5.0, 6.0}; + std::vector D = {1.0, 1.5, 2.0, 2.5, 3.0}; + std::vector P_max = {10.0, 10.0, 10.0, 10.0, 10.0}; + std::vector P_min = {0.0, 0.0, 0.0, 0.0, 0.0}; double initial_level = 5.0; double capa = 20.0; - vector inflow = {3.0, 3.0, 3.0, 3.0, 3.0}; + std::vector inflow = {3.0, 3.0, 3.0, 3.0, 3.0}; - // Call the function auto [new_H, new_D] = new_remix_hydro(G, H, D, P_max, P_min, initial_level, capa, inflow); BOOST_CHECK(true);