From 2fc0adac9ead16d56c2f4a74a2f5a523392246ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Omn=C3=A8s?= Date: Fri, 6 Dec 2024 14:25:50 +0100 Subject: [PATCH] Add compatibility parameter for hydro pmax I/O [ANT-2278] (#2514) Co-authored-by: payetvin <113102157+payetvin@users.noreply.github.com> Co-authored-by: Vincent Payet --- simtest.json | 2 +- src/CMakeLists.txt | 2 +- src/libs/antares/study/area/list.cpp | 13 ++++- .../study/include/antares/study/parameters.h | 15 ++++++ .../antares/study/parts/hydro/series.h | 6 ++- src/libs/antares/study/parameters.cpp | 53 ++++++++++++++++++- .../antares/study/parts/hydro/container.cpp | 3 +- src/libs/antares/study/parts/hydro/series.cpp | 3 +- .../study/parameters/parameters-tests.cpp | 25 ++++++++- 9 files changed, 113 insertions(+), 9 deletions(-) diff --git a/simtest.json b/simtest.json index 26875e3a2e..11b8cee038 100644 --- a/simtest.json +++ b/simtest.json @@ -1,3 +1,3 @@ { - "version": "v9.2.0f" + "version": "v9.2.0g" } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 24ef38e558..56dc5e2bf8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,7 +8,7 @@ set(ANTARES_VERSION_REVISION 0) # Beta release set(ANTARES_BETA 0) -set(ANTARES_RC 6) +set(ANTARES_RC 7) set(ANTARES_VERSION_YEAR 2024) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index b9353937d9..cf2624515f 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -950,20 +950,29 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, ret = area.hydro.series->loadGenerationTS(area.id, hydroSeries, studyVersion) && ret; } - if (studyVersion < StudyVersion(9, 1)) + switch (study.parameters.compatibility.hydroPmax) + { + case Parameters::Compatibility::HydroPmax::Daily: { HydroMaxTimeSeriesReader reader(area.hydro, area.id.to(), area.name.to()); ret = reader.read(pathHydro.string(), study.usedByTheSolver) && ret; + break; } - else + case Parameters::Compatibility::HydroPmax::Hourly: { ret = area.hydro.series->LoadMaxPower(area.id, hydroSeries) && ret; + break; + } + default: + throw std::invalid_argument( + "Value not supported for study.parameters.compatibility.hydroPmax"); } area.hydro.series->resizeTSinDeratedMode(study.parameters.derated, studyVersion, + study.parameters.compatibility.hydroPmax, study.usedByTheSolver); } diff --git a/src/libs/antares/study/include/antares/study/parameters.h b/src/libs/antares/study/include/antares/study/parameters.h index 0df3a8b157..38228bc23b 100644 --- a/src/libs/antares/study/include/antares/study/parameters.h +++ b/src/libs/antares/study/include/antares/study/parameters.h @@ -399,6 +399,18 @@ class Parameters final } include; + struct Compatibility + { + enum class HydroPmax + { + Daily, + Hourly + }; + HydroPmax hydroPmax = HydroPmax::Daily; + }; + + Compatibility compatibility; + // Shedding struct { @@ -518,6 +530,9 @@ const char* SimulationModeToCString(SimulationMode mode); */ bool StringToSimulationMode(SimulationMode& mode, Yuni::CString<20, false> text); +const char* CompatibilityHydroPmaxToCString(Parameters::Compatibility::HydroPmax); +bool StringToCompatibilityHydroPmax(Parameters::Compatibility::HydroPmax&, const std::string& text); + } // namespace Antares::Data #endif // __ANTARES_LIBS_STUDY_PARAMETERS_H__ diff --git a/src/libs/antares/study/include/antares/study/parts/hydro/series.h b/src/libs/antares/study/include/antares/study/parts/hydro/series.h index 4bb8367ac3..c3b587c0de 100644 --- a/src/libs/antares/study/include/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/include/antares/study/parts/hydro/series.h @@ -23,6 +23,7 @@ #include #include +#include #include #include "../../fwd.h" @@ -137,7 +138,10 @@ class DataSeriesHydro uint TScount() const; // Setting TS's when derated mode is on - void resizeTSinDeratedMode(bool derated, StudyVersion version, bool useBySolver); + void resizeTSinDeratedMode(bool derated, + StudyVersion version, + Parameters::Compatibility::HydroPmax hydroPmax, + bool useBySolver); }; // class DataSeriesHydro } // namespace Data } // namespace Antares diff --git a/src/libs/antares/study/parameters.cpp b/src/libs/antares/study/parameters.cpp index e26e57c6f7..54f5b6db74 100644 --- a/src/libs/antares/study/parameters.cpp +++ b/src/libs/antares/study/parameters.cpp @@ -208,6 +208,39 @@ const char* SimulationModeToCString(SimulationMode mode) } } +const char* CompatibilityHydroPmaxToCString(Parameters::Compatibility::HydroPmax mode) +{ + switch (mode) + { + case Parameters::Compatibility::HydroPmax::Daily: + return "daily"; + case Parameters::Compatibility::HydroPmax::Hourly: + return "hourly"; + default: + return "Unknown"; + } +} + +bool StringToCompatibilityHydroPmax(Parameters::Compatibility::HydroPmax& mode, + const std::string& text) +{ + if (text.empty()) + { + return false; + } + if (text == "daily") + { + mode = Parameters::Compatibility::HydroPmax::Daily; + return true; + } + if (text == "hourly") + { + mode = Parameters::Compatibility::HydroPmax::Hourly; + return true; + } + return false; +} + bool Parameters::economy() const { return mode == SimulationMode::Economy; @@ -1053,6 +1086,19 @@ static bool SGDIntLoadFamily_SeedsMersenneTwister(Parameters& d, return false; } +static bool SGDIntLoadFamily_Compatibility(Parameters& d, + const String& key, + const String& value, + const String&) +{ + if (key == "hydro-pmax") + { + return StringToCompatibilityHydroPmax(d.compatibility.hydroPmax, value); + } + + return false; +} + static bool SGDIntLoadFamily_Legacy(Parameters& d, const String& key, const String& value, @@ -1170,7 +1216,8 @@ bool Parameters::loadFromINI(const IniFile& ini, const StudyVersion& version) {"advanced parameters", &SGDIntLoadFamily_AdvancedParameters}, {"playlist", &SGDIntLoadFamily_Playlist}, {"variables selection", &SGDIntLoadFamily_VariablesSelection}, - {"seeds - mersenne twister", &SGDIntLoadFamily_SeedsMersenneTwister}}; + {"seeds - mersenne twister", &SGDIntLoadFamily_SeedsMersenneTwister}, + {"compatibility", &SGDIntLoadFamily_Compatibility}}; Callback handleAllKeysInSection; // Foreach section on the ini file... @@ -1967,6 +2014,10 @@ void Parameters::saveToINI(IniFile& ini) const section->add(SeedToID((SeedIndex)sd), seed[sd]); } } + { + auto* section = ini.addSection("compatibility"); + section->add("hydro-pmax", CompatibilityHydroPmaxToCString(compatibility.hydroPmax)); + } } bool Parameters::loadFromFile(const std::filesystem::path& filename, const StudyVersion& version) diff --git a/src/libs/antares/study/parts/hydro/container.cpp b/src/libs/antares/study/parts/hydro/container.cpp index 6ee131b4f3..52e6ef1d83 100644 --- a/src/libs/antares/study/parts/hydro/container.cpp +++ b/src/libs/antares/study/parts/hydro/container.cpp @@ -156,7 +156,8 @@ bool PartHydro::LoadFromFolder(Study& study, const fs::path& folder) area.hydro.pumpingEfficiency = 1.; area.hydro.deltaBetweenFinalAndInitialLevels.resize(study.parameters.nbYears); - if (study.header.version >= StudyVersion(9, 1)) + if (study.parameters.compatibility.hydroPmax + == Parameters::Compatibility::HydroPmax::Hourly) { // GUI part patch : // We need to know, when estimating the RAM required by the solver, if the current diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index a9f62664c8..2ae774fbdf 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -230,6 +230,7 @@ uint DataSeriesHydro::TScount() const void DataSeriesHydro::resizeTSinDeratedMode(bool derated, StudyVersion studyVersion, + Parameters::Compatibility::HydroPmax hydroPmax, bool usedBySolver) { if (!(derated && usedBySolver)) @@ -243,7 +244,7 @@ void DataSeriesHydro::resizeTSinDeratedMode(bool derated, { mingen.averageTimeseries(); - if (studyVersion >= StudyVersion(9, 1)) + if (hydroPmax == Parameters::Compatibility::HydroPmax::Hourly) { maxHourlyGenPower.averageTimeseries(); maxHourlyPumpPower.averageTimeseries(); diff --git a/src/tests/src/libs/antares/study/parameters/parameters-tests.cpp b/src/tests/src/libs/antares/study/parameters/parameters-tests.cpp index 5e0da57a10..6015fcbbc0 100644 --- a/src/tests/src/libs/antares/study/parameters/parameters-tests.cpp +++ b/src/tests/src/libs/antares/study/parameters/parameters-tests.cpp @@ -104,6 +104,26 @@ BOOST_FIXTURE_TEST_CASE(invalidValues, Fixture) BOOST_CHECK_EQUAL(p.renewableGeneration(), rgUnknown); } +BOOST_FIXTURE_TEST_CASE(hydroPmax, Fixture) +{ + BOOST_CHECK(p.compatibility.hydroPmax == Parameters::Compatibility::HydroPmax::Daily); + + writeValidFile(); + BOOST_CHECK(p.loadFromFile(path.string(), version)); + p.validateOptions(options); + p.fixBadValues(); + + BOOST_CHECK(p.compatibility.hydroPmax == Parameters::Compatibility::HydroPmax::Hourly); + + BOOST_CHECK_EQUAL(CompatibilityHydroPmaxToCString(p.compatibility.hydroPmax), "hourly"); + BOOST_CHECK_EQUAL(CompatibilityHydroPmaxToCString(Parameters::Compatibility::HydroPmax::Daily), + "daily"); + + BOOST_CHECK(StringToCompatibilityHydroPmax(p.compatibility.hydroPmax, "daily")); + BOOST_CHECK(!StringToCompatibilityHydroPmax(p.compatibility.hydroPmax, "")); + BOOST_CHECK(!StringToCompatibilityHydroPmax(p.compatibility.hydroPmax, "abc")); +} + BOOST_AUTO_TEST_SUITE_END() void Fixture::writeInvalidFile() @@ -215,7 +235,10 @@ void Fixture::writeValidFile() seed-spilled-energy-costs = 7005489 seed-thermal-costs = 8005489 seed-hydro-costs = 9005489 - seed-initial-reservoir-levels = 10005489)"; + seed-initial-reservoir-levels = 10005489 + + [compatibility] + hydro-pmax = hourly)"; outfile.close(); }