diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index 8c5207dc16..8e9aac07e3 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -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 @@ -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 " @@ -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; @@ -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; } } } @@ -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; }