Skip to content

Commit

Permalink
Remove state from hydro ventilation (#2143)
Browse files Browse the repository at this point in the history
**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**
  • Loading branch information
guilpier-code authored Jun 7, 2024
1 parent a89c067 commit 8d6cdc4
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
17 changes: 5 additions & 12 deletions src/solver/hydro/management/daily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -546,22 +544,17 @@ 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);
}
}
}

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
3 changes: 1 addition & 2 deletions src/solver/hydro/management/management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -534,7 +533,7 @@ void HydroManagement::makeVentilation(double* randomReservoirLevel,
prepareEffectiveDemand();

prepareMonthlyOptimalGenerations(randomReservoirLevel, y);
prepareDailyOptimalGenerations(state, y, scratchmap);
prepareDailyOptimalGenerations(y, scratchmap);
}

} // namespace Antares
1 change: 1 addition & 0 deletions src/solver/simulation/adequacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ bool Adequacy::year(Progression::Task& progression,
currentProblem.year = state.year;

PrepareRandomNumbers(study, currentProblem, randomForYear);
SetInitialHydroLevel(study, currentProblem, hydroVentilationResults);

state.startANewYear();

Expand Down
17 changes: 17 additions & 0 deletions src/solver/simulation/common-eco-adq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/solver/simulation/economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ bool Economy::year(Progression::Task& progression,
currentProblem.year = state.year;

PrepareRandomNumbers(study, currentProblem, randomForYear);
SetInitialHydroLevel(study, currentProblem, hydroVentilationResults);

state.startANewYear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ public:
// 4 - Hydraulic ventilation
pDurationCollector("hydro_ventilation") << [&] {
hydroManagement.makeVentilation(randomReservoirLevel,
state[numSpace],
y,
scratchmap);
};
Expand Down

0 comments on commit 8d6cdc4

Please sign in to comment.