From 8abf5711ddccb2d2e490e776322965a17a3e46e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Omn=C3=A8s?= Date: Wed, 26 Jun 2024 11:16:11 +0200 Subject: [PATCH 01/42] Small refactor on hydro final checks (#2192) --- .../include/antares/solver/hydro/management/HydroInputsChecker.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h index f45f1712ca..90536fba7e 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h @@ -23,6 +23,7 @@ #include "antares/date/date.h" #include "antares/solver/hydro/management/MinGenerationScaling.h" #include "antares/solver/hydro/management/PrepareInflows.h" +#include "antares/solver/simulation/hydro-final-reservoir-level-functions.h" #include "antares/study/study.h" namespace Antares { From 899f2c9e5ded4b8fa7f9efb076c6581f54593dea Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Wed, 26 Jun 2024 14:54:53 +0200 Subject: [PATCH 02/42] HydroErrorsCollector --- src/solver/hydro/CMakeLists.txt | 4 +- .../hydro/management/HydroErrorsCollector.h | 69 +++++++++++++++++++ .../hydro/management/HydroErrorsCollector.cpp | 11 +++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h create mode 100644 src/solver/hydro/management/HydroErrorsCollector.cpp diff --git a/src/solver/hydro/CMakeLists.txt b/src/solver/hydro/CMakeLists.txt index 657c52e17a..c306ade18d 100644 --- a/src/solver/hydro/CMakeLists.txt +++ b/src/solver/hydro/CMakeLists.txt @@ -58,8 +58,8 @@ set(SRC_MANAGEMENT management/MinGenerationScaling.cpp include/antares/solver/hydro/management/HydroInputsChecker.h management/HydroInputsChecker.cpp - include/antares/solver/hydro/management/hydro-final-reservoir-level-functions.h - management/hydro-final-reservoir-level-functions.cpp + include/antares/solver/hydro/management/HydroErrorsCollector.h + management/HydroErrorsCollector.cpp ) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h new file mode 100644 index 0000000000..abd429232d --- /dev/null +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -0,0 +1,69 @@ +/* +** Copyright 2007-2024, RTE (https://www.rte-france.com) +** See AUTHORS.txt +** SPDX-License-Identifier: MPL-2.0 +** This file is part of Antares-Simulator, +** Adequacy and Performance assessment for interconnected energy networks. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the Mozilla Public Licence 2.0 as published by +** the Mozilla Foundation, either version 2 of the License, or +** (at your option) any later version. +** +** Antares_Simulator is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** Mozilla Public Licence 2.0 for more details. +** +** You should have received a copy of the Mozilla Public Licence 2.0 +** along with Antares_Simulator. If not, see . +*/ + +#pragma once +#include <> +#include +#include + +#include + +#include + +class HydroErrorsCollector +{ +public: + HydroErrorsCollector() = default; + + // endl + HydroErrorsCollector& operator<<(std::ostream& (*function)(std::ostream&)) + { + function(*stream_); + messages_.push_back(buffer.str()); + return *this; + } + + HydroErrorsCollector& operator<<(const Antares::Data::Area& area) + { + error_counter_per_area_[&area]++; + // 10 par zone ? + flush_ = error_counter_per_area_[&area] > 10; + return *this; + } + template + std::ostream& operator<<(const T& obj); + bool ReadyToFlush() const; + bool ExceptionHasToBeThrown() const; + +private: + std::vector messages_; + std::unordered_map error_counter_per_area_; + bool flush_ = false; +}; + +template +HydroErrorsCollector& HydroErrorsCollector::operator<<(const T& obj) +{ + std::ostringstream buffer; + buffer << obj; + messages_.push_back(buffer.str()); + return *this; +} diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp new file mode 100644 index 0000000000..c1a137b1a9 --- /dev/null +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -0,0 +1,11 @@ +#include "antares/solver/hydro/management/HydroErrorsCollector.h" + +bool HydroErrorsCollector::ReadyToFlush() const +{ + return flush_; +} + +bool HydroErrorsCollector::ExceptionHasToBeThrown() const +{ + return !error_counter_per_area_.empty(); +} From 5cb7f71531d223b00b9c3eed67c8723f416dfe76 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Wed, 26 Jun 2024 15:14:20 +0200 Subject: [PATCH 03/42] update --- .../hydro/management/HydroErrorsCollector.h | 38 ++++++++++++++----- .../hydro/management/HydroErrorsCollector.cpp | 20 ++++++++++ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index abd429232d..c290e86f74 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -24,10 +24,19 @@ #include #include -#include - #include +struct AreaErrors +{ + explicit AreaErrors(const std::string& name); + std::string name_; + uint errors_counter_ = 10; + // const Antares::Data::Area& area_; + std::vector messages_; + + void PrintErrors() const; +} + class HydroErrorsCollector { public: @@ -36,16 +45,21 @@ class HydroErrorsCollector // endl HydroErrorsCollector& operator<<(std::ostream& (*function)(std::ostream&)) { - function(*stream_); - messages_.push_back(buffer.str()); + if (current_area_) + { + std::ostringstream buffer; + function(buffer); + + error_counter_per_area_[current_area_].messages_.push_back(buffer.str()); + } return *this; } HydroErrorsCollector& operator<<(const Antares::Data::Area& area) { - error_counter_per_area_[&area]++; + error_counter_per_area_[&area].errors_counter_++; // 10 par zone ? - flush_ = error_counter_per_area_[&area] > 10; + flush_ = error_counter_per_area_[&area].errors_counter_ > 10; return *this; } template @@ -55,15 +69,19 @@ class HydroErrorsCollector private: std::vector messages_; - std::unordered_map error_counter_per_area_; + std::unordered_map error_counter_per_area_; bool flush_ = false; + Antares::Data::Area* current_area_ = nullptr; }; template HydroErrorsCollector& HydroErrorsCollector::operator<<(const T& obj) { - std::ostringstream buffer; - buffer << obj; - messages_.push_back(buffer.str()); + if (current_area_) + { + std::ostringstream buffer; + buffer << obj; + error_counter_per_area_[current_area_].messages_.push_back(buffer.str()); + } return *this; } diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index c1a137b1a9..217d8137f8 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -1,5 +1,24 @@ #include "antares/solver/hydro/management/HydroErrorsCollector.h" +#include + +AreaErrors::AreaErrors(const std::string& name): + name_(name) +{ +} + +void AreaErrors::PrintErrors() const +{ + if (!messages_.empty()) + { + logs.error() << "In Area " << name_; + for (const auto& msg: messages) + { + logs.error() << msg; + } + } +} + bool HydroErrorsCollector::ReadyToFlush() const { return flush_; @@ -9,3 +28,4 @@ bool HydroErrorsCollector::ExceptionHasToBeThrown() const { return !error_counter_per_area_.empty(); } + From 4a93e61fa9bf0bc0fc9f7fc5388df9ea3a8c2bf4 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 12:32:05 +0200 Subject: [PATCH 04/42] update --- .../hydro/management/HydroErrorsCollector.h | 61 +++------------- .../hydro/management/HydroInputsChecker.h | 8 ++- .../hydro-final-reservoir-level-functions.h | 41 ----------- .../hydro/management/HydroErrorsCollector.cpp | 49 +++++++++---- .../hydro/management/HydroInputsChecker.cpp | 57 +++++++++++++-- .../hydro-final-reservoir-level-functions.cpp | 69 ------------------- .../antares/solver/simulation/solver.hxx | 14 +++- 7 files changed, 111 insertions(+), 188 deletions(-) delete mode 100644 src/solver/hydro/include/antares/solver/hydro/management/hydro-final-reservoir-level-functions.h delete mode 100644 src/solver/hydro/management/hydro-final-reservoir-level-functions.cpp diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index c290e86f74..7137b4c87a 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -20,68 +20,23 @@ */ #pragma once -#include <> #include #include #include -struct AreaErrors -{ - explicit AreaErrors(const std::string& name); - std::string name_; - uint errors_counter_ = 10; - // const Antares::Data::Area& area_; - std::vector messages_; - - void PrintErrors() const; -} - class HydroErrorsCollector { public: HydroErrorsCollector() = default; - - // endl - HydroErrorsCollector& operator<<(std::ostream& (*function)(std::ostream&)) - { - if (current_area_) - { - std::ostringstream buffer; - function(buffer); - - error_counter_per_area_[current_area_].messages_.push_back(buffer.str()); - } - return *this; - } - - HydroErrorsCollector& operator<<(const Antares::Data::Area& area) - { - error_counter_per_area_[&area].errors_counter_++; - // 10 par zone ? - flush_ = error_counter_per_area_[&area].errors_counter_ > 10; - return *this; - } - template - std::ostream& operator<<(const T& obj); - bool ReadyToFlush() const; - bool ExceptionHasToBeThrown() const; + void IncreaseCounterForArea(const Antares::Data::Area* area); + bool StopExecution() const; + bool ErrorsLimitReached() const; + void FatalErrorHit(); + // void RecordFatalErrors(const std::string& msg, uint year); private: - std::vector messages_; - std::unordered_map error_counter_per_area_; - bool flush_ = false; - Antares::Data::Area* current_area_ = nullptr; + std::unordered_map area_errors_counter_; + bool errors_limit_reached_ = false; + // std::vector fatal_errors_; }; - -template -HydroErrorsCollector& HydroErrorsCollector::operator<<(const T& obj) -{ - if (current_area_) - { - std::ostringstream buffer; - buffer << obj; - error_counter_per_area_[current_area_].messages_.push_back(buffer.str()); - } - return *this; -} diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h index 90536fba7e..70d622f221 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h @@ -21,9 +21,9 @@ #pragma once #include #include "antares/date/date.h" +#include "antares/solver/hydro/management/HydroErrorsCollector.h" #include "antares/solver/hydro/management/MinGenerationScaling.h" #include "antares/solver/hydro/management/PrepareInflows.h" -#include "antares/solver/simulation/hydro-final-reservoir-level-functions.h" #include "antares/study/study.h" namespace Antares { @@ -32,7 +32,8 @@ class HydroInputsChecker { public: explicit HydroInputsChecker(Antares::Data::Study& study); - void Execute(uint year); + bool Execute(uint year); + bool StopExecution() const; private: Data::AreaList& areas_; @@ -45,6 +46,7 @@ class HydroInputsChecker MinGenerationScaling minGenerationScaling_; const Data::TimeSeries::TS& scenarioInitialHydroLevels_; const Data::TimeSeries::TS& scenarioFinalHydroLevels_; + HydroErrorsCollector errorCollector_; //! return false if checkGenerationPowerConsistency or checkMinGeneration returns false bool checkMonthlyMinGeneration(uint year, const Data::Area& area) const; @@ -58,6 +60,8 @@ class HydroInputsChecker bool checksOnGenerationPowerBounds(uint year) const; //! check minimum generation is lower than available inflows bool checkMinGeneration(uint year) const; + + void CheckFinalReservoirLevelsConfiguration(uint year); }; } // namespace Antares diff --git a/src/solver/hydro/include/antares/solver/hydro/management/hydro-final-reservoir-level-functions.h b/src/solver/hydro/include/antares/solver/hydro/management/hydro-final-reservoir-level-functions.h deleted file mode 100644 index 9ded556947..0000000000 --- a/src/solver/hydro/include/antares/solver/hydro/management/hydro-final-reservoir-level-functions.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -** Copyright 2007-2023 RTE -** Authors: RTE-international / Redstork / Antares_Simulator Team -** -** This file is part of Antares_Simulator. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** There are special exceptions to the terms and conditions of the -** license as they are applied to this software. View the full text of -** the exceptions in file COPYING.txt in the directory of this software -** distribution -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Antares_Simulator. If not, see . -** -** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions -*/ -#ifndef __SOLVER_SIMULATION_HYDRO_FINAL_RESERVOIR_PRE_CHECKS_H__ -#define __SOLVER_SIMULATION_HYDRO_FINAL_RESERVOIR_PRE_CHECKS_H__ - -#include "antares/study/study.h" - -namespace Antares::Solver -{ -void CheckFinalReservoirLevelsConfiguration(Data::AreaList& areas, - const Data::Parameters& parameters, - const Data::TimeSeries::TS& scenarioInitialHydroLevels, - const Data::TimeSeries::TS& scenarioFinalHydroLevels, - uint year); -} // namespace Antares::Solver - -#endif // __SOLVER_SIMULATION_HYDRO_FINAL_RESERVOIR_PRE_CHECKS_H__ diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index 217d8137f8..e1f1994cbc 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -2,30 +2,49 @@ #include -AreaErrors::AreaErrors(const std::string& name): - name_(name) +void HydroErrorsCollector::IncreaseCounterForArea(const Antares::Data::Area* area) { + if (stop && !area) + { + return; + } + + area_errors_counter_[area]++; + errors_limit_reached_ = area_errors_counter_[area] > 10; + stop_ = true; } -void AreaErrors::PrintErrors() const +bool HydroErrorsCollector::ErrorsLimitReached() const { - if (!messages_.empty()) - { - logs.error() << "In Area " << name_; - for (const auto& msg: messages) - { - logs.error() << msg; - } - } + return errors_limit_reached_; } -bool HydroErrorsCollector::ReadyToFlush() const +bool HydroErrorsCollector::StopExecution() const { - return flush_; + return stop_ || errors_limit_reached_; } -bool HydroErrorsCollector::ExceptionHasToBeThrown() const +void HydroErrorsCollector::FatalErrorHit() { - return !error_counter_per_area_.empty(); + stop_ = true; } +// void HydroErrorsCollector::RecordFatalErrors(const std::string& msg, uint year) +// { +// fatal_errors_.push_back("In year " + std::to_string(year) + " " + msg); +// } + +// void HydroErrorsCollector::RecordFatalErrors(const std::string& msg, +// uint year, +// const Antares::Data::Area* area) +// { +// fatal_errors_.push_back("In area " + area.name + " " + std::to_string(year) + " " + msg); +// } + +// void HydroErrorsCollector::PrintFatalsErrors() const +// { +// for (const auto& msg: fatal_errors) +// { +// logs.error() << msg; +// } +// } diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index 613e760f74..acf5d6ccb6 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -28,7 +28,7 @@ #include "antares/solver/hydro/monthly/h2o_m_donnees_annuelles.h" #include "antares/solver/hydro/monthly/h2o_m_fonctions.h" #include "antares/solver/simulation/common-eco-adq.h" - +#include "antares/study/parts/hydro/finalLevelValidator.h" namespace Antares { @@ -46,19 +46,20 @@ HydroInputsChecker::HydroInputsChecker(Antares::Data::Study& study): { } -void HydroInputsChecker::Execute(uint year) +bool HydroInputsChecker::Execute(uint year) { prepareInflows_.Run(year); minGenerationScaling_.Run(year); - if (!checksOnGenerationPowerBounds(year)) { - throw FatalError("hydro inputs checks: invalid minimum generation"); + errorCollector_.FatalErrorHit(); + logs.error() << "hydro inputs checks: invalid minimum generation"; } if (parameters_.useCustomScenario) { - CheckFinalReservoirLevelsConfiguration(areas_, parameters_, scenarioInitialHydroLevels_, scenarioFinalHydroLevels_, year); + CheckFinalReservoirLevelsConfiguration(year); } + return !errorCollector_.ErrorsLimitReached(); } bool HydroInputsChecker::checksOnGenerationPowerBounds(uint year) const @@ -123,6 +124,7 @@ bool HydroInputsChecker::checkWeeklyMinGeneration(uint year, const Data::Area& a } if (totalWeekMingen > totalWeekInflows) { + errorCollector_.IncreaseCounterForArea(&area); logs.error() << "In Area " << area.name << " the minimum generation of " << totalWeekMingen << " MW in week " << week + 1 << " of TS-" << area.hydro.series->mingen.getSeriesIndex(year) + 1 @@ -138,6 +140,7 @@ bool HydroInputsChecker::checkYearlyMinGeneration(uint year, const Data::Area& a const auto& data = area.hydro.managementData.at(year); if (data.totalYearMingen > data.totalYearInflows) { + errorCollector_.IncreaseCounterForArea(&area); // Yearly minimum generation <= Yearly inflows logs.error() << "In Area " << area.name << " the minimum generation of " << data.totalYearMingen << " MW of TS-" @@ -148,7 +151,7 @@ bool HydroInputsChecker::checkYearlyMinGeneration(uint year, const Data::Area& a return true; } -bool HydroInputsChecker::checkMonthlyMinGeneration(uint year, const Data::Area& area) const +void HydroInputsChecker::checkMonthlyMinGeneration(uint year, const Data::Area& area) const { const auto& data = area.hydro.managementData.at(year); for (uint month = 0; month != 12; ++month) @@ -157,6 +160,7 @@ bool HydroInputsChecker::checkMonthlyMinGeneration(uint year, const Data::Area& // Monthly minimum generation <= Monthly inflows for each month if (data.totalMonthMingen[realmonth] > data.totalMonthInflows[realmonth]) { + errorCollector_.IncreaseCounterForArea(&area); logs.error() << "In Area " << area.name << " the minimum generation of " << data.totalMonthMingen[realmonth] << " MW in month " << month + 1 << " of TS-" << area.hydro.series->mingen.getSeriesIndex(year) + 1 @@ -188,6 +192,7 @@ bool HydroInputsChecker::checkGenerationPowerConsistency(uint year) const if (max < min) { + errorCollector_.IncreaseCounterForArea(&area); logs.error() << "In area: " << area.name << " [hourly] minimum generation of " << min << " MW in timestep " << h + 1 << " of TS-" << tsIndexMin + 1 << " is incompatible with the maximum generation of " << max @@ -201,4 +206,44 @@ bool HydroInputsChecker::checkGenerationPowerConsistency(uint year) const return ret; } + +void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) +{ + if (!parameters.yearsFilter.at(year)) + { + return; + } + + areas.each( + [&areas_, ¶meters_, &scenarioInitialHydroLevels_, &scenarioFinalHydroLevels_, year]( + Data::Area& area) + { + double initialLevel = scenarioInitialHydroLevels.entry[area.index][year]; + double finalLevel = scenarioFinalHydroLevels.entry[area.index][year]; + + Data::FinalLevelValidator validator(area.hydro, + area.index, + area.name, + initialLevel, + finalLevel, + year, + parameters.simulationDays.end, + parameters.firstMonthInYear); + if (!validator.check()) + { + errorCollector_.FatalErrorHit(); + logs.error() << "hydro final level : infeasibility"; + } + if (validator.finalLevelFineForUse()) + { + area.hydro.deltaBetweenFinalAndInitialLevels[year] = finalLevel - initialLevel; + } + }); +} // End function CheckFinalReservoirLevelsConfiguration + +bool HydroInputsChecker::StopExecution() const +{ + return errorCollector_.StopExecution(); +} + } // namespace Antares diff --git a/src/solver/hydro/management/hydro-final-reservoir-level-functions.cpp b/src/solver/hydro/management/hydro-final-reservoir-level-functions.cpp deleted file mode 100644 index 3aa1d7e426..0000000000 --- a/src/solver/hydro/management/hydro-final-reservoir-level-functions.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* -** Copyright 2007-2023 RTE -** Authors: RTE-international / Redstork / Antares_Simulator Team -** -** This file is part of Antares_Simulator. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** There are special exceptions to the terms and conditions of the -** license as they are applied to this software. View the full text of -** the exceptions in file COPYING.txt in the directory of this software -** distribution -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Antares_Simulator. If not, see . -** -** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions -*/ - -#include "antares/solver/hydro/management/hydro-final-reservoir-level-functions.h" - -#include -#include "antares/study/parts/hydro/finalLevelValidator.h" - -namespace Antares::Solver -{ - -void CheckFinalReservoirLevelsConfiguration(Data::AreaList& areas, - const Data::Parameters& parameters, - const Data::TimeSeries::TS& scenarioInitialHydroLevels, - const Data::TimeSeries::TS& scenarioFinalHydroLevels, - uint year) -{ - if (!parameters.yearsFilter.at(year)) - return; - - areas.each([&areas, ¶meters, &scenarioInitialHydroLevels, &scenarioFinalHydroLevels, year](Data::Area &area) - { - double initialLevel = scenarioInitialHydroLevels.entry[area.index][year]; - double finalLevel = scenarioFinalHydroLevels.entry[area.index][year]; - - Data::FinalLevelValidator validator(area.hydro, - area.index, - area.name, - initialLevel, - finalLevel, - year, - parameters.simulationDays.end, - parameters.firstMonthInYear); - if (!validator.check()) - { - throw FatalError("hydro final level : infeasibility"); - } - if (validator.finalLevelFineForUse()) - { - area.hydro.deltaBetweenFinalAndInitialLevels[year] = finalLevel - initialLevel; - } - }); -} // End function CheckFinalReservoirLevelsConfiguration - -} // namespace Antares::Solver diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.hxx b/src/solver/simulation/include/antares/solver/simulation/solver.hxx index 093cb1e350..de4efd75e8 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.hxx +++ b/src/solver/simulation/include/antares/solver/simulation/solver.hxx @@ -973,10 +973,17 @@ void ISimulation::loopThroughYears(uint firstYear, } for (auto year: batch.yearsIndices) { - hydroInputsChecker.Execute(year); + if (!hydroInputsChecker.Execute(year)) + { + throw FatalError("Hydro input validation has failed!"); + } } } + if (hydroInputsChecker.StopExecution()) + { + throw FatalError("Hydro input validation has failed!"); + } logs.info() << " Starting the simulation"; // Loop over sets of parallel years to run the simulation @@ -999,7 +1006,10 @@ void ISimulation::loopThroughYears(uint firstYear, for (auto y: batch.yearsIndices) { // for each year not handled earlier - hydroInputsChecker.Execute(y); + if (!hydroInputsChecker.Execute(y) || hydroInputsChecker.StopExecution()) + { + throw FatalError("Hydro input validation has failed!"); + } bool performCalculations = batch.isYearPerformed[y]; unsigned int numSpace = 999999; if (performCalculations) From e1b27941b08f3724b5cd4a9468bc40c9234869c1 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 12:35:19 +0200 Subject: [PATCH 05/42] update --- src/solver/hydro/management/HydroErrorsCollector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index e1f1994cbc..79f114a327 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -4,7 +4,7 @@ void HydroErrorsCollector::IncreaseCounterForArea(const Antares::Data::Area* area) { - if (stop && !area) + if (errors_limit_reached_ || !area) { return; } From b0952f895baa092cdbbf49a27cf02fab1c6e8ab4 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 12:38:25 +0200 Subject: [PATCH 06/42] fix --- .../antares/solver/hydro/management/HydroErrorsCollector.h | 1 + src/solver/hydro/management/HydroErrorsCollector.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index 7137b4c87a..22e2f1d255 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -38,5 +38,6 @@ class HydroErrorsCollector private: std::unordered_map area_errors_counter_; bool errors_limit_reached_ = false; + bool stop_ = false; // std::vector fatal_errors_; }; diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index 79f114a327..b3b45ee363 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -10,7 +10,7 @@ void HydroErrorsCollector::IncreaseCounterForArea(const Antares::Data::Area* are } area_errors_counter_[area]++; - errors_limit_reached_ = area_errors_counter_[area] > 10; + errors_limit_reached_ = area_errors_counter_[area] > 10 || errors_limit_reached_; stop_ = true; } From 082860eb910b72b13c68f14eefd5429e6ba78569 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 12:40:01 +0200 Subject: [PATCH 07/42] logic --- src/solver/hydro/management/HydroInputsChecker.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index acf5d6ccb6..93a3e4cf87 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -24,7 +24,6 @@ #include #include "antares/antares/fatal-error.h" -#include "antares/solver/hydro/management/hydro-final-reservoir-level-functions.h" #include "antares/solver/hydro/monthly/h2o_m_donnees_annuelles.h" #include "antares/solver/hydro/monthly/h2o_m_fonctions.h" #include "antares/solver/simulation/common-eco-adq.h" From a78dfc4f01cec9c6a06fa6990e1b94e78a5e34dd Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 12:52:56 +0200 Subject: [PATCH 08/42] update --- .../hydro/management/HydroInputsChecker.h | 12 ++++---- .../hydro/management/HydroInputsChecker.cpp | 29 +++++++++---------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h index 70d622f221..e970e01216 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h @@ -49,17 +49,17 @@ class HydroInputsChecker HydroErrorsCollector errorCollector_; //! return false if checkGenerationPowerConsistency or checkMinGeneration returns false - bool checkMonthlyMinGeneration(uint year, const Data::Area& area) const; + bool checkMonthlyMinGeneration(uint year, const Data::Area& area); //! check Yearly minimum generation is lower than available inflows - bool checkYearlyMinGeneration(uint year, const Data::Area& area) const; + bool checkYearlyMinGeneration(uint year, const Data::Area& area); //! check Weekly minimum generation is lower than available inflows - bool checkWeeklyMinGeneration(uint year, const Data::Area& area) const; + bool checkWeeklyMinGeneration(uint year, const Data::Area& area); //! check Hourly minimum generation is lower than available inflows - bool checkGenerationPowerConsistency(uint year) const; + bool checkGenerationPowerConsistency(uint year); //! return false if checkGenerationPowerConsistency or checkMinGeneration returns false - bool checksOnGenerationPowerBounds(uint year) const; + bool checksOnGenerationPowerBounds(uint year); //! check minimum generation is lower than available inflows - bool checkMinGeneration(uint year) const; + bool checkMinGeneration(uint year); void CheckFinalReservoirLevelsConfiguration(uint year); }; diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index 93a3e4cf87..b57077124d 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -61,12 +61,12 @@ bool HydroInputsChecker::Execute(uint year) return !errorCollector_.ErrorsLimitReached(); } -bool HydroInputsChecker::checksOnGenerationPowerBounds(uint year) const +bool HydroInputsChecker::checksOnGenerationPowerBounds(uint year) { return checkMinGeneration(year) && checkGenerationPowerConsistency(year); } -bool HydroInputsChecker::checkMinGeneration(uint year) const +bool HydroInputsChecker::checkMinGeneration(uint year) { bool ret = true; areas_.each( @@ -99,7 +99,7 @@ bool HydroInputsChecker::checkMinGeneration(uint year) const return ret; } -bool HydroInputsChecker::checkWeeklyMinGeneration(uint year, const Data::Area& area) const +bool HydroInputsChecker::checkWeeklyMinGeneration(uint year, const Data::Area& area) { const auto& srcinflows = area.hydro.series->storage.getColumn(year); const auto& srcmingen = area.hydro.series->mingen.getColumn(year); @@ -134,7 +134,7 @@ bool HydroInputsChecker::checkWeeklyMinGeneration(uint year, const Data::Area& a return true; } -bool HydroInputsChecker::checkYearlyMinGeneration(uint year, const Data::Area& area) const +bool HydroInputsChecker::checkYearlyMinGeneration(uint year, const Data::Area& area) { const auto& data = area.hydro.managementData.at(year); if (data.totalYearMingen > data.totalYearInflows) @@ -150,7 +150,7 @@ bool HydroInputsChecker::checkYearlyMinGeneration(uint year, const Data::Area& a return true; } -void HydroInputsChecker::checkMonthlyMinGeneration(uint year, const Data::Area& area) const +bool HydroInputsChecker::checkMonthlyMinGeneration(uint year, const Data::Area& area) { const auto& data = area.hydro.managementData.at(year); for (uint month = 0; month != 12; ++month) @@ -171,12 +171,12 @@ void HydroInputsChecker::checkMonthlyMinGeneration(uint year, const Data::Area& return true; } -bool HydroInputsChecker::checkGenerationPowerConsistency(uint year) const +bool HydroInputsChecker::checkGenerationPowerConsistency(uint year) { bool ret = true; areas_.each( - [&ret, &year](const Data::Area& area) + [this, &ret, &year](const Data::Area& area) { const auto& srcmingen = area.hydro.series->mingen.getColumn(year); const auto& srcmaxgen = area.hydro.series->maxHourlyGenPower.getColumn(year); @@ -208,17 +208,16 @@ bool HydroInputsChecker::checkGenerationPowerConsistency(uint year) const void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) { - if (!parameters.yearsFilter.at(year)) + if (!parameters_.yearsFilter.at(year)) { return; } - areas.each( - [&areas_, ¶meters_, &scenarioInitialHydroLevels_, &scenarioFinalHydroLevels_, year]( - Data::Area& area) + areas_.each( + [this, year](Data::Area& area) { - double initialLevel = scenarioInitialHydroLevels.entry[area.index][year]; - double finalLevel = scenarioFinalHydroLevels.entry[area.index][year]; + double initialLevel = scenarioInitialHydroLevels_.entry[area.index][year]; + double finalLevel = scenarioFinalHydroLevels_.entry[area.index][year]; Data::FinalLevelValidator validator(area.hydro, area.index, @@ -226,8 +225,8 @@ void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) initialLevel, finalLevel, year, - parameters.simulationDays.end, - parameters.firstMonthInYear); + parameters_.simulationDays.end, + parameters_.firstMonthInYear); if (!validator.check()) { errorCollector_.FatalErrorHit(); From 63d6bb63689d960b478e170a5f3c352b8722ba52 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 14:23:37 +0200 Subject: [PATCH 09/42] fix --- .../solver/hydro/management/HydroInputsChecker.h | 3 +-- .../test-hydro-final-reservoir-level-functions.cpp | 12 +++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h index e970e01216..0abbb61233 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h @@ -34,6 +34,7 @@ class HydroInputsChecker explicit HydroInputsChecker(Antares::Data::Study& study); bool Execute(uint year); bool StopExecution() const; + void CheckFinalReservoirLevelsConfiguration(uint year); private: Data::AreaList& areas_; @@ -60,8 +61,6 @@ class HydroInputsChecker bool checksOnGenerationPowerBounds(uint year); //! check minimum generation is lower than available inflows bool checkMinGeneration(uint year); - - void CheckFinalReservoirLevelsConfiguration(uint year); }; } // namespace Antares 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 70e4b62357..fda0b86a9a 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 @@ -8,7 +8,7 @@ #include -#include "include/antares/solver/hydro/management/hydro-final-reservoir-level-functions.h" +#include "include/antares/solver/hydro/management/HydroInputsChecker.h" #include "include/antares/study/parts/hydro/finalLevelValidator.h" using namespace Antares::Solver; @@ -258,13 +258,11 @@ BOOST_AUTO_TEST_CASE(final_level_unreachable_because_of_too_few_inflows___check_ BOOST_AUTO_TEST_CASE(check_all_areas_final_levels_when_config_is_ok___all_checks_succeed) { - for (uint year : {0, 1}) + HydroInputsChecker hydro_input_checker(study); + + for (uint year: {0, 1}) { - CheckFinalReservoirLevelsConfiguration(study->areas, - study->parameters, - study->scenarioInitialHydroLevels, - study->scenarioFinalHydroLevels, - year); + hydro_input_checker.CheckFinalReservoirLevelsConfiguration(year); } // CheckFinalReservoirLevelsConfiguration(*study, 0); // CheckFinalReservoirLevelsConfiguration(*study, 1); From fd387a0e5ffaafe5471cdee1162069ab0efe4068 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 14:36:18 +0200 Subject: [PATCH 10/42] fix test --- .../simulation/test-hydro-final-reservoir-level-functions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fda0b86a9a..80d53b1057 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 @@ -258,7 +258,7 @@ BOOST_AUTO_TEST_CASE(final_level_unreachable_because_of_too_few_inflows___check_ BOOST_AUTO_TEST_CASE(check_all_areas_final_levels_when_config_is_ok___all_checks_succeed) { - HydroInputsChecker hydro_input_checker(study); + HydroInputsChecker hydro_input_checker(*study); for (uint year: {0, 1}) { From bb397bb1f4d605034ced4e64082c910ad617e24e Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 14:36:58 +0200 Subject: [PATCH 11/42] fix app From b1f086fc241330017656377f56b5a93041a81aca Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 16:00:27 +0200 Subject: [PATCH 12/42] update --- .../antares/solver/hydro/management/HydroInputsChecker.h | 3 --- src/solver/hydro/management/HydroInputsChecker.cpp | 3 --- 2 files changed, 6 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h index 0abbb61233..c2315996c4 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h @@ -40,9 +40,6 @@ class HydroInputsChecker Data::AreaList& areas_; const Data::Parameters& parameters_; const Date::Calendar& calendar_; - Data::SimulationMode simulationMode_; - const uint firstYear_; - const uint endYear_; PrepareInflows prepareInflows_; MinGenerationScaling minGenerationScaling_; const Data::TimeSeries::TS& scenarioInitialHydroLevels_; diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index b57077124d..a2ee7bebf8 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -35,9 +35,6 @@ HydroInputsChecker::HydroInputsChecker(Antares::Data::Study& study): areas_(study.areas), parameters_(study.parameters), calendar_(study.calendar), - simulationMode_(study.runtime->mode), - firstYear_(0), - endYear_(1 + study.runtime->rangeLimits.year[Data::rangeEnd]), prepareInflows_(study.areas, study.calendar), minGenerationScaling_(study.areas, study.calendar), scenarioInitialHydroLevels_(study.scenarioInitialHydroLevels), From 094ca3850e3c7131944e4f12817743517934444a Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 16:31:13 +0200 Subject: [PATCH 13/42] update --- src/libs/antares/study/CMakeLists.txt | 2 -- src/solver/hydro/CMakeLists.txt | 2 ++ .../hydro/management}/finalLevelValidator.h | 13 +++++++-- .../hydro/management/HydroInputsChecker.cpp | 5 ++-- .../hydro/management}/finalLevelValidator.cpp | 6 ++-- ...-hydro-final-reservoir-level-functions.cpp | 28 +++++++++++++------ 6 files changed, 38 insertions(+), 18 deletions(-) rename src/{libs/antares/study/include/antares/study/parts/hydro => solver/hydro/include/antares/solver/hydro/management}/finalLevelValidator.h (93%) rename src/{libs/antares/study/parts/hydro => solver/hydro/management}/finalLevelValidator.cpp (96%) diff --git a/src/libs/antares/study/CMakeLists.txt b/src/libs/antares/study/CMakeLists.txt index 65ad5398a6..3ec77caaed 100644 --- a/src/libs/antares/study/CMakeLists.txt +++ b/src/libs/antares/study/CMakeLists.txt @@ -122,8 +122,6 @@ set(SRC_STUDY_PART_HYDRO include/antares/study/parts/hydro/allocation.h include/antares/study/parts/hydro/allocation.hxx parts/hydro/allocation.cpp - include/antares/study/parts/hydro/finalLevelValidator.h - parts/hydro/finalLevelValidator.cpp include/antares/study/parts/hydro/hydromaxtimeseriesreader.h parts/hydro/hydromaxtimeseriesreader.cpp ) diff --git a/src/solver/hydro/CMakeLists.txt b/src/solver/hydro/CMakeLists.txt index c306ade18d..3ba25e80d4 100644 --- a/src/solver/hydro/CMakeLists.txt +++ b/src/solver/hydro/CMakeLists.txt @@ -60,6 +60,8 @@ set(SRC_MANAGEMENT management/HydroInputsChecker.cpp include/antares/solver/hydro/management/HydroErrorsCollector.h management/HydroErrorsCollector.cpp + include/antares/solver/hydro/management/finalLevelValidator.h + management/finalLevelValidator.cpp ) diff --git a/src/libs/antares/study/include/antares/study/parts/hydro/finalLevelValidator.h b/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h similarity index 93% rename from src/libs/antares/study/include/antares/study/parts/hydro/finalLevelValidator.h rename to src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h index 518e29d40b..09bee08835 100644 --- a/src/libs/antares/study/include/antares/study/parts/hydro/finalLevelValidator.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h @@ -28,10 +28,15 @@ #include "antares/study/parts/hydro/container.h" -namespace Antares::Data +namespace Antares +{ +namespace Data { class PartHydro; +} +namespace Solver +{ class FinalLevelValidator { public: @@ -69,5 +74,9 @@ class FinalLevelValidator double finalLevel_; bool finalLevelFineForUse_ = false; + + // area input errors + HydroErrorsCollector& errorCollector_; }; -} // namespace Antares::Data +} // namespace Solver +} // namespace Antares diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index a2ee7bebf8..ae68f7132c 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -24,10 +24,10 @@ #include #include "antares/antares/fatal-error.h" +#include "antares/solver/hydro/management/finalLevelValidator.h" #include "antares/solver/hydro/monthly/h2o_m_donnees_annuelles.h" #include "antares/solver/hydro/monthly/h2o_m_fonctions.h" #include "antares/solver/simulation/common-eco-adq.h" -#include "antares/study/parts/hydro/finalLevelValidator.h" namespace Antares { @@ -223,7 +223,8 @@ void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) finalLevel, year, parameters_.simulationDays.end, - parameters_.firstMonthInYear); + parameters_.firstMonthInYear, + errorCollector_); if (!validator.check()) { errorCollector_.FatalErrorHit(); diff --git a/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp b/src/solver/hydro/management/finalLevelValidator.cpp similarity index 96% rename from src/libs/antares/study/parts/hydro/finalLevelValidator.cpp rename to src/solver/hydro/management/finalLevelValidator.cpp index c3ea96ca08..0de138ffb0 100644 --- a/src/libs/antares/study/parts/hydro/finalLevelValidator.cpp +++ b/src/solver/hydro/management/finalLevelValidator.cpp @@ -25,12 +25,12 @@ ** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions */ -#include "antares/study/parts/hydro/finalLevelValidator.h" +#include "antares/solver/hydro/management/finalLevelValidator.h" -namespace Antares::Data +namespace Antares::Solver { -FinalLevelValidator::FinalLevelValidator(PartHydro& hydro, +FinalLevelValidator::FinalLevelValidator(Antares::Data::PartHydro& hydro, unsigned int areaIndex, const AreaName areaName, // gp : to std::string double initialLevel, 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 80d53b1057..343f7b79f9 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 @@ -7,9 +7,10 @@ #include #include +#include "antares/solver/hydro/management/HydroErrorsCollector.h" +#include "antares/solver/hydro/management/finalLevelValidator.h" #include "include/antares/solver/hydro/management/HydroInputsChecker.h" -#include "include/antares/study/parts/hydro/finalLevelValidator.h" using namespace Antares::Solver; using namespace Antares::Data; @@ -106,6 +107,7 @@ struct Fixture Study::Ptr study = std::make_shared(); Area* area_1; Area* area_2; + HydroErrorsCollector hydro_errors_collector; }; BOOST_FIXTURE_TEST_SUITE(final_level_validator, Fixture) @@ -120,7 +122,8 @@ BOOST_AUTO_TEST_CASE(all_parameters_good___check_succeeds_and_final_level_is_usa study->scenarioFinalHydroLevels[area_1->index][year], year, study->parameters.simulationDays.end, - study->parameters.firstMonthInYear); + study->parameters.firstMonthInYear, + hydro_errors_collector); BOOST_CHECK_EQUAL(validator.check(), true); BOOST_CHECK_EQUAL(validator.finalLevelFineForUse(), true); @@ -137,7 +140,8 @@ BOOST_AUTO_TEST_CASE(no_reservoir_management___check_succeeds_but_final_level_no study->scenarioFinalHydroLevels[area_1->index][year], year, study->parameters.simulationDays.end, - study->parameters.firstMonthInYear); + study->parameters.firstMonthInYear, + hydro_errors_collector); BOOST_CHECK_EQUAL(validator.check(), true); BOOST_CHECK_EQUAL(validator.finalLevelFineForUse(), false); @@ -155,7 +159,8 @@ BOOST_AUTO_TEST_CASE(use_water_value_is_true___check_succeeds_but_final_level_no study->scenarioFinalHydroLevels[area_1->index][year], year, study->parameters.simulationDays.end, - study->parameters.firstMonthInYear); + study->parameters.firstMonthInYear, + hydro_errors_collector); BOOST_CHECK_EQUAL(validator.check(), true); BOOST_CHECK_EQUAL(validator.finalLevelFineForUse(), false); @@ -173,7 +178,8 @@ BOOST_AUTO_TEST_CASE(final_level_not_set_by_user____check_succeeds_but_final_lev study->scenarioFinalHydroLevels[area_1->index][year], year, study->parameters.simulationDays.end, - study->parameters.firstMonthInYear); + study->parameters.firstMonthInYear, + hydro_errors_collector); BOOST_CHECK_EQUAL(validator.check(), true); BOOST_CHECK_EQUAL(validator.finalLevelFineForUse(), false); @@ -191,7 +197,8 @@ BOOST_AUTO_TEST_CASE(initial_level_month_and_simulation_first_month_different___ study->scenarioFinalHydroLevels[area_1->index][year], year, study->parameters.simulationDays.end, - study->parameters.firstMonthInYear); + study->parameters.firstMonthInYear, + hydro_errors_collector); BOOST_CHECK_EQUAL(validator.check(), false); BOOST_CHECK_EQUAL(validator.finalLevelFineForUse(), false); @@ -209,7 +216,8 @@ BOOST_AUTO_TEST_CASE(simulation_does_last_a_whole_year___check_fails_and_final_l study->scenarioFinalHydroLevels[area_1->index][year], year, study->parameters.simulationDays.end, - study->parameters.firstMonthInYear); + study->parameters.firstMonthInYear, + hydro_errors_collector); BOOST_CHECK_EQUAL(validator.check(), false); BOOST_CHECK_EQUAL(validator.finalLevelFineForUse(), false); @@ -228,7 +236,8 @@ BOOST_AUTO_TEST_CASE(final_level_out_of_rule_curves___check_fails_and_final_leve study->scenarioFinalHydroLevels[area_1->index][year], year, study->parameters.simulationDays.end, - study->parameters.firstMonthInYear); + study->parameters.firstMonthInYear, + hydro_errors_collector); BOOST_CHECK_EQUAL(validator.check(), false); BOOST_CHECK_EQUAL(validator.finalLevelFineForUse(), false); @@ -250,7 +259,8 @@ BOOST_AUTO_TEST_CASE(final_level_unreachable_because_of_too_few_inflows___check_ study->scenarioFinalHydroLevels[area_1->index][year], year, study->parameters.simulationDays.end, - study->parameters.firstMonthInYear); + study->parameters.firstMonthInYear, + hydro_errors_collector); BOOST_CHECK_EQUAL(validator.check(), false); BOOST_CHECK_EQUAL(validator.finalLevelFineForUse(), false); From 1939315e89d6e57894173c4373710a496e848fcf Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 16:32:40 +0200 Subject: [PATCH 14/42] add param --- .../solver/hydro/management/finalLevelValidator.h | 3 ++- .../hydro/management/finalLevelValidator.cpp | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h b/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h index 09bee08835..7362a0e967 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h @@ -47,7 +47,8 @@ class FinalLevelValidator double finalLevel, const unsigned int year, const unsigned int lastSimulationDay, - const unsigned int firstMonthOfSimulation); + const unsigned int firstMonthOfSimulation, + HydroErrorsCollector& errorCollector); bool check(); bool finalLevelFineForUse(); diff --git a/src/solver/hydro/management/finalLevelValidator.cpp b/src/solver/hydro/management/finalLevelValidator.cpp index 0de138ffb0..ff7fbc93b2 100644 --- a/src/solver/hydro/management/finalLevelValidator.cpp +++ b/src/solver/hydro/management/finalLevelValidator.cpp @@ -37,15 +37,17 @@ FinalLevelValidator::FinalLevelValidator(Antares::Data::PartHydro& hydro, double finalLevel, const unsigned int year, const unsigned int lastSimulationDay, - const unsigned int firstMonthOfSimulation) : - year_(year), - lastSimulationDay_(lastSimulationDay), - firstMonthOfSimulation_(firstMonthOfSimulation), + const unsigned int firstMonthOfSimulation, + HydroErrorsCollector& errorCollector): hydro_(hydro), - areaIndex_(areaIndex), areaName_(areaName), + areaIndex_(areaIndex), initialLevel_(initialLevel), - finalLevel_(finalLevel) + finalLevel_(finalLevel), + year_(year), + lastSimulationDay_(lastSimulationDay), + firstMonthOfSimulation_(firstMonthOfSimulation), + errorCollector_(errorCollector) { } From 0c574ff5ba39eba97cd009497340239429f4960f Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 16:36:09 +0200 Subject: [PATCH 15/42] update --- .../antares/solver/hydro/management/finalLevelValidator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h b/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h index 7362a0e967..1775b914ef 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h @@ -40,7 +40,7 @@ namespace Solver class FinalLevelValidator { public: - FinalLevelValidator(PartHydro& hydro, + FinalLevelValidator(Antares::Data::PartHydro& hydro, unsigned int areaIndex, const AreaName areaName, double initialLevel, From 9968b0644f911c3533388bea0e6ab9b46055b753 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 16:40:11 +0200 Subject: [PATCH 16/42] update namespace --- .../hydro/management/finalLevelValidator.h | 2 +- .../hydro/management/finalLevelValidator.cpp | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h b/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h index 1775b914ef..6fe9c69f19 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h @@ -42,7 +42,7 @@ class FinalLevelValidator public: FinalLevelValidator(Antares::Data::PartHydro& hydro, unsigned int areaIndex, - const AreaName areaName, + const Antares::Data::AreaName areaName, double initialLevel, double finalLevel, const unsigned int year, diff --git a/src/solver/hydro/management/finalLevelValidator.cpp b/src/solver/hydro/management/finalLevelValidator.cpp index ff7fbc93b2..eaff83c35a 100644 --- a/src/solver/hydro/management/finalLevelValidator.cpp +++ b/src/solver/hydro/management/finalLevelValidator.cpp @@ -30,15 +30,16 @@ namespace Antares::Solver { -FinalLevelValidator::FinalLevelValidator(Antares::Data::PartHydro& hydro, - unsigned int areaIndex, - const AreaName areaName, // gp : to std::string - double initialLevel, - double finalLevel, - const unsigned int year, - const unsigned int lastSimulationDay, - const unsigned int firstMonthOfSimulation, - HydroErrorsCollector& errorCollector): +FinalLevelValidator::FinalLevelValidator( + Antares::Data::PartHydro& hydro, + unsigned int areaIndex, + const Antares::Data::AreaName areaName, // gp : to std::string + double initialLevel, + double finalLevel, + const unsigned int year, + const unsigned int lastSimulationDay, + const unsigned int firstMonthOfSimulation, + HydroErrorsCollector& errorCollector): hydro_(hydro), areaName_(areaName), areaIndex_(areaIndex), From 4edf2d4d615e98579c7aec91d7a2302fe8dd95c2 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 16:41:48 +0200 Subject: [PATCH 17/42] add include --- .../antares/solver/hydro/management/finalLevelValidator.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h b/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h index 6fe9c69f19..d24d2200f6 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h @@ -26,6 +26,7 @@ */ #pragma once +#include "antares/solver/hydro/management/HydroErrorsCollector.h" #include "antares/study/parts/hydro/container.h" namespace Antares From 5fe27cfc655dc15ad5867d6a7e6a65c4827737e7 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 16:43:14 +0200 Subject: [PATCH 18/42] update member var --- .../antares/solver/hydro/management/finalLevelValidator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h b/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h index d24d2200f6..ecbcd8ed31 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/finalLevelValidator.h @@ -69,9 +69,9 @@ class FinalLevelValidator unsigned int firstMonthOfSimulation_ = 0; // Data from area - PartHydro& hydro_; + Antares::Data::PartHydro& hydro_; unsigned int areaIndex_; - const AreaName areaName_; + const Antares::Data::AreaName areaName_; double initialLevel_; double finalLevel_; From 1c0ee4330b0efaab96ae5360239e1179d89865c8 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 27 Jun 2024 16:44:42 +0200 Subject: [PATCH 19/42] update namespace --- .../hydro/management/HydroInputsChecker.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index ae68f7132c..b3d7df2815 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -216,15 +216,15 @@ void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) double initialLevel = scenarioInitialHydroLevels_.entry[area.index][year]; double finalLevel = scenarioFinalHydroLevels_.entry[area.index][year]; - Data::FinalLevelValidator validator(area.hydro, - area.index, - area.name, - initialLevel, - finalLevel, - year, - parameters_.simulationDays.end, - parameters_.firstMonthInYear, - errorCollector_); + Antares::Solver::FinalLevelValidator validator(area.hydro, + area.index, + area.name, + initialLevel, + finalLevel, + year, + parameters_.simulationDays.end, + parameters_.firstMonthInYear, + errorCollector_); if (!validator.check()) { errorCollector_.FatalErrorHit(); From 9b4a09c55bc3674a0e2228c1eb098dd96634cbca Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 28 Jun 2024 09:31:15 +0200 Subject: [PATCH 20/42] update --- src/solver/hydro/management/HydroInputsChecker.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index b3d7df2815..dde6362aa1 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -227,6 +227,7 @@ void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) errorCollector_); if (!validator.check()) { + errorCollector_.IncreaseCounterForArea(&area); errorCollector_.FatalErrorHit(); logs.error() << "hydro final level : infeasibility"; } From e5a8085d8f0babc7835cdcf916bca1bfce02ddfa Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 28 Jun 2024 12:22:49 +0200 Subject: [PATCH 21/42] update --- .../hydro/management/HydroErrorsCollector.h | 15 ++--- .../hydro/management/HydroInputsChecker.h | 4 +- .../hydro/management/HydroErrorsCollector.cpp | 65 +++++++++---------- .../hydro/management/HydroInputsChecker.cpp | 57 ++++++++-------- .../hydro/management/finalLevelValidator.cpp | 29 +++++---- .../antares/solver/simulation/solver.hxx | 17 ++--- 6 files changed, 92 insertions(+), 95 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index 22e2f1d255..a42296b174 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -23,21 +23,20 @@ #include #include -#include - +namespace Antares +{ class HydroErrorsCollector { public: HydroErrorsCollector() = default; - void IncreaseCounterForArea(const Antares::Data::Area* area); - bool StopExecution() const; - bool ErrorsLimitReached() const; - void FatalErrorHit(); - // void RecordFatalErrors(const std::string& msg, uint year); + void Collect(const std::string& area_name, const std::string& message); + void Collect(const std::string& message); + bool CheckForFatalErrors() const; private: - std::unordered_map area_errors_counter_; + std::unordered_map area_errors_counter_; bool errors_limit_reached_ = false; bool stop_ = false; // std::vector fatal_errors_; }; +} // namespace Antares diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h index c2315996c4..05462dff69 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h @@ -32,8 +32,8 @@ class HydroInputsChecker { public: explicit HydroInputsChecker(Antares::Data::Study& study); - bool Execute(uint year); - bool StopExecution() const; + Execute(uint year); + void CheckForFatalErrors() const; void CheckFinalReservoirLevelsConfiguration(uint year); private: diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index b3b45ee363..6f3f33a25f 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -2,49 +2,44 @@ #include -void HydroErrorsCollector::IncreaseCounterForArea(const Antares::Data::Area* area) +#include "antares/antares/fatal-error.h" + +namespace Antares +{ +void HydroErrorsCollector::Collect(const std::string& area_name, const std::string& message) { - if (errors_limit_reached_ || !area) + if (errors_limit_reached_) { - return; + throw FatalError("Hydro validation has failed !") + } + else + { + logs.error() << "In Area " << area_name << " " << message; + area_errors_counter_[area_name]++; + errors_limit_reached_ = area_errors_counter_[area] > 10; + stop_ = true; } - - area_errors_counter_[area]++; - errors_limit_reached_ = area_errors_counter_[area] > 10 || errors_limit_reached_; - stop_ = true; -} - -bool HydroErrorsCollector::ErrorsLimitReached() const -{ - return errors_limit_reached_; } -bool HydroErrorsCollector::StopExecution() const +void HydroErrorsCollector::Collect(const std::string& message) { - return stop_ || errors_limit_reached_; + if (errors_limit_reached_) + { + throw FatalError("Hydro validation has failed !") + } + else + { + logs.error() << message; + stop_ = true; + } } -void HydroErrorsCollector::FatalErrorHit() +void HydroErrorsCollector::CheckForFatalErrors() const { - stop_ = true; + if (stop_ || errors_limit_reached_) + { + throw FatalError("Hydro validation has failed !") + } } -// void HydroErrorsCollector::RecordFatalErrors(const std::string& msg, uint year) -// { -// fatal_errors_.push_back("In year " + std::to_string(year) + " " + msg); -// } - -// void HydroErrorsCollector::RecordFatalErrors(const std::string& msg, -// uint year, -// const Antares::Data::Area* area) -// { -// fatal_errors_.push_back("In area " + area.name + " " + std::to_string(year) + " " + msg); -// } - -// void HydroErrorsCollector::PrintFatalsErrors() const -// { -// for (const auto& msg: fatal_errors) -// { -// logs.error() << msg; -// } -// } +} // namespace Antares diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index dde6362aa1..2ec31c8836 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -23,7 +23,6 @@ #include #include -#include "antares/antares/fatal-error.h" #include "antares/solver/hydro/management/finalLevelValidator.h" #include "antares/solver/hydro/monthly/h2o_m_donnees_annuelles.h" #include "antares/solver/hydro/monthly/h2o_m_fonctions.h" @@ -42,20 +41,20 @@ HydroInputsChecker::HydroInputsChecker(Antares::Data::Study& study): { } -bool HydroInputsChecker::Execute(uint year) +HydroInputsChecker::Execute(uint year) { prepareInflows_.Run(year); minGenerationScaling_.Run(year); if (!checksOnGenerationPowerBounds(year)) { - errorCollector_.FatalErrorHit(); - logs.error() << "hydro inputs checks: invalid minimum generation"; + std::ostringstream msg; + msg << "hydro inputs checks: invalid minimum generation in year " << year; + errorCollector_.Collect(msg.str()); } if (parameters_.useCustomScenario) { CheckFinalReservoirLevelsConfiguration(year); } - return !errorCollector_.ErrorsLimitReached(); } bool HydroInputsChecker::checksOnGenerationPowerBounds(uint year) @@ -120,11 +119,12 @@ bool HydroInputsChecker::checkWeeklyMinGeneration(uint year, const Data::Area& a } if (totalWeekMingen > totalWeekInflows) { - errorCollector_.IncreaseCounterForArea(&area); - logs.error() << "In Area " << area.name << " the minimum generation of " - << totalWeekMingen << " MW in week " << week + 1 << " of TS-" - << area.hydro.series->mingen.getSeriesIndex(year) + 1 - << " is incompatible with the inflows of " << totalWeekInflows << " MW."; + std::ostringstream msg; + msg << "In Area " << area.name << " the minimum generation of " << totalWeekMingen + << " MW in week " << week + 1 << " of TS-" + << area.hydro.series->mingen.getSeriesIndex(year) + 1 + << " is incompatible with the inflows of " << totalWeekInflows << " MW."; + errorCollector_.Collect(area.name, msg); return false; } } @@ -136,12 +136,13 @@ bool HydroInputsChecker::checkYearlyMinGeneration(uint year, const Data::Area& a const auto& data = area.hydro.managementData.at(year); if (data.totalYearMingen > data.totalYearInflows) { - errorCollector_.IncreaseCounterForArea(&area); + std::ostringstream msg; + // Yearly minimum generation <= Yearly inflows - logs.error() << "In Area " << area.name << " the minimum generation of " - << data.totalYearMingen << " MW of TS-" - << area.hydro.series->mingen.getSeriesIndex(year) + 1 - << " is incompatible with the inflows of " << data.totalYearInflows << " MW."; + msg << "In Area " << area.name << " the minimum generation of " << data.totalYearMingen + << " MW of TS-" << area.hydro.series->mingen.getSeriesIndex(year) + 1 + << " is incompatible with the inflows of " << data.totalYearInflows << " MW."; + errorCollector_.Collect(area.name, msg); return false; } return true; @@ -156,12 +157,13 @@ bool HydroInputsChecker::checkMonthlyMinGeneration(uint year, const Data::Area& // Monthly minimum generation <= Monthly inflows for each month if (data.totalMonthMingen[realmonth] > data.totalMonthInflows[realmonth]) { - errorCollector_.IncreaseCounterForArea(&area); - logs.error() << "In Area " << area.name << " the minimum generation of " - << data.totalMonthMingen[realmonth] << " MW in month " << month + 1 - << " of TS-" << area.hydro.series->mingen.getSeriesIndex(year) + 1 - << " is incompatible with the inflows of " - << data.totalMonthInflows[realmonth] << " MW."; + std::ostringstream msg; + msg << "In Area " << area.name << " the minimum generation of " + << data.totalMonthMingen[realmonth] << " MW in month " << month + 1 << " of TS-" + << area.hydro.series->mingen.getSeriesIndex(year) + 1 + << " is incompatible with the inflows of " << data.totalMonthInflows[realmonth] + << " MW."; + errorCollector_.Collect(area.name, msg); return false; } } @@ -188,12 +190,13 @@ bool HydroInputsChecker::checkGenerationPowerConsistency(uint year) if (max < min) { - errorCollector_.IncreaseCounterForArea(&area); + std::ostringstream msg; logs.error() << "In area: " << area.name << " [hourly] minimum generation of " << min << " MW in timestep " << h + 1 << " of TS-" << tsIndexMin + 1 << " is incompatible with the maximum generation of " << max << " MW in timestep " << h + 1 << " of TS-" << tsIndexMax + 1 << " MW."; + errorCollector_.Collect(area.name, msg); ret = false; return; } @@ -227,9 +230,9 @@ void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) errorCollector_); if (!validator.check()) { - errorCollector_.IncreaseCounterForArea(&area); - errorCollector_.FatalErrorHit(); - logs.error() << "hydro final level : infeasibility"; + std::ostringstream msg; + msg << "hydro final level : infeasibility"; + errorCollector_.Collect(area.name, msg); } if (validator.finalLevelFineForUse()) { @@ -238,9 +241,9 @@ void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) }); } // End function CheckFinalReservoirLevelsConfiguration -bool HydroInputsChecker::StopExecution() const +bool HydroInputsChecker::CheckForFatalErrors() const { - return errorCollector_.StopExecution(); + errorCollector_.CheckForFatalErrors(); } } // namespace Antares diff --git a/src/solver/hydro/management/finalLevelValidator.cpp b/src/solver/hydro/management/finalLevelValidator.cpp index eaff83c35a..9dcbb64a15 100644 --- a/src/solver/hydro/management/finalLevelValidator.cpp +++ b/src/solver/hydro/management/finalLevelValidator.cpp @@ -103,9 +103,12 @@ bool FinalLevelValidator::hydroAllocationStartMatchesSimulation() const if (lastSimulationDay_ == DAYS_PER_YEAR && initReservoirLvlMonth == firstMonthOfSimulation_) return true; - logs.error() << "Year " << year_ + 1 << ", area '" << areaName_ << "' : " - << "Hydro allocation must start on the 1st simulation month and " - << "simulation last a whole year"; + std::ostringstream msg; + msg << "Year " << year_ + 1 << ", area '" << areaName_ + << "' : " << "Hydro allocation must start on the 1st simulation month and " + << "simulation last a whole year"; + errorCollector_.Collect(areaName_, msg); + return false; } @@ -116,10 +119,12 @@ bool FinalLevelValidator::isFinalLevelReachable() const if ((finalLevel_ - initialLevel_) * reservoirCapacity > totalYearInflows) { - logs.error() << "Year: " << year_ + 1 << ". Area: " << areaName_ - << ". Incompatible total inflows: " << totalYearInflows - << " with initial: " << initialLevel_ - << " and final: " << finalLevel_ << " reservoir levels."; + std::ostringstream msg; + msg << "Year: " << year_ + 1 << ". Area: " << areaName_ + << ". Incompatible total inflows: " << totalYearInflows + << " with initial: " << initialLevel_ << " and final: " << finalLevel_ + << " reservoir levels."; + errorCollector_.Collect(areaName_, msg); return false; } return true; @@ -143,10 +148,12 @@ bool FinalLevelValidator::isBetweenRuleCurves() const if (finalLevel_ < lowLevelLastDay || finalLevel_ > highLevelLastDay) { - logs.error() << "Year: " << year_ + 1 << ". Area: " << areaName_ - << ". Specifed final reservoir level: " << finalLevel_ - << " is incompatible with reservoir level rule curve [" << lowLevelLastDay - << " , " << highLevelLastDay << "]"; + std::ostringstream msg; + msg << "Year: " << year_ + 1 << ". Area: " << areaName_ + << ". Specifed final reservoir level: " << finalLevel_ + << " is incompatible with reservoir level rule curve [" << lowLevelLastDay << " , " + << highLevelLastDay << "]"; + errorCollector_.Collect(areaName_, msg); return false; } return true; diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.hxx b/src/solver/simulation/include/antares/solver/simulation/solver.hxx index de4efd75e8..253d153641 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.hxx +++ b/src/solver/simulation/include/antares/solver/simulation/solver.hxx @@ -973,17 +973,11 @@ void ISimulation::loopThroughYears(uint firstYear, } for (auto year: batch.yearsIndices) { - if (!hydroInputsChecker.Execute(year)) - { - throw FatalError("Hydro input validation has failed!"); - } + hydroInputsChecker.Execute(year); } } + hydroInputsChecker.CheckForFatalErrors(); - if (hydroInputsChecker.StopExecution()) - { - throw FatalError("Hydro input validation has failed!"); - } logs.info() << " Starting the simulation"; // Loop over sets of parallel years to run the simulation @@ -1006,10 +1000,9 @@ void ISimulation::loopThroughYears(uint firstYear, for (auto y: batch.yearsIndices) { // for each year not handled earlier - if (!hydroInputsChecker.Execute(y) || hydroInputsChecker.StopExecution()) - { - throw FatalError("Hydro input validation has failed!"); - } + hydroInputsChecker.Execute(y); + hydroInputsChecker.CheckForFatalErrors(); + bool performCalculations = batch.isYearPerformed[y]; unsigned int numSpace = 999999; if (performCalculations) From 341912780cba3ed2b1775d66bc0a88b782732881 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 28 Jun 2024 12:28:54 +0200 Subject: [PATCH 22/42] update --- .../hydro/management/HydroInputsChecker.h | 2 +- .../hydro/management/HydroErrorsCollector.cpp | 23 ++++++------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h index 05462dff69..9b35dc62cd 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h @@ -32,7 +32,7 @@ class HydroInputsChecker { public: explicit HydroInputsChecker(Antares::Data::Study& study); - Execute(uint year); + void Execute(uint year); void CheckForFatalErrors() const; void CheckFinalReservoirLevelsConfiguration(uint year); diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index 6f3f33a25f..9fe8fbd2ca 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -8,30 +8,21 @@ namespace Antares { void HydroErrorsCollector::Collect(const std::string& area_name, const std::string& message) { + logs.error() << "In Area " << area_name << " " << message; + area_errors_counter_[area_name]++; + errors_limit_reached_ = area_errors_counter_[area] > 10; + stop_ = true; + if (errors_limit_reached_) { throw FatalError("Hydro validation has failed !") } - else - { - logs.error() << "In Area " << area_name << " " << message; - area_errors_counter_[area_name]++; - errors_limit_reached_ = area_errors_counter_[area] > 10; - stop_ = true; - } } void HydroErrorsCollector::Collect(const std::string& message) { - if (errors_limit_reached_) - { - throw FatalError("Hydro validation has failed !") - } - else - { - logs.error() << message; - stop_ = true; - } + logs.error() << message; + stop_ = true; } void HydroErrorsCollector::CheckForFatalErrors() const From eb94414e5b987ee07e145b7f5aa948d321d02a1e Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 28 Jun 2024 14:14:52 +0200 Subject: [PATCH 23/42] fix --- src/solver/hydro/management/HydroInputsChecker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index 2ec31c8836..567869e726 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -41,7 +41,7 @@ HydroInputsChecker::HydroInputsChecker(Antares::Data::Study& study): { } -HydroInputsChecker::Execute(uint year) +void HydroInputsChecker::Execute(uint year) { prepareInflows_.Run(year); minGenerationScaling_.Run(year); From ad58ea19542fbd091f03a0c1a2630fbb50b398a0 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 28 Jun 2024 14:35:24 +0200 Subject: [PATCH 24/42] fix --- src/solver/hydro/management/HydroInputsChecker.cpp | 10 +++++----- src/solver/hydro/management/finalLevelValidator.cpp | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index 567869e726..f692790b70 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -124,7 +124,7 @@ bool HydroInputsChecker::checkWeeklyMinGeneration(uint year, const Data::Area& a << " MW in week " << week + 1 << " of TS-" << area.hydro.series->mingen.getSeriesIndex(year) + 1 << " is incompatible with the inflows of " << totalWeekInflows << " MW."; - errorCollector_.Collect(area.name, msg); + errorCollector_.Collect(area.name, msg.str()); return false; } } @@ -142,7 +142,7 @@ bool HydroInputsChecker::checkYearlyMinGeneration(uint year, const Data::Area& a msg << "In Area " << area.name << " the minimum generation of " << data.totalYearMingen << " MW of TS-" << area.hydro.series->mingen.getSeriesIndex(year) + 1 << " is incompatible with the inflows of " << data.totalYearInflows << " MW."; - errorCollector_.Collect(area.name, msg); + errorCollector_.Collect(area.name, msg.str()); return false; } return true; @@ -163,7 +163,7 @@ bool HydroInputsChecker::checkMonthlyMinGeneration(uint year, const Data::Area& << area.hydro.series->mingen.getSeriesIndex(year) + 1 << " is incompatible with the inflows of " << data.totalMonthInflows[realmonth] << " MW."; - errorCollector_.Collect(area.name, msg); + errorCollector_.Collect(area.name, msg.str()); return false; } } @@ -196,7 +196,7 @@ bool HydroInputsChecker::checkGenerationPowerConsistency(uint year) << " is incompatible with the maximum generation of " << max << " MW in timestep " << h + 1 << " of TS-" << tsIndexMax + 1 << " MW."; - errorCollector_.Collect(area.name, msg); + errorCollector_.Collect(area.name, msg.str()); ret = false; return; } @@ -232,7 +232,7 @@ void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) { std::ostringstream msg; msg << "hydro final level : infeasibility"; - errorCollector_.Collect(area.name, msg); + errorCollector_.Collect(area.name, msg.str()); } if (validator.finalLevelFineForUse()) { diff --git a/src/solver/hydro/management/finalLevelValidator.cpp b/src/solver/hydro/management/finalLevelValidator.cpp index 9dcbb64a15..7457ddef3d 100644 --- a/src/solver/hydro/management/finalLevelValidator.cpp +++ b/src/solver/hydro/management/finalLevelValidator.cpp @@ -107,7 +107,7 @@ bool FinalLevelValidator::hydroAllocationStartMatchesSimulation() const msg << "Year " << year_ + 1 << ", area '" << areaName_ << "' : " << "Hydro allocation must start on the 1st simulation month and " << "simulation last a whole year"; - errorCollector_.Collect(areaName_, msg); + errorCollector_.Collect(areaName_, msg.str()); return false; } @@ -124,7 +124,7 @@ bool FinalLevelValidator::isFinalLevelReachable() const << ". Incompatible total inflows: " << totalYearInflows << " with initial: " << initialLevel_ << " and final: " << finalLevel_ << " reservoir levels."; - errorCollector_.Collect(areaName_, msg); + errorCollector_.Collect(areaName_, msg.str()); return false; } return true; @@ -153,7 +153,7 @@ bool FinalLevelValidator::isBetweenRuleCurves() const << ". Specifed final reservoir level: " << finalLevel_ << " is incompatible with reservoir level rule curve [" << lowLevelLastDay << " , " << highLevelLastDay << "]"; - errorCollector_.Collect(areaName_, msg); + errorCollector_.Collect(areaName_, msg.str()); return false; } return true; From dbb743bbf3bc95257750d0aeed020cc042c14f6b Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 28 Jun 2024 15:08:11 +0200 Subject: [PATCH 25/42] change container --- .../antares/solver/hydro/management/HydroErrorsCollector.h | 7 +++---- src/solver/hydro/management/HydroErrorsCollector.cpp | 6 +++--- src/solver/hydro/management/HydroInputsChecker.cpp | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index a42296b174..5810f4fcba 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -20,9 +20,8 @@ */ #pragma once +#include #include -#include - namespace Antares { class HydroErrorsCollector @@ -31,10 +30,10 @@ class HydroErrorsCollector HydroErrorsCollector() = default; void Collect(const std::string& area_name, const std::string& message); void Collect(const std::string& message); - bool CheckForFatalErrors() const; + void CheckForFatalErrors() const; private: - std::unordered_map area_errors_counter_; + std::map area_errors_counter_; bool errors_limit_reached_ = false; bool stop_ = false; // std::vector fatal_errors_; diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index 9fe8fbd2ca..ec8152e836 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -10,12 +10,12 @@ void HydroErrorsCollector::Collect(const std::string& area_name, const std::stri { logs.error() << "In Area " << area_name << " " << message; area_errors_counter_[area_name]++; - errors_limit_reached_ = area_errors_counter_[area] > 10; + errors_limit_reached_ = area_errors_counter_[area_name] > 10; stop_ = true; if (errors_limit_reached_) { - throw FatalError("Hydro validation has failed !") + throw FatalError("Hydro validation has failed !"); } } @@ -29,7 +29,7 @@ void HydroErrorsCollector::CheckForFatalErrors() const { if (stop_ || errors_limit_reached_) { - throw FatalError("Hydro validation has failed !") + throw FatalError("Hydro validation has failed !"); } } diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index f692790b70..8bef6c09dc 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -241,7 +241,7 @@ void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) }); } // End function CheckFinalReservoirLevelsConfiguration -bool HydroInputsChecker::CheckForFatalErrors() const +void HydroInputsChecker::CheckForFatalErrors() const { errorCollector_.CheckForFatalErrors(); } From 37aac75b11e5426e43265a5c3c7ad3d08f60d32b Mon Sep 17 00:00:00 2001 From: Florian OMNES Date: Mon, 1 Jul 2024 11:27:24 +0200 Subject: [PATCH 26/42] Format --- .../antares/solver/hydro/management/HydroErrorsCollector.h | 1 + src/solver/hydro/management/HydroInputsChecker.cpp | 1 + src/solver/hydro/management/finalLevelValidator.cpp | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index 5810f4fcba..af1d4177cc 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -22,6 +22,7 @@ #pragma once #include #include + namespace Antares { class HydroErrorsCollector diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index 8bef6c09dc..1560b4c0c4 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -27,6 +27,7 @@ #include "antares/solver/hydro/monthly/h2o_m_donnees_annuelles.h" #include "antares/solver/hydro/monthly/h2o_m_fonctions.h" #include "antares/solver/simulation/common-eco-adq.h" + namespace Antares { diff --git a/src/solver/hydro/management/finalLevelValidator.cpp b/src/solver/hydro/management/finalLevelValidator.cpp index f02eefa69d..4d756a5286 100644 --- a/src/solver/hydro/management/finalLevelValidator.cpp +++ b/src/solver/hydro/management/finalLevelValidator.cpp @@ -178,4 +178,4 @@ bool FinalLevelValidator::finalLevelFineForUse() return finalLevelFineForUse_; } -} // namespace Antares::Data +} // namespace Antares::Solver From 18afdbb38451a1565335277bc1582878c69dd0dd Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Mon, 1 Jul 2024 14:34:53 +0200 Subject: [PATCH 27/42] update --- .../solver/hydro/management/HydroErrorsCollector.h | 11 +++++++++++ src/solver/hydro/management/HydroErrorsCollector.cpp | 9 +++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index af1d4177cc..946acd8561 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -32,11 +32,22 @@ class HydroErrorsCollector void Collect(const std::string& area_name, const std::string& message); void Collect(const std::string& message); void CheckForFatalErrors() const; + template + std::ostream& operator<<(const T& obj); private: + // for log + constexpr unsigned int TRHESHOLD_NUMBER_OF_ERRORS_FOR_ONE_AREA = 10; std::map area_errors_counter_; bool errors_limit_reached_ = false; bool stop_ = false; // std::vector fatal_errors_; }; + +template +HydroErrorsCollector& HydroErrorsCollector::operator<<(const T& obj) +{ + logs.error() << obj; + return *this; +} } // namespace Antares diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index ec8152e836..93374314d4 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -9,13 +9,14 @@ namespace Antares void HydroErrorsCollector::Collect(const std::string& area_name, const std::string& message) { logs.error() << "In Area " << area_name << " " << message; - area_errors_counter_[area_name]++; - errors_limit_reached_ = area_errors_counter_[area_name] > 10; + auto error_count = area_errors_counter_[area_name]++; + errors_limit_reached_ = error_count > TRHESHOLD_NUMBER_OF_ERRORS_FOR_ONE_AREA; stop_ = true; if (errors_limit_reached_) { - throw FatalError("Hydro validation has failed !"); + logs.error() << "Hydro validation has failed !"; + logs.error() << error_count << " errors found in Area " << area_name; } } @@ -27,7 +28,7 @@ void HydroErrorsCollector::Collect(const std::string& message) void HydroErrorsCollector::CheckForFatalErrors() const { - if (stop_ || errors_limit_reached_) + if (stop_) { throw FatalError("Hydro validation has failed !"); } From 8885fa7a7017e20ee855dd8adfba56884dca71ae Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Mon, 1 Jul 2024 15:24:14 +0200 Subject: [PATCH 28/42] update --- .../hydro/management/HydroErrorsCollector.h | 36 ++++++------ .../hydro/management/HydroInputsChecker.h | 2 +- .../hydro/management/HydroErrorsCollector.cpp | 39 +++++++------ .../hydro/management/HydroInputsChecker.cpp | 57 ++++++++----------- .../hydro/management/finalLevelValidator.cpp | 28 ++++----- .../antares/solver/simulation/solver.hxx | 4 +- 6 files changed, 79 insertions(+), 87 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index 946acd8561..bc49001267 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -25,29 +25,33 @@ namespace Antares { +using AreaErrorMessages = std::vector; + class HydroErrorsCollector { public: + class AreaReference + { + public: + AreaReference(HydroErrorsCollector* collector, const std::string& name); + friend void operator<<(const AreaReference& ref, const std::string& msg); + + ~AreaReference() + { + // std::cout << areasErrorMap_ << std::endl; + } + + private: + AreaErrorMessages& areasErrorMessages_; + }; + + AreaReference operator()(const std::string& name); HydroErrorsCollector() = default; - void Collect(const std::string& area_name, const std::string& message); - void Collect(const std::string& message); - void CheckForFatalErrors() const; - template - std::ostream& operator<<(const T& obj); + void CheckForErrors() const; private: // for log - constexpr unsigned int TRHESHOLD_NUMBER_OF_ERRORS_FOR_ONE_AREA = 10; - std::map area_errors_counter_; - bool errors_limit_reached_ = false; - bool stop_ = false; - // std::vector fatal_errors_; + std::map areasErrorMap_; }; -template -HydroErrorsCollector& HydroErrorsCollector::operator<<(const T& obj) -{ - logs.error() << obj; - return *this; -} } // namespace Antares diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h index a24651dc83..af9049a97e 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroInputsChecker.h @@ -34,7 +34,7 @@ class HydroInputsChecker public: explicit HydroInputsChecker(Antares::Data::Study& study); void Execute(uint year); - void CheckForFatalErrors() const; + void CheckForErrors() const; void CheckFinalReservoirLevelsConfiguration(uint year); private: diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index 93374314d4..9b775fe3c6 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -6,32 +6,37 @@ namespace Antares { -void HydroErrorsCollector::Collect(const std::string& area_name, const std::string& message) -{ - logs.error() << "In Area " << area_name << " " << message; - auto error_count = area_errors_counter_[area_name]++; - errors_limit_reached_ = error_count > TRHESHOLD_NUMBER_OF_ERRORS_FOR_ONE_AREA; - stop_ = true; - if (errors_limit_reached_) +void HydroErrorsCollector::CheckForErrors() const +{ + if (!aresErrorMap_.empty()) { - logs.error() << "Hydro validation has failed !"; - logs.error() << error_count << " errors found in Area " << area_name; + for (const auto& [area_name, area_msgs]: areasErrorMap_) + { + logs.error() << "In Area " << area_name; + for (const auto& msg: area_msgs) + { + logs.error() << msg; + } + } + throw FatalError("Hydro validation has failed !"); } } -void HydroErrorsCollector::Collect(const std::string& message) +HydroErrorsCollector::AreaReference::AreaReference(HydroErrorsCollector* collector, + const std::string& name): + areasErrorMap_(collector->areasErrorMap_[name]) { - logs.error() << message; - stop_ = true; } -void HydroErrorsCollector::CheckForFatalErrors() const +HydroErrorsCollector::AreaReference HydroErrorsCollector::operator()(const std::string& name) { - if (stop_) - { - throw FatalError("Hydro validation has failed !"); - } + return AreaReference(this, name); } +void operator<<(const HydroErrorsCollector::AreaReference& ref, const std::string& msg) +{ + // TODO what to do with empty msg? + ref.areasErrorMessages_.push_back(msg); +} } // namespace Antares diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index 1560b4c0c4..de33ad1ac7 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -48,9 +48,7 @@ void HydroInputsChecker::Execute(uint year) minGenerationScaling_.Run(year); if (!checksOnGenerationPowerBounds(year)) { - std::ostringstream msg; - msg << "hydro inputs checks: invalid minimum generation in year " << year; - errorCollector_.Collect(msg.str()); + logs.error() << "hydro inputs checks: invalid minimum generation in year " << year; } if (parameters_.useCustomScenario) { @@ -120,12 +118,10 @@ bool HydroInputsChecker::checkWeeklyMinGeneration(uint year, const Data::Area& a } if (totalWeekMingen > totalWeekInflows) { - std::ostringstream msg; - msg << "In Area " << area.name << " the minimum generation of " << totalWeekMingen - << " MW in week " << week + 1 << " of TS-" - << area.hydro.series->mingen.getSeriesIndex(year) + 1 - << " is incompatible with the inflows of " << totalWeekInflows << " MW."; - errorCollector_.Collect(area.name, msg.str()); + errorCollector_(area.name) + << " the minimum generation of " << totalWeekMingen << " MW in week " << week + 1 + << " of TS-" << area.hydro.series->mingen.getSeriesIndex(year) + 1 + << " is incompatible with the inflows of " << totalWeekInflows << " MW."; return false; } } @@ -137,13 +133,11 @@ bool HydroInputsChecker::checkYearlyMinGeneration(uint year, const Data::Area& a const auto& data = area.hydro.managementData.at(year); if (data.totalYearMingen > data.totalYearInflows) { - std::ostringstream msg; - // Yearly minimum generation <= Yearly inflows - msg << "In Area " << area.name << " the minimum generation of " << data.totalYearMingen - << " MW of TS-" << area.hydro.series->mingen.getSeriesIndex(year) + 1 - << " is incompatible with the inflows of " << data.totalYearInflows << " MW."; - errorCollector_.Collect(area.name, msg.str()); + errorCollector_(area.name) + << " the minimum generation of " << data.totalYearMingen << " MW of TS-" + << area.hydro.series->mingen.getSeriesIndex(year) + 1 + << " is incompatible with the inflows of " << data.totalYearInflows << " MW."; return false; } return true; @@ -158,13 +152,12 @@ bool HydroInputsChecker::checkMonthlyMinGeneration(uint year, const Data::Area& // Monthly minimum generation <= Monthly inflows for each month if (data.totalMonthMingen[realmonth] > data.totalMonthInflows[realmonth]) { - std::ostringstream msg; - msg << "In Area " << area.name << " the minimum generation of " - << data.totalMonthMingen[realmonth] << " MW in month " << month + 1 << " of TS-" - << area.hydro.series->mingen.getSeriesIndex(year) + 1 - << " is incompatible with the inflows of " << data.totalMonthInflows[realmonth] - << " MW."; - errorCollector_.Collect(area.name, msg.str()); + errorCollector_(area.name) + << " the minimum generation of " << data.totalMonthMingen[realmonth] + << " MW in month " << month + 1 << " of TS-" + << area.hydro.series->mingen.getSeriesIndex(year) + 1 + << " is incompatible with the inflows of " << data.totalMonthInflows[realmonth] + << " MW."; return false; } } @@ -191,13 +184,11 @@ bool HydroInputsChecker::checkGenerationPowerConsistency(uint year) if (max < min) { - std::ostringstream msg; - logs.error() << "In area: " << area.name << " [hourly] minimum generation of " - << min << " MW in timestep " << h + 1 << " of TS-" << tsIndexMin + 1 - << " is incompatible with the maximum generation of " << max - << " MW in timestep " << h + 1 << " of TS-" << tsIndexMax + 1 - << " MW."; - errorCollector_.Collect(area.name, msg.str()); + errorCollector_(area.name) + << "In area: " << area.name << " [hourly] minimum generation of " << min + << " MW in timestep " << h + 1 << " of TS-" << tsIndexMin + 1 + << " is incompatible with the maximum generation of " << max + << " MW in timestep " << h + 1 << " of TS-" << tsIndexMax + 1 << " MW."; ret = false; return; } @@ -231,9 +222,7 @@ void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) errorCollector_); if (!validator.check()) { - std::ostringstream msg; - msg << "hydro final level : infeasibility"; - errorCollector_.Collect(area.name, msg.str()); + logs.error() << "hydro final level : infeasibility"; } if (validator.finalLevelFineForUse()) { @@ -242,9 +231,9 @@ void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) }); } // End function CheckFinalReservoirLevelsConfiguration -void HydroInputsChecker::CheckForFatalErrors() const +void HydroInputsChecker::CheckForErrors() const { - errorCollector_.CheckForFatalErrors(); + errorCollector_.CheckForErrors(); } } // namespace Antares diff --git a/src/solver/hydro/management/finalLevelValidator.cpp b/src/solver/hydro/management/finalLevelValidator.cpp index 4d756a5286..8986f4b233 100644 --- a/src/solver/hydro/management/finalLevelValidator.cpp +++ b/src/solver/hydro/management/finalLevelValidator.cpp @@ -115,11 +115,9 @@ bool FinalLevelValidator::hydroAllocationStartMatchesSimulation() const return true; } - std::ostringstream msg; - msg << "Year " << year_ + 1 << ", area '" << areaName_ - << "' : " << "Hydro allocation must start on the 1st simulation month and " - << "simulation last a whole year"; - errorCollector_.Collect(areaName_, msg.str()); + errorCollector_(areaName_) << "Year " << year_ + 1 << ": " + << "Hydro allocation must start on the 1st simulation month and " + << "simulation last a whole year"; return false; } @@ -131,12 +129,10 @@ bool FinalLevelValidator::isFinalLevelReachable() const if ((finalLevel_ - initialLevel_) * reservoirCapacity > totalYearInflows) { - std::ostringstream msg; - msg << "Year: " << year_ + 1 << ". Area: " << areaName_ - << ". Incompatible total inflows: " << totalYearInflows - << " with initial: " << initialLevel_ << " and final: " << finalLevel_ - << " reservoir levels."; - errorCollector_.Collect(areaName_, msg.str()); + errorCollector_(areaName_) + << "Year: " << year_ + 1 << " Incompatible total inflows: " << totalYearInflows + << " with initial: " << initialLevel_ << " and final: " << finalLevel_ + << " reservoir levels."; return false; } return true; @@ -162,12 +158,10 @@ bool FinalLevelValidator::isBetweenRuleCurves() const if (finalLevel_ < lowLevelLastDay || finalLevel_ > highLevelLastDay) { - std::ostringstream msg; - msg << "Year: " << year_ + 1 << ". Area: " << areaName_ - << ". Specifed final reservoir level: " << finalLevel_ - << " is incompatible with reservoir level rule curve [" << lowLevelLastDay << " , " - << highLevelLastDay << "]"; - errorCollector_.Collect(areaName_, msg.str()); + errorCollector_(areaName_) + << "Year: " << year_ + 1 << " Specifed final reservoir level: " << finalLevel_ + << " is incompatible with reservoir level rule curve [" << lowLevelLastDay << " , " + << highLevelLastDay << "]"; return false; } return true; diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.hxx b/src/solver/simulation/include/antares/solver/simulation/solver.hxx index 52da117daf..da3477591e 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.hxx +++ b/src/solver/simulation/include/antares/solver/simulation/solver.hxx @@ -973,7 +973,7 @@ void ISimulation::loopThroughYears(uint firstYear, hydroInputsChecker.Execute(year); } } - hydroInputsChecker.CheckForFatalErrors(); + hydroInputsChecker.CheckForErrors(); logs.info() << " Starting the simulation"; @@ -998,7 +998,7 @@ void ISimulation::loopThroughYears(uint firstYear, { // for each year not handled earlier hydroInputsChecker.Execute(y); - hydroInputsChecker.CheckForFatalErrors(); + hydroInputsChecker.CheckForErrors(); bool performCalculations = batch.isYearPerformed[y]; unsigned int numSpace = 999999; From fda4e1146e952bd7b1fc418255a3dbb13f6494c9 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Mon, 1 Jul 2024 16:36:22 +0200 Subject: [PATCH 29/42] update --- .../hydro/management/HydroErrorsCollector.h | 23 +++++++++++++++---- .../hydro/management/HydroErrorsCollector.cpp | 23 ++++++++----------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index bc49001267..1e571ed8fc 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -25,16 +25,22 @@ namespace Antares { -using AreaErrorMessages = std::vector; class HydroErrorsCollector { public: + struct AreaSingleErrorMessage + { + std::string message = ""; + unsigned int message_number = 0; + }; + class AreaReference { public: AreaReference(HydroErrorsCollector* collector, const std::string& name); - friend void operator<<(const AreaReference& ref, const std::string& msg); + template + AreaReference& operator<<(const T& msg); ~AreaReference() { @@ -42,7 +48,7 @@ class HydroErrorsCollector } private: - AreaErrorMessages& areasErrorMessages_; + AreaSingleErrorMessage& areaSingleErrorMessage_; }; AreaReference operator()(const std::string& name); @@ -51,7 +57,16 @@ class HydroErrorsCollector private: // for log - std::map areasErrorMap_; + std::multimap areasErrorMap_; }; +template +HydroErrorsCollector::AreaReference& operator<<(const T& msg) +{ + std::ostringstream strfy; + strfy << msg; + areaSingleErrorMessage_.message += strfy.str(); + return *this; +} + } // namespace Antares diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index 9b775fe3c6..d6f7149b54 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -9,15 +9,11 @@ namespace Antares void HydroErrorsCollector::CheckForErrors() const { - if (!aresErrorMap_.empty()) + if (!areasErrorMap_.empty()) { - for (const auto& [area_name, area_msgs]: areasErrorMap_) + for (const auto& [area_name, msg]: areasErrorMap_) { - logs.error() << "In Area " << area_name; - for (const auto& msg: area_msgs) - { - logs.error() << msg; - } + logs.error() << "In Area " << area_name << msg; } throw FatalError("Hydro validation has failed !"); } @@ -25,7 +21,13 @@ void HydroErrorsCollector::CheckForErrors() const HydroErrorsCollector::AreaReference::AreaReference(HydroErrorsCollector* collector, const std::string& name): - areasErrorMap_(collector->areasErrorMap_[name]) + areaSingleErrorMessage_( + collector->areasErrorMap_ + .insert( + + {name, + {.message = "", .message_number = (unsigned int)collector->areasErrorMap_.count(name)}}) + ->second) { } @@ -34,9 +36,4 @@ HydroErrorsCollector::AreaReference HydroErrorsCollector::operator()(const std:: return AreaReference(this, name); } -void operator<<(const HydroErrorsCollector::AreaReference& ref, const std::string& msg) -{ - // TODO what to do with empty msg? - ref.areasErrorMessages_.push_back(msg); -} } // namespace Antares From 967cea27e7e27c489ac11bba593a140f8ba02a75 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Mon, 1 Jul 2024 16:40:18 +0200 Subject: [PATCH 30/42] fix --- .../antares/solver/hydro/management/HydroErrorsCollector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index 1e571ed8fc..c79ada01dd 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -61,7 +61,7 @@ class HydroErrorsCollector }; template -HydroErrorsCollector::AreaReference& operator<<(const T& msg) +HydroErrorsCollector::AreaReference& HydroErrorsCollector::AreaReference::operator<<(const T& msg) { std::ostringstream strfy; strfy << msg; From 2b657ee21763ca462954b16e037c15fe6c4baa68 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Mon, 1 Jul 2024 16:42:28 +0200 Subject: [PATCH 31/42] fix --- src/solver/hydro/management/HydroErrorsCollector.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index d6f7149b54..8864738fc4 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -11,9 +11,9 @@ void HydroErrorsCollector::CheckForErrors() const { if (!areasErrorMap_.empty()) { - for (const auto& [area_name, msg]: areasErrorMap_) + for (const auto& [area_name, area_msg]: areasErrorMap_) { - logs.error() << "In Area " << area_name << msg; + logs.error() << "In Area " << area_name << area_msg.message; } throw FatalError("Hydro validation has failed !"); } From 5add1734b77115fdd16efb443726a19e3858eaf9 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Mon, 1 Jul 2024 16:46:09 +0200 Subject: [PATCH 32/42] update includes --- .../antares/solver/hydro/management/HydroErrorsCollector.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index c79ada01dd..01469c3712 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -21,6 +21,7 @@ #pragma once #include +#include #include namespace Antares From 131e0685ecf327e380a84b1761265dae13f9f26f Mon Sep 17 00:00:00 2001 From: Abdoulbari Zaher <32519851+a-zakir@users.noreply.github.com> Date: Mon, 1 Jul 2024 16:57:28 +0200 Subject: [PATCH 33/42] Update src/solver/hydro/management/HydroInputsChecker.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Florian Omnès --- src/solver/hydro/management/HydroInputsChecker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index de33ad1ac7..ff94990ee2 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -222,7 +222,7 @@ void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) errorCollector_); if (!validator.check()) { - logs.error() << "hydro final level : infeasibility"; + errorCollector_(area.name) << "hydro final level : infeasibility"; } if (validator.finalLevelFineForUse()) { From db0561c587805d0e5df5ed83b18ec134780fe682 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Mon, 1 Jul 2024 16:58:30 +0200 Subject: [PATCH 34/42] update --- .../antares/solver/hydro/management/HydroErrorsCollector.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index 01469c3712..775ab47d18 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -43,11 +43,6 @@ class HydroErrorsCollector template AreaReference& operator<<(const T& msg); - ~AreaReference() - { - // std::cout << areasErrorMap_ << std::endl; - } - private: AreaSingleErrorMessage& areaSingleErrorMessage_; }; From 0d047fb4c24df60d7bd3b3bc9b7ae31293e2aa2c Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Mon, 1 Jul 2024 16:59:18 +0200 Subject: [PATCH 35/42] update --- .../antares/solver/hydro/management/HydroErrorsCollector.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index 775ab47d18..de46d98110 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -52,7 +52,6 @@ class HydroErrorsCollector void CheckForErrors() const; private: - // for log std::multimap areasErrorMap_; }; From 5292428caa59ccd230464bba350a527cc1ab0285 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Mon, 1 Jul 2024 18:26:48 +0200 Subject: [PATCH 36/42] test --- .../hydro/management/HydroErrorsCollector.h | 12 +++------- .../hydro/management/HydroErrorsCollector.cpp | 22 +++++++++++-------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index de46d98110..4ff8b4a842 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -30,12 +30,6 @@ namespace Antares class HydroErrorsCollector { public: - struct AreaSingleErrorMessage - { - std::string message = ""; - unsigned int message_number = 0; - }; - class AreaReference { public: @@ -44,7 +38,7 @@ class HydroErrorsCollector AreaReference& operator<<(const T& msg); private: - AreaSingleErrorMessage& areaSingleErrorMessage_; + std::string& areaSingleErrorMessage_; }; AreaReference operator()(const std::string& name); @@ -52,7 +46,7 @@ class HydroErrorsCollector void CheckForErrors() const; private: - std::multimap areasErrorMap_; + std::multimap areasErrorMap_; }; template @@ -60,7 +54,7 @@ HydroErrorsCollector::AreaReference& HydroErrorsCollector::AreaReference::operat { std::ostringstream strfy; strfy << msg; - areaSingleErrorMessage_.message += strfy.str(); + areaSingleErrorMessage_ += strfy.str(); return *this; } diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index 8864738fc4..9c3d445a11 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -1,5 +1,7 @@ #include "antares/solver/hydro/management/HydroErrorsCollector.h" +#include + #include #include "antares/antares/fatal-error.h" @@ -11,9 +13,17 @@ void HydroErrorsCollector::CheckForErrors() const { if (!areasErrorMap_.empty()) { - for (const auto& [area_name, area_msg]: areasErrorMap_) + for (const auto& key: areasErrorMap_ | std::views::keys) { - logs.error() << "In Area " << area_name << area_msg.message; + auto first_elements = areasErrorMap_ + | std::views::filter([&key](const auto& p) + { return p.first == key; }) + | std::views::take(10); + + for (const auto& value: first_elements) + { + logs.error() << "In Area " << value.first << ": " << value.second << " "; + } } throw FatalError("Hydro validation has failed !"); } @@ -21,13 +31,7 @@ void HydroErrorsCollector::CheckForErrors() const HydroErrorsCollector::AreaReference::AreaReference(HydroErrorsCollector* collector, const std::string& name): - areaSingleErrorMessage_( - collector->areasErrorMap_ - .insert( - - {name, - {.message = "", .message_number = (unsigned int)collector->areasErrorMap_.count(name)}}) - ->second) + areaSingleErrorMessage_(collector->areasErrorMap_.insert({name, ""})->second) { } From d0e15f2c56625e72b8d5877265e5ab5633bc4206 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Tue, 2 Jul 2024 10:03:49 +0200 Subject: [PATCH 37/42] update --- src/solver/hydro/management/HydroErrorsCollector.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index 9c3d445a11..764ad3e767 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -15,12 +15,10 @@ void HydroErrorsCollector::CheckForErrors() const { for (const auto& key: areasErrorMap_ | std::views::keys) { - auto first_elements = areasErrorMap_ - | std::views::filter([&key](const auto& p) - { return p.first == key; }) - | std::views::take(10); - - for (const auto& value: first_elements) + for (const auto& value: + areasErrorMap_ + | std::views::filter([&key](const auto& p) { return p.first == key; }) + | std::views::take(10)) { logs.error() << "In Area " << value.first << ": " << value.second << " "; } From 60a97745936feb23f15294bcb38b2baf91b382a7 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Tue, 2 Jul 2024 10:49:32 +0200 Subject: [PATCH 38/42] filter keys --- .../hydro/management/HydroErrorsCollector.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index 764ad3e767..db1ed3a5eb 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -13,16 +13,13 @@ void HydroErrorsCollector::CheckForErrors() const { if (!areasErrorMap_.empty()) { - for (const auto& key: areasErrorMap_ | std::views::keys) + for (const auto& value: + areasErrorMap_ | std::views::filter([&key](const auto& p) { return p.first == key; }) + | std::views::take(10)) { - for (const auto& value: - areasErrorMap_ - | std::views::filter([&key](const auto& p) { return p.first == key; }) - | std::views::take(10)) - { - logs.error() << "In Area " << value.first << ": " << value.second << " "; - } + logs.error() << "In Area " << value.first << ": " << value.second << " "; } + throw FatalError("Hydro validation has failed !"); } } From c2b21cc0e6f9c77857e42410a06bda6214b8759b Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Tue, 2 Jul 2024 11:32:27 +0200 Subject: [PATCH 39/42] revert --- .../hydro/management/HydroErrorsCollector.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index db1ed3a5eb..764ad3e767 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -13,13 +13,16 @@ void HydroErrorsCollector::CheckForErrors() const { if (!areasErrorMap_.empty()) { - for (const auto& value: - areasErrorMap_ | std::views::filter([&key](const auto& p) { return p.first == key; }) - | std::views::take(10)) + for (const auto& key: areasErrorMap_ | std::views::keys) { - logs.error() << "In Area " << value.first << ": " << value.second << " "; + for (const auto& value: + areasErrorMap_ + | std::views::filter([&key](const auto& p) { return p.first == key; }) + | std::views::take(10)) + { + logs.error() << "In Area " << value.first << ": " << value.second << " "; + } } - throw FatalError("Hydro validation has failed !"); } } From ace4ab296e6bbe698fcbdbd5087b954895fd5f54 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Tue, 2 Jul 2024 14:42:13 +0200 Subject: [PATCH 40/42] update --- .../hydro/management/HydroErrorsCollector.cpp | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index 764ad3e767..81429161d7 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -1,6 +1,7 @@ #include "antares/solver/hydro/management/HydroErrorsCollector.h" #include +#include #include @@ -13,7 +14,13 @@ void HydroErrorsCollector::CheckForErrors() const { if (!areasErrorMap_.empty()) { - for (const auto& key: areasErrorMap_ | std::views::keys) + std::set uniqueKeys; + std::transform(areasErrorMap_.begin(), + areasErrorMap_.end(), + std::inserter(uniqueKeys, uniqueKeys.begin()), + [](const auto& pair) { return pair.first; }); + + for (const auto& key: uniqueKeys) { for (const auto& value: areasErrorMap_ @@ -23,6 +30,23 @@ void HydroErrorsCollector::CheckForErrors() const logs.error() << "In Area " << value.first << ": " << value.second << " "; } } + + // for (auto value = areasErrorMap_.begin(); value != areasErrorMap_.end();) + // { + // const auto& key = value->first; + // const auto& rangeEnd = areasErrorMap_.upper_bound(key); + + // const auto& limit = std::min(value + 10, rangeEnd); + + // for (; value != limit; ++value) + // { + // logs.error() << "In Area " << value.first << ": " << value.second << " "; + // } + + // // Move iterator to the next key + // value = rangeEnd; + // } + throw FatalError("Hydro validation has failed !"); } } From 9e22ab3268881f1de3fa6c490cea22cbc2a0420b Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Tue, 2 Jul 2024 15:36:04 +0200 Subject: [PATCH 41/42] update --- .../hydro/management/HydroErrorsCollector.h | 4 +- .../hydro/management/HydroErrorsCollector.cpp | 38 +++++-------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h index 4ff8b4a842..d6054f12b6 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/HydroErrorsCollector.h @@ -23,6 +23,7 @@ #include #include #include +#include namespace Antares { @@ -46,7 +47,8 @@ class HydroErrorsCollector void CheckForErrors() const; private: - std::multimap areasErrorMap_; + std::map> areasErrorMap_; + std::string& CurrentMessage(const std::string& name); }; template diff --git a/src/solver/hydro/management/HydroErrorsCollector.cpp b/src/solver/hydro/management/HydroErrorsCollector.cpp index 81429161d7..729726e14e 100644 --- a/src/solver/hydro/management/HydroErrorsCollector.cpp +++ b/src/solver/hydro/management/HydroErrorsCollector.cpp @@ -14,46 +14,21 @@ void HydroErrorsCollector::CheckForErrors() const { if (!areasErrorMap_.empty()) { - std::set uniqueKeys; - std::transform(areasErrorMap_.begin(), - areasErrorMap_.end(), - std::inserter(uniqueKeys, uniqueKeys.begin()), - [](const auto& pair) { return pair.first; }); - - for (const auto& key: uniqueKeys) + for (const auto& [key, values]: areasErrorMap_) { - for (const auto& value: - areasErrorMap_ - | std::views::filter([&key](const auto& p) { return p.first == key; }) - | std::views::take(10)) + for (const auto& value: values | std::views::take(10)) { - logs.error() << "In Area " << value.first << ": " << value.second << " "; + logs.error() << "In Area " << key << ": " << value << " "; } } - // for (auto value = areasErrorMap_.begin(); value != areasErrorMap_.end();) - // { - // const auto& key = value->first; - // const auto& rangeEnd = areasErrorMap_.upper_bound(key); - - // const auto& limit = std::min(value + 10, rangeEnd); - - // for (; value != limit; ++value) - // { - // logs.error() << "In Area " << value.first << ": " << value.second << " "; - // } - - // // Move iterator to the next key - // value = rangeEnd; - // } - throw FatalError("Hydro validation has failed !"); } } HydroErrorsCollector::AreaReference::AreaReference(HydroErrorsCollector* collector, const std::string& name): - areaSingleErrorMessage_(collector->areasErrorMap_.insert({name, ""})->second) + areaSingleErrorMessage_(collector->CurrentMessage(name)) { } @@ -62,4 +37,9 @@ HydroErrorsCollector::AreaReference HydroErrorsCollector::operator()(const std:: return AreaReference(this, name); } +std::string& HydroErrorsCollector::CurrentMessage(const std::string& name) +{ + auto& msgs = areasErrorMap_[name]; + return *msgs.insert(msgs.end(), ""); +} } // namespace Antares From f77b6e19a3656961e1aa5cd8ae56aec01f40745e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Omn=C3=A8s?= Date: Tue, 2 Jul 2024 15:57:13 +0200 Subject: [PATCH 42/42] Complete hydro logs (#2221) - Instead of return, use a flag to record all possible errors - Add precision for final level reservoir, hopefully it will make this log message more useful Remark : We use the newly-introduced errorCollector to limit output to 10 entries per area --- .../hydro/management/HydroInputsChecker.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/solver/hydro/management/HydroInputsChecker.cpp b/src/solver/hydro/management/HydroInputsChecker.cpp index ff94990ee2..d9956e94a2 100644 --- a/src/solver/hydro/management/HydroInputsChecker.cpp +++ b/src/solver/hydro/management/HydroInputsChecker.cpp @@ -99,6 +99,7 @@ bool HydroInputsChecker::checkWeeklyMinGeneration(uint year, const Data::Area& a const auto& srcinflows = area.hydro.series->storage.getColumn(year); const auto& srcmingen = area.hydro.series->mingen.getColumn(year); // Weekly minimum generation <= Weekly inflows for each week + bool ret = true; for (uint week = 0; week < calendar_.maxWeeksInYear - 1; ++week) { double totalWeekMingen = 0.0; @@ -122,15 +123,16 @@ bool HydroInputsChecker::checkWeeklyMinGeneration(uint year, const Data::Area& a << " the minimum generation of " << totalWeekMingen << " MW in week " << week + 1 << " of TS-" << area.hydro.series->mingen.getSeriesIndex(year) + 1 << " is incompatible with the inflows of " << totalWeekInflows << " MW."; - return false; + ret = false; } } - return true; + return ret; } bool HydroInputsChecker::checkYearlyMinGeneration(uint year, const Data::Area& area) { const auto& data = area.hydro.managementData.at(year); + bool ret = true; if (data.totalYearMingen > data.totalYearInflows) { // Yearly minimum generation <= Yearly inflows @@ -138,14 +140,15 @@ bool HydroInputsChecker::checkYearlyMinGeneration(uint year, const Data::Area& a << " the minimum generation of " << data.totalYearMingen << " MW of TS-" << area.hydro.series->mingen.getSeriesIndex(year) + 1 << " is incompatible with the inflows of " << data.totalYearInflows << " MW."; - return false; + ret = false; } - return true; + return ret; } bool HydroInputsChecker::checkMonthlyMinGeneration(uint year, const Data::Area& area) { const auto& data = area.hydro.managementData.at(year); + bool ret = true; for (uint month = 0; month != 12; ++month) { uint realmonth = calendar_.months[month].realmonth; @@ -158,10 +161,10 @@ bool HydroInputsChecker::checkMonthlyMinGeneration(uint year, const Data::Area& << area.hydro.series->mingen.getSeriesIndex(year) + 1 << " is incompatible with the inflows of " << data.totalMonthInflows[realmonth] << " MW."; - return false; + ret = false; } } - return true; + return ret; } bool HydroInputsChecker::checkGenerationPowerConsistency(uint year) @@ -222,7 +225,9 @@ void HydroInputsChecker::CheckFinalReservoirLevelsConfiguration(uint year) errorCollector_); if (!validator.check()) { - errorCollector_(area.name) << "hydro final level : infeasibility"; + errorCollector_(area.name) + << "hydro final level : infeasibility for area " << area.name + << " please check the corresponding final level data (scenario-builder)"; } if (validator.finalLevelFineForUse()) {