Skip to content

Commit

Permalink
New hydro remix : some cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
guilpier-code committed Dec 12, 2024
1 parent 6871e98 commit 33a96ea
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 61 deletions.
82 changes: 36 additions & 46 deletions src/solver/simulation/hydro-remix-new.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <numeric>
#include <vector>

using namespace std;

namespace Antares::Solver::Simulation
{

bool new_remix_hydro()
{
return true;
}

int find_min_index(const vector<double>& G_plus_H,
const vector<double>& new_D,
const vector<double>& new_H,
const vector<int>& tried_creux,
const vector<double>& P_max,
int find_min_index(const std::vector<double>& G_plus_H,
const std::vector<double>& new_D,
const std::vector<double>& new_H,
const std::vector<int>& tried_creux,
const std::vector<double>& P_max,
double top)
{
double min_val = top;
Expand All @@ -39,10 +27,10 @@ int find_min_index(const vector<double>& G_plus_H,
return min_idx;
}

int find_max_index(const vector<double>& G_plus_H,
const vector<double>& new_H,
const vector<int>& tried_pic,
const vector<double>& P_min,
int find_max_index(const std::vector<double>& G_plus_H,
const std::vector<double>& new_H,
const std::vector<int>& tried_pic,
const std::vector<double>& P_min,
double ref_value,
double eps)
{
Expand All @@ -62,27 +50,28 @@ int find_max_index(const vector<double>& G_plus_H,
return max_idx;
}

pair<vector<double>, vector<double>> new_remix_hydro(const vector<double>& G,
const vector<double>& H,
const vector<double>& D,
const vector<double>& P_max,
const vector<double>& P_min,
double initial_level,
double capa,
const vector<double>& inflow)
std::pair<std::vector<double>, std::vector<double>> new_remix_hydro(
const std::vector<double>& G,
const std::vector<double>& H,
const std::vector<double>& D,
const std::vector<double>& P_max,
const std::vector<double>& P_min,
double initial_level,
double capa,
const std::vector<double>& inflow)
{
vector<double> new_H = H;
vector<double> new_D = D;
std::vector<double> new_H = H;
std::vector<double> 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<double> G_plus_H(G.size());
transform(G.begin(), G.end(), new_H.begin(), G_plus_H.begin(), plus<>());
std::vector<double> G_plus_H(G.size());
transform(G.begin(), G.end(), new_H.begin(), G_plus_H.begin(), std::plus<>());

vector<double> level(G.size());
std::vector<double> level(G.size());
level[0] = initial_level + inflow[0] - new_H[0];
for (size_t i = 1; i < level.size(); ++i)
{
Expand All @@ -91,7 +80,7 @@ pair<vector<double>, vector<double>> new_remix_hydro(const vector<double>& G,

while (loop-- > 0)
{
vector<int> tried_creux(G.size(), 0);
std::vector<int> tried_creux(G.size(), 0);
double delta = 0;

while (true)
Expand All @@ -102,7 +91,7 @@ pair<vector<double>, vector<double>> new_remix_hydro(const vector<double>& G,
break;
}

vector<int> tried_pic(G.size(), 0);
std::vector<int> tried_pic(G.size(), 0);
while (true)
{
int idx_pic = find_max_index(G_plus_H,
Expand All @@ -116,20 +105,21 @@ pair<vector<double>, vector<double>> new_remix_hydro(const vector<double>& G,
break;
}

vector<double> intermediate_level(level.begin() + min(idx_creux, idx_pic),
level.begin() + max(idx_creux, idx_pic));
std::vector<double> 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)
{
Expand Down Expand Up @@ -157,7 +147,7 @@ pair<vector<double>, vector<double>> new_remix_hydro(const vector<double>& 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)
{
Expand Down
22 changes: 7 additions & 15 deletions src/tests/src/solver/simulation/test-hydro-remix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Antares::Solver::Simulation
{
bool new_remix_hydro();
std::pair<std::vector<double>, std::vector<double>> new_remix_hydro(
const std::vector<double>& G,
const std::vector<double>& H,
Expand All @@ -18,28 +17,21 @@ std::pair<std::vector<double>, std::vector<double>> new_remix_hydro(
double initial_level,
double capa,
const std::vector<double>& 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<double> G = {1.0, 2.0, 3.0, 4.0, 5.0};
vector<double> H = {2.0, 3.0, 4.0, 5.0, 6.0};
vector<double> D = {1.0, 1.5, 2.0, 2.5, 3.0};
vector<double> P_max = {10.0, 10.0, 10.0, 10.0, 10.0};
vector<double> P_min = {0.0, 0.0, 0.0, 0.0, 0.0};
std::vector<double> G = {1.0, 2.0, 3.0, 4.0, 5.0};
std::vector<double> H = {2.0, 3.0, 4.0, 5.0, 6.0};
std::vector<double> D = {1.0, 1.5, 2.0, 2.5, 3.0};
std::vector<double> P_max = {10.0, 10.0, 10.0, 10.0, 10.0};
std::vector<double> P_min = {0.0, 0.0, 0.0, 0.0, 0.0};
double initial_level = 5.0;
double capa = 20.0;
vector<double> inflow = {3.0, 3.0, 3.0, 3.0, 3.0};
std::vector<double> 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);
Expand Down

0 comments on commit 33a96ea

Please sign in to comment.