From 39c1d1c12492c62490cefbe94f90739b2fc729e2 Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:58:20 +0100 Subject: [PATCH 01/20] Add `enabled` property for ST storage objects --- .../antares/study/parts/short-term-storage/container.cpp | 6 +++++- src/libs/antares/study/parts/short-term-storage/container.h | 2 +- .../antares/study/parts/short-term-storage/properties.cpp | 5 ++++- .../antares/study/parts/short-term-storage/properties.h | 3 +++ src/solver/simulation/sim_calcul_economique.cpp | 3 +++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/libs/antares/study/parts/short-term-storage/container.cpp b/src/libs/antares/study/parts/short-term-storage/container.cpp index 3b0cba2a36..ac9c68f903 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -109,6 +109,10 @@ bool STStorageInput::saveDataSeriesToFolder(const std::string& folder) const std::size_t STStorageInput::count() const { - return storagesByIndex.size(); + return std::count_if(storagesByIndex.begin(), + storagesByIndex.end(), + [](const STStorageCluster* st) { + return st->properties.enabled; + }); } } // namespace Antares::Data::ShortTermStorage diff --git a/src/libs/antares/study/parts/short-term-storage/container.h b/src/libs/antares/study/parts/short-term-storage/container.h index 00673cebcd..0c186a4f93 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.h +++ b/src/libs/antares/study/parts/short-term-storage/container.h @@ -40,7 +40,7 @@ class STStorageInput bool createSTStorageClustersFromIniFile(const std::string& path); // 2. Read ALL series bool loadSeriesFromFolder(const std::string& folder) const; - // Number of ST storages + // Number of enabled ST storages, ignoring disabled ST storages std::size_t count() const; bool saveToFolder(const std::string& folder) const; diff --git a/src/libs/antares/study/parts/short-term-storage/properties.cpp b/src/libs/antares/study/parts/short-term-storage/properties.cpp index 058a8b5f3a..bee25006d5 100644 --- a/src/libs/antares/study/parts/short-term-storage/properties.cpp +++ b/src/libs/antares/study/parts/short-term-storage/properties.cpp @@ -115,6 +115,9 @@ bool Properties::loadKey(const IniFile::Property* p) return false; } + if (p->key == "enabled") + return p->value.to(this->enabled); + return false; } @@ -147,7 +150,7 @@ bool Properties::saveToFolder(const std::string& folder) const s->add("efficiency", this->efficiencyFactor); s->add("initialleveloptim", this->initialLevelOptim); - + s->add("enabled", this->enabled); return ini.save(pathIni); } diff --git a/src/libs/antares/study/parts/short-term-storage/properties.h b/src/libs/antares/study/parts/short-term-storage/properties.h index 58e79b1241..fd6201727b 100644 --- a/src/libs/antares/study/parts/short-term-storage/properties.h +++ b/src/libs/antares/study/parts/short-term-storage/properties.h @@ -73,6 +73,9 @@ class Properties // cluster name std::string name; + // Enabled ? + bool enabled; + static const std::map ST_STORAGE_PROPERTY_GROUP_ENUM; private: static constexpr double initiallevelDefault = .5; diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 201f6b9899..2b2ec59688 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -53,6 +53,9 @@ static void importShortTermStorages( int storageIndex = 0; for (auto st : areas[areaIndex]->shortTermStorage.storagesByIndex) { + if (!st->properties.enabled) + continue; + ::ShortTermStorage::PROPERTIES& toInsert = ShortTermStorageOut[areaIndex][storageIndex]; toInsert.clusterGlobalIndex = clusterGlobalIndex; From 0e5ad1a2b5615d138c85840c4c651c0e4615d4a0 Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Mon, 4 Dec 2023 10:00:12 +0100 Subject: [PATCH 02/20] Enabled by default --- src/libs/antares/study/parts/short-term-storage/properties.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/antares/study/parts/short-term-storage/properties.h b/src/libs/antares/study/parts/short-term-storage/properties.h index fd6201727b..7d408a163e 100644 --- a/src/libs/antares/study/parts/short-term-storage/properties.h +++ b/src/libs/antares/study/parts/short-term-storage/properties.h @@ -74,7 +74,7 @@ class Properties std::string name; // Enabled ? - bool enabled; + bool enabled = true; static const std::map ST_STORAGE_PROPERTY_GROUP_ENUM; private: From bfd23226c01d5a6a57b541b944067701caa7fb47 Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Mon, 4 Dec 2023 10:17:45 +0100 Subject: [PATCH 03/20] Add unit test for load --- .../short-term-storage-input.cpp | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp b/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp index bc2c4b0f8c..711f40f7fa 100644 --- a/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp +++ b/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp @@ -15,6 +15,7 @@ using namespace std; using namespace Antares::Data; +namespace { std::string getFolder() { std::filesystem::path tmpDir = std::filesystem::temp_directory_path(); @@ -76,7 +77,7 @@ void createFileSeries(unsigned int size) createIndividualFileSeries(folder + SEP + "upper-rule-curve.txt", size); } -void createIniFile() +void createIniFile(bool enabled) { std::string folder = getFolder(); @@ -91,7 +92,7 @@ void createIniFile() outfile << "reservoircapacity = 31200.000000" << std::endl; outfile << "efficiency = 0.75" << std::endl; outfile << "initiallevel = 0.50000" << std::endl; - + outfile << "enabled = " << (enabled ? "true" : "false") << std::endl; outfile.close(); } @@ -129,6 +130,7 @@ void removeIniFile() std::string folder = getFolder(); std::filesystem::remove(folder + SEP + "list.ini"); } +} // ================= // The fixture @@ -244,12 +246,30 @@ BOOST_FIXTURE_TEST_CASE(check_cluster_series_load_vector, Fixture) && cluster.series->lowerRuleCurve[6392] == 0.5); } -BOOST_FIXTURE_TEST_CASE(check_container_properties_load, Fixture) +BOOST_FIXTURE_TEST_CASE(check_container_properties_enabled_load, Fixture) { - createIniFile(); + createIniFile(true); BOOST_CHECK(container.createSTStorageClustersFromIniFile(folder)); - BOOST_CHECK(container.storagesByIndex[0]->properties.validate()); + + auto& properties = container.storagesByIndex[0]->properties; + + BOOST_CHECK(properties.enabled); + BOOST_CHECK(properties.validate()); + + removeIniFile(); +} + +BOOST_FIXTURE_TEST_CASE(check_container_properties_disabled_load, Fixture) +{ + createIniFile(false); + + BOOST_CHECK(container.createSTStorageClustersFromIniFile(folder)); + + auto& properties = container.storagesByIndex[0]->properties; + + BOOST_CHECK(!properties.enabled); + BOOST_CHECK(properties.validate()); removeIniFile(); } @@ -275,7 +295,7 @@ BOOST_FIXTURE_TEST_CASE(check_container_properties_empty_file, Fixture) BOOST_FIXTURE_TEST_CASE(check_file_save, Fixture) { - createIniFile(); + createIniFile(true); BOOST_CHECK(container.createSTStorageClustersFromIniFile(folder)); From c56060d04f390fe1cccb5835a9cf53a73c192901 Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Mon, 4 Dec 2023 14:14:06 +0100 Subject: [PATCH 04/20] Add test on container's count --- .../study/short-term-storage-input/short-term-storage-input.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp b/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp index 711f40f7fa..93c44fa80e 100644 --- a/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp +++ b/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp @@ -255,6 +255,7 @@ BOOST_FIXTURE_TEST_CASE(check_container_properties_enabled_load, Fixture) auto& properties = container.storagesByIndex[0]->properties; BOOST_CHECK(properties.enabled); + BOOST_CHECK_EQUAL(container.count(), 1); BOOST_CHECK(properties.validate()); removeIniFile(); @@ -269,6 +270,7 @@ BOOST_FIXTURE_TEST_CASE(check_container_properties_disabled_load, Fixture) auto& properties = container.storagesByIndex[0]->properties; BOOST_CHECK(!properties.enabled); + BOOST_CHECK_EQUAL(container.count(), 0); BOOST_CHECK(properties.validate()); removeIniFile(); From 83a1ebf4c0b330fb7ff8193c2c69a3f42f3753d1 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 11 Dec 2023 11:20:15 +0100 Subject: [PATCH 05/20] [DEV] Add enabled function for sts clusters --- .../study/parts/short-term-storage/cluster.cpp | 5 +++++ .../study/parts/short-term-storage/cluster.h | 3 ++- .../parts/short-term-storage/properties.h | 18 +++++++++--------- .../simulation/sim_calcul_economique.cpp | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/libs/antares/study/parts/short-term-storage/cluster.cpp b/src/libs/antares/study/parts/short-term-storage/cluster.cpp index 50789c7435..af4fb319fd 100644 --- a/src/libs/antares/study/parts/short-term-storage/cluster.cpp +++ b/src/libs/antares/study/parts/short-term-storage/cluster.cpp @@ -63,6 +63,11 @@ bool STStorageCluster::loadFromSection(const IniFile::Section& section) return true; } +bool STStorageCluster::enabled() const +{ + return properties.enabled; +} + bool STStorageCluster::validate() { logs.debug() << "Validating properties and series for st storage: " << id; diff --git a/src/libs/antares/study/parts/short-term-storage/cluster.h b/src/libs/antares/study/parts/short-term-storage/cluster.h index 4e909962a0..8a439e5edd 100644 --- a/src/libs/antares/study/parts/short-term-storage/cluster.h +++ b/src/libs/antares/study/parts/short-term-storage/cluster.h @@ -38,8 +38,9 @@ class STStorageCluster { public: bool validate(); - bool loadFromSection(const IniFile::Section& section); + bool enabled() const; + bool loadFromSection(const IniFile::Section& section); bool loadSeries(const std::string& folder) const; bool saveProperties(const std::string& path) const; diff --git a/src/libs/antares/study/parts/short-term-storage/properties.h b/src/libs/antares/study/parts/short-term-storage/properties.h index 7d408a163e..24a3b0d2e1 100644 --- a/src/libs/antares/study/parts/short-term-storage/properties.h +++ b/src/libs/antares/study/parts/short-term-storage/properties.h @@ -56,24 +56,24 @@ class Properties bool loadKey(const IniFile::Property* p); bool saveToFolder(const std::string& folder) const; - // Not optional Injection nominal capacity, >= 0 + /// Not optional Injection nominal capacity, >= 0 std::optional injectionNominalCapacity; - // Not optional Withdrawal nominal capacity, >= 0 + /// Not optional Withdrawal nominal capacity, >= 0 std::optional withdrawalNominalCapacity; - // Not optional Reservoir capacity in MWh, >= 0 + /// Not optional Reservoir capacity in MWh, >= 0 std::optional reservoirCapacity; - // Initial level, <= 1 + /// Initial level, <= 1 double initialLevel = initiallevelDefault; - // Bool to optimise or not initial level + /// Bool to optimise or not initial level bool initialLevelOptim = false; - // Efficiency factor between 0 and 1 + /// Efficiency factor between 0 and 1 double efficiencyFactor = 1; - // Used to sort outputs + /// Used to sort outputs Group group = Group::Other1; - // cluster name + /// cluster name std::string name; - // Enabled ? + /// Enabled ? bool enabled = true; static const std::map ST_STORAGE_PROPERTY_GROUP_ENUM; diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 2b2ec59688..839f884dcb 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -53,7 +53,7 @@ static void importShortTermStorages( int storageIndex = 0; for (auto st : areas[areaIndex]->shortTermStorage.storagesByIndex) { - if (!st->properties.enabled) + if (!st->enabled()) continue; ::ShortTermStorage::PROPERTIES& toInsert = ShortTermStorageOut[areaIndex][storageIndex]; From 9bc07d0a6bda79d09a6846f33e7b5d86659818e3 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 11 Dec 2023 11:48:37 +0100 Subject: [PATCH 06/20] [DEV] Add enabled check in output var --- src/solver/variable/economy/STStorageCashFlowByCluster.h | 2 ++ src/solver/variable/economy/STStorageInjectionByCluster.h | 2 ++ src/solver/variable/economy/STStorageLevelsByCluster.h | 2 ++ src/solver/variable/economy/STStorageWithdrawalByCluster.h | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/solver/variable/economy/STStorageCashFlowByCluster.h b/src/solver/variable/economy/STStorageCashFlowByCluster.h index 6ea3456132..26e7e1139a 100644 --- a/src/solver/variable/economy/STStorageCashFlowByCluster.h +++ b/src/solver/variable/economy/STStorageCashFlowByCluster.h @@ -282,6 +282,8 @@ class STstorageCashFlowByCluster : public Variable::IVariableenabled()) + continue; results.variableCaption = cluster->properties.name; results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][clusterIndex] diff --git a/src/solver/variable/economy/STStorageInjectionByCluster.h b/src/solver/variable/economy/STStorageInjectionByCluster.h index 31ccb7912a..4b71595b63 100644 --- a/src/solver/variable/economy/STStorageInjectionByCluster.h +++ b/src/solver/variable/economy/STStorageInjectionByCluster.h @@ -284,6 +284,8 @@ class STstorageInjectionByCluster : public Variable::IVariableenabled()) + continue; results.variableCaption = cluster->properties.name; results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][clusterIndex] diff --git a/src/solver/variable/economy/STStorageLevelsByCluster.h b/src/solver/variable/economy/STStorageLevelsByCluster.h index 2e220e08ab..1b5f819e07 100644 --- a/src/solver/variable/economy/STStorageLevelsByCluster.h +++ b/src/solver/variable/economy/STStorageLevelsByCluster.h @@ -284,6 +284,8 @@ class STstorageLevelsByCluster { // Write the data for the current year const auto* cluster = shortTermStorage.storagesByIndex[clusterIndex]; + if (!cluster->enabled()) + continue; results.variableCaption = cluster->properties.name; results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][clusterIndex].template buildAnnualSurveyReport( diff --git a/src/solver/variable/economy/STStorageWithdrawalByCluster.h b/src/solver/variable/economy/STStorageWithdrawalByCluster.h index e0887b64d8..2dded8cf2a 100644 --- a/src/solver/variable/economy/STStorageWithdrawalByCluster.h +++ b/src/solver/variable/economy/STStorageWithdrawalByCluster.h @@ -284,6 +284,8 @@ class STstorageWithdrawalByCluster { // Write the data for the current year const auto* cluster = shortTermStorage.storagesByIndex[clusterIndex]; + if (!cluster->enabled()) + continue; results.variableCaption = cluster->properties.name; results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][clusterIndex].template buildAnnualSurveyReport( From 42d383c98b05494cc458fb2e862dd0f9211e2cb7 Mon Sep 17 00:00:00 2001 From: payetvin <113102157+payetvin@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:46:47 +0100 Subject: [PATCH 07/20] Remove sts container (#1804) Remove storageById --- .../parts/short-term-storage/cluster.cpp | 2 +- .../study/parts/short-term-storage/cluster.h | 4 ++-- .../parts/short-term-storage/container.cpp | 19 ++++++++++--------- .../parts/short-term-storage/container.h | 4 +--- .../simulation/sim_calcul_economique.cpp | 18 +++++++++--------- .../economy/STStorageCashFlowByCluster.h | 7 ++++--- .../economy/STStorageInjectionByCluster.h | 7 ++++--- .../economy/STStorageLevelsByCluster.h | 7 ++++--- .../economy/STStorageWithdrawalByCluster.h | 7 ++++--- .../variable/economy/shortTermStorage.h | 4 ++-- src/solver/variable/info.h | 2 +- .../short-term-storage-input.cpp | 6 +++--- 12 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/libs/antares/study/parts/short-term-storage/cluster.cpp b/src/libs/antares/study/parts/short-term-storage/cluster.cpp index af4fb319fd..eb202920b2 100644 --- a/src/libs/antares/study/parts/short-term-storage/cluster.cpp +++ b/src/libs/antares/study/parts/short-term-storage/cluster.cpp @@ -68,7 +68,7 @@ bool STStorageCluster::enabled() const return properties.enabled; } -bool STStorageCluster::validate() +bool STStorageCluster::validate() const { logs.debug() << "Validating properties and series for st storage: " << id; return properties.validate() && series->validate(); diff --git a/src/libs/antares/study/parts/short-term-storage/cluster.h b/src/libs/antares/study/parts/short-term-storage/cluster.h index 8a439e5edd..114e109f2d 100644 --- a/src/libs/antares/study/parts/short-term-storage/cluster.h +++ b/src/libs/antares/study/parts/short-term-storage/cluster.h @@ -37,8 +37,8 @@ namespace Antares::Data::ShortTermStorage class STStorageCluster { public: - bool validate(); bool enabled() const; + bool validate() const; bool loadFromSection(const IniFile::Section& section); bool loadSeries(const std::string& folder) const; @@ -49,7 +49,7 @@ class STStorageCluster std::string id; std::shared_ptr series = std::make_shared(); - Properties properties; + mutable Properties properties; }; } // namespace Antares::Data::ShortTermStorage diff --git a/src/libs/antares/study/parts/short-term-storage/container.cpp b/src/libs/antares/study/parts/short-term-storage/container.cpp index ac9c68f903..02d2a1fec3 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "container.h" @@ -39,7 +40,7 @@ namespace Antares::Data::ShortTermStorage bool STStorageInput::validate() const { return std::all_of(storagesByIndex.cbegin(), storagesByIndex.cend(), [](auto& cluster) { - return cluster->validate(); + return cluster.validate(); }); } @@ -61,12 +62,12 @@ bool STStorageInput::createSTStorageClustersFromIniFile(const std::string& path) if (!cluster.loadFromSection(*section)) return false; - storagesById.try_emplace(cluster.properties.name, cluster); + storagesByIndex.push_back(cluster); } - storagesByIndex.reserve(storagesById.size()); - for (auto& [id, storage] : storagesById) - storagesByIndex.push_back(&storage); + std::sort(storagesByIndex.begin(), storagesByIndex.end(), [&](const auto& a, const auto& b){ + return a.properties.name < b.properties.name; + }); return true; } @@ -80,8 +81,8 @@ bool STStorageInput::loadSeriesFromFolder(const std::string& folder) const for (auto& cluster : storagesByIndex) { - const std::string buffer(folder + SEP + cluster->id); - ret = cluster->loadSeries(buffer) && ret; + const std::string buffer(folder + SEP + cluster.id); + ret = cluster.loadSeries(buffer) && ret; } return ret; @@ -95,7 +96,7 @@ bool STStorageInput::saveToFolder(const std::string& folder) const logs.notice() << "created empty ini: " << folder + SEP + "list.ini"; return std::all_of(storagesByIndex.cbegin(), storagesByIndex.cend(), [&folder](auto& storage) { - return storage->saveProperties(folder); + return storage.saveProperties(folder); }); } @@ -103,7 +104,7 @@ bool STStorageInput::saveDataSeriesToFolder(const std::string& folder) const { Yuni::IO::Directory::Create(folder); return std::all_of(storagesByIndex.cbegin(), storagesByIndex.cend(), [&folder](auto& storage) { - return storage->saveSeries(folder + SEP + storage->id); + return storage.saveSeries(folder + SEP + storage.id); }); } diff --git a/src/libs/antares/study/parts/short-term-storage/container.h b/src/libs/antares/study/parts/short-term-storage/container.h index 0c186a4f93..7aa4133942 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.h +++ b/src/libs/antares/study/parts/short-term-storage/container.h @@ -46,8 +46,6 @@ class STStorageInput bool saveToFolder(const std::string& folder) const; bool saveDataSeriesToFolder(const std::string& folder) const; - - std::vector storagesByIndex; - std::map storagesById; + std::vector storagesByIndex; }; } // namespace Antares::Data::ShortTermStorage diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 839f884dcb..d5aea655e9 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -60,15 +60,15 @@ static void importShortTermStorages( toInsert.clusterGlobalIndex = clusterGlobalIndex; // Properties - toInsert.reservoirCapacity = st->properties.reservoirCapacity.value(); - toInsert.efficiency = st->properties.efficiencyFactor; - toInsert.injectionNominalCapacity = st->properties.injectionNominalCapacity.value(); - toInsert.withdrawalNominalCapacity = st->properties.withdrawalNominalCapacity.value(); - toInsert.initialLevel = st->properties.initialLevel; - toInsert.initialLevelOptim = st->properties.initialLevelOptim; - toInsert.name = st->properties.name; - - toInsert.series = st->series; + toInsert.reservoirCapacity = st.properties.reservoirCapacity.value(); + toInsert.efficiency = st.properties.efficiencyFactor; + toInsert.injectionNominalCapacity = st.properties.injectionNominalCapacity.value(); + toInsert.withdrawalNominalCapacity = st.properties.withdrawalNominalCapacity.value(); + toInsert.initialLevel = st.properties.initialLevel; + toInsert.initialLevelOptim = st.properties.initialLevelOptim; + toInsert.name = st.properties.name; + + toInsert.series = st.series; // TODO add missing properties, or use the same struct storageIndex++; diff --git a/src/solver/variable/economy/STStorageCashFlowByCluster.h b/src/solver/variable/economy/STStorageCashFlowByCluster.h index 26e7e1139a..509d77cb80 100644 --- a/src/solver/variable/economy/STStorageCashFlowByCluster.h +++ b/src/solver/variable/economy/STStorageCashFlowByCluster.h @@ -281,10 +281,11 @@ class STstorageCashFlowByCluster : public Variable::IVariableenabled()) + const auto& cluster = shortTermStorage.storagesByIndex[clusterIndex]; + if (cluster.enabled()) continue; - results.variableCaption = cluster->properties.name; + + results.variableCaption = cluster.properties.name; results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][clusterIndex] .template buildAnnualSurveyReport(results, fileLevel, precision); diff --git a/src/solver/variable/economy/STStorageInjectionByCluster.h b/src/solver/variable/economy/STStorageInjectionByCluster.h index 4b71595b63..29726416ec 100644 --- a/src/solver/variable/economy/STStorageInjectionByCluster.h +++ b/src/solver/variable/economy/STStorageInjectionByCluster.h @@ -283,10 +283,11 @@ class STstorageInjectionByCluster : public Variable::IVariableenabled()) + const auto& cluster = shortTermStorage.storagesByIndex[clusterIndex]; + if (!cluster.enabled()) continue; - results.variableCaption = cluster->properties.name; + + results.variableCaption = cluster.properties.name; results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][clusterIndex] .template buildAnnualSurveyReport(results, fileLevel, precision); diff --git a/src/solver/variable/economy/STStorageLevelsByCluster.h b/src/solver/variable/economy/STStorageLevelsByCluster.h index 1b5f819e07..c5ba21522d 100644 --- a/src/solver/variable/economy/STStorageLevelsByCluster.h +++ b/src/solver/variable/economy/STStorageLevelsByCluster.h @@ -283,10 +283,11 @@ class STstorageLevelsByCluster for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex) { // Write the data for the current year - const auto* cluster = shortTermStorage.storagesByIndex[clusterIndex]; - if (!cluster->enabled()) + const auto& cluster = shortTermStorage.storagesByIndex[clusterIndex]; + if (!cluster.enabled()) continue; - results.variableCaption = cluster->properties.name; + + results.variableCaption = cluster.properties.name; results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][clusterIndex].template buildAnnualSurveyReport( results, fileLevel, precision); diff --git a/src/solver/variable/economy/STStorageWithdrawalByCluster.h b/src/solver/variable/economy/STStorageWithdrawalByCluster.h index 2dded8cf2a..c1efd48c67 100644 --- a/src/solver/variable/economy/STStorageWithdrawalByCluster.h +++ b/src/solver/variable/economy/STStorageWithdrawalByCluster.h @@ -283,10 +283,11 @@ class STstorageWithdrawalByCluster for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex) { // Write the data for the current year - const auto* cluster = shortTermStorage.storagesByIndex[clusterIndex]; - if (!cluster->enabled()) + const auto& cluster = shortTermStorage.storagesByIndex[clusterIndex]; + if (!cluster.enabled()) continue; - results.variableCaption = cluster->properties.name; + + results.variableCaption = cluster.properties.name; results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][clusterIndex].template buildAnnualSurveyReport( results, fileLevel, precision); diff --git a/src/solver/variable/economy/shortTermStorage.h b/src/solver/variable/economy/shortTermStorage.h index 959d4a49be..77aab56a7a 100644 --- a/src/solver/variable/economy/shortTermStorage.h +++ b/src/solver/variable/economy/shortTermStorage.h @@ -237,8 +237,8 @@ class ShortTermStorageByGroup using namespace Antares::Data::ShortTermStorage; for (uint stsIndex = 0; stsIndex < state.area->shortTermStorage.count(); stsIndex++) { - const auto* cluster = state.area->shortTermStorage.storagesByIndex[stsIndex]; - const uint group = groupIndex(cluster->properties.group); + const auto& cluster = state.area->shortTermStorage.storagesByIndex[stsIndex]; + const uint group = groupIndex(cluster.properties.group); // Injection pValuesForTheCurrentYear[numSpace][3 * group][state.hourInTheYear] diff --git a/src/solver/variable/info.h b/src/solver/variable/info.h index 416bbd188b..d766dafc5e 100644 --- a/src/solver/variable/info.h +++ b/src/solver/variable/info.h @@ -413,7 +413,7 @@ struct VariableAccessor if (st_storage_details) { auto& st_storage_part = results.data.area->shortTermStorage; - results.variableCaption = st_storage_part.storagesByIndex[idx]->properties.name; + results.variableCaption = st_storage_part.storagesByIndex[idx].properties.name; return true; } return true; diff --git a/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp b/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp index 93c44fa80e..fa73cc6306 100644 --- a/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp +++ b/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp @@ -252,7 +252,7 @@ BOOST_FIXTURE_TEST_CASE(check_container_properties_enabled_load, Fixture) BOOST_CHECK(container.createSTStorageClustersFromIniFile(folder)); - auto& properties = container.storagesByIndex[0]->properties; + auto& properties = container.storagesByIndex[0].properties; BOOST_CHECK(properties.enabled); BOOST_CHECK_EQUAL(container.count(), 1); @@ -267,7 +267,7 @@ BOOST_FIXTURE_TEST_CASE(check_container_properties_disabled_load, Fixture) BOOST_CHECK(container.createSTStorageClustersFromIniFile(folder)); - auto& properties = container.storagesByIndex[0]->properties; + auto& properties = container.storagesByIndex[0].properties; BOOST_CHECK(!properties.enabled); BOOST_CHECK_EQUAL(container.count(), 0); @@ -281,7 +281,7 @@ BOOST_FIXTURE_TEST_CASE(check_container_properties_wrong_value, Fixture) createIniFileWrongValue(); BOOST_CHECK(container.createSTStorageClustersFromIniFile(folder)); - BOOST_CHECK(!container.storagesByIndex[0]->properties.validate()); + BOOST_CHECK(!container.storagesByIndex[0].properties.validate()); removeIniFile(); } From 5ecf4f5857f1bac32c76c642686cec11a5143f23 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Dec 2023 10:19:32 +0100 Subject: [PATCH 08/20] [FIX] Compile --- src/solver/simulation/sim_calcul_economique.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index d5aea655e9..81b40c7387 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -53,7 +53,7 @@ static void importShortTermStorages( int storageIndex = 0; for (auto st : areas[areaIndex]->shortTermStorage.storagesByIndex) { - if (!st->enabled()) + if (!st.enabled()) continue; ::ShortTermStorage::PROPERTIES& toInsert = ShortTermStorageOut[areaIndex][storageIndex]; From 754f7845a2ee84e65ca37e5378b4bb31dc5fe9af Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 13 Dec 2023 12:22:29 +0100 Subject: [PATCH 09/20] [DEV] Use correct indexes in output var --- src/solver/variable/economy/STStorageCashFlowByCluster.h | 8 +++++--- src/solver/variable/economy/STStorageInjectionByCluster.h | 6 ++++-- src/solver/variable/economy/STStorageLevelsByCluster.h | 6 ++++-- .../variable/economy/STStorageWithdrawalByCluster.h | 6 ++++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/solver/variable/economy/STStorageCashFlowByCluster.h b/src/solver/variable/economy/STStorageCashFlowByCluster.h index 509d77cb80..e79c763700 100644 --- a/src/solver/variable/economy/STStorageCashFlowByCluster.h +++ b/src/solver/variable/economy/STStorageCashFlowByCluster.h @@ -278,17 +278,19 @@ class STstorageCashFlowByCluster : public Variable::IVariableshortTermStorage; // Write the data for the current year - for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex) + uint clusterIndex = 0; + for (const auto& cluster : shortTermStorage.storagesByIndex) { // Write the data for the current year - const auto& cluster = shortTermStorage.storagesByIndex[clusterIndex]; - if (cluster.enabled()) + if (!cluster.enabled()) continue; results.variableCaption = cluster.properties.name; results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][clusterIndex] .template buildAnnualSurveyReport(results, fileLevel, precision); + + clusterIndex++; } } } diff --git a/src/solver/variable/economy/STStorageInjectionByCluster.h b/src/solver/variable/economy/STStorageInjectionByCluster.h index 29726416ec..42e45884dd 100644 --- a/src/solver/variable/economy/STStorageInjectionByCluster.h +++ b/src/solver/variable/economy/STStorageInjectionByCluster.h @@ -280,10 +280,10 @@ class STstorageInjectionByCluster : public Variable::IVariableshortTermStorage; // Write the data for the current year - for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex) + uint clusterIndex = 0; + for (const auto& cluster : shortTermStorage.storagesByIndex) { // Write the data for the current year - const auto& cluster = shortTermStorage.storagesByIndex[clusterIndex]; if (!cluster.enabled()) continue; @@ -291,6 +291,8 @@ class STstorageInjectionByCluster : public Variable::IVariable(results, fileLevel, precision); + + clusterIndex++; } } } diff --git a/src/solver/variable/economy/STStorageLevelsByCluster.h b/src/solver/variable/economy/STStorageLevelsByCluster.h index c5ba21522d..dbb674fea3 100644 --- a/src/solver/variable/economy/STStorageLevelsByCluster.h +++ b/src/solver/variable/economy/STStorageLevelsByCluster.h @@ -280,10 +280,10 @@ class STstorageLevelsByCluster const auto& shortTermStorage = results.data.area->shortTermStorage; // Write the data for the current year - for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex) + uint clusterIndex = 0; + for (const auto& cluster : shortTermStorage.storagesByIndex) { // Write the data for the current year - const auto& cluster = shortTermStorage.storagesByIndex[clusterIndex]; if (!cluster.enabled()) continue; @@ -291,6 +291,8 @@ class STstorageLevelsByCluster results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][clusterIndex].template buildAnnualSurveyReport( results, fileLevel, precision); + + clusterIndex++; } } } diff --git a/src/solver/variable/economy/STStorageWithdrawalByCluster.h b/src/solver/variable/economy/STStorageWithdrawalByCluster.h index c1efd48c67..33fa4de9f5 100644 --- a/src/solver/variable/economy/STStorageWithdrawalByCluster.h +++ b/src/solver/variable/economy/STStorageWithdrawalByCluster.h @@ -280,10 +280,10 @@ class STstorageWithdrawalByCluster const auto& shortTermStorage = results.data.area->shortTermStorage; // Write the data for the current year - for (uint clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex) + uint clusterIndex = 0; + for (const auto& cluster : shortTermStorage.storagesByIndex) { // Write the data for the current year - const auto& cluster = shortTermStorage.storagesByIndex[clusterIndex]; if (!cluster.enabled()) continue; @@ -291,6 +291,8 @@ class STstorageWithdrawalByCluster results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][clusterIndex].template buildAnnualSurveyReport( results, fileLevel, precision); + + clusterIndex++; } } } From c2f20e6a829cd800d6c2d709c70425cf77f40194 Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Mon, 18 Dec 2023 16:37:39 +0100 Subject: [PATCH 10/20] Fix build --- src/libs/antares/study/parts/short-term-storage/container.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/antares/study/parts/short-term-storage/container.cpp b/src/libs/antares/study/parts/short-term-storage/container.cpp index 02d2a1fec3..d8388b5e14 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -112,8 +112,8 @@ std::size_t STStorageInput::count() const { return std::count_if(storagesByIndex.begin(), storagesByIndex.end(), - [](const STStorageCluster* st) { - return st->properties.enabled; + [](const STStorageCluster& st) { + return st.properties.enabled; }); } } // namespace Antares::Data::ShortTermStorage From 3345294a51015ef30321dcafc77f7b49ef6d575e Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Mon, 18 Dec 2023 17:21:40 +0100 Subject: [PATCH 11/20] Fix ST storage results --- src/solver/variable/economy/shortTermStorage.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/solver/variable/economy/shortTermStorage.h b/src/solver/variable/economy/shortTermStorage.h index 77aab56a7a..9ca4b00272 100644 --- a/src/solver/variable/economy/shortTermStorage.h +++ b/src/solver/variable/economy/shortTermStorage.h @@ -235,22 +235,28 @@ class ShortTermStorageByGroup void hourForEachArea(State& state, unsigned int numSpace) { using namespace Antares::Data::ShortTermStorage; - for (uint stsIndex = 0; stsIndex < state.area->shortTermStorage.count(); stsIndex++) + const auto& shortTermStorage = state.area->shortTermStorage; + + // Write the data for the current year + uint clusterIndex = 0; + for (const auto& cluster : shortTermStorage.storagesByIndex) { - const auto& cluster = state.area->shortTermStorage.storagesByIndex[stsIndex]; - const uint group = groupIndex(cluster.properties.group); + if (!cluster.enabled()) + continue; + const uint group = groupIndex(cluster.properties.group); // Injection pValuesForTheCurrentYear[numSpace][3 * group][state.hourInTheYear] - += state.hourlyResults->ShortTermStorage[state.hourInTheWeek].injection[stsIndex]; + += state.hourlyResults->ShortTermStorage[state.hourInTheWeek].injection[clusterIndex]; // Withdrawal pValuesForTheCurrentYear[numSpace][3 * group + 1][state.hourInTheYear] - += state.hourlyResults->ShortTermStorage[state.hourInTheWeek].withdrawal[stsIndex]; + += state.hourlyResults->ShortTermStorage[state.hourInTheWeek].withdrawal[clusterIndex]; // Levels pValuesForTheCurrentYear[numSpace][3 * group + 2][state.hourInTheYear] - += state.hourlyResults->ShortTermStorage[state.hourInTheWeek].level[stsIndex]; + += state.hourlyResults->ShortTermStorage[state.hourInTheWeek].level[clusterIndex]; + clusterIndex++; } // Next item in the list From b0a01000747bf11b43a6ab47cb6e3d78864f260d Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 19 Dec 2023 11:40:46 +0100 Subject: [PATCH 12/20] [DEV] Remove disabled sts clusters --- .../study/parts/short-term-storage/container.cpp | 12 ++++++++++++ .../study/parts/short-term-storage/container.h | 9 ++++++--- src/libs/antares/study/runtime/runtime.cpp | 7 +++++++ src/libs/antares/study/runtime/runtime.h | 1 + 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/libs/antares/study/parts/short-term-storage/container.cpp b/src/libs/antares/study/parts/short-term-storage/container.cpp index d8388b5e14..c51a7ce9e0 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -116,4 +116,16 @@ std::size_t STStorageInput::count() const return st.properties.enabled; }); } + +uint STStorageInput::removeDisabledClusters() +{ + const auto& it = std::remove_if(storagesByIndex.begin(), storagesByIndex.end(), + [](const auto& c) { return c.enabled(); }); + + uint count = std::distance(it, storagesByIndex.end()); + storagesByIndex.erase(it, storagesByIndex.end()); + + return count; +} + } // namespace Antares::Data::ShortTermStorage diff --git a/src/libs/antares/study/parts/short-term-storage/container.h b/src/libs/antares/study/parts/short-term-storage/container.h index 7aa4133942..b53aebf60b 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.h +++ b/src/libs/antares/study/parts/short-term-storage/container.h @@ -36,12 +36,15 @@ class STStorageInput { public: bool validate() const; - // 1. Read list.ini + /// 1. Read list.ini bool createSTStorageClustersFromIniFile(const std::string& path); - // 2. Read ALL series + /// 2. Read ALL series bool loadSeriesFromFolder(const std::string& folder) const; - // Number of enabled ST storages, ignoring disabled ST storages + /// Number of enabled ST storages, ignoring disabled ST storages std::size_t count() const; + /// erase disabled cluster from the vector + uint removeDisabledClusters(); + bool saveToFolder(const std::string& folder) const; bool saveDataSeriesToFolder(const std::string& folder) const; diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index 1a58a14f73..85fcb853ba 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -423,6 +423,13 @@ void StudyRuntimeInfos::removeDisabledRenewableClustersFromSolverComputations(St }); } +void StudyRuntimeInfos::removeDisabledShortTermStorageClustersFromSolverComputations(Study& study) +{ + removeClusters( + study, "short term storage", [](Area& area) + { return area.shortTermStorage.removeDisabledClusters(); }); +} + void StudyRuntimeInfos::removeAllRenewableClustersFromSolverComputations(Study& study) { removeClusters( diff --git a/src/libs/antares/study/runtime/runtime.h b/src/libs/antares/study/runtime/runtime.h index a499f47483..10c0d54e3b 100644 --- a/src/libs/antares/study/runtime/runtime.h +++ b/src/libs/antares/study/runtime/runtime.h @@ -138,6 +138,7 @@ class StudyRuntimeInfos void initializeThermalClustersInMustRunMode(Study& study) const; void removeDisabledThermalClustersFromSolverComputations(Study& study); void removeDisabledRenewableClustersFromSolverComputations(Study& study); + void removeDisabledShortTermStorageClustersFromSolverComputations(Study& study); void removeAllRenewableClustersFromSolverComputations(Study& study); void disableAllFilters(Study& study); void checkThermalTSGeneration(Study& study); From 6b81c6109943d4618a6c9a3999031c118b6696f9 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 19 Dec 2023 11:42:40 +0100 Subject: [PATCH 13/20] [DEV] don't validate disabled clusters --- src/libs/antares/study/parts/short-term-storage/cluster.cpp | 3 +++ src/libs/antares/study/parts/short-term-storage/container.cpp | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libs/antares/study/parts/short-term-storage/cluster.cpp b/src/libs/antares/study/parts/short-term-storage/cluster.cpp index eb202920b2..1b2724f72f 100644 --- a/src/libs/antares/study/parts/short-term-storage/cluster.cpp +++ b/src/libs/antares/study/parts/short-term-storage/cluster.cpp @@ -70,6 +70,9 @@ bool STStorageCluster::enabled() const bool STStorageCluster::validate() const { + if (!cluster.enabled) + return true; + logs.debug() << "Validating properties and series for st storage: " << id; return properties.validate() && series->validate(); } diff --git a/src/libs/antares/study/parts/short-term-storage/container.cpp b/src/libs/antares/study/parts/short-term-storage/container.cpp index c51a7ce9e0..0199d357c7 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -122,10 +122,10 @@ uint STStorageInput::removeDisabledClusters() const auto& it = std::remove_if(storagesByIndex.begin(), storagesByIndex.end(), [](const auto& c) { return c.enabled(); }); - uint count = std::distance(it, storagesByIndex.end()); + uint disabledCount = std::distance(it, storagesByIndex.end()); storagesByIndex.erase(it, storagesByIndex.end()); - return count; + return disabledCount; } } // namespace Antares::Data::ShortTermStorage From 47c0d6d3bbe103477eb0f66bd5de58c36e1158e8 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 19 Dec 2023 11:44:29 +0100 Subject: [PATCH 14/20] [DEV] remove enable check from output --- src/solver/simulation/sim_calcul_economique.cpp | 3 --- src/solver/variable/economy/STStorageCashFlowByCluster.h | 3 --- src/solver/variable/economy/STStorageInjectionByCluster.h | 3 --- src/solver/variable/economy/STStorageLevelsByCluster.h | 3 --- src/solver/variable/economy/STStorageWithdrawalByCluster.h | 3 --- src/solver/variable/economy/shortTermStorage.h | 3 --- 6 files changed, 18 deletions(-) diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 81b40c7387..4ea8e6d150 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -53,9 +53,6 @@ static void importShortTermStorages( int storageIndex = 0; for (auto st : areas[areaIndex]->shortTermStorage.storagesByIndex) { - if (!st.enabled()) - continue; - ::ShortTermStorage::PROPERTIES& toInsert = ShortTermStorageOut[areaIndex][storageIndex]; toInsert.clusterGlobalIndex = clusterGlobalIndex; diff --git a/src/solver/variable/economy/STStorageCashFlowByCluster.h b/src/solver/variable/economy/STStorageCashFlowByCluster.h index e79c763700..1d85df5cb5 100644 --- a/src/solver/variable/economy/STStorageCashFlowByCluster.h +++ b/src/solver/variable/economy/STStorageCashFlowByCluster.h @@ -282,9 +282,6 @@ class STstorageCashFlowByCluster : public Variable::IVariable( diff --git a/src/solver/variable/economy/STStorageWithdrawalByCluster.h b/src/solver/variable/economy/STStorageWithdrawalByCluster.h index 33fa4de9f5..277b133088 100644 --- a/src/solver/variable/economy/STStorageWithdrawalByCluster.h +++ b/src/solver/variable/economy/STStorageWithdrawalByCluster.h @@ -284,9 +284,6 @@ class STstorageWithdrawalByCluster for (const auto& cluster : shortTermStorage.storagesByIndex) { // Write the data for the current year - if (!cluster.enabled()) - continue; - results.variableCaption = cluster.properties.name; results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][clusterIndex].template buildAnnualSurveyReport( diff --git a/src/solver/variable/economy/shortTermStorage.h b/src/solver/variable/economy/shortTermStorage.h index 9ca4b00272..0b9370ddd3 100644 --- a/src/solver/variable/economy/shortTermStorage.h +++ b/src/solver/variable/economy/shortTermStorage.h @@ -241,9 +241,6 @@ class ShortTermStorageByGroup uint clusterIndex = 0; for (const auto& cluster : shortTermStorage.storagesByIndex) { - if (!cluster.enabled()) - continue; - const uint group = groupIndex(cluster.properties.group); // Injection pValuesForTheCurrentYear[numSpace][3 * group][state.hourInTheYear] From d3584e54d32a74bc417d3cb89ab024d6905866ac Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 19 Dec 2023 11:55:43 +0100 Subject: [PATCH 15/20] [DEV] change save by passing ini --- .../study/parts/short-term-storage/cluster.cpp | 6 +++--- .../study/parts/short-term-storage/cluster.h | 2 +- .../study/parts/short-term-storage/container.cpp | 12 ++++++++---- .../parts/short-term-storage/properties.cpp | 16 +--------------- .../study/parts/short-term-storage/properties.h | 2 +- 5 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/libs/antares/study/parts/short-term-storage/cluster.cpp b/src/libs/antares/study/parts/short-term-storage/cluster.cpp index 1b2724f72f..dfd32affd7 100644 --- a/src/libs/antares/study/parts/short-term-storage/cluster.cpp +++ b/src/libs/antares/study/parts/short-term-storage/cluster.cpp @@ -70,7 +70,7 @@ bool STStorageCluster::enabled() const bool STStorageCluster::validate() const { - if (!cluster.enabled) + if (!enabled()) return true; logs.debug() << "Validating properties and series for st storage: " << id; @@ -84,9 +84,9 @@ bool STStorageCluster::loadSeries(const std::string& folder) const return ret; } -bool STStorageCluster::saveProperties(const std::string& path) const +void STStorageCluster::saveProperties(IniFile& ini) const { - return properties.saveToFolder(path); + properties.saveToFolder(ini); } bool STStorageCluster::saveSeries(const std::string& path) const diff --git a/src/libs/antares/study/parts/short-term-storage/cluster.h b/src/libs/antares/study/parts/short-term-storage/cluster.h index 114e109f2d..3c827c7d35 100644 --- a/src/libs/antares/study/parts/short-term-storage/cluster.h +++ b/src/libs/antares/study/parts/short-term-storage/cluster.h @@ -43,7 +43,7 @@ class STStorageCluster bool loadFromSection(const IniFile::Section& section); bool loadSeries(const std::string& folder) const; - bool saveProperties(const std::string& path) const; + void saveProperties(IniFile& ini) const; bool saveSeries(const std::string& path) const; std::string id; diff --git a/src/libs/antares/study/parts/short-term-storage/container.cpp b/src/libs/antares/study/parts/short-term-storage/container.cpp index 0199d357c7..0a88c77175 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -92,12 +92,16 @@ bool STStorageInput::saveToFolder(const std::string& folder) const { // create empty list.ini if there's no sts in this area Yuni::IO::Directory::Create(folder); - Yuni::IO::File::CreateEmptyFile(folder + SEP + "list.ini"); - logs.notice() << "created empty ini: " << folder + SEP + "list.ini"; + const std::string pathIni(folder + SEP + "list.ini"); + IniFile ini; - return std::all_of(storagesByIndex.cbegin(), storagesByIndex.cend(), [&folder](auto& storage) { - return storage.saveProperties(folder); + logs.debug() << "saving file " << pathIni; + + std::for_each(storagesByIndex.cbegin(), storagesByIndex.cend(), [&ini](auto& storage) { + return storage.saveProperties(ini); }); + + return ini.save(pathIni); } bool STStorageInput::saveDataSeriesToFolder(const std::string& folder) const diff --git a/src/libs/antares/study/parts/short-term-storage/properties.cpp b/src/libs/antares/study/parts/short-term-storage/properties.cpp index bee25006d5..ab6f9474a9 100644 --- a/src/libs/antares/study/parts/short-term-storage/properties.cpp +++ b/src/libs/antares/study/parts/short-term-storage/properties.cpp @@ -121,20 +121,8 @@ bool Properties::loadKey(const IniFile::Property* p) return false; } -bool Properties::saveToFolder(const std::string& folder) const +void Properties::saveToFolder(IniFile& ini) const { - const std::string pathIni(folder + SEP + "list.ini"); - - // Make sure the folder is created - if (!Yuni::IO::Directory::Create(folder)) - { - logs.warning() << "Couldn't create dir for sts: " << folder; - return false; - } - - logs.debug() << "saving file " << pathIni; - - IniFile ini; IniFile::Section* s = ini.addSection(this->name); s->add("name", this->name); @@ -151,8 +139,6 @@ bool Properties::saveToFolder(const std::string& folder) const s->add("efficiency", this->efficiencyFactor); s->add("initialleveloptim", this->initialLevelOptim); s->add("enabled", this->enabled); - - return ini.save(pathIni); } bool Properties::validate() diff --git a/src/libs/antares/study/parts/short-term-storage/properties.h b/src/libs/antares/study/parts/short-term-storage/properties.h index 24a3b0d2e1..e68e3c8958 100644 --- a/src/libs/antares/study/parts/short-term-storage/properties.h +++ b/src/libs/antares/study/parts/short-term-storage/properties.h @@ -54,7 +54,7 @@ class Properties public: bool validate(); bool loadKey(const IniFile::Property* p); - bool saveToFolder(const std::string& folder) const; + void saveToFolder(IniFile& ini) const; /// Not optional Injection nominal capacity, >= 0 std::optional injectionNominalCapacity; From da8d4a9ccebbfbf8846c44949a89274e67cefcba Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 19 Dec 2023 15:28:13 +0100 Subject: [PATCH 16/20] [DEV] rename save properties --- src/libs/antares/study/parts/short-term-storage/cluster.cpp | 2 +- src/libs/antares/study/parts/short-term-storage/container.cpp | 2 +- src/libs/antares/study/parts/short-term-storage/properties.cpp | 2 +- src/libs/antares/study/parts/short-term-storage/properties.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/antares/study/parts/short-term-storage/cluster.cpp b/src/libs/antares/study/parts/short-term-storage/cluster.cpp index dfd32affd7..9b4efcb761 100644 --- a/src/libs/antares/study/parts/short-term-storage/cluster.cpp +++ b/src/libs/antares/study/parts/short-term-storage/cluster.cpp @@ -86,7 +86,7 @@ bool STStorageCluster::loadSeries(const std::string& folder) const void STStorageCluster::saveProperties(IniFile& ini) const { - properties.saveToFolder(ini); + properties.save(ini); } bool STStorageCluster::saveSeries(const std::string& path) const diff --git a/src/libs/antares/study/parts/short-term-storage/container.cpp b/src/libs/antares/study/parts/short-term-storage/container.cpp index 0a88c77175..8538044806 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -124,7 +124,7 @@ std::size_t STStorageInput::count() const uint STStorageInput::removeDisabledClusters() { const auto& it = std::remove_if(storagesByIndex.begin(), storagesByIndex.end(), - [](const auto& c) { return c.enabled(); }); + std::mem_fn(&STStorageCluster::enabled)); uint disabledCount = std::distance(it, storagesByIndex.end()); storagesByIndex.erase(it, storagesByIndex.end()); diff --git a/src/libs/antares/study/parts/short-term-storage/properties.cpp b/src/libs/antares/study/parts/short-term-storage/properties.cpp index ab6f9474a9..cce442ce98 100644 --- a/src/libs/antares/study/parts/short-term-storage/properties.cpp +++ b/src/libs/antares/study/parts/short-term-storage/properties.cpp @@ -121,7 +121,7 @@ bool Properties::loadKey(const IniFile::Property* p) return false; } -void Properties::saveToFolder(IniFile& ini) const +void Properties::save(IniFile& ini) const { IniFile::Section* s = ini.addSection(this->name); diff --git a/src/libs/antares/study/parts/short-term-storage/properties.h b/src/libs/antares/study/parts/short-term-storage/properties.h index e68e3c8958..67c402f5fc 100644 --- a/src/libs/antares/study/parts/short-term-storage/properties.h +++ b/src/libs/antares/study/parts/short-term-storage/properties.h @@ -54,7 +54,7 @@ class Properties public: bool validate(); bool loadKey(const IniFile::Property* p); - void saveToFolder(IniFile& ini) const; + void save(IniFile& ini) const; /// Not optional Injection nominal capacity, >= 0 std::optional injectionNominalCapacity; From b25b7d677b041955726c1713962b2f112f132e69 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 19 Dec 2023 15:29:17 +0100 Subject: [PATCH 17/20] [DEV] change testfile name --- .../libs/antares/study/short-term-storage-input/CMakeLists.txt | 2 +- ...rm-storage-input.cpp => short-term-storage-input-output.cpp} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/tests/src/libs/antares/study/short-term-storage-input/{short-term-storage-input.cpp => short-term-storage-input-output.cpp} (100%) diff --git a/src/tests/src/libs/antares/study/short-term-storage-input/CMakeLists.txt b/src/tests/src/libs/antares/study/short-term-storage-input/CMakeLists.txt index 458fa7b28f..045e8ed944 100644 --- a/src/tests/src/libs/antares/study/short-term-storage-input/CMakeLists.txt +++ b/src/tests/src/libs/antares/study/short-term-storage-input/CMakeLists.txt @@ -5,7 +5,7 @@ set(src_libs_antares_study "${CMAKE_SOURCE_DIR}/libs/antares/study") # Tests on reading scenario-builder # ==================================== set(SRC_SC_BUILDER_READ - short-term-storage-input.cpp + short-term-storage-input-output.cpp ) add_executable(short-term-storage-input ${SRC_SC_BUILDER_READ}) diff --git a/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp b/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp similarity index 100% rename from src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input.cpp rename to src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp From c437d1a0d1ab341e8d69d8636de6238e68a4ce34 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 19 Dec 2023 15:58:05 +0100 Subject: [PATCH 18/20] [DEV] call disable function --- src/libs/antares/study/runtime/runtime.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index 85fcb853ba..c92afbe931 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -292,6 +292,7 @@ bool StudyRuntimeInfos::loadFromStudy(Study& study) // Removing disabled thermal clusters from solver computations removeDisabledThermalClustersFromSolverComputations(study); + removeDisabledShortTermStorageClustersFromSolverComputations(study); switch (gd.renewableGeneration()) { From a26e5460488874eabc1ee101bde9f40eb6f02492 Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Tue, 19 Dec 2023 16:00:25 +0100 Subject: [PATCH 19/20] Add relevant comment --- src/libs/antares/study/runtime/runtime.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index c92afbe931..e7ea5bcd5f 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -292,6 +292,8 @@ bool StudyRuntimeInfos::loadFromStudy(Study& study) // Removing disabled thermal clusters from solver computations removeDisabledThermalClustersFromSolverComputations(study); + + // Removing disabled short-term storage objects from solver computations removeDisabledShortTermStorageClustersFromSolverComputations(study); switch (gd.renewableGeneration()) From a8a757a6be217025da8a6b6455d7f877d328b2fb Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Tue, 19 Dec 2023 16:22:02 +0100 Subject: [PATCH 20/20] Bugfix : remove disabled ST storages (not enabled ones) --- src/libs/antares/study/parts/short-term-storage/container.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/antares/study/parts/short-term-storage/container.cpp b/src/libs/antares/study/parts/short-term-storage/container.cpp index 8538044806..309637e94d 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -124,7 +124,7 @@ std::size_t STStorageInput::count() const uint STStorageInput::removeDisabledClusters() { const auto& it = std::remove_if(storagesByIndex.begin(), storagesByIndex.end(), - std::mem_fn(&STStorageCluster::enabled)); + [](const auto& c) { return !c.enabled(); }); uint disabledCount = std::distance(it, storagesByIndex.end()); storagesByIndex.erase(it, storagesByIndex.end());