Skip to content

Commit

Permalink
Refactor hydro pmin checks (#1381)
Browse files Browse the repository at this point in the history
* [vcpkg] Use tag 2023.04.15

* Fix cost for short-term storage variables

* Prepare v8.6.1

* Adding tests on v860 in CI

* Set reference results tag (v8.6.1 on simTest)

* Refactor hydro Pmin checks

* Fix test run twice

* Fix build

* Hydro Pmin : remove redundancy in testing conditions

* Hydro Pmin : kind of factorize the useHeuristicTarget for 3 checks

* Hydro Pmin : kind of factorize the followLoadModulations for 2 checks

---------

Co-authored-by: Florian OMNES <[email protected]>
Co-authored-by: Florian Omnes <[email protected]>
  • Loading branch information
3 people authored Sep 21, 2023
1 parent fbaa325 commit f5be0da
Showing 1 changed file with 62 additions and 60 deletions.
122 changes: 62 additions & 60 deletions src/solver/hydro/management/management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ bool HydroManagement::checkMonthlyMinGeneration(uint numSpace, uint tsIndex, con
{
uint realmonth = calendar_.months[month].realmonth;
// Monthly minimum generation <= Monthly inflows for each month
if (area.hydro.followLoadModulations &&
!area.hydro.reservoirManagement &&
data.totalMonthMingen[realmonth] > data.totalMonthInflows[realmonth])
if (data.totalMonthMingen[realmonth] > data.totalMonthInflows[realmonth])
{
logs.error() << "In Area " << area.name << " the minimum generation of "
<< data.totalMonthMingen[realmonth] << " MW in month " << month + 1
Expand All @@ -261,9 +259,7 @@ bool HydroManagement::checkMonthlyMinGeneration(uint numSpace, uint tsIndex, con
bool HydroManagement::checkYearlyMinGeneration(uint numSpace, uint tsIndex, const Data::Area& area) const
{
const auto& data = tmpDataByArea_[numSpace][area.index];
if (area.hydro.followLoadModulations &&
area.hydro.reservoirManagement &&
data.totalYearMingen > data.totalYearInflows)
if (data.totalYearMingen > data.totalYearInflows)
{
// Yearly minimum generation <= Yearly inflows
logs.error() << "In Area " << area.name << " the minimum generation of "
Expand All @@ -276,38 +272,35 @@ bool HydroManagement::checkYearlyMinGeneration(uint numSpace, uint tsIndex, cons

bool HydroManagement::checkWeeklyMinGeneration(uint tsIndex, Data::Area& area) const
{
if (!area.hydro.followLoadModulations)
auto& inflowsmatrix = area.hydro.series->storage;
auto& mingenmatrix = area.hydro.series->mingen;
auto const& srcinflows = inflowsmatrix[tsIndex < inflowsmatrix.width ? tsIndex : 0];
auto const& srcmingen = mingenmatrix[tsIndex < mingenmatrix.width ? tsIndex : 0];
// Weekly minimum generation <= Weekly inflows for each week
for (uint week = 0; week < calendar_.maxWeeksInYear - 1; ++week)
{
auto& inflowsmatrix = area.hydro.series->storage;
auto& mingenmatrix = area.hydro.series->mingen;
auto const& srcinflows = inflowsmatrix[tsIndex < inflowsmatrix.width ? tsIndex : 0];
auto const& srcmingen = mingenmatrix[tsIndex < mingenmatrix.width ? tsIndex : 0];
// Weekly minimum generation <= Weekly inflows for each week
for (uint week = 0; week < calendar_.maxWeeksInYear - 1; ++week)
double totalWeekMingen = 0.0;
double totalWeekInflows = 0.0;
for (uint hour = calendar_.weeks[week].hours.first;
hour < calendar_.weeks[week].hours.end && hour < HOURS_PER_YEAR;
++hour)
{
double totalWeekMingen = 0.0;
double totalWeekInflows = 0.0;
for (uint hour = calendar_.weeks[week].hours.first;
hour < calendar_.weeks[week].hours.end && hour < HOURS_PER_YEAR;
++hour)
{
totalWeekMingen += srcmingen[hour];
}
totalWeekMingen += srcmingen[hour];
}

for (uint day = calendar_.weeks[week].daysYear.first;
day < calendar_.weeks[week].daysYear.end;
++day)
{
totalWeekInflows += srcinflows[day];
}
if (totalWeekMingen > totalWeekInflows)
{
logs.error() << "In Area " << area.name << " the minimum generation of "
<< totalWeekMingen << " MW in week " << week + 1 << " of TS-"
<< tsIndex + 1 << " is incompatible with the inflows of "
<< totalWeekInflows << " MW.";
return false;
}
for (uint day = calendar_.weeks[week].daysYear.first;
day < calendar_.weeks[week].daysYear.end;
++day)
{
totalWeekInflows += srcinflows[day];
}
if (totalWeekMingen > totalWeekInflows)
{
logs.error() << "In Area " << area.name << " the minimum generation of "
<< totalWeekMingen << " MW in week " << week + 1 << " of TS-"
<< tsIndex + 1 << " is incompatible with the inflows of "
<< totalWeekInflows << " MW.";
return false;
}
}
return true;
Expand All @@ -321,30 +314,27 @@ bool HydroManagement::checkHourlyMinGeneration(uint tsIndex, Data::Area& area) c
auto const& maxPower = area.hydro.maxPower;
auto const& maxP = maxPower[Data::PartHydro::genMaxP];

if (!area.hydro.reservoirManagement)
for (uint month = 0; month != 12; ++month)
{
for (uint month = 0; month != 12; ++month)
{
uint realmonth = calendar_.months[month].realmonth;
uint simulationMonth = calendar_.mapping.months[realmonth];
auto daysPerMonth = calendar_.months[simulationMonth].days;
uint firstDay = calendar_.months[simulationMonth].daysYear.first;
uint endDay = firstDay + daysPerMonth;
uint realmonth = calendar_.months[month].realmonth;
uint simulationMonth = calendar_.mapping.months[realmonth];
auto daysPerMonth = calendar_.months[simulationMonth].days;
uint firstDay = calendar_.months[simulationMonth].daysYear.first;
uint endDay = firstDay + daysPerMonth;

for (uint day = firstDay; day != endDay; ++day)
for (uint day = firstDay; day != endDay; ++day)
{
for (uint h = 0; h < 24; ++h)
{
for (uint h = 0; h < 24; ++h)
if (srcmingen[day * 24 + h] > maxP[day])
{
if (srcmingen[day * 24 + h] > maxP[day])
{
logs.error()
<< "In area: " << area.name << " [hourly] minimum generation of "
<< srcmingen[day * 24 + h] << " MW in timestep " << day * 24 + h + 1
<< " of TS-" << tsIndex + 1
<< " is incompatible with the maximum generation of " << maxP[day]
<< " MW.";
return false;
}
logs.error()
<< "In area: " << area.name << " [hourly] minimum generation of "
<< srcmingen[day * 24 + h] << " MW in timestep " << day * 24 + h + 1
<< " of TS-" << tsIndex + 1
<< " is incompatible with the maximum generation of " << maxP[day]
<< " MW.";
return false;
}
}
}
Expand All @@ -361,14 +351,26 @@ bool HydroManagement::checkMinGeneration(uint numSpace)
const auto& ptchro = NumeroChroniquesTireesParPays[numSpace][z];
auto tsIndex = (uint)ptchro.Hydraulique;

if (area.hydro.useHeuristicTarget)
bool useHeuristicTarget = area.hydro.useHeuristicTarget;
bool followLoadModulations = area.hydro.followLoadModulations;
bool reservoirManagement = area.hydro.reservoirManagement;

if (!reservoirManagement)
ret = checkHourlyMinGeneration(tsIndex, area) && ret;

if (!useHeuristicTarget)
return;

if (!followLoadModulations)
{
ret = checkMonthlyMinGeneration(numSpace, tsIndex, area) && ret;
ret = checkYearlyMinGeneration(numSpace, tsIndex, area) && ret;
ret = checkWeeklyMinGeneration(tsIndex, area) && ret;
return;
}

ret = checkHourlyMinGeneration(tsIndex, area) && ret;

if (reservoirManagement)
ret = checkYearlyMinGeneration(numSpace, tsIndex, area) && ret;
else
ret = checkMonthlyMinGeneration(numSpace, tsIndex, area) && ret;
});
return ret;
}
Expand Down

0 comments on commit f5be0da

Please sign in to comment.