From 8d6cdc4156357f630babc524ffb49612704f6306 Mon Sep 17 00:00:00 2001 From: guilpier-code <62292552+guilpier-code@users.noreply.github.com> Date: Fri, 7 Jun 2024 09:08:52 +0200 Subject: [PATCH] Remove state from hydro ventilation (#2143) **State** type is passed to the hydro ventilation. The object **state** is used by the hydro ventilation to reach the weekly optimization problem, in order to update the hydro initial level of a MC year. This important update is hidden in the depth of the code whereas it should be more highlighted (when a year starts). Furthermore, removing state alleviates a bit the hydro ventilation, already too complicated. Eventually, removing dependency of class **HydroManagement** to **State** allows to : - highlight the update of hydro initial level when beginning a year - loose a dependency to **State** --- .../solver/hydro/management/management.h | 7 ++----- src/solver/hydro/management/daily.cpp | 17 +++++------------ src/solver/hydro/management/management.cpp | 3 +-- src/solver/simulation/adequacy.cpp | 1 + src/solver/simulation/common-eco-adq.cpp | 17 +++++++++++++++++ src/solver/simulation/economy.cpp | 1 + .../antares/solver/simulation/common-eco-adq.h | 4 ++++ .../antares/solver/simulation/solver.hxx | 1 - 8 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/management.h b/src/solver/hydro/include/antares/solver/hydro/management/management.h index 29f64fbd93..78f3d4e6ea 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/management.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/management.h @@ -112,7 +112,6 @@ class HydroManagement final //! Perform the hydro ventilation void makeVentilation(double* randomReservoirLevel, - Solver::Variable::State& state, uint y, Antares::Data::Area::ScratchMap& scratchmap); @@ -152,12 +151,10 @@ class HydroManagement final // \return The total inflow for the whole year double prepareMonthlyTargetGenerations(Data::Area& area, TmpDataByArea& data); - void prepareDailyOptimalGenerations(Solver::Variable::State& state, - uint y, + void prepareDailyOptimalGenerations(uint y, Antares::Data::Area::ScratchMap& scratchmap); - void prepareDailyOptimalGenerations(Solver::Variable::State& state, - Data::Area& area, + void prepareDailyOptimalGenerations(Data::Area& area, uint y, Antares::Data::Area::ScratchMap& scratchmap); diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index 649de96f5d..8391b523d0 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -40,7 +40,6 @@ #include "antares/solver/hydro/daily2/h2o2_j_fonctions.h" #include "antares/solver/hydro/management/management.h" #include "antares/solver/simulation/sim_extern_variables_globales.h" -#include "antares/solver/variable/state.h" using namespace Yuni; @@ -220,10 +219,9 @@ struct DebugData }; inline void HydroManagement::prepareDailyOptimalGenerations( - Solver::Variable::State& state, - Data::Area& area, - uint y, - Antares::Data::Area::ScratchMap& scratchmap) + Data::Area& area, + uint y, + Antares::Data::Area::ScratchMap& scratchmap) { const auto srcinflows = area.hydro.series->storage.getColumn(y); @@ -546,10 +544,6 @@ inline void HydroManagement::prepareDailyOptimalGenerations( H2O2_J_Free(problem); } - uint firstDaySimu = parameters_.simulationDays.first; - state.problemeHebdo->previousSimulationFinalLevel[area.index] - = ventilationResults.NiveauxReservoirsDebutJours[firstDaySimu] * reservoirCapacity; - if (debugData) { debugData->writeDailyDebugData(calendar_, initReservoirLvlMonth, y, area.name); @@ -557,11 +551,10 @@ inline void HydroManagement::prepareDailyOptimalGenerations( } } -void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::State& state, - uint y, +void HydroManagement::prepareDailyOptimalGenerations(uint y, Antares::Data::Area::ScratchMap& scratchmap) { areas_.each([&](Data::Area& area) - { prepareDailyOptimalGenerations(state, area, y, scratchmap); }); + { prepareDailyOptimalGenerations(area, y, scratchmap); }); } } // namespace Antares diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index 5d8fb79d47..fe9311280d 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -519,7 +519,6 @@ bool HydroManagement::checksOnGenerationPowerBounds(uint year) const } void HydroManagement::makeVentilation(double* randomReservoirLevel, - Solver::Variable::State& state, uint y, Antares::Data::Area::ScratchMap& scratchmap) { @@ -534,7 +533,7 @@ void HydroManagement::makeVentilation(double* randomReservoirLevel, prepareEffectiveDemand(); prepareMonthlyOptimalGenerations(randomReservoirLevel, y); - prepareDailyOptimalGenerations(state, y, scratchmap); + prepareDailyOptimalGenerations(y, scratchmap); } } // namespace Antares diff --git a/src/solver/simulation/adequacy.cpp b/src/solver/simulation/adequacy.cpp index 5d3a54b261..f4e7f433d7 100644 --- a/src/solver/simulation/adequacy.cpp +++ b/src/solver/simulation/adequacy.cpp @@ -136,6 +136,7 @@ bool Adequacy::year(Progression::Task& progression, currentProblem.year = state.year; PrepareRandomNumbers(study, currentProblem, randomForYear); + SetInitialHydroLevel(study, currentProblem, hydroVentilationResults); state.startANewYear(); diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index 8abcb0cb98..b413b632d5 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -395,6 +395,23 @@ void PrepareRandomNumbers(Data::Study& study, }); } + +void SetInitialHydroLevel(Data::Study& study, + PROBLEME_HEBDO& problem, + const HYDRO_VENTILATION_RESULTS& hydroVentilationResults) +{ + uint firstDaySimu = study.parameters.simulationDays.first; + study.areas.each([&](Data::Area& area) + { + if (area.hydro.reservoirManagement) + { + double capacity = area.hydro.reservoirCapacity; + problem.previousSimulationFinalLevel[area.index] = + hydroVentilationResults[area.index].NiveauxReservoirsDebutJours[firstDaySimu] * capacity; + } + }); +} + void BuildThermalPartOfWeeklyProblem(Data::Study& study, PROBLEME_HEBDO& problem, const int PasDeTempsDebut, diff --git a/src/solver/simulation/economy.cpp b/src/solver/simulation/economy.cpp index 558c4f2095..0ffdf71d7b 100644 --- a/src/solver/simulation/economy.cpp +++ b/src/solver/simulation/economy.cpp @@ -126,6 +126,7 @@ bool Economy::year(Progression::Task& progression, currentProblem.year = state.year; PrepareRandomNumbers(study, currentProblem, randomForYear); + SetInitialHydroLevel(study, currentProblem, hydroVentilationResults); state.startANewYear(); diff --git a/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h b/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h index 2110c4cbe9..14d260af09 100644 --- a/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h +++ b/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h @@ -56,6 +56,10 @@ void PrepareRandomNumbers(Data::Study& study, PROBLEME_HEBDO& problem, yearRandomNumbers& randomForYear); +void SetInitialHydroLevel(Data::Study& study, + PROBLEME_HEBDO& problem, + const HYDRO_VENTILATION_RESULTS& hydroVentilationResults); + void BuildThermalPartOfWeeklyProblem(Data::Study& study, PROBLEME_HEBDO& problem, const int PasDeTempsDebut, diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.hxx b/src/solver/simulation/include/antares/solver/simulation/solver.hxx index 70d88c47af..dc2a7d4e09 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.hxx +++ b/src/solver/simulation/include/antares/solver/simulation/solver.hxx @@ -172,7 +172,6 @@ public: // 4 - Hydraulic ventilation pDurationCollector("hydro_ventilation") << [&] { hydroManagement.makeVentilation(randomReservoirLevel, - state[numSpace], y, scratchmap); };