From ddd1fdc23700aa7ca41f31d136e6c19604ccc329 Mon Sep 17 00:00:00 2001 From: Milos <97689304+Milos-RTEi@users.noreply.github.com> Date: Thu, 28 Sep 2023 14:50:14 +0200 Subject: [PATCH] Update Final reservoir level implementation - cr25 (#1564) * fix - isApplicable * add logs if fin-lvl not applicable * fix - only check active years * fix - failed unit test yearFilter * refactor unit test * improve info log + refactor * CR-25 - add-info : correction after merge from develop --------- Co-authored-by: Guillaume PIERRE --- .../parts/hydro/finallevelinflowsmodifyer.cpp | 17 ++++++++++++++++- .../parts/hydro/finallevelinflowsmodifyer.h | 1 + .../hydro-final-reservoir-level-functions.cpp | 5 +++-- ...st-hydro-final-reservoir-level-functions.cpp | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/libs/antares/study/parts/hydro/finallevelinflowsmodifyer.cpp b/src/libs/antares/study/parts/hydro/finallevelinflowsmodifyer.cpp index 36b6809c98..83648840c0 100644 --- a/src/libs/antares/study/parts/hydro/finallevelinflowsmodifyer.cpp +++ b/src/libs/antares/study/parts/hydro/finallevelinflowsmodifyer.cpp @@ -46,6 +46,7 @@ FinalLevelInflowsModifier::FinalLevelInflowsModifier(const PartHydro& hydro, bool FinalLevelInflowsModifier::CheckInfeasibility(unsigned int year) { ComputeDelta(year); + logInfoFinLvlNotApplicable(year); if (!isActive()) return true; @@ -147,6 +148,20 @@ bool FinalLevelInflowsModifier::isActive() isValidLevel(initialReservoirLevel_); } +// if the user specifies the final reservoir level, but does not specifies initial reservoir level +// or uses wrong hydro options +// we should inform the user that the final reservoir level wont be reached +void FinalLevelInflowsModifier::logInfoFinLvlNotApplicable(unsigned int year) +{ + if (isValidLevel(finalReservoirLevel_) + && (!hydro_.reservoirManagement || hydro_.useWaterValue + || !isValidLevel(initialReservoirLevel_))) + logs.info() << "Final reservoir level not applicable! Year:" << year + 1 + << ", Area:" << areaName_ + << ". Check: Reservoir management = Yes, Use water values = No and proper initial " + "reservoir level is provided "; +} + bool FinalLevelInflowsModifier::makeChecks(unsigned int year) { // Simulation must end on day 365 and reservoir level must be initiated in January @@ -169,7 +184,7 @@ bool FinalLevelInflowsModifier::isApplicable(unsigned int year) { // If isApplicable_.size() == 0, then instance was not properly initialized // and is not applicable. - return isActive() && isApplicable_.size() && isApplicable_.at(year); + return !isApplicable_.empty() && isApplicable_.at(year); } } // namespace Antares::Data diff --git a/src/libs/antares/study/parts/hydro/finallevelinflowsmodifyer.h b/src/libs/antares/study/parts/hydro/finallevelinflowsmodifyer.h index 0c9f3e3708..492c313448 100644 --- a/src/libs/antares/study/parts/hydro/finallevelinflowsmodifyer.h +++ b/src/libs/antares/study/parts/hydro/finallevelinflowsmodifyer.h @@ -59,6 +59,7 @@ class FinalLevelInflowsModifier private: bool isActive(); + void logInfoFinLvlNotApplicable(uint year); void ComputeDelta(unsigned int year); bool makeChecks(unsigned int year); void storeDeltaLevels(unsigned int year); diff --git a/src/solver/simulation/hydro-final-reservoir-level-functions.cpp b/src/solver/simulation/hydro-final-reservoir-level-functions.cpp index 09735e0990..8fada405e0 100644 --- a/src/solver/simulation/hydro-final-reservoir-level-functions.cpp +++ b/src/solver/simulation/hydro-final-reservoir-level-functions.cpp @@ -56,12 +56,13 @@ void CheckFinalReservoirLevelsForYear(const Data::Study& study, uint year) void CheckFinalReservoirLevelsConfiguration(const Data::Study& study) { initializeFinalLevelData(study); - + uint nbYears = study.parameters.nbYears; for (uint year = 0; year != nbYears; ++year) { - CheckFinalReservoirLevelsForYear(study, year); + if (study.parameters.yearsFilter.at(year)) + CheckFinalReservoirLevelsForYear(study, year); } } diff --git a/src/tests/src/solver/simulation/test-hydro-final-reservoir-level-functions.cpp b/src/tests/src/solver/simulation/test-hydro-final-reservoir-level-functions.cpp index 4edf657601..58450ce096 100644 --- a/src/tests/src/solver/simulation/test-hydro-final-reservoir-level-functions.cpp +++ b/src/tests/src/solver/simulation/test-hydro-final-reservoir-level-functions.cpp @@ -55,6 +55,8 @@ struct Fixture // ------------------------------------------------------- uint areasCount = study->areas.size(); + study->parameters.yearsFilter.assign(2, true); + study->scenarioInitialHydroLevels.resize(nbYears, areasCount); study->scenarioFinalHydroLevels.resize(nbYears, areasCount);