Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Jun 11, 2024
1 parent b78e537 commit 4c8a9d8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ enum dayYearCount
dayYearCount = 366
};

// TODO Rename
struct HydroSpecific
{
//! Net demand, for each day of the year, for each area
std::array<double, dayYearCount> DLN;

//! Daily local effective load
std::array<double, dayYearCount> DLE;
};
//! Temporary data
struct HydroManagementData
{
Expand All @@ -51,12 +60,6 @@ struct HydroManagementData
//! monthly minimal generation
std::array<double, 12> mingens;

//! Net demand, for each day of the year, for each area
std::array<double, dayYearCount> DLN;
//! Daily local effective load
std::array<double, dayYearCount> DLE;
//! Daily optimized Generation
std::array<double, dayYearCount> DOG;
//! daily minimal generation
std::array<double, dayYearCount> dailyMinGen;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ class HydroManagement final
//! Prepare the net demand for each area
void prepareNetDemand(uint year,
Data::SimulationMode mode,
const Antares::Data::Area::ScratchMap& scratchmap);
const Antares::Data::Area::ScratchMap& scratchmap,
Antares::Data::HydroSpecific& hydro_specific);
//! Prepare the effective demand for each area
void prepareEffectiveDemand(uint year);
void prepareEffectiveDemand(uint year, Antares::Data::HydroSpecific& hydro_specific);
//! Monthly Optimal generations
void prepareMonthlyOptimalGenerations(double* random_reservoir_level, uint y);

Expand All @@ -94,11 +95,13 @@ class HydroManagement final
Antares::Data::HydroManagementData& data);

void prepareDailyOptimalGenerations(uint y,
Antares::Data::Area::ScratchMap& scratchmap);
Antares::Data::Area::ScratchMap& scratchmap,
Antares::Data::HydroSpecific& hydro_specific);

void prepareDailyOptimalGenerations(Data::Area& area,
uint y,
Antares::Data::Area::ScratchMap& scratchmap);
Antares::Data::Area::ScratchMap& scratchmap,
Antares::Data::HydroSpecific& hydro_specific);

private:
const Data::AreaList& areas_;
Expand Down
33 changes: 20 additions & 13 deletions src/solver/hydro/management/daily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ struct DebugData
const ReservoirLevelType& lowLevel;
const double reservoirCapacity;

const Antares::Data::HydroSpecific& hydro_specific

DebugData(Solver::IResultWriter& writer,
const Antares::Data::HydroManagementData& data,
const VENTILATION_HYDRO_RESULTS_BY_AREA& ventilationResults,
Expand All @@ -110,7 +112,8 @@ struct DebugData
const MaxPowerType& maxE,
const double* dailyTargetGen,
const ReservoirLevelType& lowLevel,
double reservoirCapacity):
double reservoirCapacity,
const Antares::Data::HydroSpecific& hydro_specific):
pWriter(writer),
data(data),
ventilationResults(ventilationResults),
Expand All @@ -119,7 +122,8 @@ struct DebugData
maxE(maxE),
dailyTargetGen(dailyTargetGen),
lowLevel(lowLevel),
reservoirCapacity(reservoirCapacity)
reservoirCapacity(reservoirCapacity),
hydro_specific(hydro_specific)
{
OVF.fill(0);
DEV.fill(0);
Expand All @@ -141,7 +145,7 @@ struct DebugData
{
double value = ventilationResults.HydrauliqueModulableQuotidien[day];
buffer << day << '\t' << value << '\t' << OPP[day] << '\t' << DailyTargetGen[day]
<< '\t' << data.DLE[day] << '\t' << data.DLN[day];
<< '\t' << hydro_specific.DLE[day] << '\t' << hydro_specific.DLN[day];
buffer << '\n';
}
auto buffer_str = buffer.str();
Expand Down Expand Up @@ -219,9 +223,10 @@ struct DebugData
};

inline void HydroManagement::prepareDailyOptimalGenerations(
Data::Area& area,
uint y,
Antares::Data::Area::ScratchMap& scratchmap)
Data::Area& area,
uint y,
Antares::Data::Area::ScratchMap& scratchmap,
Antares::Data::HydroSpecific& hydro_specific)
{
const auto srcinflows = area.hydro.series->storage.getColumn(y);

Expand Down Expand Up @@ -262,7 +267,8 @@ inline void HydroManagement::prepareDailyOptimalGenerations(
maxE,
dailyTargetGen,
lowLevel,
reservoirCapacity);
reservoirCapacity,
hydro_specific);
}

for (uint month = 0; month != 12; ++month)
Expand Down Expand Up @@ -317,9 +323,9 @@ inline void HydroManagement::prepareDailyOptimalGenerations(
for (uint day = 0; day != daysPerMonth; ++day)
{
auto dYear = day + dayYear;
if (data.DLE[dYear] > demandMax)
if (hydro_specific.DLE[dYear] > demandMax)
{
demandMax = data.DLE[dYear];
demandMax = hydro_specific.DLE[dYear];
}
}

Expand All @@ -331,7 +337,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(
for (uint day = 0; day != daysPerMonth; ++day)
{
auto dYear = day + dayYear;
coeff += std::pow(data.DLE[dYear] / demandMax,
coeff += std::pow(hydro_specific.DLE[dYear] / demandMax,
area.hydro.interDailyBreakdown);
}
coeff = data.MOG[realmonth] / coeff;
Expand All @@ -340,7 +346,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(
{
auto dYear = day + dayYear;
dailyTargetGen[dYear] = coeff
* std::pow(data.DLE[dYear] / demandMax,
* std::pow(hydro_specific.DLE[dYear] / demandMax,
area.hydro.interDailyBreakdown);
}
}
Expand Down Expand Up @@ -552,9 +558,10 @@ inline void HydroManagement::prepareDailyOptimalGenerations(
}

void HydroManagement::prepareDailyOptimalGenerations(uint y,
Antares::Data::Area::ScratchMap& scratchmap)
Antares::Data::Area::ScratchMap& scratchmap,
Antares::Data::HydroSpecific& hydro_specific)
{
areas_.each([&](Data::Area& area)
{ prepareDailyOptimalGenerations(area, y, scratchmap); });
{ prepareDailyOptimalGenerations(area, y, scratchmap, hydro_specific); });
}
} // namespace Antares
27 changes: 15 additions & 12 deletions src/solver/hydro/management/management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ HydroManagement::HydroManagement(const Data::AreaList& areas,

void HydroManagement::prepareNetDemand(uint year,
Data::SimulationMode mode,
const Antares::Data::Area::ScratchMap& scratchmap)
const Antares::Data::Area::ScratchMap& scratchmap,
HydroSpecific& hydro_specific)
{
areas_.each(
[this, &year, &scratchmap, &mode](Data::Area& area)
Expand Down Expand Up @@ -191,12 +192,13 @@ void HydroManagement::prepareNetDemand(uint year,

assert(!std::isnan(netdemand)
&& "hydro management: NaN detected when calculating the net demande");
data.DLN[dayYear] += netdemand;
hydro_specific.DLN[dayYear] += netdemand;
}
});
}

void HydroManagement::prepareEffectiveDemand(uint year)
void HydroManagement::prepareEffectiveDemand(uint year,
Antares::Data::HydroSpecific& hydro_specific)
{
areas_.each(
[&](Data::Area& area)
Expand All @@ -215,14 +217,14 @@ void HydroManagement::prepareEffectiveDemand(uint year)
[&](unsigned areaIndex, double value)
{
const auto* area = areas_.byIndex[areaIndex];
effectiveDemand += area->hydro.managementData.at(year).DLN[day] * value;
effectiveDemand += hydro_specific.DLN[day] * value;
});

assert(!std::isnan(effectiveDemand) && "nan value detected for effectiveDemand");
data.DLE[day] += effectiveDemand;
hydro_specific.DLE[day] += effectiveDemand;
data.MLE[realmonth] += effectiveDemand;

assert(not std::isnan(data.DLE[day]) && "nan value detected for DLE");
assert(not std::isnan(hydro_specific.DLE[day]) && "nan value detected for DLE");
assert(not std::isnan(data.MLE[realmonth]) && "nan value detected for DLE");
}

Expand All @@ -238,17 +240,17 @@ void HydroManagement::prepareEffectiveDemand(uint year)
for (uint d = 0; d != daysPerMonth; ++d)
{
auto dYear = d + dayYear;
if (data.DLE[dYear] < minimumMonth)
if (hydro_specific.DLE[dYear] < minimumMonth)
{
minimumMonth = data.DLE[dYear];
minimumMonth = hydro_specific.DLE[dYear];
}
}

if (minimumMonth < 0.)
{
for (uint d = 0; d != daysPerMonth; ++d)
{
data.DLE[dayYear + d] -= minimumMonth - 1e-4;
hydro_specific.DLE[dayYear + d] -= minimumMonth - 1e-4;
}
}

Expand All @@ -274,11 +276,12 @@ void HydroManagement::makeVentilation(double* randomReservoirLevel,
uint y,
Antares::Data::Area::ScratchMap& scratchmap)
{
prepareNetDemand(y, parameters_.mode, scratchmap);
prepareEffectiveDemand(y);
Antares::Data::HydroSpecific hydro_specific;
prepareNetDemand(y, parameters_.mode, scratchmap, hydro_specific);
prepareEffectiveDemand(y, hydro_specific);

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

} // namespace Antares

0 comments on commit 4c8a9d8

Please sign in to comment.