Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/global var hydro modulable #1614

Merged
merged 6 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/solver/hydro/daily2/h2o2_j_donnees_optimisation.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ constexpr unsigned int seed = 0x79683264; // "hyd2" in hexa
class Hydro_problem_costs
{
public:
Hydro_problem_costs(const Data::Study& study);
Hydro_problem_costs(const Data::Parameters& parameters);

inline double get_end_days_levels_cost() const
{
Expand Down
4 changes: 2 additions & 2 deletions src/solver/hydro/daily2/h2o2_j_optim_costs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
#include "h2o2_j_donnees_optimisation.h"
#include "antares/study/fwd.h"

Hydro_problem_costs::Hydro_problem_costs(const Data::Study& study)
Hydro_problem_costs::Hydro_problem_costs(const Data::Parameters& parameters)
{
noiseGenerator.reset(Constants::seed);
end_days_levels = -1. / 32.;
overflow = 32 * 68. + 1.;
deviations = 1.;
violations = 68.;

switch (study.parameters.hydroHeuristicPolicy.hhPolicy)
switch (parameters.hydroHeuristicPolicy.hhPolicy)
{
case Data::hhpMaximizeGeneration:
waste = 33 * 68.;
Expand Down
89 changes: 43 additions & 46 deletions src/solver/hydro/management/daily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ enum

struct DebugData
{
using PerArea = HydroManagement::PerArea;
using InflowsType = Matrix<double, Yuni::sint32>::ColumnType;
using MaxPowerType = Matrix<double, double>::ColumnType;
using ReservoirLevelType = Matrix<double>::ColumnType;
Expand All @@ -99,8 +98,8 @@ struct DebugData
std::array<double, 12> previousMonthWaste{0};

Solver::IResultWriter::Ptr pWriter;
const PerArea& data;
const VALEURS_GENEREES_PAR_PAYS& valgen;
const TmpDataByArea& data;
const VENTILATION_HYDRO_RESULTS_BY_AREA& ventilationResults;
const InflowsType& srcinflows;
const MaxPowerType& maxP;
const MaxPowerType& maxE;
Expand All @@ -109,8 +108,8 @@ struct DebugData
const double reservoirCapacity;

DebugData(Solver::IResultWriter::Ptr writer,
const PerArea& data,
const VALEURS_GENEREES_PAR_PAYS& valgen,
const TmpDataByArea& data,
const VENTILATION_HYDRO_RESULTS_BY_AREA& ventilationResults,
const InflowsType& srcinflows,
const MaxPowerType& maxP,
const MaxPowerType& maxE,
Expand All @@ -119,7 +118,7 @@ struct DebugData
double reservoirCapacity) :
pWriter(writer),
data(data),
valgen(valgen),
ventilationResults(ventilationResults),
srcinflows(srcinflows),
maxP(maxP),
maxE(maxE),
Expand All @@ -145,7 +144,7 @@ struct DebugData
buffer << "\tTurbine\t\t\tOPP\t\t\t\tTurbine Cible\tDLE\t\t\t\tDLN\n";
for (uint day = 0; day != 365; ++day)
{
double value = valgen.HydrauliqueModulableQuotidien[day];
double value = ventilationResults.HydrauliqueModulableQuotidien[day];
buffer << day << '\t' << value << '\t' << OPP[day] << '\t' << DailyTargetGen[day]
<< '\t' << data.DLE[day] << '\t' << data.DLN[day];
buffer << '\n';
Expand Down Expand Up @@ -189,9 +188,9 @@ struct DebugData
uint dayMonth = 1;
for (uint day = firstDay; day != endDay; ++day)
{
double turbines = valgen.HydrauliqueModulableQuotidien[day] / reservoirCapacity;
double niveauDeb = valgen.NiveauxReservoirsDebutJours[day];
double niveauFin = valgen.NiveauxReservoirsFinJours[day];
double turbines = ventilationResults.HydrauliqueModulableQuotidien[day] / reservoirCapacity;
double niveauDeb = ventilationResults.NiveauxReservoirsDebutJours[day];
double niveauFin = ventilationResults.NiveauxReservoirsFinJours[day];
double apports = srcinflows[day] / reservoirCapacity;
double turbMax = maxP[day] * maxE[day] / reservoirCapacity;
double turbCible = dailyTargetGen[day] / reservoirCapacity;
Expand Down Expand Up @@ -226,11 +225,10 @@ struct DebugData
inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::State& state,
Data::Area& area,
uint y,
uint numSpace,
VAL_GEN_PAR_PAYS& valeursGenereesParPays)
uint numSpace)
{
uint z = area.index;
assert(z < study.areas.size());
assert(z < areas_.size());

auto& ptchro = NumeroChroniquesTireesParPays[numSpace][z];

Expand All @@ -239,7 +237,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
auto tsIndex = (uint)ptchro.Hydraulique;
auto const& srcinflows = inflowsmatrix[tsIndex < inflowsmatrix.width ? tsIndex : 0];

auto& data = pAreas[numSpace][z];
auto& data = tmpDataByArea_[numSpace][z];

auto& scratchpad = area.scratchpad[numSpace];

Expand All @@ -258,15 +256,15 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
auto const& maxP = maxPower[Data::PartHydro::genMaxP];
auto const& maxE = maxPower[Data::PartHydro::genMaxE];

auto& valgen = valeursGenereesParPays[numSpace][z];

auto& ventilationResults = ventilationResults_[numSpace][z];
std::shared_ptr<DebugData> debugData(nullptr);

if (study.parameters.hydroDebug && study.resultWriter)
if (parameters_.hydroDebug && resultWriter_)
{
debugData = std::make_shared<DebugData>(study.resultWriter,
debugData = std::make_shared<DebugData>(resultWriter_,
data,
valgen,
ventilationResults,
srcinflows,
maxP,
maxE,
Expand All @@ -277,7 +275,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St

for (uint month = 0; month != 12; ++month)
{
auto daysPerMonth = study.calendar.months[month].days;
auto daysPerMonth = calendar_.months[month].days;
assert(daysPerMonth <= maxOPP);
assert(daysPerMonth <= maxDailyTargetGen);
assert(daysPerMonth + dayYear - 1 < maxPower.height);
Expand All @@ -302,7 +300,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
dayYear = 0;
for (uint month = 0; month != 12; ++month)
{
auto daysPerMonth = study.calendar.months[month].days;
auto daysPerMonth = calendar_.months[month].days;
for (uint day = 0; day != daysPerMonth; ++day)
{
dailyTargetGen[dayYear + day] = srcinflows[dayYear + day];
Expand All @@ -317,8 +315,8 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
dayYear = 0;
for (uint month = 0; month != 12; ++month)
{
uint realmonth = study.calendar.months[month].realmonth;
auto daysPerMonth = study.calendar.months[month].days;
uint realmonth = calendar_.months[month].realmonth;
auto daysPerMonth = calendar_.months[month].days;

if (area.hydro.followLoadModulations)
{
Expand Down Expand Up @@ -369,7 +367,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
{
for (uint month = 0; month != 12; ++month)
{
auto daysPerMonth = study.calendar.months[month].days;
auto daysPerMonth = calendar_.months[month].days;

for (uint day = 0; day != daysPerMonth; ++day)
{
Expand All @@ -384,11 +382,11 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
for (uint month = 0; month != 12; ++month)
{
uint realmonth = (initReservoirLvlMonth + month) % 12;
uint simulationMonth = study.calendar.mapping.months[realmonth];
uint simulationMonth = calendar_.mapping.months[realmonth];

auto daysPerMonth = study.calendar.months[simulationMonth].days;
auto daysPerMonth = calendar_.months[simulationMonth].days;

uint firstDay = study.calendar.months[simulationMonth].daysYear.first;
uint firstDay = calendar_.months[simulationMonth].daysYear.first;
uint endDay = firstDay + daysPerMonth;

DONNEES_MENSUELLES& problem = *H2O_J_Instanciation();
Expand All @@ -412,7 +410,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
dayMonth = 0;
for (uint day = firstDay; day != endDay; ++day)
{
valgen.HydrauliqueModulableQuotidien[day] = problem.Turbine[dayMonth];
ventilationResults.HydrauliqueModulableQuotidien[day] = problem.Turbine[dayMonth];
dayMonth++;
}
break;
Expand All @@ -429,8 +427,8 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
#ifndef NDEBUG
for (uint day = firstDay; day != endDay; ++day)
{
assert(!Math::NaN(valgen.HydrauliqueModulableQuotidien[day]));
assert(!Math::Infinite(valgen.HydrauliqueModulableQuotidien[day]));
assert(!Math::NaN(ventilationResults.HydrauliqueModulableQuotidien[day]));
assert(!Math::Infinite(ventilationResults.HydrauliqueModulableQuotidien[day]));
}
#endif
}
Expand All @@ -447,16 +445,16 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
double monthInitialLevel = data.MOL[initReservoirLvlMonth];
double wasteFromPreviousMonth = 0.;

Hydro_problem_costs h2o2_optim_costs(study);
Hydro_problem_costs h2o2_optim_costs(parameters_);

for (uint month = 0; month != 12; ++month)
{
uint realmonth = (initReservoirLvlMonth + month) % 12;
uint simulationMonth = study.calendar.mapping.months[realmonth];
uint simulationMonth = calendar_.mapping.months[realmonth];

auto daysPerMonth = study.calendar.months[simulationMonth].days;
auto daysPerMonth = calendar_.months[simulationMonth].days;

uint firstDay = study.calendar.months[simulationMonth].daysYear.first;
uint firstDay = calendar_.months[simulationMonth].daysYear.first;
uint endDay = firstDay + daysPerMonth;

DONNEES_MENSUELLES_ETENDUES& problem = *H2O2_J_Instanciation();
Expand Down Expand Up @@ -506,10 +504,10 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
dayMonth = 0;
for (uint day = firstDay; day != endDay; ++day)
{
valgen.HydrauliqueModulableQuotidien[day]
ventilationResults.HydrauliqueModulableQuotidien[day]
= problem.Turbine[dayMonth] * reservoirCapacity;

valgen.NiveauxReservoirsFinJours[day] = problem.niveauxFinJours[dayMonth];
ventilationResults.NiveauxReservoirsFinJours[day] = problem.niveauxFinJours[dayMonth];

if (debugData)
{
Expand All @@ -521,10 +519,10 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
dayMonth++;
}

valgen.NiveauxReservoirsDebutJours[firstDay] = monthInitialLevel;
ventilationResults.NiveauxReservoirsDebutJours[firstDay] = monthInitialLevel;
for (uint day = firstDay + 1; day != endDay; ++day)
valgen.NiveauxReservoirsDebutJours[day]
= valgen.NiveauxReservoirsFinJours[day - 1];
ventilationResults.NiveauxReservoirsDebutJours[day]
= ventilationResults.NiveauxReservoirsFinJours[day - 1];

monthInitialLevel = problem.niveauxFinJours[dayMonth - 1];

Expand All @@ -542,25 +540,24 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
H2O2_J_Free(&problem);
}

uint firstDaySimu = study.parameters.simulationDays.first;
uint firstDaySimu = parameters_.simulationDays.first;
state.problemeHebdo->previousSimulationFinalLevel[z]
= valgen.NiveauxReservoirsDebutJours[firstDaySimu] * reservoirCapacity;
= ventilationResults.NiveauxReservoirsDebutJours[firstDaySimu] * reservoirCapacity;

if (debugData)
{
debugData->writeDailyDebugData(study.calendar, initReservoirLvlMonth, y, area.name);
debugData->writeDailyDebugData(calendar_, initReservoirLvlMonth, y, area.name);
}
}
}

void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::State& state,
uint y,
uint numSpace,
VAL_GEN_PAR_PAYS& valeursGenereesParPays)
uint numSpace)
{
study.areas.each(
areas_.each(
[&](Data::Area& area) {
prepareDailyOptimalGenerations(state, area, y, numSpace, valeursGenereesParPays);
prepareDailyOptimalGenerations(state, area, y, numSpace);
});
}

Expand Down
Loading