From 8d3a971a4006372312bcdf404f97449e06a9d67a Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 4 Dec 2023 17:47:49 +0100 Subject: [PATCH 01/88] [DEV] remove cluster in renewable container --- .../study/parts/renewable/container.cpp | 5 --- .../antares/study/parts/renewable/container.h | 16 -------- .../RenewableTSNumberData.cpp | 7 ++-- src/solver/simulation/timeseries-numbers.cpp | 39 ++++++++----------- .../economy/productionByRenewablePlant.h | 8 ++-- .../variable/economy/renewableGeneration.h | 5 +-- src/solver/variable/info.h | 2 +- .../test-sc-builder-file-read-line.cpp | 1 - .../test-sc-builder-file-save.cpp | 1 - .../solver/simulation/tests-ts-numbers.cpp | 1 - 10 files changed, 28 insertions(+), 57 deletions(-) diff --git a/src/libs/antares/study/parts/renewable/container.cpp b/src/libs/antares/study/parts/renewable/container.cpp index 1fbde6732c..ea7cbdb0fd 100644 --- a/src/libs/antares/study/parts/renewable/container.cpp +++ b/src/libs/antares/study/parts/renewable/container.cpp @@ -63,19 +63,15 @@ void PartRenewable::prepareAreaWideIndexes() // And init the areaWideIndex (unique index for a given area) if (list.empty()) { - clusters.clear(); return; } - clusters.assign(list.size(), nullptr); - auto end = list.end(); uint idx = 0; for (auto i = list.begin(); i != end; ++i) { RenewableCluster* t = i->second.get(); t->areaWideIndex = idx; - clusters[idx] = t; ++idx; } } @@ -107,7 +103,6 @@ uint PartRenewable::removeDisabledClusters() void PartRenewable::reset() { list.clear(); - clusters.clear(); } } // namespace Data diff --git a/src/libs/antares/study/parts/renewable/container.h b/src/libs/antares/study/parts/renewable/container.h index 11c7489741..ccb20d5b7f 100644 --- a/src/libs/antares/study/parts/renewable/container.h +++ b/src/libs/antares/study/parts/renewable/container.h @@ -97,22 +97,6 @@ class PartRenewable //! List of all renewable clusters (enabled and disabled) RenewableClusterList list; - /*! - ** \brief All clusters for the area - ** - ** This variable is only available at runtime from the solver. - ** It is initialized in the same time that the runtime data. - ** - ** This list is mainly used to ensure the same order of the - ** renewable clusters in the outputs. - */ - std::vector clusters; - //! How many clusters have we got ? - // Only available from the solver - inline size_t clusterCount() const - { - return clusters.size(); - } }; // class PartRenewable } // namespace Data diff --git a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp index 7b176ab304..2db0ec2420 100644 --- a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp @@ -29,13 +29,13 @@ bool renewableTSNumberData::apply(Study& study) Area& area = *(study.areas.byIndex[pArea->index]); // The total number of clusters for the area // WARNING: We may have some renewable clusters with the `mustrun` option - auto clusterCount = (uint)area.renewable.clusterCount(); const uint tsGenCountRenewable = get_tsGenCount(study); - for (uint clusterIndex = 0; clusterIndex != clusterCount; ++clusterIndex) + uint clusterIndex = 0; + for (auto& c : area.renewable.list) { - auto& cluster = *(area.renewable.clusters[clusterIndex]); + auto& cluster = *c.second; // alias to the current column assert(clusterIndex < pTSNumberRules.width); const auto& col = pTSNumberRules[clusterIndex]; @@ -43,6 +43,7 @@ bool renewableTSNumberData::apply(Study& study) logprefix.clear() << "Renewable: area '" << area.name << "', cluster: '" << cluster.name() << "': "; ret = ApplyToMatrix(errors, logprefix, cluster.series, col, tsGenCountRenewable) && ret; + clusterIndex++; } return ret; } diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index dc22c1db53..3973f17ccc 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -100,9 +100,9 @@ static bool GenerateDeratedMode(Study& study) cluster.series.timeseriesNumbers.zero(); } - for (uint i = 0; i != area.renewable.clusterCount(); ++i) + for (auto& c : area.renewable.list) { - auto& cluster = *(area.renewable.clusters[i]); + auto& cluster = *c.second; cluster.series.timeseriesNumbers.zero(); } }); @@ -229,10 +229,9 @@ class renewClustersAreaNumberOfTSretriever : public areaNumberOfTSretriever std::vector getAreaTimeSeriesNumber(const Area& area) { std::vector to_return; - uint clusterCount = (uint)area.renewable.clusterCount(); - for (uint i = 0; i != clusterCount; ++i) + for (auto& c : area.renewable.list) { - auto& cluster = *(area.renewable.clusters[i]); + auto& cluster = *c.second; to_return.push_back(cluster.series.timeSeries.width); } return to_return; @@ -448,10 +447,9 @@ bool checkInterModalConsistencyForArea(Area& area, indexTS = ts_to_tsIndex.at(timeSeriesRenewable); if (isTSintermodal[indexTS]) { - const uint clusterCount = (uint)area.renewable.clusterCount(); - for (uint j = 0; j != clusterCount; ++j) + for (auto& c : area.renewable.list) { - auto& cluster = *(area.renewable.clusters[j]); + auto& cluster = *c.second; uint nbTimeSeries = cluster.series.timeSeries.width; listNumberTsOverArea.push_back(nbTimeSeries); } @@ -753,8 +751,8 @@ Matrix* getFirstTSnumberInterModalMatrixFoundInArea( && area.thermal.clusterCount() > 0) tsNumbersMtx = &(area.thermal.clusters[0]->series.timeseriesNumbers); else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)] - && area.renewable.clusterCount() > 0) - tsNumbersMtx = &(area.renewable.clusters[0]->series.timeseriesNumbers); + && area.renewable.list.size() > 0) + tsNumbersMtx = &(area.renewable.list.byIndex[0]->series.timeseriesNumbers); } assert(tsNumbersMtx); @@ -799,10 +797,9 @@ void applyMatrixDrawsToInterModalModesInArea(Matrix* tsNumbersMtx, } if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)]) { - uint clusterCount = (uint)area.renewable.clusterCount(); - for (uint i = 0; i != clusterCount; ++i) + for (auto& c : area.renewable.list) { - auto& cluster = *(area.renewable.clusters[i]); + auto& cluster = *c.second; assert(year < cluster.series.timeseriesNumbers.height); cluster.series.timeseriesNumbers[0][year] = draw; } @@ -850,15 +847,13 @@ static void fixTSNumbersWhenWidthIsOne(Study& study) }); // Renewables - std::for_each(area.renewable.clusters.cbegin(), - area.renewable.clusters.cend(), - [&years](Data::RenewableCluster* cluster) - - { - fixTSNumbersSingleAreaSingleMode(cluster->series.timeseriesNumbers, - cluster->series.timeSeries.width, - years); - }); + for (auto& c : area.renewable.list) + { + auto& cluster = c.second; + fixTSNumbersSingleAreaSingleMode(cluster->series.timeseriesNumbers, + cluster->series.timeSeries.width, + years); + } // NTC std::for_each(area.links.cbegin(), diff --git a/src/solver/variable/economy/productionByRenewablePlant.h b/src/solver/variable/economy/productionByRenewablePlant.h index 2f7ed60eac..630666d722 100644 --- a/src/solver/variable/economy/productionByRenewablePlant.h +++ b/src/solver/variable/economy/productionByRenewablePlant.h @@ -159,7 +159,7 @@ class ProductionByRenewablePlant : public Variable::IVariablerenewable.clusterCount(); + pSize = area->renewable.list.size(); if (pSize) { AncestorType::pResults.resize(pSize); @@ -277,9 +277,9 @@ class ProductionByRenewablePlant : public Variable::IVariablerenewable.clusterCount(); ++clusterIndex) + for (const auto& c : state.area->renewable.list) { - const auto* renewableCluster = state.area->renewable.clusters[clusterIndex]; + const auto& renewableCluster = c.second; double renewableClusterProduction = renewableCluster->valueAtTimeStep(state.year, state.hourInTheYear); pValuesForTheCurrentYear[numSpace][renewableCluster->areaWideIndex].hour[state.hourInTheYear] @@ -328,7 +328,7 @@ class ProductionByRenewablePlant : public Variable::IVariablename(); + results.variableCaption = renewable.list.byIndex[i]->name(); results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][i].template buildAnnualSurveyReport( results, fileLevel, precision); diff --git a/src/solver/variable/economy/renewableGeneration.h b/src/solver/variable/economy/renewableGeneration.h index 93d92b96be..8b6919ff47 100644 --- a/src/solver/variable/economy/renewableGeneration.h +++ b/src/solver/variable/economy/renewableGeneration.h @@ -267,10 +267,9 @@ class RenewableGeneration void hourForEachArea(State& state, unsigned int numSpace) { - for (uint clusterIndex = 0; clusterIndex != state.area->renewable.clusterCount(); - ++clusterIndex) + for (auto& rc : state.area->renewable.list) { - const auto* renewableCluster = state.area->renewable.clusters[clusterIndex]; + const auto& renewableCluster = rc.second; double renewableClusterProduction = renewableCluster->valueAtTimeStep(state.year, state.hourInTheYear); diff --git a/src/solver/variable/info.h b/src/solver/variable/info.h index 416bbd188b..088b4ddf7f 100644 --- a/src/solver/variable/info.h +++ b/src/solver/variable/info.h @@ -407,7 +407,7 @@ struct VariableAccessor if (renewable_details) { auto& renewable = results.data.area->renewable; - results.variableCaption = renewable.clusters[idx]->name(); + results.variableCaption = renewable.list.byIndex[idx]->name(); return true; } if (st_storage_details) diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index ad39460e08..36935b8e36 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -25,7 +25,6 @@ void addClusterToAreaList(Area* area, std::shared_ptr cluster) void addClusterToAreaList(Area* area, std::shared_ptr cluster) { - area->renewable.clusters.push_back(cluster.get()); area->renewable.list.add(cluster); } diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 0fef661c93..db422282dc 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -66,7 +66,6 @@ void addClusterToAreaList(Area* area, std::shared_ptr cluster) void addClusterToAreaList(Area* area, std::shared_ptr cluster) { - area->renewable.clusters.push_back(cluster.get()); area->renewable.list.add(cluster); } diff --git a/src/tests/src/solver/simulation/tests-ts-numbers.cpp b/src/tests/src/solver/simulation/tests-ts-numbers.cpp index 132564294c..34c2fa5c62 100644 --- a/src/tests/src/solver/simulation/tests-ts-numbers.cpp +++ b/src/tests/src/solver/simulation/tests-ts-numbers.cpp @@ -58,7 +58,6 @@ void addClusterToAreaList(Area* area, std::shared_ptr cluster) template<> void addClusterToAreaList(Area* area, std::shared_ptr cluster) { - area->renewable.clusters.push_back(cluster.get()); area->renewable.list.add(cluster); } From 3a1202cb644d0659676419b515ce2c01cc16ff53 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 5 Dec 2023 11:28:53 +0100 Subject: [PATCH 02/88] [DEV] use vector for byIndex --- .../study/parts/common/cluster_list.cpp | 19 ++++--------------- .../antares/study/parts/common/cluster_list.h | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index ee9ae9c8cb..8fd39670a1 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -95,7 +95,7 @@ bool ClusterList::exists(const Data::ClusterName& id) const } template -Data::ClusterList::ClusterList() : byIndex(nullptr), groupCount(ClusterT::groupMax, 0) +Data::ClusterList::ClusterList() : groupCount(ClusterT::groupMax, 0) { } @@ -109,12 +109,7 @@ Data::ClusterList::~ClusterList() template void ClusterList::clear() { - if (byIndex) - { - delete[] byIndex; - byIndex = nullptr; - } - + byIndex.clear(); if (not cluster.empty()) cluster.clear(); } @@ -184,16 +179,12 @@ void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer template void ClusterList::rebuildIndex() { - delete[] byIndex; + byIndex.clear(); if (not empty()) { uint indx = 0; - using ClusterWeakPtr = ClusterT*; - byIndex = new ClusterWeakPtr[size()]; - - auto end = cluster.end(); - for (auto i = cluster.begin(); i != end; ++i) + for (auto i = cluster.begin(); i != cluster.end(); ++i) { auto cluster = i->second.get(); byIndex[indx] = cluster; @@ -201,8 +192,6 @@ void ClusterList::rebuildIndex() ++indx; } } - else - byIndex = nullptr; } template diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 5fde367e39..14f90d9fa3 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -220,7 +220,7 @@ class ClusterList public: //! All clusters by their index - ClusterT** byIndex; + std::vector byIndex; //! All clusters Map cluster; From ff6795de50e250523ffac997d260f70efa3d5bb4 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 5 Dec 2023 11:37:50 +0100 Subject: [PATCH 03/88] [DEV] remove uselss renewlist constructor --- src/libs/antares/study/parts/renewable/cluster_list.cpp | 7 ------- src/libs/antares/study/parts/renewable/cluster_list.h | 2 -- 2 files changed, 9 deletions(-) diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index c7c01a00bd..5669429dff 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -9,13 +9,6 @@ namespace Antares { namespace Data { -RenewableClusterList::~RenewableClusterList() -{ -} - -RenewableClusterList::RenewableClusterList() -{ -} YString RenewableClusterList::typeID() const { diff --git a/src/libs/antares/study/parts/renewable/cluster_list.h b/src/libs/antares/study/parts/renewable/cluster_list.h index 15746180fc..e4c3018ace 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.h +++ b/src/libs/antares/study/parts/renewable/cluster_list.h @@ -16,8 +16,6 @@ namespace Data class RenewableClusterList : public ClusterList { public: - RenewableClusterList(); - ~RenewableClusterList(); // Overriden virtual methods YString typeID() const override; bool loadFromFolder(const AnyString& folder, Area* area); From 947b5ffa2730ba2dec80ae0480c867bb0c4d62cf Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 5 Dec 2023 12:04:14 +0100 Subject: [PATCH 04/88] [FIX] segfault --- src/libs/antares/study/parts/common/cluster_list.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 8fd39670a1..3f08915727 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -184,6 +184,7 @@ void ClusterList::rebuildIndex() if (not empty()) { uint indx = 0; + byIndex.resize(size()); for (auto i = cluster.begin(); i != cluster.end(); ++i) { auto cluster = i->second.get(); From 8dfc03f4b8a0b9de28938e72c92c111c6c49999d Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 5 Dec 2023 12:44:47 +0100 Subject: [PATCH 05/88] [DEV] Code smells --- .../RenewableTSNumberData.cpp | 7 ++--- src/solver/simulation/timeseries-numbers.cpp | 29 +++++++------------ .../economy/productionByRenewablePlant.h | 3 +- .../variable/economy/renewableGeneration.h | 3 +- 4 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp index 2db0ec2420..338f13a4b2 100644 --- a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp @@ -33,16 +33,15 @@ bool renewableTSNumberData::apply(Study& study) const uint tsGenCountRenewable = get_tsGenCount(study); uint clusterIndex = 0; - for (auto& c : area.renewable.list) + for (const auto& [name, cluster] : area.renewable.list) { - auto& cluster = *c.second; // alias to the current column assert(clusterIndex < pTSNumberRules.width); const auto& col = pTSNumberRules[clusterIndex]; - logprefix.clear() << "Renewable: area '" << area.name << "', cluster: '" << cluster.name() + logprefix.clear() << "Renewable: area '" << area.name << "', cluster: '" << cluster->name() << "': "; - ret = ApplyToMatrix(errors, logprefix, cluster.series, col, tsGenCountRenewable) && ret; + ret = ApplyToMatrix(errors, logprefix, cluster->series, col, tsGenCountRenewable) && ret; clusterIndex++; } return ret; diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 3973f17ccc..82fb8a3273 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -100,11 +100,8 @@ static bool GenerateDeratedMode(Study& study) cluster.series.timeseriesNumbers.zero(); } - for (auto& c : area.renewable.list) - { - auto& cluster = *c.second; - cluster.series.timeseriesNumbers.zero(); - } + for (const auto& [name, cluster] : area.renewable.list) + cluster->series.timeseriesNumbers.zero(); }); return true; @@ -229,10 +226,9 @@ class renewClustersAreaNumberOfTSretriever : public areaNumberOfTSretriever std::vector getAreaTimeSeriesNumber(const Area& area) { std::vector to_return; - for (auto& c : area.renewable.list) + for (const auto& [name, cluster] : area.renewable.list) { - auto& cluster = *c.second; - to_return.push_back(cluster.series.timeSeries.width); + to_return.push_back(cluster->series.timeSeries.width); } return to_return; } @@ -447,10 +443,9 @@ bool checkInterModalConsistencyForArea(Area& area, indexTS = ts_to_tsIndex.at(timeSeriesRenewable); if (isTSintermodal[indexTS]) { - for (auto& c : area.renewable.list) + for (const auto& [name, cluster] : area.renewable.list) { - auto& cluster = *c.second; - uint nbTimeSeries = cluster.series.timeSeries.width; + uint nbTimeSeries = cluster->series.timeSeries.width; listNumberTsOverArea.push_back(nbTimeSeries); } } @@ -797,11 +792,10 @@ void applyMatrixDrawsToInterModalModesInArea(Matrix* tsNumbersMtx, } if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)]) { - for (auto& c : area.renewable.list) + for (auto& [name, cluster] : area.renewable.list) { - auto& cluster = *c.second; - assert(year < cluster.series.timeseriesNumbers.height); - cluster.series.timeseriesNumbers[0][year] = draw; + assert(year < cluster->series.timeseriesNumbers.height); + cluster->series.timeseriesNumbers[0][year] = draw; } } } @@ -847,13 +841,10 @@ static void fixTSNumbersWhenWidthIsOne(Study& study) }); // Renewables - for (auto& c : area.renewable.list) - { - auto& cluster = c.second; + for (const auto& [name, cluster] : area.renewable.list) fixTSNumbersSingleAreaSingleMode(cluster->series.timeseriesNumbers, cluster->series.timeSeries.width, years); - } // NTC std::for_each(area.links.cbegin(), diff --git a/src/solver/variable/economy/productionByRenewablePlant.h b/src/solver/variable/economy/productionByRenewablePlant.h index 630666d722..26e0cbc0b6 100644 --- a/src/solver/variable/economy/productionByRenewablePlant.h +++ b/src/solver/variable/economy/productionByRenewablePlant.h @@ -277,9 +277,8 @@ class ProductionByRenewablePlant : public Variable::IVariablerenewable.list) + for (const auto& [name, renewableCluster] : state.area->renewable.list) { - const auto& renewableCluster = c.second; double renewableClusterProduction = renewableCluster->valueAtTimeStep(state.year, state.hourInTheYear); pValuesForTheCurrentYear[numSpace][renewableCluster->areaWideIndex].hour[state.hourInTheYear] diff --git a/src/solver/variable/economy/renewableGeneration.h b/src/solver/variable/economy/renewableGeneration.h index 8b6919ff47..5634338ec8 100644 --- a/src/solver/variable/economy/renewableGeneration.h +++ b/src/solver/variable/economy/renewableGeneration.h @@ -267,9 +267,8 @@ class RenewableGeneration void hourForEachArea(State& state, unsigned int numSpace) { - for (auto& rc : state.area->renewable.list) + for (const auto& [name, renewableCluster] : state.area->renewable.list) { - const auto& renewableCluster = rc.second; double renewableClusterProduction = renewableCluster->valueAtTimeStep(state.year, state.hourInTheYear); From 206f45eac5a2a8a5d9bfdc8526d5f12815734338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jason=20Mar=C3=A9chal?= <45510813+JasonMarechal25@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:16:27 +0100 Subject: [PATCH 06/88] [CHERRY-PICK] enable cpp 20 --- .github/workflows/centos7.yml | 13 +++++-- .github/workflows/oracle8.yml | 12 +++--- .github/workflows/sonarcloud.yml | 39 ++++++++++--------- .../workflows/ubuntu-system-deps-build.yml | 3 +- .github/workflows/ubuntu.yml | 3 ++ src/CMakeLists.txt | 2 +- src/cmake/common-settings.cmake | 2 +- src/ext/yuni/src/yuni/CMakeLists.txt | 2 +- .../yuni/src/yuni/core/string/operators.hxx | 12 +++--- .../src/libs/antares/study/test_study.cpp | 4 +- .../component/spotlight/listbox-panel.cpp | 5 ++- src/ui/simulator/application/main/main.cpp | 2 +- .../components/datagrid/renderer/layers.cpp | 4 +- .../windows/bindingconstraint/edit.cpp | 2 +- .../windows/correlation/datasources.hxx | 2 +- src/ui/simulator/windows/hydro/dailypower.cpp | 11 ------ src/ui/simulator/windows/hydro/management.cpp | 14 +++---- 17 files changed, 65 insertions(+), 67 deletions(-) diff --git a/.github/workflows/centos7.yml b/.github/workflows/centos7.yml index 547c72ad07..2ad3f82202 100644 --- a/.github/workflows/centos7.yml +++ b/.github/workflows/centos7.yml @@ -4,8 +4,8 @@ on: release: types: [created] push: - branches: - - develop + - branches: + - develop schedule: - cron: '21 2 * * *' @@ -54,9 +54,14 @@ jobs: unzip -q ortools.zip rm ortools.zip + - name: Install gcc 10 + run: | + yum install -y centos-release-scl + yum install -y devtoolset-10-gcc* + - name: Configure run: | - source /opt/rh/devtoolset-9/enable + source /opt/rh/devtoolset-10/enable cmake3 -B _build -S src \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ @@ -70,7 +75,7 @@ jobs: - name: Build run: | - source /opt/rh/devtoolset-9/enable + source /opt/rh/devtoolset-10/enable source /opt/rh/rh-git227/enable cmake3 --build _build --config Release -j2 ccache -s diff --git a/.github/workflows/oracle8.yml b/.github/workflows/oracle8.yml index 2dc9f229da..0ab2fa1530 100644 --- a/.github/workflows/oracle8.yml +++ b/.github/workflows/oracle8.yml @@ -4,8 +4,8 @@ on: release: types: [created] push: - branches: - - develop + - branches: + - develop schedule: - cron: '21 2 * * *' @@ -34,7 +34,7 @@ jobs: - name: Install libraries run: | dnf install -y epel-release git cmake wget rpm-build redhat-lsb-core - dnf install -y unzip libuuid-devel boost-test boost-devel gcc-toolset-9-toolchain zlib-devel + dnf install -y unzip libuuid-devel boost-test boost-devel gcc-toolset-10-toolchain zlib-devel - name: Checkout run: | @@ -51,7 +51,7 @@ jobs: - name: Configure run: | - source /opt/rh/gcc-toolset-9/enable + source /opt/rh/gcc-toolset-10/enable cmake -B _build -S src \ -DCMAKE_BUILD_TYPE=release \ -DBUILD_TESTING=ON \ @@ -60,8 +60,8 @@ jobs: - name: Build run: | - source /opt/rh/gcc-toolset-9/enable - cmake --build _build --config Release -j2 + source /opt/rh/gcc-toolset-10/enable + cmake --build _build --config Release -j$(nproc) - name: Run unit and end-to-end tests if: ${{ env.IS_PUSH == 'true' }} diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index fb797a0805..44908b595c 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -15,7 +15,7 @@ jobs: if: "!contains(github.event.head_commit.message, '[skip ci]')" strategy: matrix: - os: [ubuntu-20.04] + os: [ ubuntu-20.04 ] env: SONAR_SERVER_URL: "https://sonarcloud.io" @@ -37,9 +37,10 @@ jobs: - name: Install libraries run: | - sudo apt-get update - sudo apt-get install uuid-dev libwxgtk3.0-gtk3-dev - sudo apt-get install libboost-test-dev + sudo apt-get update + sudo apt-get install uuid-dev libwxgtk3.0-gtk3-dev + sudo apt-get install libboost-test-dev + sudo apt-get install g++-10 gcc-10 - name: Read antares-deps version id: antares-deps-version @@ -67,8 +68,8 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip - pip3 install -r src/tests/examples/requirements.txt + python -m pip install --upgrade pip + pip3 install -r src/tests/examples/requirements.txt - name: Init submodule run: | @@ -77,21 +78,23 @@ jobs: - name: Configure run: | - cmake -B _build -S src \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DDEPS_INSTALL_DIR=./rte-antares-deps-Debug \ - -DCODE_COVERAGE=ON \ - -DCMAKE_BUILD_TYPE=debug \ - -DCMAKE_PREFIX_PATH="../install;${{ env.ORTOOLS_DIR }}/install" \ - -DBUILD_TESTING=ON \ - -DMZ_CODE_COVERAGE=ON \ - -DBUILD_not_system=OFF \ - -DPython3_EXECUTABLE='${{ steps.setup-python.outputs.python-path }}' + cmake -B _build -S src \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_C_COMPILER=/usr/bin/gcc-10 \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 \ + -DDEPS_INSTALL_DIR=./rte-antares-deps-Debug \ + -DCODE_COVERAGE=ON \ + -DCMAKE_BUILD_TYPE=debug \ + -DCMAKE_PREFIX_PATH="../install;${{ env.ORTOOLS_DIR }}/install" \ + -DBUILD_TESTING=ON \ + -DMZ_CODE_COVERAGE=ON \ + -DBUILD_not_system=OFF \ + -DPython3_EXECUTABLE='${{ steps.setup-python.outputs.python-path }}' - name: Build run: | - build-wrapper-linux-x86-64 --out-dir $GITHUB_WORKSPACE/_build/output cmake --build _build --config release -j2 + build-wrapper-linux-x86-64 --out-dir $GITHUB_WORKSPACE/_build/output cmake --build _build --config release -j2 - name: Test and generate coverage continue-on-error: true diff --git a/.github/workflows/ubuntu-system-deps-build.yml b/.github/workflows/ubuntu-system-deps-build.yml index 34fcc2d91a..bd81673e9e 100644 --- a/.github/workflows/ubuntu-system-deps-build.yml +++ b/.github/workflows/ubuntu-system-deps-build.yml @@ -25,6 +25,7 @@ jobs: sudo apt-get update sudo apt-get install uuid-dev libwxgtk3.0-gtk3-dev sudo apt-get install libboost-test-dev + sudo apt-get install g++-10 gcc-10 - name: Set up Python uses: actions/setup-python@v4 @@ -42,7 +43,7 @@ jobs: - name: Configure run: | - cmake -B _build -S src -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_BUILD_TYPE=release -DBUILD_TESTING=ON + cmake -B _build -S src -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER=/usr/bin/gcc-10 -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 -DCMAKE_BUILD_TYPE=release -DBUILD_TESTING=ON - name: Build run: | diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 0c26d71abd..e770a66d15 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -51,6 +51,7 @@ jobs: sudo apt-get update sudo apt-get install uuid-dev libwxgtk3.0-gtk3-dev sudo apt-get install libboost-test-dev + sudo apt-get install g++-10 gcc-10 - name: Read antares-deps version id: antares-deps-version @@ -92,7 +93,9 @@ jobs: run: | cmake -B _build -S src \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_C_COMPILER=/usr/bin/gcc-10 \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 \ -DDEPS_INSTALL_DIR=${{github.workspace}}/rte-antares-deps-Release \ -DCMAKE_BUILD_TYPE=release \ -DBUILD_TESTING=ON \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 878d934250..fb3cff9705 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,7 +35,7 @@ include(CheckCXXCompilerFlag) include(CMakeDependentOption) include(FetchContent) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) if (DEFINED VCPKG_ROOT) include(${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) diff --git a/src/cmake/common-settings.cmake b/src/cmake/common-settings.cmake index 644111506c..8a3f7626fc 100644 --- a/src/cmake/common-settings.cmake +++ b/src/cmake/common-settings.cmake @@ -1,7 +1,7 @@ # # Common FLAGS for all compilers # -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(COMMON_GCC_FLAGS "-Wall -W -Wextra -Wfatal-errors") if (NOT WIN32) diff --git a/src/ext/yuni/src/yuni/CMakeLists.txt b/src/ext/yuni/src/yuni/CMakeLists.txt index 758a906e5c..5914a15a3c 100644 --- a/src/ext/yuni/src/yuni/CMakeLists.txt +++ b/src/ext/yuni/src/yuni/CMakeLists.txt @@ -31,7 +31,7 @@ include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/common-settings.cmake") include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules.cmake") -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) if(YUNI_MODULE_CORE) # The header yuni.h must be available diff --git a/src/ext/yuni/src/yuni/core/string/operators.hxx b/src/ext/yuni/src/yuni/core/string/operators.hxx index e7e26e52da..2ef7c24fca 100644 --- a/src/ext/yuni/src/yuni/core/string/operators.hxx +++ b/src/ext/yuni/src/yuni/core/string/operators.hxx @@ -112,39 +112,39 @@ inline Yuni::CString operator+(const Yuni::CString& rh template inline bool operator==(const char* lhs, const Yuni::CString& rhs) { - return rhs == lhs; + return rhs.equals(lhs); } template inline bool operator!=(const char* lhs, const Yuni::CString& rhs) { - return rhs != lhs; + return !rhs.equals(lhs); } template inline bool operator==(const char lhs[N], const Yuni::CString& rhs) { - return rhs == lhs; + return rhs.equals(lhs); } template inline bool operator!=(const char lhs[N], const Yuni::CString& rhs) { - return rhs != lhs; + return !rhs.equals(lhs); } template inline bool operator==(const std::basic_string& lhs, const Yuni::CString& rhs) { - return rhs == lhs; + return rhs.equals(lhs); } template inline bool operator!=(const std::basic_string& lhs, const Yuni::CString& rhs) { - return rhs != lhs; + return !rhs.equals(lhs); } inline bool operator==(const AnyString& mbs, Yuni::UTF8::Char c) diff --git a/src/tests/src/libs/antares/study/test_study.cpp b/src/tests/src/libs/antares/study/test_study.cpp index 91c8718140..8ab0d731e1 100644 --- a/src/tests/src/libs/antares/study/test_study.cpp +++ b/src/tests/src/libs/antares/study/test_study.cpp @@ -53,9 +53,9 @@ BOOST_AUTO_TEST_SUITE(areas_operations) BOOST_AUTO_TEST_CASE(area_add) { Study study; - Area* areaA = study.areaAdd("A"); + const auto areaA = study.areaAdd("A"); BOOST_CHECK(areaA != nullptr); - BOOST_CHECK(areaA->name == "A"); + BOOST_CHECK_EQUAL(areaA->name, "A"); BOOST_CHECK(areaA->id == "a"); } diff --git a/src/ui/common/component/spotlight/listbox-panel.cpp b/src/ui/common/component/spotlight/listbox-panel.cpp index 969d9672a3..9f3c8703d7 100644 --- a/src/ui/common/component/spotlight/listbox-panel.cpp +++ b/src/ui/common/component/spotlight/listbox-panel.cpp @@ -222,7 +222,8 @@ void ListboxPanel::onDraw(wxPaintEvent&) { auto& item = *(items[i]); auto& group = item.group(); - if (!(!group) && group != pLastGroupName) + + if (!(!group) && YString(group) != pLastGroupName) pLastGroupName = group; } continue; @@ -234,7 +235,7 @@ void ListboxPanel::onDraw(wxPaintEvent&) // Draw of the group name if the flag is enabled if ((0 != (pFlags & Spotlight::optGroups))) { - if (!(!group) && group != pLastGroupName) + if (!(!group) && YString(group) != pLastGroupName) { // Drawing the new group bounds.x = 0; diff --git a/src/ui/simulator/application/main/main.cpp b/src/ui/simulator/application/main/main.cpp index d4cca35472..909175937b 100644 --- a/src/ui/simulator/application/main/main.cpp +++ b/src/ui/simulator/application/main/main.cpp @@ -809,7 +809,7 @@ void ApplWnd::title(const wxString& s) wxString t; if (StudyHasBeenModified()) t << wxT("* "); - t << (s.IsEmpty() ? wxT("") : s) << wxT(" - Antares Simulator") + t << (s.IsEmpty() ? wxString(wxT("")) : s) << wxT(" - Antares Simulator") #ifndef NDEBUG << wxT(" - DEVELOPER PREVIEW") #endif diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/layers.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/layers.cpp index e5d30d6164..2072c2cb73 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/layers.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/layers.cpp @@ -227,13 +227,13 @@ wxString LayersUI::cellValue(int x, int y) const return layerPosition != layerListEnd ? wxString::Format(wxT("%d"), pArea->ui->layerX[layerIterator->first]) - : wxT("-"); + : wxString(wxT("-")); case 2: return layerPosition != layerListEnd ? wxString::Format(wxT("%d"), pArea->ui->layerY[layerIterator->first]) - : wxT("-"); + : wxString(wxT("-")); } } return wxEmptyString; diff --git a/src/ui/simulator/windows/bindingconstraint/edit.cpp b/src/ui/simulator/windows/bindingconstraint/edit.cpp index 42b1e30d84..60242c67d3 100644 --- a/src/ui/simulator/windows/bindingconstraint/edit.cpp +++ b/src/ui/simulator/windows/bindingconstraint/edit.cpp @@ -273,7 +273,7 @@ void BindingConstraintInfoEditor::onSave(void*) if (pConstraint) { - if (not newname.empty() and pConstraint->name() != newname) + if (not newname.empty() and pConstraint->name() != Data::ConstraintName(newname)) { if (not study.bindingConstraints.rename(pConstraint, newname)) { diff --git a/src/ui/simulator/windows/correlation/datasources.hxx b/src/ui/simulator/windows/correlation/datasources.hxx index aedafb6d17..07468e3dd9 100644 --- a/src/ui/simulator/windows/correlation/datasources.hxx +++ b/src/ui/simulator/windows/correlation/datasources.hxx @@ -182,7 +182,7 @@ public: { int lastLevel = 0; int j = 0; - Yuni::CString<15, false> old; + Yuni::CString<12, false> old; wxColour color; wxColour colorIdentity; const Data::Area::Vector::const_iterator end = pArray.end(); diff --git a/src/ui/simulator/windows/hydro/dailypower.cpp b/src/ui/simulator/windows/hydro/dailypower.cpp index 8a99499e05..538236c1bd 100644 --- a/src/ui/simulator/windows/hydro/dailypower.cpp +++ b/src/ui/simulator/windows/hydro/dailypower.cpp @@ -26,15 +26,12 @@ */ #include "dailypower.h" -#include #include "../../toolbox/components/datagrid/renderer/area/hydroprepro.h" #include "../../toolbox/components/datagrid/renderer/area/inflowpattern.h" #include "../../toolbox/components/datagrid/renderer/area/hydromonthlypower.h" #include "../../toolbox/components/datagrid/renderer/area/creditmodulations.h" -#include "../../toolbox/components/button.h" #include "../../toolbox/validator.h" #include "../../toolbox/create.h" -#include "../../application/menus.h" #include using namespace Yuni; @@ -73,14 +70,6 @@ void Dailypower::createComponents() wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); pSupport->SetSizer(sizer); - const wxSize ourDefaultSize(55, wxDefaultSize.GetHeight()); - - enum - { - right = wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, - left = wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, - }; - wxBoxSizer* sizerHigh = new wxBoxSizer(wxHORIZONTAL); sizer->Add(sizerHigh, 2, wxALL | wxEXPAND | wxFIXED_MINSIZE); diff --git a/src/ui/simulator/windows/hydro/management.cpp b/src/ui/simulator/windows/hydro/management.cpp index c76bfc6d05..666fd9b01d 100644 --- a/src/ui/simulator/windows/hydro/management.cpp +++ b/src/ui/simulator/windows/hydro/management.cpp @@ -26,15 +26,14 @@ */ #include "management.h" -#include +#include +#include + #include "../../toolbox/components/datagrid/renderer/area/hydroprepro.h" #include "../../toolbox/components/datagrid/renderer/area/inflowpattern.h" -#include "../../toolbox/components/datagrid/renderer/area/hydromonthlypower.h" -#include "../../toolbox/components/button.h" #include "../../toolbox/validator.h" #include "../../toolbox/create.h" #include "../../application/menus.h" -#include using namespace Yuni; @@ -69,11 +68,8 @@ void Management::createComponents() const wxSize ourDefaultSize(55, wxDefaultSize.GetHeight()); - enum - { - right = wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, - left = wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, - }; + const auto right = (wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + const auto left = (wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); auto* pGrid = new wxFlexGridSizer(6, 0, 8); sizer->Add(pGrid, 0, wxALL, 15); From a4cdc1c93c5c5cec35d0cfb8c796caee2811484d Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:07:52 +0100 Subject: [PATCH 07/88] Revert faulty YML files --- .github/workflows/centos7.yml | 4 ++-- .github/workflows/oracle8.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/centos7.yml b/.github/workflows/centos7.yml index 85c692f581..10c2c59b0e 100644 --- a/.github/workflows/centos7.yml +++ b/.github/workflows/centos7.yml @@ -4,8 +4,8 @@ on: release: types: [created] push: - - branches: - - develop + branches: + - develop schedule: - cron: '21 2 * * *' diff --git a/.github/workflows/oracle8.yml b/.github/workflows/oracle8.yml index 0ab2fa1530..75c05f845f 100644 --- a/.github/workflows/oracle8.yml +++ b/.github/workflows/oracle8.yml @@ -4,8 +4,8 @@ on: release: types: [created] push: - - branches: - - develop + branches: + - develop schedule: - cron: '21 2 * * *' From fbf0ade6922087ddae67968adb243a76ee638fdb Mon Sep 17 00:00:00 2001 From: payetvin <113102157+payetvin@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:37:23 +0100 Subject: [PATCH 08/88] Refactor common ClusterList class (#1813) This PR handles a part of issue #1487 (simplify and clarify cluster lists) : Co-authored-by: Guillaume PIERRE --- .../InfoCollection/StudyInfoCollector.cpp | 11 +- src/libs/antares/study/area/list.cpp | 4 +- .../antares/study/cleaner/cleaner-v20.cpp | 26 +- .../antares/study/parts/common/cluster.cpp | 55 ++-- src/libs/antares/study/parts/common/cluster.h | 4 +- .../study/parts/common/cluster_list.cpp | 267 +++++------------- .../antares/study/parts/common/cluster_list.h | 179 ++++-------- .../study/parts/renewable/cluster_list.cpp | 6 +- .../study/parts/renewable/cluster_list.h | 3 +- .../study/parts/renewable/container.cpp | 30 +- .../antares/study/parts/renewable/container.h | 12 - .../study/parts/thermal/cluster_list.cpp | 115 +++----- .../study/parts/thermal/cluster_list.h | 7 +- .../antares/study/parts/thermal/container.cpp | 93 ++---- .../antares/study/parts/thermal/container.h | 12 - src/libs/antares/study/runtime/runtime.cpp | 4 +- .../RenewableTSNumberData.cpp | 6 +- .../scenario-builder/ThermalTSNumberData.cpp | 4 +- src/libs/antares/study/study.cpp | 12 +- src/libs/antares/sys/policy.cpp | 2 +- .../optimisation/post_process_commands.cpp | 8 +- src/solver/simulation/common-eco-adq.cpp | 37 +-- .../simulation/sim_calcul_economique.cpp | 2 +- src/solver/simulation/timeseries-numbers.cpp | 20 +- .../economy/avail-dispatchable-generation.h | 2 +- .../economy/productionByRenewablePlant.h | 4 +- .../variable/economy/renewableGeneration.h | 2 +- src/solver/variable/info.h | 2 +- .../variable/surveyresults/reportbuilder.hxx | 10 +- src/tools/yby-aggregator/job.cpp | 2 +- .../handler/antares-study/area/create.cpp | 8 +- .../antares-study/thermal-cluster/create.cpp | 1 - .../renderer/area/renewable.areasummary.cpp | 8 +- .../renderer/area/thermal.areasummary.cpp | 8 +- .../scenario-builder-renewable-renderer.cpp | 4 +- .../scenario-builder-thermal-renderer.cpp | 4 +- .../datasource/renewable-cluster-order.cpp | 2 +- .../datasource/thermal-cluster-order.cpp | 2 +- .../toolbox/components/map/manager.cpp | 2 +- .../toolbox/input/renewable-cluster.cpp | 3 - .../toolbox/input/thermal-cluster.cpp | 3 - src/ui/simulator/windows/inspector/frame.cpp | 25 +- src/ui/simulator/windows/inspector/frame.h | 1 - .../simulator/windows/inspector/inspector.cpp | 2 +- .../windows/output/spotlight-provider.cpp | 6 +- 45 files changed, 310 insertions(+), 710 deletions(-) diff --git a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp index 05f9894f12..ba626a59ed 100644 --- a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp +++ b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp @@ -59,13 +59,8 @@ void StudyInfoCollector::enabledThermalClustersCountToFileContent(FileContent& f for (auto i = study_.areas.begin(); i != end; ++i) { Area& area = *(i->second); - auto end = area.thermal.list.end(); - for (auto i = area.thermal.list.begin(); i != end; ++i) - { - auto& cluster = i->second; - if (cluster->enabled) - nbEnabledThermalClusters++; - } + nbEnabledThermalClusters += + std::ranges::count_if(area.thermal.list, [](const auto& c) { return c->enabled; }); } // Adding an item related to number of enabled thermal clusters to the file content @@ -152,4 +147,4 @@ void SimulationInfoCollector::toFileContent(FileContent& file_content) "optimization problem", "non-zero coefficients", opt_info_.nbNonZeroCoeffs); } -} \ No newline at end of file +} diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index f06ec3ac87..423904475a 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -1535,8 +1535,8 @@ ThermalCluster* AreaList::findClusterFromINIKey(const AnyString& key) Area* parentArea = findFromName(parentName); if (parentArea == nullptr) return nullptr; - ThermalCluster* i = parentArea->thermal.list.find(id); - return (i != nullptr) ? i : nullptr; + return parentArea->thermal.list.find(id); + } void AreaList::updateNameIDSet() const diff --git a/src/libs/antares/study/cleaner/cleaner-v20.cpp b/src/libs/antares/study/cleaner/cleaner-v20.cpp index a0f4dea784..5f8e6636e1 100644 --- a/src/libs/antares/study/cleaner/cleaner-v20.cpp +++ b/src/libs/antares/study/cleaner/cleaner-v20.cpp @@ -135,23 +135,19 @@ static void listOfFilesAnDirectoriesToKeepForArea(PathList& e, PathList& p, cons buffer.clear() << "input/thermal/clusters/" << id << "/list.ini"; e.add(buffer); - auto end = area->thermal.list.end(); - for (auto i = area->thermal.list.begin(); i != end; ++i) + for (const auto& cluster : area->thermal.list) { - // Reference to the thermal cluster - auto& cluster = *(i->second); - - buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster.id(); + buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster->id(); p.add(buffer); - buffer.clear() << "input/thermal/series/" << id << '/' << cluster.id(); + buffer.clear() << "input/thermal/series/" << id << '/' << cluster->id(); p.add(buffer); - buffer.clear() << "input/thermal/series/" << id << '/' << cluster.id() << "/series.txt"; + buffer.clear() << "input/thermal/series/" << id << '/' << cluster->id() << "/series.txt"; e.add(buffer); - buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster.id() << "/data.txt"; + buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster->id() << "/data.txt"; e.add(buffer); - buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster.id() + buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster->id() << "/modulation.txt"; e.add(buffer); } @@ -168,16 +164,12 @@ static void listOfFilesAnDirectoriesToKeepForArea(PathList& e, PathList& p, cons buffer.clear() << "input/renewables/clusters/" << id << "/list.ini"; e.add(buffer); - auto end = area->renewable.list.end(); - for (auto i = area->renewable.list.begin(); i != end; ++i) + for (const auto& cluster : area->renewable.list) { - // Reference to the thermal cluster - auto& cluster = *(i->second); - - buffer.clear() << "input/renewables/series/" << id << '/' << cluster.id(); + buffer.clear() << "input/renewables/series/" << id << '/' << cluster->id(); p.add(buffer); - buffer.clear() << "input/renewables/series/" << id << '/' << cluster.id() + buffer.clear() << "input/renewables/series/" << id << '/' << cluster->id() << "/series.txt"; e.add(buffer); } diff --git a/src/libs/antares/study/parts/common/cluster.cpp b/src/libs/antares/study/parts/common/cluster.cpp index 64e925f8a5..265b8f4d51 100644 --- a/src/libs/antares/study/parts/common/cluster.cpp +++ b/src/libs/antares/study/parts/common/cluster.cpp @@ -49,45 +49,38 @@ void Cluster::setName(const AnyString& newname) } #define SEP Yuni::IO::Separator -int Cluster::saveDataSeriesToFolder(const AnyString& folder) const +bool Cluster::saveDataSeriesToFolder(const AnyString& folder) const { - if (not folder.empty()) - { - Yuni::Clob buffer; - - buffer.clear() << folder << SEP << parentArea->id << SEP << id(); - if (Yuni::IO::Directory::Create(buffer)) - { - int ret = 1; - buffer.clear() << folder << SEP << parentArea->id << SEP << id() << SEP << "series.txt"; - ret = series.timeSeries.saveToCSVFile(buffer, precision()) && ret; - - return ret; - } - return 0; - } - return 1; + if (folder.empty()) + return true; + + Yuni::Clob buffer; + buffer.clear() << folder << SEP << parentArea->id << SEP << id(); + if (!Yuni::IO::Directory::Create(buffer)) + return true; + + buffer.clear() << folder << SEP << parentArea->id << SEP << id() << SEP << "series.txt"; + return series.timeSeries.saveToCSVFile(buffer, precision()); } -int Cluster::loadDataSeriesFromFolder(Study& s, const AnyString& folder) +bool Cluster::loadDataSeriesFromFolder(Study& s, const AnyString& folder) { - if (not folder.empty()) - { - auto& buffer = s.bufferLoadingTS; + if (folder.empty()) + return true; + + auto& buffer = s.bufferLoadingTS; - int ret = 1; - buffer.clear() << folder << SEP << parentArea->id << SEP << id() << SEP << "series." - << s.inputExtension; - ret = series.timeSeries.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &s.dataBuffer) && ret; + bool ret = true; + buffer.clear() << folder << SEP << parentArea->id << SEP << id() << SEP << "series." + << s.inputExtension; + ret = series.timeSeries.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &s.dataBuffer) && ret; - if (s.usedByTheSolver && s.parameters.derated) - series.timeSeries.averageTimeseries(); + if (s.usedByTheSolver && s.parameters.derated) + series.timeSeries.averageTimeseries(); - series.timeseriesNumbers.clear(); + series.timeseriesNumbers.clear(); - return ret; - } - return 1; + return ret; } #undef SEP diff --git a/src/libs/antares/study/parts/common/cluster.h b/src/libs/antares/study/parts/common/cluster.h index eee596ede1..d552eb54b8 100644 --- a/src/libs/antares/study/parts/common/cluster.h +++ b/src/libs/antares/study/parts/common/cluster.h @@ -142,8 +142,8 @@ class Cluster //! Set of clusters using Set = std::set; - int saveDataSeriesToFolder(const AnyString& folder) const; - int loadDataSeriesFromFolder(Study& s, const AnyString& folder); + bool saveDataSeriesToFolder(const AnyString& folder) const; + bool loadDataSeriesFromFolder(Study& s, const AnyString& folder); private: virtual unsigned int precision() const = 0; diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 3f08915727..bc5f8e5aa5 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "cluster_list.h" #include #include "../../study.h" @@ -22,137 +24,63 @@ using namespace Antares; template inline uint ClusterList::size() const { - return (uint)cluster.size(); + return (uint)clusters.size(); } template inline bool ClusterList::empty() const { - return cluster.empty(); + return clusters.empty(); } template typename ClusterList::iterator ClusterList::begin() { - return std::begin(cluster); + return std::begin(clusters); } template typename ClusterList::const_iterator ClusterList::begin() const { - return std::begin(cluster); + return std::begin(clusters); } template typename ClusterList::iterator ClusterList::end() { - return std::end(cluster); + return std::end(clusters); } template typename ClusterList::const_iterator ClusterList::end() const { - return std::end(cluster); + return std::end(clusters); } template -const ClusterT* ClusterList::find(const Data::ClusterName& id) const +ClusterT* ClusterList::find(const Data::ClusterName& id) const { - auto i = cluster.find(id); - return (i != cluster.end()) ? i->second.get() : nullptr; -} - -template -ClusterT* ClusterList::find(const Data::ClusterName& id) -{ - auto i = cluster.find(id); - return (i != cluster.end()) ? i->second.get() : nullptr; -} + const auto& it = std::ranges::find_if(clusters, [&id](auto& c) { return c->id() == id; }); -template -typename std::shared_ptr ClusterList::detach(iterator i) -{ - SharedPtr c = i->second; - cluster.erase(i); - return c; -} - -template -void ClusterList::remove(iterator i) -{ - cluster.erase(i); + return (it != clusters.end()) ? it->get() : nullptr; } template bool ClusterList::exists(const Data::ClusterName& id) const { - if (not cluster.empty()) - { - auto element = cluster.find(id); - return (element != cluster.end()); - } - return false; -} - -template -Data::ClusterList::ClusterList() : groupCount(ClusterT::groupMax, 0) -{ -} - -template -Data::ClusterList::~ClusterList() -{ - // deleting all renewable clusters - clear(); + return std::ranges::any_of(clusters, [&id](const auto& c){ return c->id() == id; }); } template void ClusterList::clear() { - byIndex.clear(); - if (not cluster.empty()) - cluster.clear(); -} - -template -const ClusterT* ClusterList::find(const ClusterT* p) const -{ - auto end = cluster.end(); - for (auto i = cluster.begin(); i != end; ++i) - { - if (p == i->second.get()) - return i->second.get(); - } - return nullptr; -} - -template -ClusterT* ClusterList::find(const ClusterT* p) -{ - auto end = cluster.end(); - for (auto i = cluster.begin(); i != end; ++i) - { - if (p == i->second.get()) - return i->second.get(); - } - return nullptr; + clusters.clear(); } template void ClusterList::resizeAllTimeseriesNumbers(uint n) { - assert(n < 200000); // arbitrary number - if (not cluster.empty()) - { - if (0 == n) - { - each([&](Cluster& cluster) { cluster.series.timeseriesNumbers.clear(); }); - } - else - { - each([&](Cluster& cluster) { cluster.series.timeseriesNumbers.resize(1, n); }); - } - } + each([&](Cluster& cluster) { cluster.series.timeseriesNumbers.resize(1, n); }); } #define SEP IO::Separator @@ -160,9 +88,6 @@ void ClusterList::resizeAllTimeseriesNumbers(uint n) template void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer) const { - if (cluster.empty()) - return; - TSNumbersPredicate predicate; Clob path; std::string ts_content; @@ -179,38 +104,28 @@ void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer template void ClusterList::rebuildIndex() { - byIndex.clear(); + std::sort(clusters.begin(), clusters.end(), [](const auto& a, const auto& b){ + return a->id() < b->id(); + }); - if (not empty()) - { - uint indx = 0; - byIndex.resize(size()); - for (auto i = cluster.begin(); i != cluster.end(); ++i) - { - auto cluster = i->second.get(); - byIndex[indx] = cluster; - cluster->index = indx; - ++indx; - } - } + uint indx = 0; + for (auto& c : clusters) + c->index = indx++; } template typename ClusterList::SharedPtr ClusterList::add( - const ClusterList::SharedPtr& newcluster) + const ClusterList::SharedPtr newcluster) { - if (newcluster) - { - if (exists(newcluster->id())) - return cluster[newcluster->id()]; - - newcluster->index = (uint)size(); - cluster[newcluster->id()] = newcluster; - ++(groupCount[newcluster->groupId()]); - rebuildIndex(); - return cluster[newcluster->id()]; - } - return nullptr; + if (!newcluster) + return nullptr; + + if (exists(newcluster->id())) + return newcluster; + + clusters.push_back(newcluster); + rebuildIndex(); + return newcluster; } template @@ -218,7 +133,7 @@ uint64_t ClusterList::memoryUsage() const { uint64_t ret = sizeof(ClusterList) + (2 * sizeof(void*)) * this->size(); - each([&](const ClusterT& cluster) { ret += cluster.memoryUsage(); }); + each([&](const ClusterT& clusters) { ret += clusters.memoryUsage(); }); return ret; } @@ -241,37 +156,32 @@ bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName Data::ClusterName newID; Antares::TransformNameIntoID(newName, newID); - // Looking for the renewable cluster in the list - auto it = cluster.find(idToFind); - if (it == cluster.end()) + // Looking for the renewable clusters in the list + auto* cluster_ptr = this->find(idToFind); + if (!cluster_ptr) return true; - SharedPtr p = it->second; - if (idToFind == newID) { - p->setName(newName); + cluster_ptr->setName(newName); return true; } // The name is the same. Aborting nicely. - if (p->name() == newName) + if (cluster_ptr->name() == newName) return true; // Already exist if (this->exists(newID)) return false; - cluster.erase(it); - - p->setName(newName); - cluster[newID] = p; + cluster_ptr->setName(newName); // Invalidate matrices attached to the area - // It is a bit excessive (all matrices not only those related to the renewable cluster) + // It is a bit excessive (all matrices not only those related to the renewable clusters) // will be rewritten but currently it is the less error-prone. - if (p->parentArea) - (p->parentArea)->invalidateJIT = true; + if (cluster_ptr->parentArea) + (cluster_ptr->parentArea)->invalidateJIT = true; // Rebuilding the index rebuildIndex(); @@ -281,88 +191,61 @@ bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName template bool ClusterList::forceReload(bool reload) const { - bool ret = true; - auto end = cluster.end(); - for (auto i = cluster.begin(); i != end; ++i) - ret = (i->second)->forceReload(reload) and ret; - return ret; + return std::ranges::all_of(clusters, [&reload](const auto& c){ + return c->forceReload(reload); + }); + } template void ClusterList::markAsModified() const { - auto end = cluster.end(); - for (auto i = cluster.begin(); i != end; ++i) - (i->second)->markAsModified(); + for (const auto& c : clusters) + c->markAsModified(); } template bool ClusterList::remove(const Data::ClusterName& id) { - auto i = cluster.find(id); - if (i == cluster.end()) - return false; - - // Getting the pointer on the cluster - SharedPtr c = i->second; + auto nbDeletion = std::erase_if(clusters, [&id](const SharedPtr& c) { return c->id() == id; }); - // Removing it from the list - cluster.erase(i); // Invalidating the parent area - c->parentArea->forceReload(); + forceReload(); // Rebuilding the index rebuildIndex(); - return true; + + return nbDeletion > 0; } template -int ClusterList::saveDataSeriesToFolder(const AnyString& folder) const +bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) const { - if (empty()) - return 1; - - int ret = 1; - - auto end = cluster.end(); - for (auto it = cluster.begin(); it != end; ++it) - { - auto& cluster = *(it->second); - ret = cluster.saveDataSeriesToFolder(folder) and ret; - } - return ret; + return std::ranges::all_of(clusters, [&folder](const auto& c){ + return c->saveDataSeriesToFolder(folder); + }); } template -int ClusterList::saveDataSeriesToFolder(const AnyString& folder, const String& msg) const +bool ClusterList::saveDataSeriesToFolder(const AnyString& folder, const String& msg) const { - if (empty()) - return 1; - - int ret = 1; uint ticks = 0; - auto end = cluster.end(); - for (auto it = cluster.begin(); it != end; ++it) + return std::ranges::all_of(clusters, [&](const auto& c) { - auto& cluster = *(it->second); - logs.info() << msg << " " << (ticks * 100 / (1 + this->cluster.size())) + logs.info() << msg << " " << (ticks * 100 / (1 + this->clusters.size())) << "% complete"; - ret = cluster.saveDataSeriesToFolder(folder) and ret; ++ticks; - } - return ret; + return c->saveDataSeriesToFolder(folder); + }); } template -int ClusterList::loadDataSeriesFromFolder(Study& s, +bool ClusterList::loadDataSeriesFromFolder(Study& s, const StudyLoadOptions& options, const AnyString& folder) { - if (empty()) - return 1; - - int ret = 1; + bool ret = true; each([&](ClusterT& c) { ret = c.loadDataSeriesFromFolder(s, folder) and ret; @@ -379,22 +262,26 @@ void ClusterList::retrieveTotalCapacityAndUnitCount(double& total, uin total = 0.; unitCount = 0; - if (not cluster.empty()) + for (const auto& c : clusters) { - auto end = cluster.cend(); - for (auto i = cluster.cbegin(); i != end; ++i) - { - if (not i->second) - return; - - // Reference to the thermal cluster - auto& cluster = *(i->second); - unitCount += cluster.unitCount; - total += cluster.unitCount * cluster.nominalCapacity; - } + unitCount += c->unitCount; + total += c->unitCount * c->nominalCapacity; } } +template +uint ClusterList::removeDisabledClusters() +{ + // nothing to do if there is no clusters available + if (empty()) + return 0; + + auto count = std::erase_if(clusters, [] (auto& c) { return !c->enabled; }); + + rebuildIndex(); + + return count; +} // Force template instantiation template class ClusterList; template class ClusterList; diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 14f90d9fa3..9f3899aa8b 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -6,6 +6,7 @@ #include +#include #include #include @@ -14,65 +15,30 @@ namespace Antares namespace Data { /*! -** \brief List of clusters +** \brief Generic list of clusters ** \ingroup renewableclusters +** This class implements the base functions for a list of cluster +** It's used for thermal and renewable clusters */ template class ClusterList { public: - // Shared pointer using SharedPtr = typename std::shared_ptr; - // Map container - using Map = typename std::map; - //! iterator - using iterator = typename Map::iterator; - //! const iterator - using const_iterator = typename Map::const_iterator; + using Vect = typename std::vector; + using iterator = typename Vect::iterator; + using const_iterator = typename Vect::const_iterator; -public: - //! \name Constructor & Destructor - //@{ - /*! - ** \brief Default constructor - */ - ClusterList(); - /*! - ** \brief Destructor - */ - virtual ~ClusterList(); - //@} - - //! \name Iterating - //@{ - /*! - ** \brief Iterate through all clusters - */ - template - void each(const PredicateT& predicate) - { - auto end = cluster.cend(); - for (auto i = cluster.cbegin(); i != end; ++i) - { - auto& it = *(i->second); - predicate(it); - } - } /*! ** \brief Iterate through all clusters (const) */ template void each(const PredicateT& predicate) const { - auto end = cluster.end(); - for (auto i = cluster.begin(); i != end; ++i) - { - const auto& it = *(i->second); - predicate(it); - } + std::ranges::for_each(clusters, [&predicate](const auto& c) { predicate(*c); }); } - //! \name Cluster management + //! \name clusters management //@{ /*! ** \brief Destroy all clusters @@ -85,57 +51,15 @@ class ClusterList ** \param t The cluster to add ** \return True if the cluster has been added, false otherwise */ - - SharedPtr add(const SharedPtr& t); - /*! - ** \brief Detach a cluster represented by an iterator - ** - ** The cluster will be removed from the list but _not_ - ** destroyed. - ** The iterator should considered as invalid after using this method. - ** \return A pointer to the cluster, NULL if an error has occured - */ - SharedPtr detach(iterator i); - - /*! - ** \brief Remove a cluster represented by an iterator - ** - ** The cluster will be removed from the list but _not_ - ** destroyed. - ** The iterator should considered as invalid after using this method. - ** \return void - */ - virtual void remove(iterator i); + SharedPtr add(const SharedPtr clusters); - /*! - ** \brief Try to find a cluster from its id - ** - ** \param id ID of the cluster to find - ** \return A pointer to a cluster. nullptr if not found - */ - ClusterT* find(const Data::ClusterName& id); /*! ** \brief Try to find a cluster from its id (const) ** ** \param id ID of the cluster to find ** \return A pointer to a cluster. nullptr if not found */ - const ClusterT* find(const Data::ClusterName& id) const; - - /*! - ** \brief Try to find a cluster from its pointer - ** - ** \param p Pointer of the cluster to find - ** \return A pointer to a cluster. nullptr if not found - */ - ClusterT* find(const ClusterT* p); - /*! - ** \brief Try to find a cluster from its pointer (const) - ** - ** \param p Pointer of the cluster to find - ** \return A pointer to a cluster. nullptr if not found - */ - const ClusterT* find(const ClusterT* p) const; + ClusterT* find(const Data::ClusterName& id) const; /*! ** \brief Get if a cluster exists @@ -165,20 +89,18 @@ class ClusterList //! Get the number of items in the list uint size() const; - //! Get if the list is empty + //! Return true if the list is empty bool empty() const; //@} - //! iterator to the begining of the list iterator begin(); - //! iterator to the begining of the list const_iterator begin() const; - //! iterator to the end of the list iterator end(); - //! iterator to the end of the list const_iterator end() const; + SharedPtr operator[](std::size_t idx) { return clusters[idx]; } + const SharedPtr operator[](std::size_t idx) const { return clusters[idx]; } /*! ** \brief Resize all matrices dedicated to the sampled timeseries numbers ** @@ -190,27 +112,16 @@ class ClusterList //@} - //! \name Memory management - //@{ /*! ** \brief Invalidate all clusters */ bool forceReload(bool reload = false) const; /*! - ** \brief Mark the cluster as modified + ** \brief Mark the clusters as modified */ void markAsModified() const; - /*! - ** \brief Rebuild the index of clusters - ** - ** As a list of clusters is a hash table, it is not - ** possible to directly accees to a cluster from its index. - ** However an index can be built but it must be re-built when - ** the hash table is modified. - */ - void rebuildIndex(); /*! ** \brief Get the size (bytes) occupied in memory by a `ClusterList` structure @@ -218,48 +129,54 @@ class ClusterList */ uint64_t memoryUsage() const; -public: - //! All clusters by their index - std::vector byIndex; - //! All clusters - Map cluster; - - // thermal, renewable, etc. - virtual YString typeID() const = 0; - - /*! - ** \brief Number of dispatchable cluster per group - ** - ** You should rely on these values only after the loading of the study - ** and until the study is not modified. - ** These values are modified by 'ClusterListAdd()' - */ - std::vector groupCount; - - int loadDataSeriesFromFolder(Study& study, + /// \name IO functions + /// @{ + bool loadDataSeriesFromFolder(Study& study, const StudyLoadOptions& options, const AnyString& folder); - int saveDataSeriesToFolder(const AnyString& folder) const; + bool saveDataSeriesToFolder(const AnyString& folder) const; - int saveDataSeriesToFolder(const AnyString& folder, const YString& msg) const; + bool saveDataSeriesToFolder(const AnyString& folder, const YString& msg) const; virtual bool saveToFolder(const AnyString& folder) const = 0; + ///@} - //! \name Informations - //@{ /*! ** \brief Retrieve the total capacity and the total unit count ** ** Pseudo code: ** \code - ** each thermal cluster do - ** total += cluster{unit count} * cluster{nominal capacity} - ** unit += cluster{unit count} + ** each thermal clusters do + ** total += clusters{unit count} * clusters{nominal capacity} + ** unit += clusters{unit count} ** \endcode */ void retrieveTotalCapacityAndUnitCount(double& total, uint& unitCount) const; - //@} + + /*! + ** \brief Removes disabled clusters + ** + ** All clusters with the flag 'enabled' turned to false will be removed from 'list'. + ** As a consequence, they will no longer be seen as thermal clusters + ** from the solver's point of view. + ** \warning This method should only be used from the solver + ** + ** \return The number of disabled clusters found + */ + uint removeDisabledClusters(); + +protected: + /// The vector containing the clusters + Vect clusters; + + /// thermal, renewable, etc. + virtual std::string typeID() const = 0; + +private: + /// Sort the vector, set index value for each cluster + void rebuildIndex(); + }; // class ClusterList } // namespace Data } // namespace Antares diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index 5669429dff..e23f84fe2a 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -10,13 +10,13 @@ namespace Antares namespace Data { -YString RenewableClusterList::typeID() const +#define SEP IO::Separator + +std::string RenewableClusterList::typeID() const { return "renewables"; } -#define SEP IO::Separator - bool RenewableClusterList::saveToFolder(const AnyString& folder) const { // Make sure the folder is created diff --git a/src/libs/antares/study/parts/renewable/cluster_list.h b/src/libs/antares/study/parts/renewable/cluster_list.h index e4c3018ace..21f50b3694 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.h +++ b/src/libs/antares/study/parts/renewable/cluster_list.h @@ -16,8 +16,7 @@ namespace Data class RenewableClusterList : public ClusterList { public: - // Overriden virtual methods - YString typeID() const override; + std::string typeID() const override; bool loadFromFolder(const AnyString& folder, Area* area); bool saveToFolder(const AnyString& folder) const override; }; // class RenewableClusterList diff --git a/src/libs/antares/study/parts/renewable/container.cpp b/src/libs/antares/study/parts/renewable/container.cpp index ea7cbdb0fd..fee7793cdb 100644 --- a/src/libs/antares/study/parts/renewable/container.cpp +++ b/src/libs/antares/study/parts/renewable/container.cpp @@ -66,40 +66,14 @@ void PartRenewable::prepareAreaWideIndexes() return; } - auto end = list.end(); uint idx = 0; - for (auto i = list.begin(); i != end; ++i) + for (const auto& cluster : list) { - RenewableCluster* t = i->second.get(); - t->areaWideIndex = idx; + cluster->areaWideIndex = idx; ++idx; } } -uint PartRenewable::removeDisabledClusters() -{ - // nothing to do if there is no cluster available - if (list.empty()) - return 0; - - std::vector disabledClusters; - - for (auto& it : list) - { - if (!it.second->enabled) - disabledClusters.push_back(it.first); - } - - for (auto& cluster : disabledClusters) - list.remove(cluster); - - const auto count = disabledClusters.size(); - if (count) - list.rebuildIndex(); - - return count; -} - void PartRenewable::reset() { list.clear(); diff --git a/src/libs/antares/study/parts/renewable/container.h b/src/libs/antares/study/parts/renewable/container.h index ccb20d5b7f..ae4d439608 100644 --- a/src/libs/antares/study/parts/renewable/container.h +++ b/src/libs/antares/study/parts/renewable/container.h @@ -71,18 +71,6 @@ class PartRenewable */ void prepareAreaWideIndexes(); - /*! - ** \brief Removes disabled renewable clusters - ** - ** All clusters with the flag 'enabled' turned to false will be removed from 'list'. - ** As a consequence, they will no longer be seen as renewable clusters - ** from the solver's point of view. - ** \warning This method should only be used from the solver - ** - ** \return The number of disabled clusters found - */ - uint removeDisabledClusters(); - /*! ** \brief Invalidate all JIT data */ diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 2cd45cfa14..3867bfeca4 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -1,6 +1,7 @@ #include "cluster_list.h" #include "cluster.h" #include "../../study.h" +#include namespace // anonymous { @@ -32,6 +33,11 @@ ThermalClusterList::~ThermalClusterList() #define SEP IO::Separator +std::string ThermalClusterList::typeID() const +{ + return "thermal"; +} + static bool ThermalClusterLoadFromSection(const AnyString& filename, ThermalCluster& cluster, const IniFile::Section& section); @@ -145,11 +151,6 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A return ret; } -YString ThermalClusterList::typeID() const -{ - return "thermal"; -} - static bool ThermalClusterLoadFromProperty(ThermalCluster& cluster, const IniFile::Property* p) { if (p->key.empty()) @@ -278,31 +279,7 @@ void ThermalClusterList::calculationOfSpinning() void ThermalClusterList::reverseCalculationOfSpinning() { - auto end = cluster.end(); - for (auto it = cluster.begin(); it != end; ++it) - { - auto& cluster = *(it->second); - cluster.reverseCalculationOfSpinning(); - } -} - -bool ThermalClusterList::remove(const ClusterName& id) -{ - auto i = cluster.find(id); - if (i == cluster.end()) - return false; - - // Getting the pointer on the cluster - SharedPtr c = i->second; - - // Removing it from the list - cluster.erase(i); - // Invalidating the parent area - c->parentArea->forceReload(); - - // Rebuilding the index - rebuildIndex(); - return true; + each([&](ThermalCluster& cluster) { cluster.reverseCalculationOfSpinning(); }); } void ThermalClusterList::enableMustrunForEveryone() @@ -313,13 +290,9 @@ void ThermalClusterList::enableMustrunForEveryone() void ThermalClusterList::ensureDataPrepro() { - auto end = cluster.end(); - for (auto it = cluster.begin(); it != end; ++it) - { - auto c = it->second; - if (not c->prepro) + for (const auto& c : clusters) + if (!c->prepro) c->prepro = new PreproThermal(c); - } } bool ThermalClusterList::saveToFolder(const AnyString& folder) const @@ -391,7 +364,7 @@ bool ThermalClusterList::saveToFolder(const AnyString& folder) const // costs if (c.costgeneration != setManually) - s->add("costgeneration", c.costgeneration); + s->add("costgeneration", c.costgeneration); if (not Math::Zero(c.marginalCost)) s->add("marginal-cost", Math::Round(c.marginalCost, 3)); if (not Math::Zero(c.spreadCost)) @@ -439,9 +412,6 @@ bool ThermalClusterList::saveToFolder(const AnyString& folder) const bool ThermalClusterList::savePreproToFolder(const AnyString& folder) const { - if (empty()) - return true; - Clob buffer; bool ret = true; @@ -458,9 +428,6 @@ bool ThermalClusterList::savePreproToFolder(const AnyString& folder) const bool ThermalClusterList::saveEconomicCosts(const AnyString& folder) const { - if (empty()) - return true; - Clob buffer; bool ret = true; @@ -476,59 +443,47 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, const StudyLoadOptions& options, const AnyString& folder) { - if (empty()) - return true; - const bool globalThermalTSgeneration - = study.parameters.timeSeriesToGenerate & timeSeriesThermal; + = study.parameters.timeSeriesToGenerate & timeSeriesThermal; Clob buffer; - bool ret = true; - - for (auto& [name, c] : cluster) + auto hasPrepro = [&](auto c) + { + ++options.progressTicks; + options.pushProgressLogs(); + return (bool) c->prepro; + }; + + auto loadAndCheckPrepro = [&](auto c) { - if (c->prepro) - { - assert(c->parentArea and "cluster: invalid parent area"); - buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); + assert(c->parentArea && "cluster: invalid parent area"); + buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); - bool result = c->prepro->loadFromFolder(study, buffer); + bool result = c->prepro->loadFromFolder(study, buffer); - if (result && study.usedByTheSolver && c->doWeGenerateTS(globalThermalTSgeneration)) - { - // checking NPO max - result = c->prepro->normalizeAndCheckNPO(); - } - - ret = result and ret; + if (result && study.usedByTheSolver && c->doWeGenerateTS(globalThermalTSgeneration)) + { + result = c->prepro->normalizeAndCheckNPO(); } - - ++options.progressTicks; - options.pushProgressLogs(); - } - return ret; -} + return result; + }; + return std::ranges::all_of(clusters | std::views::filter(hasPrepro), + loadAndCheckPrepro); +} bool ThermalClusterList::loadEconomicCosts(Study& study, const AnyString& folder) { - if (empty()) - return true; - - Clob buffer; - bool ret = true; - - for (auto& [name, c] : cluster) + return std::ranges::all_of(clusters, [&study, folder](const auto& c) { - assert(c->parentArea and "cluster: invalid parent area"); + assert(c->parentArea && "cluster: invalid parent area"); + Clob buffer; buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); bool result = c->ecoInput.loadFromFolder(study, buffer); c->ComputeCostTimeSeries(); - - ret = result && ret; - } - return ret; + return result; + }); } } // namespace Data diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 1d15b028a9..b23164bfb0 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -13,8 +13,9 @@ namespace Data class ThermalClusterList : public ClusterList { public: - // Overriden pure virtual methods - YString typeID() const override; + std::string typeID() const override; + // Map container + using Map = typename std::map>; /*! ** \brief Get the size (bytes) occupied in memory by a `ThermalClusterList` structure @@ -58,8 +59,6 @@ class ThermalClusterList : public ClusterList void enableMustrunForEveryone(); //@} - bool remove(const ClusterName& id) override; - Map mapping; /*! diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index 55cebd6440..a88bdf1e72 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -40,7 +40,6 @@ namespace Antares { namespace Data { -using NamedCluster = std::pair; PartThermal::PartThermal() : unsuppliedEnergyCost(0.), spilledEnergyCost(0.) { @@ -76,13 +75,11 @@ void PartThermal::prepareAreaWideIndexes() clusters.assign(list.size(), nullptr); - auto end = list.end(); uint idx = 0; - for (auto i = list.begin(); i != end; ++i) + for (const auto& cluster : list) { - ThermalCluster* t = i->second.get(); - t->areaWideIndex = idx; - clusters[idx] = t; + cluster->areaWideIndex = idx; + clusters[idx] = cluster.get(); ++idx; } } @@ -99,66 +96,34 @@ uint PartThermal::prepareClustersInMustRunMode() do { mustContinue = false; - auto end = list.end(); - for (auto i = list.begin(); i != end; ++i) + for (auto cluster : list) { - if ((i->second)->mustrun) + if (!cluster->mustrun) + continue; + + // Detaching the thermal cluster from the main list... + list.remove(cluster->id()); + if (!cluster->enabled) + continue; + // ...and attaching it into the second list + if (!mustrunList.add(cluster)) { - // Detaching the thermal cluster from the main list... - std::shared_ptr cluster = list.detach(i); - if (!cluster->enabled) - continue; - // ...and attaching it into the second list - if (!mustrunList.add(cluster)) - { - logs.error() << "Impossible to prepare the thermal cluster in 'must-run' mode: " - << cluster->parentArea->name << "::" << cluster->name(); - } - else - { - ++count; - logs.info() << "enabling 'must-run' mode for the cluster " - << cluster->parentArea->name << "::" << cluster->name(); - } - - // the iterator has been invalidated, loop again - mustContinue = true; - break; + logs.error() << "Impossible to prepare the thermal cluster in 'must-run' mode: " + << cluster->parentArea->name << "::" << cluster->name(); } + else + { + ++count; + logs.info() << "enabling 'must-run' mode for the cluster " + << cluster->parentArea->name << "::" << cluster->name(); + } + + // the iterator has been invalidated, loop again + mustContinue = true; + break; } } while (mustContinue); - // if some thermal cluster has been moved, we must rebuild all the indexes - if (count) - { - list.rebuildIndex(); - mustrunList.rebuildIndex(); - } - - return count; -} - -uint PartThermal::removeDisabledClusters() -{ - // nothing to do if there is no cluster available - if (list.empty()) - return 0; - - std::vector disabledClusters; - - for (auto& it : list) - { - if (!it.second->enabled) - disabledClusters.push_back(it.first); - } - - for (const auto& cluster : disabledClusters) - list.remove(cluster); - - const auto count = disabledClusters.size(); - if (count) - list.rebuildIndex(); - return count; } @@ -175,16 +140,16 @@ void PartThermal::reset() bool PartThermal::hasForcedTimeseriesGeneration() const { using Behavior = LocalTSGenerationBehavior; - return std::any_of(list.begin(), list.end(), [](const NamedCluster& namedCluster) { - return namedCluster.second->tsGenBehavior == Behavior::forceGen; + return std::any_of(list.begin(), list.end(), [](const ThermalClusterList::SharedPtr& cluster) { + return cluster->tsGenBehavior == Behavior::forceGen; }); } bool PartThermal::hasForcedNoTimeseriesGeneration() const { using Behavior = LocalTSGenerationBehavior; - return std::any_of(list.begin(), list.end(), [](const NamedCluster& namedCluster) { - return namedCluster.second->tsGenBehavior == Behavior::forceNoGen; + return std::any_of(list.begin(), list.end(), [](const ThermalClusterList::SharedPtr& cluster) { + return cluster->tsGenBehavior == Behavior::forceNoGen; }); } diff --git a/src/libs/antares/study/parts/thermal/container.h b/src/libs/antares/study/parts/thermal/container.h index 0c860abe53..6a413c479e 100644 --- a/src/libs/antares/study/parts/thermal/container.h +++ b/src/libs/antares/study/parts/thermal/container.h @@ -81,18 +81,6 @@ class PartThermal */ uint prepareClustersInMustRunMode(); - /*! - ** \brief Removes disabled thermal clusters - ** - ** All clusters with the flag 'enabled' turned to false will be removed from 'list'. - ** As a consequence, they will no longer be seen as thermal clusters - ** from the solver's point of view. - ** \warning This method should only be used from the solver - ** - ** \return The number of disabled clusters found - */ - uint removeDisabledClusters(); - /*! ** \brief Invalidate all JIT data */ diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index 039dbea843..78f76e475e 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -410,13 +410,13 @@ static void removeClusters(Study& study, void StudyRuntimeInfos::removeDisabledThermalClustersFromSolverComputations(Study& study) { removeClusters( - study, "thermal", [](Area& area) { return area.thermal.removeDisabledClusters(); }); + study, "thermal", [](Area& area) { return area.thermal.list.removeDisabledClusters(); }); } void StudyRuntimeInfos::removeDisabledRenewableClustersFromSolverComputations(Study& study) { removeClusters(study, "renewable", [](Area& area) { - uint ret = area.renewable.removeDisabledClusters(); + uint ret = area.renewable.list.removeDisabledClusters(); if (ret > 0) area.renewable.prepareAreaWideIndexes(); return ret; diff --git a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp index 338f13a4b2..808fa9f93b 100644 --- a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp @@ -33,7 +33,7 @@ bool renewableTSNumberData::apply(Study& study) const uint tsGenCountRenewable = get_tsGenCount(study); uint clusterIndex = 0; - for (const auto& [name, cluster] : area.renewable.list) + for (const auto& cluster : area.renewable.list) { // alias to the current column assert(clusterIndex < pTSNumberRules.width); @@ -79,12 +79,12 @@ void renewableTSNumberData::saveToINIFile(const Study& /* study */, // Foreach renewable cluster... for (uint y = 0; y != pTSNumberRules.height; ++y) { - const uint val = get(pArea->renewable.list.byIndex[index], y); + const uint val = get(pArea->renewable.list[index].get(), y); // Equals to zero means 'auto', which is the default mode if (!val) continue; file << prefix << pArea->id << "," << y << ',' - << pArea->renewable.list.byIndex[index]->id() << " = " << val << '\n'; + << pArea->renewable.list[index]->id() << " = " << val << '\n'; } } } diff --git a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp index d9fd64b378..b67ede4039 100644 --- a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp @@ -49,12 +49,12 @@ void thermalTSNumberData::saveToINIFile(const Study& /* study */, // Foreach year ... for (uint y = 0; y != pTSNumberRules.height; ++y) { - const uint val = get(pArea->thermal.list.byIndex[index], y); + const uint val = get(pArea->thermal.list[index].get(), y); // Equals to zero means 'auto', which is the default mode if (!val) continue; file << prefix << pArea->id << "," << y << ',' - << pArea->thermal.list.byIndex[index]->id() << " = " << val << '\n'; + << pArea->thermal.list[index]->id() << " = " << val << '\n'; } } } diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index adf77d95f1..f729cfde45 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -1130,12 +1130,8 @@ void Study::destroyAllWindTSGeneratorData() void Study::destroyAllThermalTSGeneratorData() { areas.each([&](Data::Area& area) { - auto pend = area.thermal.list.end(); - for (auto j = area.thermal.list.begin(); j != pend; ++j) - { - ThermalCluster& cluster = *(j->second); - FreeAndNil(cluster.prepro); - } + for (const auto& cluster : area.thermal.list) + FreeAndNil(cluster->prepro); }); } @@ -1533,10 +1529,8 @@ void Study::computePThetaInfForThermalClusters() const // Alias de la zone courant const auto& area = *(this->areas.byIndex[i]); - for (uint j = 0; j < area.thermal.list.size(); j++) + for (auto& cluster : area.thermal.list) { - // Alias du cluster courant - auto& cluster = area.thermal.list.byIndex[j]; for (uint k = 0; k < HOURS_PER_YEAR; k++) cluster->PthetaInf[k] = cluster->modulation[Data::thermalMinGenModulation][k] * cluster->unitCount * cluster->nominalCapacity; diff --git a/src/libs/antares/sys/policy.cpp b/src/libs/antares/sys/policy.cpp index c45de88af5..fd51aca74a 100644 --- a/src/libs/antares/sys/policy.cpp +++ b/src/libs/antares/sys/policy.cpp @@ -75,7 +75,7 @@ static void OpenFromINIFileWL(const String& filename, const StringT& hostname) ini.each([&](const IniFile::Section& section) { // This section is dedicated to another host if (section.name == "*:*" or section.name == "*:" ANTARES_VERSION - or section.name == hostnameAll or section.name == hostnameVersion) + or section.name.equals(hostnameAll) or section.name.equals(hostnameVersion)) { section.each([&](const IniFile::Property& property) { key = property.key; diff --git a/src/solver/optimisation/post_process_commands.cpp b/src/solver/optimisation/post_process_commands.cpp index 9c6c3f5d9d..c82892355a 100644 --- a/src/solver/optimisation/post_process_commands.cpp +++ b/src/solver/optimisation/post_process_commands.cpp @@ -31,15 +31,13 @@ void DispatchableMarginPostProcessCmd::execute(const optRuntimeData& opt_runtime { auto& hourlyResults = problemeHebdo_->ResultatsHoraires[area.index]; - auto end = area.thermal.list.end(); - for (auto i = area.thermal.list.begin(); i != end; ++i) + for (const auto& cluster : area.thermal.list) { - auto& cluster = *(i->second); - const auto& availableProduction = cluster.series.getColumn(year); + const auto& availableProduction = cluster->series.getColumn(year); for (uint h = 0; h != nbHoursInWeek; ++h) { double production = hourlyResults.ProductionThermique[h] - .ProductionThermiqueDuPalier[cluster.index]; + .ProductionThermiqueDuPalier[cluster->index]; dtgmrg[h] += availableProduction[h + hourInYear] - production; } } diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index fcda4d07e6..a2fb1c682b 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -132,40 +132,33 @@ void PrepareDataFromClustersInMustrunMode(Data::Study& study, uint numSpace, uin double* mrs = scratchpad.mustrunSum; double* adq = scratchpad.originalMustrunSum; - if (!area.thermal.mustrunList.empty()) + for (const auto& cluster : area.thermal.mustrunList) { - auto end = area.thermal.mustrunList.end(); - for (auto i = area.thermal.mustrunList.begin(); i != end; ++i) + const auto& availableProduction = cluster->series.getColumn(year); + if (inAdequacy && cluster->mustrunOrigin) { - auto& cluster = *(i->second); - const auto& availableProduction = cluster.series.getColumn(year); - if (inAdequacy && cluster.mustrunOrigin) + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) { - for (uint h = 0; h != cluster.series.timeSeries.height; ++h) - { - mrs[h] += availableProduction[h]; - adq[h] += availableProduction[h]; - } - } - else - { - for (uint h = 0; h != cluster.series.timeSeries.height; ++h) - mrs[h] += availableProduction[h]; + mrs[h] += availableProduction[h]; + adq[h] += availableProduction[h]; } } + else + { + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) + mrs[h] += availableProduction[h]; + } } if (inAdequacy) { - auto end = area.thermal.list.end(); - for (auto i = area.thermal.list.begin(); i != end; ++i) + for (const auto& cluster : area.thermal.mustrunList) { - auto& cluster = *(i->second); - if (!cluster.mustrunOrigin) + if (!cluster->mustrunOrigin) continue; - const auto& availableProduction = cluster.series.getColumn(year); - for (uint h = 0; h != cluster.series.timeSeries.height; ++h) + const auto& availableProduction = cluster->series.getColumn(year); + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) adq[h] += availableProduction[h]; } } diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 1c73276c1e..230cb39ec1 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -285,7 +285,7 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study, for (uint clusterIndex = 0; clusterIndex != area.thermal.list.size(); ++clusterIndex) { - auto& cluster = *(area.thermal.list.byIndex[clusterIndex]); + auto& cluster = *(area.thermal.list[clusterIndex]); pbPalier.NumeroDuPalierDansLEnsembleDesPaliersThermiques[clusterIndex] = NombrePaliers + clusterIndex; pbPalier.TailleUnitaireDUnGroupeDuPalierThermique[clusterIndex] diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 82fb8a3273..30cc4b32dc 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -100,7 +100,7 @@ static bool GenerateDeratedMode(Study& study) cluster.series.timeseriesNumbers.zero(); } - for (const auto& [name, cluster] : area.renewable.list) + for (const auto& cluster : area.renewable.list) cluster->series.timeseriesNumbers.zero(); }); @@ -226,7 +226,7 @@ class renewClustersAreaNumberOfTSretriever : public areaNumberOfTSretriever std::vector getAreaTimeSeriesNumber(const Area& area) { std::vector to_return; - for (const auto& [name, cluster] : area.renewable.list) + for (const auto& cluster : area.renewable.list) { to_return.push_back(cluster->series.timeSeries.width); } @@ -443,7 +443,7 @@ bool checkInterModalConsistencyForArea(Area& area, indexTS = ts_to_tsIndex.at(timeSeriesRenewable); if (isTSintermodal[indexTS]) { - for (const auto& [name, cluster] : area.renewable.list) + for (const auto& cluster : area.renewable.list) { uint nbTimeSeries = cluster->series.timeSeries.width; listNumberTsOverArea.push_back(nbTimeSeries); @@ -555,10 +555,8 @@ void storeTSnumbersForIntraModal(const array& intramo if (isTSintramodal[indexTS]) { - auto end_rn_clusters = area.renewable.list.cluster.end(); - for (auto j = area.renewable.list.cluster.begin(); j != end_rn_clusters; ++j) + for (auto& cluster : area.renewable.list) { - RenewableClusterList::SharedPtr cluster = j->second; if (cluster->enabled) cluster->series.timeseriesNumbers[0][year] = intramodal_draws[indexTS]; } @@ -667,10 +665,8 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i // -------------------------- indexTS = ts_to_tsIndex.at(timeSeriesRenewable); - auto end_rn_clusters = area.renewable.list.cluster.end(); - for (auto j = area.renewable.list.cluster.begin(); j != end_rn_clusters; ++j) + for (auto& cluster : area.renewable.list) { - RenewableClusterList::SharedPtr cluster = j->second; if (not cluster->enabled) study.runtime->random[seedTimeseriesNumbers].next(); else @@ -747,7 +743,7 @@ Matrix* getFirstTSnumberInterModalMatrixFoundInArea( tsNumbersMtx = &(area.thermal.clusters[0]->series.timeseriesNumbers); else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)] && area.renewable.list.size() > 0) - tsNumbersMtx = &(area.renewable.list.byIndex[0]->series.timeseriesNumbers); + tsNumbersMtx = &(area.renewable.list[0]->series.timeseriesNumbers); } assert(tsNumbersMtx); @@ -792,7 +788,7 @@ void applyMatrixDrawsToInterModalModesInArea(Matrix* tsNumbersMtx, } if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)]) { - for (auto& [name, cluster] : area.renewable.list) + for (const auto& cluster : area.renewable.list) { assert(year < cluster->series.timeseriesNumbers.height); cluster->series.timeseriesNumbers[0][year] = draw; @@ -841,7 +837,7 @@ static void fixTSNumbersWhenWidthIsOne(Study& study) }); // Renewables - for (const auto& [name, cluster] : area.renewable.list) + for (const auto& cluster : area.renewable.list) fixTSNumbersSingleAreaSingleMode(cluster->series.timeseriesNumbers, cluster->series.timeSeries.width, years); diff --git a/src/solver/variable/economy/avail-dispatchable-generation.h b/src/solver/variable/economy/avail-dispatchable-generation.h index 80e3356055..9cea0fb713 100644 --- a/src/solver/variable/economy/avail-dispatchable-generation.h +++ b/src/solver/variable/economy/avail-dispatchable-generation.h @@ -194,7 +194,7 @@ class AvailableDispatchGen void addThermalClusterList(Data::ThermalClusterList& list, unsigned int year, unsigned int numSpace) { - for (auto& [name, cluster] : list) + for (const auto& cluster : list) { const auto& availableProduction = cluster->series.getColumn(year); for (unsigned int hour = 0; hour != cluster->series.timeSeries.height; ++hour) diff --git a/src/solver/variable/economy/productionByRenewablePlant.h b/src/solver/variable/economy/productionByRenewablePlant.h index 26e0cbc0b6..e1b08a189f 100644 --- a/src/solver/variable/economy/productionByRenewablePlant.h +++ b/src/solver/variable/economy/productionByRenewablePlant.h @@ -277,7 +277,7 @@ class ProductionByRenewablePlant : public Variable::IVariablerenewable.list) + for (const auto& renewableCluster : state.area->renewable.list) { double renewableClusterProduction = renewableCluster->valueAtTimeStep(state.year, state.hourInTheYear); @@ -327,7 +327,7 @@ class ProductionByRenewablePlant : public Variable::IVariablename(); + results.variableCaption = renewable.list[i]->name(); results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][i].template buildAnnualSurveyReport( results, fileLevel, precision); diff --git a/src/solver/variable/economy/renewableGeneration.h b/src/solver/variable/economy/renewableGeneration.h index 5634338ec8..5035cb59f4 100644 --- a/src/solver/variable/economy/renewableGeneration.h +++ b/src/solver/variable/economy/renewableGeneration.h @@ -267,7 +267,7 @@ class RenewableGeneration void hourForEachArea(State& state, unsigned int numSpace) { - for (const auto& [name, renewableCluster] : state.area->renewable.list) + for (const auto& renewableCluster : state.area->renewable.list) { double renewableClusterProduction = renewableCluster->valueAtTimeStep(state.year, state.hourInTheYear); diff --git a/src/solver/variable/info.h b/src/solver/variable/info.h index 49b3718cf0..4cb3ecbb5a 100644 --- a/src/solver/variable/info.h +++ b/src/solver/variable/info.h @@ -407,7 +407,7 @@ struct VariableAccessor if (renewable_details) { auto& renewable = results.data.area->renewable; - results.variableCaption = renewable.list.byIndex[idx]->name(); + results.variableCaption = renewable.list[idx]->name(); return true; } if (st_storage_details) diff --git a/src/solver/variable/surveyresults/reportbuilder.hxx b/src/solver/variable/surveyresults/reportbuilder.hxx index 85f49dd3a5..28e9ef6abe 100644 --- a/src/solver/variable/surveyresults/reportbuilder.hxx +++ b/src/solver/variable/surveyresults/reportbuilder.hxx @@ -324,17 +324,15 @@ private: if (VariablesStatsByDataLevel::count) { auto& area = *results.data.area; - auto end = area.thermal.list.end(); - for (auto i = area.thermal.list.begin(); i != end; ++i) + for (const auto& cluster : area.thermal.list) { - auto& cluster = *(i->second); - results.data.thermalCluster = &cluster; + results.data.thermalCluster = cluster.get(); - logs.info() << "Exporting results : " << area.name << " :: " << cluster.name(); + logs.info() << "Exporting results : " << area.name << " :: " << cluster->name(); // The new output results.data.output.clear(); results.data.output << results.data.originalOutput << SEP << "areas" << SEP - << area.id << SEP << "thermal" << SEP << cluster.id(); + << area.id << SEP << "thermal" << SEP << cluster->id(); SurveyReportBuilderFile::Run(list, results, numSpace); } diff --git a/src/tools/yby-aggregator/job.cpp b/src/tools/yby-aggregator/job.cpp index 95b75dd7f3..6e4b405ea2 100644 --- a/src/tools/yby-aggregator/job.cpp +++ b/src/tools/yby-aggregator/job.cpp @@ -378,7 +378,7 @@ bool JobFileReader::prepareJumpTable() const DataFile::ShortString& timeLevel = datafile->timeLevel; for (uint i = 0; i != list.size(); ++i) { - if (timeLevel == list[i]) + if (timeLevel.equals(list[i])) { startIndex = i + 1; break; diff --git a/src/ui/action/handler/antares-study/area/create.cpp b/src/ui/action/handler/antares-study/area/create.cpp index 0348c2d253..e159af140d 100644 --- a/src/ui/action/handler/antares-study/area/create.cpp +++ b/src/ui/action/handler/antares-study/area/create.cpp @@ -293,11 +293,9 @@ void Create::createActionsForAStandardAreaCopy(Context& ctx, bool copyPosition) auto* root = new RootNodePlant(pOriginalAreaName); // browsing each thermal cluster - auto end = area->thermal.list.end(); - for (auto i = area->thermal.list.begin(); i != end; ++i) - { - *root += StandardActionsToCopyThermalCluster(pOriginalAreaName, i->second->name()); - } + for (auto& c : area->thermal.list) + *root += StandardActionsToCopyThermalCluster(pOriginalAreaName, c->name()); + *this += root; } } diff --git a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp index 8ec1b3a2d7..bfac4c1a32 100644 --- a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp +++ b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp @@ -182,7 +182,6 @@ bool Create::performWL(Context& ctx) ctx.cluster->setName(pFuturPlantName); ctx.cluster->reset(); (ctx.area)->thermal.list.add(std::shared_ptr(ctx.cluster)); - (ctx.area)->thermal.list.rebuildIndex(); (ctx.area)->thermal.prepareAreaWideIndexes(); } else diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp index 59ff293c0c..db746f9632 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp @@ -51,7 +51,7 @@ RenewableClusterSummarySingleArea::~RenewableClusterSummarySingleArea() wxString RenewableClusterSummarySingleArea::rowCaption(int rowIndx) const { if (pArea) - return wxStringFromUTF8(pArea->renewable.list.byIndex[rowIndx]->name()); + return wxStringFromUTF8(pArea->renewable.list[rowIndx]->name()); return wxEmptyString; } @@ -71,7 +71,7 @@ wxString RenewableClusterSummarySingleArea::columnCaption(int colIndx) const wxString RenewableClusterSummarySingleArea::cellValue(int x, int y) const { Data::RenewableCluster* cluster = (pArea and (uint) y < pArea->renewable.list.size()) - ? pArea->renewable.list.byIndex[y] + ? pArea->renewable.list[y].get() : nullptr; switch (x) { @@ -90,7 +90,7 @@ wxString RenewableClusterSummarySingleArea::cellValue(int x, int y) const double RenewableClusterSummarySingleArea::cellNumericValue(int x, int y) const { Data::RenewableCluster* cluster = (pArea and (uint) y < pArea->renewable.list.size()) - ? pArea->renewable.list.byIndex[y] + ? pArea->renewable.list[y].get() : nullptr; // gp : do we wish to have the line empty if cluster disabled // if (!cluster->enabled) @@ -112,7 +112,7 @@ double RenewableClusterSummarySingleArea::cellNumericValue(int x, int y) const bool RenewableClusterSummarySingleArea::cellValue(int x, int y, const String& v) { auto* cluster = (pArea and (uint) y < pArea->renewable.list.size()) - ? pArea->renewable.list.byIndex[y] + ? pArea->renewable.list[y].get() : nullptr; if (cluster) diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp index c49cf595a0..ce87ecace2 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp @@ -51,7 +51,7 @@ ThermalClusterSummarySingleArea::~ThermalClusterSummarySingleArea() wxString ThermalClusterSummarySingleArea::rowCaption(int rowIndx) const { if (pArea) - return wxStringFromUTF8(pArea->thermal.list.byIndex[rowIndx]->name()); + return wxStringFromUTF8(pArea->thermal.list[rowIndx]->name()); return wxEmptyString; } @@ -82,7 +82,7 @@ wxString ThermalClusterSummarySingleArea::columnCaption(int colIndx) const wxString ThermalClusterSummarySingleArea::cellValue(int x, int y) const { Data::ThermalCluster* cluster = (pArea and (uint) y < pArea->thermal.list.size()) - ? pArea->thermal.list.byIndex[y] + ? pArea->thermal.list[y].get() : nullptr; if (!cluster->enabled) return wxEmptyString; @@ -125,7 +125,7 @@ wxString ThermalClusterSummarySingleArea::cellValue(int x, int y) const double ThermalClusterSummarySingleArea::cellNumericValue(int x, int y) const { Data::ThermalCluster* cluster = (pArea and (uint) y < pArea->thermal.list.size()) - ? pArea->thermal.list.byIndex[y] + ? pArea->thermal.list[y].get() : nullptr; if (!cluster->enabled) return 0.; @@ -168,7 +168,7 @@ double ThermalClusterSummarySingleArea::cellNumericValue(int x, int y) const bool ThermalClusterSummarySingleArea::cellValue(int x, int y, const String& v) { auto* cluster = (pArea and (uint) y < pArea->thermal.list.size()) - ? pArea->thermal.list.byIndex[y] + ? pArea->thermal.list[y].get() : nullptr; if (cluster) diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp index c522544756..f2af7d9660 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp @@ -54,7 +54,7 @@ wxString renewableScBuilderRenderer::rowCaption(int rowIndx) const && (uint)rowIndx < selectedArea()->renewable.list.size()) { return wxString() << wxT( - " ") << wxStringFromUTF8(selectedArea()->renewable.list.byIndex[rowIndx]->name()) + " ") << wxStringFromUTF8(selectedArea()->renewable.list[rowIndx]->name()) << wxT(" "); } return wxEmptyString; @@ -70,7 +70,7 @@ bool renewableScBuilderRenderer::cellValue(int x, int y, const String& value) assert((uint)x < pRules->renewable[selectedArea()->index].height()); uint val = fromStringToTSnumber(value); pRules->renewable[selectedArea()->index].setTSnumber( - selectedArea()->renewable.list.byIndex[y], x, val); + selectedArea()->renewable.list[y].get(), x, val); return true; } return false; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp index 7449c3c9b0..c8e333c1c8 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp @@ -54,7 +54,7 @@ wxString thermalScBuilderRenderer::rowCaption(int rowIndx) const && (uint)rowIndx < selectedArea()->thermal.list.size()) { return wxString() << wxT(" ") - << wxStringFromUTF8(selectedArea()->thermal.list.byIndex[rowIndx]->name()) + << wxStringFromUTF8(selectedArea()->thermal.list[rowIndx]->name()) << wxT(" "); } return wxEmptyString; @@ -69,7 +69,7 @@ bool thermalScBuilderRenderer::cellValue(int x, int y, const String& value) assert((uint)y < pRules->thermal[selectedArea()->index].width()); assert((uint)x < pRules->thermal[selectedArea()->index].height()); uint val = fromStringToTSnumber(value); - pRules->thermal[selectedArea()->index].setTSnumber(selectedArea()->thermal.list.byIndex[y], x, val); + pRules->thermal[selectedArea()->index].setTSnumber(selectedArea()->thermal.list[y].get(), x, val); return true; } return false; diff --git a/src/ui/simulator/toolbox/components/htmllistbox/datasource/renewable-cluster-order.cpp b/src/ui/simulator/toolbox/components/htmllistbox/datasource/renewable-cluster-order.cpp index a79334cc6c..66681a7383 100644 --- a/src/ui/simulator/toolbox/components/htmllistbox/datasource/renewable-cluster-order.cpp +++ b/src/ui/simulator/toolbox/components/htmllistbox/datasource/renewable-cluster-order.cpp @@ -56,7 +56,7 @@ void GetRenewableClusterMap(Data::Area* area, RenewableClusterMap& l, const wxSt const Data::RenewableClusterList::iterator end = area->renewable.list.end(); for (Data::RenewableClusterList::iterator i = area->renewable.list.begin(); i != end; ++i) { - Data::RenewableCluster* cluster = i->second.get(); + Data::RenewableCluster* cluster = (*i).get(); if (search.empty()) { diff --git a/src/ui/simulator/toolbox/components/htmllistbox/datasource/thermal-cluster-order.cpp b/src/ui/simulator/toolbox/components/htmllistbox/datasource/thermal-cluster-order.cpp index 029c0b8a2f..cd8a2a8244 100644 --- a/src/ui/simulator/toolbox/components/htmllistbox/datasource/thermal-cluster-order.cpp +++ b/src/ui/simulator/toolbox/components/htmllistbox/datasource/thermal-cluster-order.cpp @@ -56,7 +56,7 @@ void GetThermalClusterMap(Data::Area* area, ThermalClusterMap& l, const wxString const Data::ThermalClusterList::iterator end = area->thermal.list.end(); for (Data::ThermalClusterList::iterator i = area->thermal.list.begin(); i != end; ++i) { - Data::ThermalCluster* cluster = i->second.get(); + Data::ThermalCluster* cluster = (*i).get(); if (search.empty()) { diff --git a/src/ui/simulator/toolbox/components/map/manager.cpp b/src/ui/simulator/toolbox/components/map/manager.cpp index 7193fbef99..d6030be21c 100644 --- a/src/ui/simulator/toolbox/components/map/manager.cpp +++ b/src/ui/simulator/toolbox/components/map/manager.cpp @@ -768,7 +768,7 @@ void Manager::selectFromBoundingBox(const wxPoint& a, const wxPoint& b, const si for (Data::ThermalClusterList::iterator t = area->thermal.list.begin(); t != tend; ++t) - clusterlist.push_back(t->second.get()); + clusterlist.push_back((*t).get()); } continue; } diff --git a/src/ui/simulator/toolbox/input/renewable-cluster.cpp b/src/ui/simulator/toolbox/input/renewable-cluster.cpp index 043ff85e3a..08bbb8f748 100644 --- a/src/ui/simulator/toolbox/input/renewable-cluster.cpp +++ b/src/ui/simulator/toolbox/input/renewable-cluster.cpp @@ -291,7 +291,6 @@ void RenewableCluster::internalDeletePlant(void*) Refresh(); MarkTheStudyAsModified(); updateInnerValues(); - pArea->renewable.list.rebuildIndex(); pArea->renewable.prepareAreaWideIndexes(); study->uiinfo->reload(); } @@ -389,7 +388,6 @@ void RenewableCluster::internalAddPlant(void*) cluster->setName(sFl); cluster->reset(); pArea->renewable.list.add(cluster); - pArea->renewable.list.rebuildIndex(); pArea->renewable.prepareAreaWideIndexes(); // Update the list @@ -467,7 +465,6 @@ void RenewableCluster::internalClonePlant(void*) cluster->copyFrom(selectedPlant); pArea->renewable.list.add(cluster); - pArea->renewable.list.rebuildIndex(); pArea->renewable.prepareAreaWideIndexes(); // Update the list diff --git a/src/ui/simulator/toolbox/input/thermal-cluster.cpp b/src/ui/simulator/toolbox/input/thermal-cluster.cpp index 0a40b9ee29..bc31719088 100644 --- a/src/ui/simulator/toolbox/input/thermal-cluster.cpp +++ b/src/ui/simulator/toolbox/input/thermal-cluster.cpp @@ -317,7 +317,6 @@ void ThermalCluster::internalDeletePlant(void*) Refresh(); MarkTheStudyAsModified(); updateInnerValues(); - pArea->thermal.list.rebuildIndex(); pArea->thermal.prepareAreaWideIndexes(); study->uiinfo->reload(); @@ -448,7 +447,6 @@ void ThermalCluster::internalAddPlant(void*) cluster->setName(sFl); cluster->reset(); pArea->thermal.list.add(cluster); - pArea->thermal.list.rebuildIndex(); pArea->thermal.prepareAreaWideIndexes(); // Update the list @@ -527,7 +525,6 @@ void ThermalCluster::internalClonePlant(void*) cluster->copyFrom(selectedPlant); pArea->thermal.list.add(cluster); - pArea->thermal.list.rebuildIndex(); pArea->thermal.prepareAreaWideIndexes(); // Update the list diff --git a/src/ui/simulator/windows/inspector/frame.cpp b/src/ui/simulator/windows/inspector/frame.cpp index d03fdfce09..7ec3c35df7 100644 --- a/src/ui/simulator/windows/inspector/frame.cpp +++ b/src/ui/simulator/windows/inspector/frame.cpp @@ -178,9 +178,8 @@ void Frame::onSelectAllPlants(wxCommandEvent&) for (auto i = data->areas.begin(); i != areaEnd; ++i) { Data::Area& area = *(*i); - auto end = area.thermal.list.end(); - for (auto i = area.thermal.list.begin(); i != end; ++i) - data->ThClusters.insert(i->second.get()); + for (auto& c : area.thermal.list) + data->ThClusters.insert(c.get()); } data->areas.clear(); data->links.clear(); @@ -204,26 +203,6 @@ void Frame::onSelectPlant(wxCommandEvent& evt) } } -// gp : never used - to be removed -void Frame::onSelectAllPlantsFromArea(wxCommandEvent& evt) -{ - InspectorData::Ptr data = gData; - if (!(!data) and gInspector and evt.GetEventObject()) - { - Data::Area* area = (Data::Area*)mapIDPointer[evt.GetId()]; - if (!area) - return; - data->ThClusters.clear(); - auto end = area->thermal.list.end(); - for (auto i = area->thermal.list.begin(); i != end; ++i) - data->ThClusters.insert(i->second.get()); - data->areas.clear(); - data->links.clear(); - data->empty = data->ThClusters.empty(); - gInspector->delayApplyGlobalSelection(); - } -} - Frame::Frame(wxWindow* parent, bool allowAnyObject) : Antares::Component::Panel(parent), pNotes(nullptr), diff --git a/src/ui/simulator/windows/inspector/frame.h b/src/ui/simulator/windows/inspector/frame.h index 9905b0c29b..d0fb0dc358 100644 --- a/src/ui/simulator/windows/inspector/frame.h +++ b/src/ui/simulator/windows/inspector/frame.h @@ -100,7 +100,6 @@ class Frame final : public Antares::Component::Panel, public Yuni::IEventObserve void onSelectAllPlants(wxCommandEvent& evt); void onSelectPlant(wxCommandEvent& evt); - void onSelectAllPlantsFromArea(wxCommandEvent& evt); void clearAssociatinsBetweenIDAndPtr() { diff --git a/src/ui/simulator/windows/inspector/inspector.cpp b/src/ui/simulator/windows/inspector/inspector.cpp index d895d26f1c..500ec48711 100644 --- a/src/ui/simulator/windows/inspector/inspector.cpp +++ b/src/ui/simulator/windows/inspector/inspector.cpp @@ -704,7 +704,7 @@ bool isConstraintSelected(const Yuni::String& constraintName) for (auto i = gData->constraints.begin(); i != end; ++i) { auto constraint = *i; - if (constraint->name() == constraintName) + if (constraint->name().equals(constraintName)) { return true; } diff --git a/src/ui/simulator/windows/output/spotlight-provider.cpp b/src/ui/simulator/windows/output/spotlight-provider.cpp index 0eb1cc5528..8f4877bf10 100644 --- a/src/ui/simulator/windows/output/spotlight-provider.cpp +++ b/src/ui/simulator/windows/output/spotlight-provider.cpp @@ -421,8 +421,8 @@ void SpotlightProviderGlobalSelection::search(Spotlight::IItem::Vector& out, auto aEnd = study.areas.end(); for (auto itArea = study.areas.begin(); itArea != aEnd; ++itArea) { - if (arealink->id == itArea->first) // this area is in the study (it is visible - // at least on layer 0) + if (arealink->id.equals(itArea->first)) // this area is in the study (it is visible + // at least on layer 0) { foundInALayer = true; break; @@ -482,7 +482,7 @@ void SpotlightProviderGlobalSelection::search(Spotlight::IItem::Vector& out, auto aEnd = study.areas.end(); for (auto itArea = study.areas.begin(); itArea != aEnd; ++itArea) { - if (arealink->id == itArea->first + if (arealink->id.equals(itArea->first) && itArea->second->isVisibleOnLayer( layerID)) // this area is in the study (it is visible at least on layer 0) { From ee1e5f5e9b1424538e040e25bdb778ae664cb9d5 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 22 Dec 2023 17:22:24 +0100 Subject: [PATCH 09/88] Clean thermal lists : simplifying added(...) function (common list class) and consequences --- .../antares/study/parts/common/cluster_list.cpp | 10 ++-------- .../antares/study/parts/common/cluster_list.h | 2 +- .../study/parts/renewable/cluster_list.cpp | 8 +------- .../antares/study/parts/thermal/cluster_list.cpp | 12 +++--------- .../antares/study/parts/thermal/container.cpp | 15 ++++----------- src/tests/end-to-end/utils/utils.cpp | 4 ++-- 6 files changed, 13 insertions(+), 38 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index bc5f8e5aa5..de4896d6bd 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -114,18 +114,12 @@ void ClusterList::rebuildIndex() } template -typename ClusterList::SharedPtr ClusterList::add( - const ClusterList::SharedPtr newcluster) +void ClusterList::add(const SharedPtr newcluster) { - if (!newcluster) - return nullptr; - if (exists(newcluster->id())) - return newcluster; - + return; clusters.push_back(newcluster); rebuildIndex(); - return newcluster; } template diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 9f3899aa8b..d92c77c36a 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -51,7 +51,7 @@ class ClusterList ** \param t The cluster to add ** \return True if the cluster has been added, false otherwise */ - SharedPtr add(const SharedPtr clusters); + void add(const SharedPtr clusters); /*! ** \brief Try to find a cluster from its id (const) diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index e23f84fe2a..5e202470dc 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -160,13 +160,7 @@ bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) cluster->integrityCheck(); // adding the renewable cluster - if (not add(cluster)) - { - // This error should never happen - logs.error() << "Impossible to add the renewable cluster '" << cluster->name() - << "'"; - continue; - } + add(cluster); } } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 3867bfeca4..07d68055e9 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -136,16 +136,10 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A cluster->integrityCheck(); // adding the thermal cluster - auto added = add(cluster); - if (not added) - { - // This error should never happen - logs.error() << "Impossible to add the thermal cluster '" << cluster->name() - << "'"; - continue; - } + add(cluster); + // keeping track of the cluster - mapping[cluster->id()] = added; + mapping[cluster->id()] = cluster; } return ret; diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index a88bdf1e72..4b4fc84215 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -106,17 +106,10 @@ uint PartThermal::prepareClustersInMustRunMode() if (!cluster->enabled) continue; // ...and attaching it into the second list - if (!mustrunList.add(cluster)) - { - logs.error() << "Impossible to prepare the thermal cluster in 'must-run' mode: " - << cluster->parentArea->name << "::" << cluster->name(); - } - else - { - ++count; - logs.info() << "enabling 'must-run' mode for the cluster " - << cluster->parentArea->name << "::" << cluster->name(); - } + mustrunList.add(cluster); + ++count; + logs.info() << "enabling 'must-run' mode for the cluster " + << cluster->parentArea->name << "::" << cluster->name(); // the iterator has been invalidated, loop again mustContinue = true; diff --git a/src/tests/end-to-end/utils/utils.cpp b/src/tests/end-to-end/utils/utils.cpp index 70920b7ca3..c760e4f511 100644 --- a/src/tests/end-to-end/utils/utils.cpp +++ b/src/tests/end-to-end/utils/utils.cpp @@ -23,9 +23,9 @@ std::shared_ptr addClusterToArea(Area* area, const std::string& cluster->setName(clusterName); cluster->reset(); - auto added = area->thermal.list.add(cluster); + area->thermal.list.add(cluster); - area->thermal.list.mapping[cluster->id()] = added; + area->thermal.list.mapping[cluster->id()] = cluster; area->thermal.prepareAreaWideIndexes(); return cluster; From 7c7b6eafcf1e790c4ba163c81638865f1b1afb06 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 22 Dec 2023 18:19:01 +0100 Subject: [PATCH 10/88] Clean thermal lists : removing use of mapping in a unit test --- .../thermal-price-definition.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp b/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp index cbd8895d80..969808b02b 100644 --- a/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp +++ b/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp @@ -150,7 +150,7 @@ BOOST_AUTO_TEST_SUITE(s) BOOST_FIXTURE_TEST_CASE(ThermalClusterList_loadFromFolder_basic, FixtureFull) { clusterList.loadFromFolder(*study, folder, area); - auto cluster = clusterList.mapping["some cluster"]; + auto cluster = clusterList.find("some cluster"); BOOST_CHECK(cluster->startupCost == 70000.0); BOOST_CHECK(cluster->costgeneration == useCostTimeseries); @@ -161,7 +161,7 @@ BOOST_FIXTURE_TEST_CASE(ThermalClusterList_loadFromFolder_basic, FixtureFull) BOOST_FIXTURE_TEST_CASE(checkCo2_checkCO2CostColumnNumber_OK, FixtureFull) { area->thermal.list.loadFromFolder(*study, folder, area); - auto cluster = area->thermal.list.mapping["some cluster"]; + auto cluster = area->thermal.list.find("some cluster"); cluster->series.timeSeries.reset(3, 8760); @@ -176,7 +176,7 @@ BOOST_FIXTURE_TEST_CASE(checkCo2_checkCO2CostColumnNumber_OK, FixtureFull) BOOST_FIXTURE_TEST_CASE(checkCo2_checkCO2CostColumnNumber_KO, FixtureFull) { area->thermal.list.loadFromFolder(*study, folder, area); - auto cluster = area->thermal.list.mapping["some cluster"]; + auto cluster = area->thermal.list.find("some cluster"); cluster->series.timeSeries.reset(3, 8760); @@ -192,7 +192,7 @@ BOOST_FIXTURE_TEST_CASE(checkCo2_checkCO2CostColumnNumber_KO, FixtureFull) BOOST_FIXTURE_TEST_CASE(checkFuelAndCo2_checkColumnNumber_OK, FixtureFull) { area->thermal.list.loadFromFolder(*study, folder, area); - auto cluster = area->thermal.list.mapping["some cluster"]; + auto cluster = area->thermal.list.find("some cluster"); cluster->series.timeSeries.reset(3, 8760); @@ -208,7 +208,7 @@ BOOST_FIXTURE_TEST_CASE(checkFuelAndCo2_checkColumnNumber_OK, FixtureFull) BOOST_FIXTURE_TEST_CASE(ThermalCluster_costGenManualCalculationOfMarketBidAndMarginalCostPerHour, FixtureFull) { clusterList.loadFromFolder(*study, folder, area); - auto cluster = clusterList.mapping["some cluster"]; + auto cluster = clusterList.find("some cluster"); cluster->costgeneration = Data::setManually; cluster->ComputeCostTimeSeries(); @@ -223,11 +223,11 @@ BOOST_FIXTURE_TEST_CASE(ThermalCluster_costGenTimeSeriesCalculationOfMarketBidAn TimeSeriesFile co2("CO2Cost.txt", 8760); clusterList.loadFromFolder(*study, folder, area); - auto cluster = clusterList.mapping["some cluster"]; + auto cluster = clusterList.find("some cluster"); cluster->modulation.reset(1, 8760); cluster->ecoInput.loadFromFolder(*study, folder); - fillThermalEconomicTimeSeries(cluster.get()); + fillThermalEconomicTimeSeries(cluster); cluster->ComputeCostTimeSeries(); @@ -238,7 +238,7 @@ BOOST_FIXTURE_TEST_CASE(ThermalCluster_costGenTimeSeriesCalculationOfMarketBidAn BOOST_FIXTURE_TEST_CASE(computeMarketBidCost, FixtureFull) { clusterList.loadFromFolder(*study, folder, area); - auto cluster = clusterList.mapping["some cluster"]; + auto cluster = clusterList.find("some cluster"); BOOST_CHECK_CLOSE(cluster->computeMarketBidCost(1, 2, 1), 24.12, 0.001); } From 8e3ba46bb9ac331c6a51a810594d20ba3a110533 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 27 Dec 2023 17:45:13 +0100 Subject: [PATCH 11/88] Clean thermal lists : update PartThermal::clusters from GUI is useless, we remove that update --- src/ui/simulator/toolbox/input/thermal-cluster.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ui/simulator/toolbox/input/thermal-cluster.cpp b/src/ui/simulator/toolbox/input/thermal-cluster.cpp index bc31719088..9b4754de86 100644 --- a/src/ui/simulator/toolbox/input/thermal-cluster.cpp +++ b/src/ui/simulator/toolbox/input/thermal-cluster.cpp @@ -317,7 +317,6 @@ void ThermalCluster::internalDeletePlant(void*) Refresh(); MarkTheStudyAsModified(); updateInnerValues(); - pArea->thermal.prepareAreaWideIndexes(); study->uiinfo->reload(); // delete associated constraints @@ -447,7 +446,6 @@ void ThermalCluster::internalAddPlant(void*) cluster->setName(sFl); cluster->reset(); pArea->thermal.list.add(cluster); - pArea->thermal.prepareAreaWideIndexes(); // Update the list update(); @@ -525,7 +523,6 @@ void ThermalCluster::internalClonePlant(void*) cluster->copyFrom(selectedPlant); pArea->thermal.list.add(cluster); - pArea->thermal.prepareAreaWideIndexes(); // Update the list update(); From e9cb22aa9b8c274fd3264947032b7b1f895f0667 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 28 Dec 2023 16:14:15 +0100 Subject: [PATCH 12/88] Clean thermal lists : adding a new vector containing all thermal clusters but used nowhere --- .../study/parts/thermal/cluster_list.cpp | 17 ++++++++++++++++- .../antares/study/parts/thermal/cluster_list.h | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 07d68055e9..97b8991888 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -42,6 +42,20 @@ static bool ThermalClusterLoadFromSection(const AnyString& filename, ThermalCluster& cluster, const IniFile::Section& section); +void ThermalClusterList::addToCompleteList(std::shared_ptr cluster) +{ + if (exists(cluster->id())) + return; + allClusters.push_back(cluster); +} + +void ThermalClusterList::sortCompleteList() +{ + std::sort(allClusters.begin(), allClusters.end(), [](const auto& a, const auto& b) { + return a->id() < b->id(); + }); +} + bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, Area* area) { assert(area and "A parent area is required"); @@ -137,11 +151,12 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A // adding the thermal cluster add(cluster); + addToCompleteList(cluster); // keeping track of the cluster mapping[cluster->id()] = cluster; } - + sortCompleteList(); return ret; } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index b23164bfb0..a112919407 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -58,6 +58,10 @@ class ThermalClusterList : public ClusterList */ void enableMustrunForEveryone(); //@} + void addToCompleteList(std::shared_ptr cluster); + void sortCompleteList(); + + std::vector> allClusters; Map mapping; From a01b80389ddccd696c5da5bab4ef9ead6828f50a Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 28 Dec 2023 16:48:40 +0100 Subject: [PATCH 13/88] Clean thermal lists : using new cluster list for thermal noises generation --- src/libs/antares/study/parts/thermal/cluster_list.cpp | 7 ++++++- src/libs/antares/study/parts/thermal/cluster_list.h | 1 + src/solver/simulation/common-eco-adq.cpp | 4 +--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 97b8991888..61ace9ba7a 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -42,9 +42,14 @@ static bool ThermalClusterLoadFromSection(const AnyString& filename, ThermalCluster& cluster, const IniFile::Section& section); +bool ThermalClusterList::alreadyInAllClusters(std::string clusterId) +{ + return std::ranges::any_of(allClusters, [&clusterId](const auto& c) { return c->id() == clusterId; }); +} + void ThermalClusterList::addToCompleteList(std::shared_ptr cluster) { - if (exists(cluster->id())) + if (alreadyInAllClusters(cluster->id())) return; allClusters.push_back(cluster); } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index a112919407..f867b272e3 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -59,6 +59,7 @@ class ThermalClusterList : public ClusterList void enableMustrunForEveryone(); //@} void addToCompleteList(std::shared_ptr cluster); + bool alreadyInAllClusters(std::string clusterName); void sortCompleteList(); std::vector> allClusters; diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index 052469ffe6..952c6de8b2 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -284,10 +284,8 @@ void PrepareRandomNumbers(Data::Study& study, //----------------------------- // Thermal noises //----------------------------- - auto end = area.thermal.list.mapping.end(); - for (auto it = area.thermal.list.mapping.begin(); it != end; ++it) + for (auto cluster : area.thermal.list.allClusters) { - auto cluster = it->second; if (!cluster->enabled) continue; uint clusterIndex = cluster->areaWideIndex; From 03307c406c073de9fdb651959c25c84e1b161f01 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 28 Dec 2023 17:12:16 +0100 Subject: [PATCH 14/88] Clean thermal lists : replace use of mapping with the new vector --- src/solver/simulation/solver.hxx | 7 +++---- src/solver/simulation/timeseries-numbers.cpp | 8 ++------ src/solver/ts-generator/thermal.cpp | 9 +++------ src/tests/end-to-end/utils/utils.cpp | 3 +-- .../scenario-builder/test-sc-builder-file-read-line.cpp | 2 +- .../study/scenario-builder/test-sc-builder-file-save.cpp | 2 +- src/tests/src/solver/simulation/tests-ts-numbers.cpp | 2 +- 7 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/solver/simulation/solver.hxx b/src/solver/simulation/solver.hxx index ccca27ec51..cd30e24e29 100644 --- a/src/solver/simulation/solver.hxx +++ b/src/solver/simulation/solver.hxx @@ -627,7 +627,7 @@ void ISimulation::allocateMemoryForRandomNumbers(randomNumbers& randomForP { // logs.info() << " area : " << a << " :"; auto& area = *(study.areas.byIndex[a]); - size_t nbClusters = area.thermal.list.mapping.size(); + size_t nbClusters = area.thermal.list.allClusters.size(); randomForParallelYears.pYears[y].pThermalNoisesByArea[a] = new double[nbClusters]; randomForParallelYears.pYears[y].pNbClustersByArea[a] = nbClusters; } @@ -691,10 +691,9 @@ void ISimulation::computeRandomNumbers(randomNumbers& randomForYears, // logs.info() << " area : " << a << " :"; auto& area = *(study.areas.byIndex[a]); - auto end = area.thermal.list.mapping.end(); - for (auto it = area.thermal.list.mapping.begin(); it != end; ++it) + for (auto cluster : area.thermal.list.allClusters) { - uint clusterIndex = it->second->areaWideIndex; + uint clusterIndex = cluster->areaWideIndex; double thermalNoise = runtime.random[Data::seedThermalCosts].next(); if (isPerformed) randomForYears.pYears[indexYear].pThermalNoisesByArea[a][clusterIndex] = thermalNoise; diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 30cc4b32dc..71fd20445b 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -539,10 +539,8 @@ void storeTSnumbersForIntraModal(const array& intramo if (isTSintramodal[indexTS]) { - auto end_th_clusters = area.thermal.list.mapping.end(); - for (auto i = area.thermal.list.mapping.begin(); i != end_th_clusters; ++i) + for (auto cluster : area.thermal.list.allClusters) { - ThermalClusterList::SharedPtr cluster = i->second; if (cluster->enabled) cluster->series.timeseriesNumbers[0][year] = intramodal_draws[indexTS]; } @@ -642,10 +640,8 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i // ------------- indexTS = ts_to_tsIndex.at(timeSeriesThermal); - auto end_th_clusters = area.thermal.list.mapping.end(); - for (auto i = area.thermal.list.mapping.begin(); i != end_th_clusters; ++i) + for (auto cluster : area.thermal.list.allClusters) { - ThermalClusterList::SharedPtr cluster = i->second; if (not cluster->enabled) study.runtime->random[seedTimeseriesNumbers].next(); else diff --git a/src/solver/ts-generator/thermal.cpp b/src/solver/ts-generator/thermal.cpp index e11d4a056c..deed83c951 100644 --- a/src/solver/ts-generator/thermal.cpp +++ b/src/solver/ts-generator/thermal.cpp @@ -625,14 +625,11 @@ bool GenerateThermalTimeSeries(Data::Study& study, generator->currentYear = year; study.areas.each([&](Data::Area& area) { - auto end = area.thermal.list.mapping.end(); - for (auto it = area.thermal.list.mapping.begin(); it != end; ++it) + for (auto cluster : area.thermal.list.allClusters) { - auto& cluster = *(it->second); - - if (cluster.doWeGenerateTS(globalThermalTSgeneration) && refreshTSonCurrentYear) + if (cluster->doWeGenerateTS(globalThermalTSgeneration) && refreshTSonCurrentYear) { - (*generator)(area, cluster); + (*generator)(area, *cluster); } ++progression; diff --git a/src/tests/end-to-end/utils/utils.cpp b/src/tests/end-to-end/utils/utils.cpp index c760e4f511..933787085a 100644 --- a/src/tests/end-to-end/utils/utils.cpp +++ b/src/tests/end-to-end/utils/utils.cpp @@ -24,8 +24,7 @@ std::shared_ptr addClusterToArea(Area* area, const std::string& cluster->reset(); area->thermal.list.add(cluster); - - area->thermal.list.mapping[cluster->id()] = cluster; + area->thermal.list.addToCompleteList(cluster); area->thermal.prepareAreaWideIndexes(); return cluster; diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index 36935b8e36..6e6f71e4bd 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -20,7 +20,7 @@ void addClusterToAreaList(Area* area, std::shared_ptr cluster) { area->thermal.clusters.push_back(cluster.get()); area->thermal.list.add(cluster); - area->thermal.list.mapping[cluster->id()] = cluster; + area->thermal.list.addToCompleteList(cluster); } void addClusterToAreaList(Area* area, std::shared_ptr cluster) diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index db422282dc..751b9d69cd 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -61,7 +61,7 @@ void addClusterToAreaList(Area* area, std::shared_ptr cluster) { area->thermal.clusters.push_back(cluster.get()); area->thermal.list.add(cluster); - area->thermal.list.mapping[cluster->id()] = cluster; + area->thermal.list.addToCompleteList(cluster); } void addClusterToAreaList(Area* area, std::shared_ptr cluster) diff --git a/src/tests/src/solver/simulation/tests-ts-numbers.cpp b/src/tests/src/solver/simulation/tests-ts-numbers.cpp index 34c2fa5c62..bc9e7db543 100644 --- a/src/tests/src/solver/simulation/tests-ts-numbers.cpp +++ b/src/tests/src/solver/simulation/tests-ts-numbers.cpp @@ -52,7 +52,7 @@ void addClusterToAreaList(Area* area, std::shared_ptr cluster) { area->thermal.clusters.push_back(cluster.get()); area->thermal.list.add(cluster); - area->thermal.list.mapping[cluster->id()] = cluster; + area->thermal.list.addToCompleteList(cluster); } template<> From 1cdcef0192d4c544737b2fb76641f8751021a561 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 28 Dec 2023 17:17:10 +0100 Subject: [PATCH 15/88] Clean thermal lists : remove mapping completely --- src/libs/antares/study/parts/thermal/cluster_list.cpp | 3 --- src/libs/antares/study/parts/thermal/cluster_list.h | 4 ---- 2 files changed, 7 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 61ace9ba7a..611f6a62ae 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -157,9 +157,6 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A // adding the thermal cluster add(cluster); addToCompleteList(cluster); - - // keeping track of the cluster - mapping[cluster->id()] = cluster; } sortCompleteList(); return ret; diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index f867b272e3..bcd1f0f5c6 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -14,8 +14,6 @@ class ThermalClusterList : public ClusterList { public: std::string typeID() const override; - // Map container - using Map = typename std::map>; /*! ** \brief Get the size (bytes) occupied in memory by a `ThermalClusterList` structure @@ -64,8 +62,6 @@ class ThermalClusterList : public ClusterList std::vector> allClusters; - Map mapping; - /*! ** \brief Ensure data for the prepro are initialized ** \ingroup thermalclusters From 319b1e74c267452c284c56420ea0628ae5f836c7 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 29 Dec 2023 13:43:56 +0100 Subject: [PATCH 16/88] Clean thermal lists (goal : keeping only one list) : defining and using a filtered std::view for list of enabled cluster --- src/libs/antares/study/parts/thermal/cluster.h | 3 +++ src/libs/antares/study/parts/thermal/cluster_list.cpp | 1 - src/libs/antares/study/parts/thermal/cluster_list.h | 7 +++++++ src/solver/simulation/common-eco-adq.cpp | 4 +--- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster.h b/src/libs/antares/study/parts/thermal/cluster.h index a75ce10a00..5f51d148d5 100644 --- a/src/libs/antares/study/parts/thermal/cluster.h +++ b/src/libs/antares/study/parts/thermal/cluster.h @@ -242,6 +242,9 @@ class ThermalCluster final : public Cluster, public std::enable_shared_from_this //! Mustrun bool mustrun; + bool isNotMustRun() { return not mustrun; } + bool isEnabled() { return enabled; } + //! Mustrun (as it were at the loading of the data) // // This value might differ from mustrun, because `mustrun` might be diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 611f6a62ae..921f81a366 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -1,7 +1,6 @@ #include "cluster_list.h" #include "cluster.h" #include "../../study.h" -#include namespace // anonymous { diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index bcd1f0f5c6..8034695f6a 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -1,6 +1,8 @@ #pragma once +#include #include "../common/cluster_list.h" +#include "cluster.h" namespace Antares { @@ -56,6 +58,11 @@ class ThermalClusterList : public ClusterList */ void enableMustrunForEveryone(); //@} + auto each_enabled() { return allClusters | std::views::filter(std::mem_fn(&ThermalCluster::isEnabled)); } + auto each_not_mustrun() { return allClusters | std::views::filter(std::mem_fn(&ThermalCluster::isNotMustRun)); } + auto each_enabled_and_not_mustrun() { return allClusters | std::views::filter(&ThermalCluster::isEnabled) + | std::views::filter(&ThermalCluster::isNotMustRun); } + void addToCompleteList(std::shared_ptr cluster); bool alreadyInAllClusters(std::string clusterName); void sortCompleteList(); diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index 952c6de8b2..9dd725e2de 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -284,10 +284,8 @@ void PrepareRandomNumbers(Data::Study& study, //----------------------------- // Thermal noises //----------------------------- - for (auto cluster : area.thermal.list.allClusters) + for (auto cluster : area.thermal.list.each_enabled()) { - if (!cluster->enabled) - continue; uint clusterIndex = cluster->areaWideIndex; double& rnd = randomForYear.pThermalNoisesByArea[indexArea][clusterIndex]; double randomClusterProdCost(0.); From b0a20b5137314fcbfa8f6e031bd0b607b08920cb Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 29 Dec 2023 17:00:17 +0100 Subject: [PATCH 17/88] Clean thermal lists (goal : remove area.thermal.clusters) : mainly building areaWideIndex by filtering all clusters list --- .../study/parts/thermal/cluster_list.cpp | 26 +++++++++++++++++++ .../study/parts/thermal/cluster_list.h | 11 +++++--- .../antares/study/parts/thermal/container.cpp | 1 - src/solver/simulation/timeseries-numbers.cpp | 5 ++-- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 921f81a366..891284d5cd 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -60,6 +60,29 @@ void ThermalClusterList::sortCompleteList() }); } +void ThermalClusterList::giveIndicesToClusters() +{ + // First, we give an index to every cluster, enabled / must-run or not. + // We do that to : + // - Stick to what was done before and not change the results + // - Avoids seg faults, for instance when storing thermal noises (solver.hxx). + // Indeed : otherwise disabled clusters have an infinite index + unsigned int index = 0; + for (auto c : allClusters) + { + c->areaWideIndex = index; + index++; + } + + index = 0; + for (auto c : each_enabled()) + { + c->areaWideIndex = index; + index++; + } + +} + bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, Area* area) { assert(area and "A parent area is required"); @@ -157,7 +180,10 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A add(cluster); addToCompleteList(cluster); } + sortCompleteList(); + giveIndicesToClusters(); + return ret; } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 8034695f6a..aee9c6209f 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -63,10 +63,6 @@ class ThermalClusterList : public ClusterList auto each_enabled_and_not_mustrun() { return allClusters | std::views::filter(&ThermalCluster::isEnabled) | std::views::filter(&ThermalCluster::isNotMustRun); } - void addToCompleteList(std::shared_ptr cluster); - bool alreadyInAllClusters(std::string clusterName); - void sortCompleteList(); - std::vector> allClusters; /*! @@ -95,6 +91,13 @@ class ThermalClusterList : public ClusterList bool saveEconomicCosts(const AnyString& folder) const; bool saveToFolder(const AnyString& folder) const override; + + void addToCompleteList(std::shared_ptr cluster); + void sortCompleteList(); + void giveIndicesToClusters(); + +private: + bool alreadyInAllClusters(std::string clusterName); }; // class ThermalClusterList } // namespace Data } // namespace Antares diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index 4b4fc84215..612f0ab1b9 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -78,7 +78,6 @@ void PartThermal::prepareAreaWideIndexes() uint idx = 0; for (const auto& cluster : list) { - cluster->areaWideIndex = idx; clusters[idx] = cluster.get(); ++idx; } diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 71fd20445b..787860b56f 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -539,10 +539,9 @@ void storeTSnumbersForIntraModal(const array& intramo if (isTSintramodal[indexTS]) { - for (auto cluster : area.thermal.list.allClusters) + for (auto cluster : area.thermal.list.each_enabled()) { - if (cluster->enabled) - cluster->series.timeseriesNumbers[0][year] = intramodal_draws[indexTS]; + cluster->series.timeseriesNumbers[0][year] = intramodal_draws[indexTS]; } } From ef867d7d0fd46a44d2d52127005651378f45e033 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Tue, 2 Jan 2024 10:37:33 +0100 Subject: [PATCH 18/88] Clean thermal lists (goal : remove area.thermal.clusters) : fix unit test + keeping on removing thermal.clusters uses --- .../antares/study/parts/thermal/cluster.h | 4 +- .../study/parts/thermal/cluster_list.h | 11 ++++-- src/solver/simulation/timeseries-numbers.cpp | 38 ++++++++----------- src/tests/end-to-end/utils/utils.cpp | 1 + .../test-sc-builder-file-read-line.cpp | 4 ++ .../test-sc-builder-file-save.cpp | 3 ++ .../thermal-price-definition.cpp | 3 ++ .../antares-study/thermal-cluster/create.cpp | 1 + 8 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster.h b/src/libs/antares/study/parts/thermal/cluster.h index 5f51d148d5..68d2050115 100644 --- a/src/libs/antares/study/parts/thermal/cluster.h +++ b/src/libs/antares/study/parts/thermal/cluster.h @@ -242,8 +242,8 @@ class ThermalCluster final : public Cluster, public std::enable_shared_from_this //! Mustrun bool mustrun; - bool isNotMustRun() { return not mustrun; } - bool isEnabled() { return enabled; } + bool isNotMustRun() const { return not mustrun; } + bool isEnabled() const { return enabled; } //! Mustrun (as it were at the loading of the data) // diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index aee9c6209f..61548982da 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -58,10 +58,13 @@ class ThermalClusterList : public ClusterList */ void enableMustrunForEveryone(); //@} - auto each_enabled() { return allClusters | std::views::filter(std::mem_fn(&ThermalCluster::isEnabled)); } - auto each_not_mustrun() { return allClusters | std::views::filter(std::mem_fn(&ThermalCluster::isNotMustRun)); } - auto each_enabled_and_not_mustrun() { return allClusters | std::views::filter(&ThermalCluster::isEnabled) - | std::views::filter(&ThermalCluster::isNotMustRun); } + auto each_enabled() const { return allClusters | std::views::filter(&ThermalCluster::isEnabled); } + auto each_not_mustrun() const { return allClusters | std::views::filter(&ThermalCluster::isNotMustRun); } + auto each_enabled_and_not_mustrun() const + { + return allClusters | std::views::filter(&ThermalCluster::isEnabled) + | std::views::filter(&ThermalCluster::isNotMustRun); + } std::vector> allClusters; diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 787860b56f..daed8c010a 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -94,10 +94,9 @@ static bool GenerateDeratedMode(Study& study) area.wind.series.timeseriesNumbers.zero(); area.hydro.series->timeseriesNumbers.zero(); - for (uint i = 0; i != area.thermal.clusterCount(); ++i) + for (auto cluster : area.thermal.list.each_enabled()) { - auto& cluster = *(area.thermal.clusters[i]); - cluster.series.timeseriesNumbers.zero(); + cluster->series.timeseriesNumbers.zero(); } for (const auto& cluster : area.renewable.list) @@ -202,11 +201,9 @@ class thermalAreaNumberOfTSretriever : public areaNumberOfTSretriever std::vector getAreaTimeSeriesNumber(const Area& area) { std::vector to_return; - uint clusterCount = (uint)area.thermal.clusterCount(); - for (uint i = 0; i != clusterCount; ++i) + for (auto cluster : area.thermal.list.each_enabled()) { - auto& cluster = *(area.thermal.clusters[i]); - to_return.push_back(cluster.series.timeSeries.width); + to_return.push_back(cluster->series.timeSeries.width); } return to_return; } @@ -429,12 +426,10 @@ bool checkInterModalConsistencyForArea(Area& area, indexTS = ts_to_tsIndex.at(timeSeriesThermal); if (isTSintermodal[indexTS]) { - const uint clusterCount = (uint)area.thermal.clusterCount(); - for (uint j = 0; j != clusterCount; ++j) + for (auto cluster : area.thermal.list.each_enabled()) { - auto& cluster = *(area.thermal.clusters[j]); uint nbTimeSeries = isTSgenerated[indexTS] ? parameters.nbTimeSeriesThermal - : cluster.series.timeSeries.width; + : cluster->series.timeSeries.width; listNumberTsOverArea.push_back(nbTimeSeries); } } @@ -773,12 +768,10 @@ void applyMatrixDrawsToInterModalModesInArea(Matrix* tsNumbersMtx, if (isTSintermodal[ts_to_tsIndex.at(timeSeriesThermal)]) { - uint clusterCount = (uint)area.thermal.clusterCount(); - for (uint i = 0; i != clusterCount; ++i) + for (auto cluster : area.thermal.list.each_enabled()) { - auto& cluster = *(area.thermal.clusters[i]); - assert(year < cluster.series.timeseriesNumbers.height); - cluster.series.timeseriesNumbers[0][year] = draw; + assert(year < cluster->series.timeseriesNumbers.height); + cluster->series.timeseriesNumbers[0][year] = draw; } } if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)]) @@ -823,13 +816,12 @@ static void fixTSNumbersWhenWidthIsOne(Study& study) area.hydro.series->timeseriesNumbers, area.hydro.series->TScount(), years); // Thermal - std::for_each(area.thermal.clusters.cbegin(), - area.thermal.clusters.cend(), - [&years](Data::ThermalCluster* cluster) { - fixTSNumbersSingleAreaSingleMode(cluster->series.timeseriesNumbers, - cluster->series.timeSeries.width, - years); - }); + for (auto cluster : area.thermal.list.each_enabled()) + { + fixTSNumbersSingleAreaSingleMode(cluster->series.timeseriesNumbers, + cluster->series.timeSeries.width, + years); + } // Renewables for (const auto& cluster : area.renewable.list) diff --git a/src/tests/end-to-end/utils/utils.cpp b/src/tests/end-to-end/utils/utils.cpp index 933787085a..676cb984c3 100644 --- a/src/tests/end-to-end/utils/utils.cpp +++ b/src/tests/end-to-end/utils/utils.cpp @@ -26,6 +26,7 @@ std::shared_ptr addClusterToArea(Area* area, const std::string& area->thermal.list.add(cluster); area->thermal.list.addToCompleteList(cluster); area->thermal.prepareAreaWideIndexes(); + area->thermal.list.giveIndicesToClusters(); return cluster; } diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index 6e6f71e4bd..694d38f2cd 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -109,6 +109,10 @@ struct Fixture area_1->thermal.prepareAreaWideIndexes(); area_2->thermal.prepareAreaWideIndexes(); area_3->thermal.prepareAreaWideIndexes(); + area_1->thermal.list.giveIndicesToClusters(); + area_2->thermal.list.giveIndicesToClusters(); + area_3->thermal.list.giveIndicesToClusters(); + // Add renewable clusters rnCluster_21 = addClusterToArea(area_2, "rn-cluster-21"); diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 751b9d69cd..4010500835 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -150,6 +150,9 @@ struct commonFixture area_1->thermal.prepareAreaWideIndexes(); area_2->thermal.prepareAreaWideIndexes(); area_3->thermal.prepareAreaWideIndexes(); + area_1->thermal.list.giveIndicesToClusters(); + area_2->thermal.list.giveIndicesToClusters(); + area_3->thermal.list.giveIndicesToClusters(); // Add renewable clusters rnCluster_21 = addClusterToArea(area_2, "rn-cluster-21"); diff --git a/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp b/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp index 969808b02b..c1a794700c 100644 --- a/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp +++ b/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp @@ -166,6 +166,7 @@ BOOST_FIXTURE_TEST_CASE(checkCo2_checkCO2CostColumnNumber_OK, FixtureFull) cluster->series.timeSeries.reset(3, 8760); area->thermal.prepareAreaWideIndexes(); + area->thermal.list.giveIndicesToClusters(); auto& ecoInput = cluster->ecoInput; ecoInput.co2cost.reset(3, 8760); @@ -181,6 +182,7 @@ BOOST_FIXTURE_TEST_CASE(checkCo2_checkCO2CostColumnNumber_KO, FixtureFull) cluster->series.timeSeries.reset(3, 8760); area->thermal.prepareAreaWideIndexes(); + area->thermal.list.giveIndicesToClusters(); auto& ecoInput = cluster->ecoInput; ecoInput.co2cost.reset(2, 8760); @@ -197,6 +199,7 @@ BOOST_FIXTURE_TEST_CASE(checkFuelAndCo2_checkColumnNumber_OK, FixtureFull) cluster->series.timeSeries.reset(3, 8760); area->thermal.prepareAreaWideIndexes(); + area->thermal.list.giveIndicesToClusters(); cluster->ecoInput.fuelcost.reset(3, 8760); cluster->ecoInput.co2cost.reset(3, 8760); diff --git a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp index bfac4c1a32..b4a659f7ec 100644 --- a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp +++ b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp @@ -183,6 +183,7 @@ bool Create::performWL(Context& ctx) ctx.cluster->reset(); (ctx.area)->thermal.list.add(std::shared_ptr(ctx.cluster)); (ctx.area)->thermal.prepareAreaWideIndexes(); + (ctx.area)->thermal.list.giveIndicesToClusters(); } else { From 0ec83cbf61b056e1f814e4e0982aa924508f5c94 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Tue, 2 Jan 2024 11:20:35 +0100 Subject: [PATCH 19/88] Clean thermal lists (goal : remove area.thermal.clusters) : keeping on removing area.thermal.clusters usages --- src/solver/simulation/timeseries-numbers.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index daed8c010a..b559d52220 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -728,9 +728,12 @@ Matrix* getFirstTSnumberInterModalMatrixFoundInArea( tsNumbersMtx = &(area.wind.series.timeseriesNumbers); else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesHydro)]) tsNumbersMtx = &(area.hydro.series->timeseriesNumbers); - else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesThermal)] - && area.thermal.clusterCount() > 0) - tsNumbersMtx = &(area.thermal.clusters[0]->series.timeseriesNumbers); + else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesThermal)] && + not area.thermal.list.each_enabled().empty() > 0) + { + std::shared_ptr cluster = *(area.thermal.list.each_enabled().begin()); + tsNumbersMtx = &(cluster->series.timeseriesNumbers); + } else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)] && area.renewable.list.size() > 0) tsNumbersMtx = &(area.renewable.list[0]->series.timeseriesNumbers); From e01ef86d570abf767f2eeed34b07409fb9545342 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Tue, 2 Jan 2024 12:21:42 +0100 Subject: [PATCH 20/88] Clean thermal lists (goal : remove area.thermal.clusters) : keeping on removing area.thermal.clusters usages --- .../scenario-builder/ThermalTSNumberData.cpp | 15 +++++---------- src/libs/antares/study/ui-runtimeinfos.cpp | 5 ++--- src/solver/variable/area.inc.hxx | 7 +++---- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp index b67ede4039..026f7f8451 100644 --- a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp @@ -79,22 +79,17 @@ bool thermalTSNumberData::apply(Study& study) assert(pArea != nullptr); assert(pArea->index < study.areas.size()); Area& area = *(study.areas.byIndex[pArea->index]); - // The total number of clusters for the area - // WARNING: We may have some thermal clusters with the `mustrun` option - auto clusterCount = (uint)area.thermal.clusterCount(); const uint tsGenCountThermal = get_tsGenCount(study); - for (uint clusterIndex = 0; clusterIndex != clusterCount; ++clusterIndex) + for (auto cluster : area.thermal.list.each_enabled()) { - auto& cluster = *(area.thermal.clusters[clusterIndex]); - // alias to the current column - assert(clusterIndex < pTSNumberRules.width); - const auto& col = pTSNumberRules[clusterIndex]; + assert(cluster->areaWideIndex < pTSNumberRules.width); + const auto& col = pTSNumberRules[cluster->areaWideIndex]; - logprefix.clear() << "Thermal: area '" << area.name << "', cluster: '" << cluster.name() + logprefix.clear() << "Thermal: area '" << area.name << "', cluster: '" << cluster->name() << "': "; - ret = ApplyToMatrix(errors, logprefix, cluster.series, col, tsGenCountThermal) && ret; + ret = ApplyToMatrix(errors, logprefix, cluster->series, col, tsGenCountThermal) && ret; } return ret; } diff --git a/src/libs/antares/study/ui-runtimeinfos.cpp b/src/libs/antares/study/ui-runtimeinfos.cpp index 0ba362f828..d78b00ceda 100644 --- a/src/libs/antares/study/ui-runtimeinfos.cpp +++ b/src/libs/antares/study/ui-runtimeinfos.cpp @@ -80,10 +80,9 @@ void UIRuntimeInfo::reload() set.insert(i->second); } - for (uint j = 0; j < area->thermal.clusterCount(); ++j) + for (auto cluster : area->thermal.list.each_enabled()) { - ThermalCluster* cluster = area->thermal.clusters[j]; - pClusters.push_back(cluster); + pClusters.push_back(cluster.get()); } } } diff --git a/src/solver/variable/area.inc.hxx b/src/solver/variable/area.inc.hxx index c6475d6110..9858f46e90 100644 --- a/src/solver/variable/area.inc.hxx +++ b/src/solver/variable/area.inc.hxx @@ -200,17 +200,16 @@ void Areas::yearEndBuild(State& state, uint year, uint numSpace) // Variables auto& variablesForArea = pAreas[area.index]; - // For each thermal cluster - for (uint j = 0; j != area.thermal.clusterCount(); ++j) + for(auto cluster : area.thermal.list.each_enabled()) { - state.thermalCluster = area.thermal.clusters[j]; + state.thermalCluster = cluster.get(); state.yearEndResetThermal(); // Variables variablesForArea.yearEndBuildPrepareDataForEachThermalCluster(state, year, numSpace); // Building the end of year - state.yearEndBuildFromThermalClusterIndex(j); + state.yearEndBuildFromThermalClusterIndex(cluster->areaWideIndex); // Variables variablesForArea.yearEndBuildForEachThermalCluster(state, year, numSpace); From 04f939e68475624051c1cfbdc4c6903494e5d2c9 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Tue, 2 Jan 2024 12:51:07 +0100 Subject: [PATCH 21/88] Clean thermal lists : keeping on removing area.thermal.clusters usages --- src/solver/variable/economy/dispatchableGeneration.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/solver/variable/economy/dispatchableGeneration.h b/src/solver/variable/economy/dispatchableGeneration.h index c9a7b7c202..6684c72fff 100644 --- a/src/solver/variable/economy/dispatchableGeneration.h +++ b/src/solver/variable/economy/dispatchableGeneration.h @@ -271,12 +271,10 @@ class DispatchableGeneration { auto area = state.area; auto& thermal = state.thermal; - for (uint clusterIndex = 0; clusterIndex != state.area->thermal.clusterCount(); - ++clusterIndex) + for (auto cluster : area->thermal.list.each_enabled()) { - const auto* thermalCluster = area->thermal.clusters[clusterIndex]; - pValuesForTheCurrentYear[numSpace][thermalCluster->groupID][state.hourInTheYear] - += thermal[area->index].thermalClustersProductions[clusterIndex]; + pValuesForTheCurrentYear[numSpace][cluster->groupID][state.hourInTheYear] + += thermal[area->index].thermalClustersProductions[cluster->areaWideIndex]; } // Next variable From d6b40467d55dde363d7120f1ee8754c306df109f Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Tue, 2 Jan 2024 15:28:00 +0100 Subject: [PATCH 22/88] Clean thermal lists (goal : remove area.thermal.clusters) : keeping on removing area.thermal.clusters usages --- .../study/parts/thermal/cluster_list.cpp | 6 ++++++ .../antares/study/parts/thermal/cluster_list.h | 3 +++ .../economy/nbOfDispatchedUnitsByPlant.h | 17 +++++++---------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 891284d5cd..01d85aede1 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -80,7 +80,13 @@ void ThermalClusterList::giveIndicesToClusters() c->areaWideIndex = index; index++; } + + enabledCount_ = ++index; +} +unsigned int ThermalClusterList::enabledCount() +{ + return enabledCount_; } bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, Area* area) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 61548982da..50056c2e45 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -98,9 +98,12 @@ class ThermalClusterList : public ClusterList void addToCompleteList(std::shared_ptr cluster); void sortCompleteList(); void giveIndicesToClusters(); + unsigned int enabledCount(); private: bool alreadyInAllClusters(std::string clusterName); + + unsigned int enabledCount_ = 0; }; // class ThermalClusterList } // namespace Data } // namespace Antares diff --git a/src/solver/variable/economy/nbOfDispatchedUnitsByPlant.h b/src/solver/variable/economy/nbOfDispatchedUnitsByPlant.h index 1e4735d29e..4efaf4003d 100644 --- a/src/solver/variable/economy/nbOfDispatchedUnitsByPlant.h +++ b/src/solver/variable/economy/nbOfDispatchedUnitsByPlant.h @@ -161,7 +161,7 @@ class NbOfDispatchedUnitsByPlant : public Variable::IVariablethermal.clusterCount(); + pSize = area->thermal.list.enabledCount(); if (pSize) { AncestorType::pResults.resize(pSize); @@ -299,13 +299,10 @@ class NbOfDispatchedUnitsByPlant : public Variable::IVariablethermal.clusterCount(); - ++clusterIndex) + for (auto cluster : area->thermal.list.each_enabled()) { - const auto* thermalCluster = area->thermal.clusters[clusterIndex]; - pValuesForTheCurrentYear[numSpace][thermalCluster->areaWideIndex] - .hour[state.hourInTheYear] - = thermal[area->index].numberOfUnitsONbyCluster[clusterIndex]; + pValuesForTheCurrentYear[numSpace][cluster->areaWideIndex].hour[state.hourInTheYear] + = thermal[area->index].numberOfUnitsONbyCluster[cluster->areaWideIndex]; } // Next variable @@ -333,12 +330,12 @@ class NbOfDispatchedUnitsByPlant : public Variable::IVariablethermal; // Write the data for the current year - for (uint i = 0; i < pSize; ++i) + for (auto cluster : thermal.list.each_enabled()) { // Write the data for the current year - results.variableCaption = thermal.clusters[i]->name(); // VCardType::Caption(); + results.variableCaption = cluster->name(); // VCardType::Caption(); results.variableUnit = VCardType::Unit(); - pValuesForTheCurrentYear[numSpace][i].template buildAnnualSurveyReport( + pValuesForTheCurrentYear[numSpace][cluster->areaWideIndex].template buildAnnualSurveyReport( results, fileLevel, precision); } } From 865f931209a0dadb74efc44dc90e27c740f4a63a Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Tue, 2 Jan 2024 16:11:20 +0100 Subject: [PATCH 23/88] Clean thermal lists (goal : remove area.thermal.clusters) : fix a bug --- src/libs/antares/study/parts/thermal/cluster_list.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 01d85aede1..87aa71e5eb 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -81,7 +81,7 @@ void ThermalClusterList::giveIndicesToClusters() index++; } - enabledCount_ = ++index; + enabledCount_ = index; } unsigned int ThermalClusterList::enabledCount() From c8272053b35e5fbe1731feee5ad70e3e2e397bd4 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 3 Jan 2024 12:45:26 +0100 Subject: [PATCH 24/88] Clean thermal lists : keeping on removing area.thermal.clusters usages --- .../economy/npCostByDispatchablePlant.h | 6 +++--- .../economy/productionByDispatchablePlant.h | 18 ++++++++---------- src/solver/variable/economy/profitByPlant.h | 16 +++++++--------- .../economy/thermalAirPollutantEmissions.h | 12 +++++------- 4 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/solver/variable/economy/npCostByDispatchablePlant.h b/src/solver/variable/economy/npCostByDispatchablePlant.h index d28ce151d5..f181bae9db 100644 --- a/src/solver/variable/economy/npCostByDispatchablePlant.h +++ b/src/solver/variable/economy/npCostByDispatchablePlant.h @@ -311,12 +311,12 @@ class NonProportionalCostByDispatchablePlant const auto& thermal = results.data.area->thermal; // Write the data for the current year - for (uint i = 0; i < pSize; ++i) + for (auto cluster : thermal.list.each_enabled()) { // Write the data for the current year - results.variableCaption = thermal.clusters[i]->name(); // VCardType::Caption(); + results.variableCaption = cluster->name(); // VCardType::Caption(); results.variableUnit = VCardType::Unit(); - pValuesForTheCurrentYear[numSpace][i].template buildAnnualSurveyReport( + pValuesForTheCurrentYear[numSpace][cluster->areaWideIndex].template buildAnnualSurveyReport( results, fileLevel, precision); } } diff --git a/src/solver/variable/economy/productionByDispatchablePlant.h b/src/solver/variable/economy/productionByDispatchablePlant.h index a43fbe31bf..a10fe678bd 100644 --- a/src/solver/variable/economy/productionByDispatchablePlant.h +++ b/src/solver/variable/economy/productionByDispatchablePlant.h @@ -309,18 +309,16 @@ class ProductionByDispatchablePlant { auto& area = state.area; auto& thermal = state.thermal; - for (uint clusterIndex = 0; clusterIndex != state.area->thermal.clusterCount(); - ++clusterIndex) + for (auto cluster : area->thermal.list.each_enabled()) { - const auto* thermalCluster = area->thermal.clusters[clusterIndex]; // Production for this hour - pValuesForTheCurrentYear[numSpace][thermalCluster->areaWideIndex] + pValuesForTheCurrentYear[numSpace][cluster->areaWideIndex] .hour[state.hourInTheYear] - += thermal[area->index].thermalClustersProductions[clusterIndex]; + += thermal[area->index].thermalClustersProductions[cluster->areaWideIndex]; - pminOfTheClusterForYear[numSpace][(thermalCluster->areaWideIndex * maxHoursInAYear) + pminOfTheClusterForYear[numSpace][(cluster->areaWideIndex * maxHoursInAYear) + state.hourInTheYear] - = thermal[area->index].PMinOfClusters[clusterIndex]; + = thermal[area->index].PMinOfClusters[cluster->areaWideIndex]; } // Next variable @@ -363,12 +361,12 @@ class ProductionByDispatchablePlant const auto& thermal = results.data.area->thermal; // Write the data for the current year - for (uint i = 0; i < pSize; ++i) + for (auto cluster : thermal.list.each_enabled()) { // Write the data for the current year - results.variableCaption = thermal.clusters[i]->name(); // VCardType::Caption(); + results.variableCaption = cluster->name(); // VCardType::Caption(); results.variableUnit = VCardType::Unit(); - pValuesForTheCurrentYear[numSpace][i].template buildAnnualSurveyReport( + pValuesForTheCurrentYear[numSpace][cluster->areaWideIndex].template buildAnnualSurveyReport( results, fileLevel, precision); } } diff --git a/src/solver/variable/economy/profitByPlant.h b/src/solver/variable/economy/profitByPlant.h index 02a471fab8..2e12bcc767 100644 --- a/src/solver/variable/economy/profitByPlant.h +++ b/src/solver/variable/economy/profitByPlant.h @@ -157,7 +157,7 @@ class ProfitByPlant : public Variable::IVariable, NextT, VC pValuesForTheCurrentYear = new VCardType::IntermediateValuesBaseType[pNbYearsParallel]; // Get the area - pNbClustersOfArea = area->thermal.clusterCount(); + pNbClustersOfArea = area->thermal.list.enabledCount(); if (pNbClustersOfArea) { AncestorType::pResults.resize(pNbClustersOfArea); @@ -271,13 +271,11 @@ class ProfitByPlant : public Variable::IVariable, NextT, VC uint hourInTheWeek = state.hourInTheWeek; uint hourInTheYear = state.hourInTheYear; - for (uint clusterIndex = 0; clusterIndex != state.area->thermal.clusterCount(); - ++clusterIndex) + for (auto cluster : area->thermal.list.each_enabled()) { - auto* cluster = state.area->thermal.clusters[clusterIndex]; double hourlyClusterProduction - = thermal[area->index].thermalClustersProductions[clusterIndex]; - double pMin = thermal[area->index].PMinOfClusters[clusterIndex]; + = thermal[area->index].thermalClustersProductions[cluster->areaWideIndex]; + double pMin = thermal[area->index].PMinOfClusters[cluster->areaWideIndex]; uint tsIndex = cluster->series.timeseriesNumbers[0][state.year]; // Thermal cluster profit @@ -312,12 +310,12 @@ class ProfitByPlant : public Variable::IVariable, NextT, VC const auto& thermal = results.data.area->thermal; // Write the data for the current year - for (uint i = 0; i < pNbClustersOfArea; ++i) + for (auto cluster : thermal.list.each_enabled()) { // Write the data for the current year - results.variableCaption = thermal.clusters[i]->name(); // VCardType::Caption(); + results.variableCaption = cluster->name(); // VCardType::Caption(); results.variableUnit = VCardType::Unit(); - pValuesForTheCurrentYear[numSpace][i].template buildAnnualSurveyReport( + pValuesForTheCurrentYear[numSpace][cluster->areaWideIndex].template buildAnnualSurveyReport( results, fileLevel, precision); } } diff --git a/src/solver/variable/economy/thermalAirPollutantEmissions.h b/src/solver/variable/economy/thermalAirPollutantEmissions.h index 1579dc64d0..3759f99eaa 100644 --- a/src/solver/variable/economy/thermalAirPollutantEmissions.h +++ b/src/solver/variable/economy/thermalAirPollutantEmissions.h @@ -246,16 +246,14 @@ class ThermalAirPollutantEmissions : public Variable::IVariablethermal.clusterCount(); ++clusterIndex) + for (auto cluster : area->thermal.list.each_enabled()) { - auto* thermalCluster = area->thermal.clusters[clusterIndex]; - // Multiply every pollutant factor with production - for (int i = 0; i < Antares::Data::Pollutant::POLLUTANT_MAX; i++) + for (int pollutant = 0; pollutant < Antares::Data::Pollutant::POLLUTANT_MAX; pollutant++) { - pValuesForTheCurrentYear[numSpace][i][state.hourInTheYear] - += thermalCluster->emissions.factors[i] - * thermal[state.area->index].thermalClustersProductions[clusterIndex]; + pValuesForTheCurrentYear[numSpace][pollutant][state.hourInTheYear] + += cluster->emissions.factors[pollutant] + * thermal[state.area->index].thermalClustersProductions[cluster->areaWideIndex]; } } From d07ee145ec1fb73af0cb133b897099c2bb1bc5e7 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 3 Jan 2024 13:31:33 +0100 Subject: [PATCH 25/88] Clean thermal lists : keeping on removing area.thermal.clusters usages (in info.h) --- .../antares/study/parts/thermal/cluster_list.cpp | 12 ++++++++++++ src/libs/antares/study/parts/thermal/cluster_list.h | 1 + src/solver/variable/info.h | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 87aa71e5eb..f450ff0387 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -193,6 +193,18 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A return ret; } +std::shared_ptr ThermalClusterList::enabledClusterAt(unsigned int index) const +{ + // No operator [] was found for std::view (returned by each_enabled()). + // The current function is there to replace it. + auto it_enabled_cluster = each_enabled().begin(); + for (unsigned int i = 0; i < index; i++) + { + it_enabled_cluster++; + } + return *it_enabled_cluster; +} + static bool ThermalClusterLoadFromProperty(ThermalCluster& cluster, const IniFile::Property* p) { if (p->key.empty()) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 50056c2e45..f5451f08cf 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -99,6 +99,7 @@ class ThermalClusterList : public ClusterList void sortCompleteList(); void giveIndicesToClusters(); unsigned int enabledCount(); + std::shared_ptr enabledClusterAt(unsigned int index) const; private: bool alreadyInAllClusters(std::string clusterName); diff --git a/src/solver/variable/info.h b/src/solver/variable/info.h index 4cb3ecbb5a..f3b643690b 100644 --- a/src/solver/variable/info.h +++ b/src/solver/variable/info.h @@ -372,7 +372,7 @@ struct VariableAccessor const Data::PartThermal& thermal = results.data.area->thermal; for (uint i = 0; i != container.size(); ++i) { - results.variableCaption = thermal.clusters[i]->name(); + results.variableCaption = thermal.list.enabledClusterAt(i)->name(); container[i].template buildDigest(results, digestLevel, dataLevel); } @@ -401,7 +401,7 @@ struct VariableAccessor if (thermal_details) { auto& thermal = results.data.area->thermal; - results.variableCaption = thermal.clusters[idx]->name(); + results.variableCaption = thermal.list.enabledClusterAt(idx)->name(); return true; } if (renewable_details) From 4236cac2ab96a32a3370f3d6d18eeeec8ad68661 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 3 Jan 2024 14:34:54 +0100 Subject: [PATCH 26/88] Clean thermal lists : keeping on removing area.thermal.clusters usages --- .../study/parts/thermal/cluster_list.cpp | 2 +- src/solver/variable/area.inc.hxx | 5 ++- src/solver/variable/state.cpp | 4 +-- .../variable/surveyresults/surveyresults.cpp | 35 +++++++++---------- .../test-sc-builder-file-read-line.cpp | 1 - .../test-sc-builder-file-save.cpp | 1 - .../solver/simulation/tests-ts-numbers.cpp | 1 - 7 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index f450ff0387..551ae4c9b7 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -198,7 +198,7 @@ std::shared_ptr ThermalClusterList::enabledClusterAt(unsigned in // No operator [] was found for std::view (returned by each_enabled()). // The current function is there to replace it. auto it_enabled_cluster = each_enabled().begin(); - for (unsigned int i = 0; i < index; i++) + for (unsigned int i = 0; i < index; i++) // Compiler won't accept : it_enabled_cluster + n { it_enabled_cluster++; } diff --git a/src/solver/variable/area.inc.hxx b/src/solver/variable/area.inc.hxx index 9858f46e90..878ad07ccb 100644 --- a/src/solver/variable/area.inc.hxx +++ b/src/solver/variable/area.inc.hxx @@ -133,11 +133,10 @@ void Areas::hourForEachArea(State& state, uint numSpace) // Initializing the state for the current area state.initFromAreaIndex(area.index, numSpace); - // For each thermal cluster - for (uint j = 0; j != area.thermal.clusterCount(); ++j) + for (auto cluster : area.thermal.list.each_enabled()) { // Intiializing the state for the current thermal cluster - state.initFromThermalClusterIndex(j); + state.initFromThermalClusterIndex(cluster->areaWideIndex); } // Variables diff --git a/src/solver/variable/state.cpp b/src/solver/variable/state.cpp index 8fe1037184..0677cacba1 100644 --- a/src/solver/variable/state.cpp +++ b/src/solver/variable/state.cpp @@ -78,7 +78,7 @@ void State::initFromThermalClusterIndex(const uint clusterAreaWideIndex) assert(clusterAreaWideIndex < area->thermal.clusterCount()); // alias to the current thermal cluster - thermalCluster = area->thermal.clusters[clusterAreaWideIndex]; + thermalCluster = area->thermal.list.enabledClusterAt(clusterAreaWideIndex).get(); double thermalClusterAvailableProduction = thermalCluster->series.getCoefficient(this->year, hourInTheYear); @@ -238,7 +238,7 @@ void State::yearEndBuildFromThermalClusterIndex(const uint clusterAreaWideIndex) // Get cluster properties - Data::ThermalCluster* currentCluster = area->thermal.clusters[clusterAreaWideIndex]; + Data::ThermalCluster* currentCluster = area->thermal.list.enabledClusterAt(clusterAreaWideIndex).get(); assert(endHourForCurrentYear <= Variable::maxHoursInAYear); assert(endHourForCurrentYear <= currentCluster->series.timeSeries.height); diff --git a/src/solver/variable/surveyresults/surveyresults.cpp b/src/solver/variable/surveyresults/surveyresults.cpp index e12d73049d..1ddebec5ed 100644 --- a/src/solver/variable/surveyresults/surveyresults.cpp +++ b/src/solver/variable/surveyresults/surveyresults.cpp @@ -137,27 +137,24 @@ static void ExportGridInfosAreas(const Data::Study& study, } // Thermal clusters - for (uint i = 0; i != area.thermal.clusterCount(); ++i) + for (auto cluster : area.thermal.list.each_enabled()) { - assert(NULL != area.thermal.clusters[i]); - auto& cluster = *(area.thermal.clusters[i]); - outThermal << area.id << '\t'; - outThermal << cluster.id() << '\t'; - outThermal << cluster.name() << '\t'; - outThermal << Data::ThermalCluster::GroupName(cluster.groupID) << '\t'; - outThermal << cluster.unitCount << '\t'; - outThermal << cluster.nominalCapacity << '\t'; - outThermal << cluster.minStablePower << '\t'; - outThermal << cluster.minUpTime << '\t'; - outThermal << cluster.minDownTime << '\t'; - outThermal << cluster.spinning << '\t'; - outThermal << cluster.emissions.factors[Antares::Data::Pollutant::CO2] << '\t'; - outThermal << cluster.marginalCost << '\t'; - outThermal << cluster.fixedCost << '\t'; - outThermal << cluster.startupCost << '\t'; - outThermal << cluster.marketBidCost << '\t'; - outThermal << cluster.spreadCost << '\n'; + outThermal << cluster->id() << '\t'; + outThermal << cluster->name() << '\t'; + outThermal << Data::ThermalCluster::GroupName(cluster->groupID) << '\t'; + outThermal << cluster->unitCount << '\t'; + outThermal << cluster->nominalCapacity << '\t'; + outThermal << cluster->minStablePower << '\t'; + outThermal << cluster->minUpTime << '\t'; + outThermal << cluster->minDownTime << '\t'; + outThermal << cluster->spinning << '\t'; + outThermal << cluster->emissions.factors[Antares::Data::Pollutant::CO2] << '\t'; + outThermal << cluster->marginalCost << '\t'; + outThermal << cluster->fixedCost << '\t'; + outThermal << cluster->startupCost << '\t'; + outThermal << cluster->marketBidCost << '\t'; + outThermal << cluster->spreadCost << '\n'; } // each thermal cluster }); // each area diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index 694d38f2cd..bc61d18b44 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -18,7 +18,6 @@ using namespace Antares::Data; void addClusterToAreaList(Area* area, std::shared_ptr cluster) { - area->thermal.clusters.push_back(cluster.get()); area->thermal.list.add(cluster); area->thermal.list.addToCompleteList(cluster); } diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 4010500835..839d75670d 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -59,7 +59,6 @@ void referenceScBuilderFile::write() void addClusterToAreaList(Area* area, std::shared_ptr cluster) { - area->thermal.clusters.push_back(cluster.get()); area->thermal.list.add(cluster); area->thermal.list.addToCompleteList(cluster); } diff --git a/src/tests/src/solver/simulation/tests-ts-numbers.cpp b/src/tests/src/solver/simulation/tests-ts-numbers.cpp index bc9e7db543..d0f9f9d23b 100644 --- a/src/tests/src/solver/simulation/tests-ts-numbers.cpp +++ b/src/tests/src/solver/simulation/tests-ts-numbers.cpp @@ -50,7 +50,6 @@ void addClusterToAreaList(Area* area, std::shared_ptr cluster); template<> void addClusterToAreaList(Area* area, std::shared_ptr cluster) { - area->thermal.clusters.push_back(cluster.get()); area->thermal.list.add(cluster); area->thermal.list.addToCompleteList(cluster); } From 7c7147e2841e21d80bd7d79683939f9ae8ae24c2 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 3 Jan 2024 15:42:46 +0100 Subject: [PATCH 27/88] Clean thermal lists (goal : remove area.thermal.clusters) : removing area.thermal.clusterCount() calls --- src/libs/antares/checks/checkLoadedInputData.cpp | 11 +++++------ src/libs/antares/study/area/area.cpp | 3 +-- src/libs/antares/study/parts/thermal/cluster_list.cpp | 6 ++---- src/libs/antares/study/parts/thermal/cluster_list.h | 2 +- src/libs/antares/study/parts/thermal/container.h | 6 ------ .../study/scenario-builder/ThermalTSNumberData.cpp | 2 +- src/solver/hydro/management/management.cpp | 2 -- src/solver/variable/adequacy/overallCost.h | 4 ++-- .../variable/economy/npCostByDispatchablePlant.h | 2 +- .../variable/economy/productionByDispatchablePlant.h | 2 +- src/solver/variable/state.cpp | 4 ++-- 11 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/libs/antares/checks/checkLoadedInputData.cpp b/src/libs/antares/checks/checkLoadedInputData.cpp index d585ffdaa1..6faaa68e76 100644 --- a/src/libs/antares/checks/checkLoadedInputData.cpp +++ b/src/libs/antares/checks/checkLoadedInputData.cpp @@ -169,16 +169,15 @@ static void checkThermalColumnNumber(const Antares::Data::AreaList& areas, for (uint areaIndex = 0; areaIndex < areas.size(); ++areaIndex) { const auto& area = *(areas.byIndex[areaIndex]); - for (uint clusterIndex = 0; clusterIndex != area.thermal.clusterCount(); ++clusterIndex) + for (auto cluster : area.thermal.list.each_enabled()) { - const auto& cluster = *(area.thermal.clusters[clusterIndex]); - if (cluster.costgeneration == Antares::Data::setManually) + if (cluster->costgeneration == Antares::Data::setManually) continue; - const uint otherMatrixWidth = (cluster.ecoInput.*matrix).width; - uint tsWidth = cluster.series.timeSeries.width; + const uint otherMatrixWidth = (cluster->ecoInput.*matrix).width; + uint tsWidth = cluster->series.timeSeries.width; if (otherMatrixWidth != 1 && otherMatrixWidth != tsWidth) { - logs.warning() << "Area: " << area.name << ". Cluster name: " << cluster.name() + logs.warning() << "Area: " << area.name << ". Cluster name: " << cluster->name() << ". " << exception.what(); error = true; } diff --git a/src/libs/antares/study/area/area.cpp b/src/libs/antares/study/area/area.cpp index 0c7a33eab8..77f87ad898 100644 --- a/src/libs/antares/study/area/area.cpp +++ b/src/libs/antares/study/area/area.cpp @@ -295,9 +295,8 @@ void Area::resizeAllTimeseriesNumbers(uint n) bool Area::thermalClustersMinStablePowerValidity(std::vector& output) const { bool noErrorMinStabPow = true; - for (uint l = 0; l != thermal.clusterCount(); ++l) + for (auto cluster : thermal.list.each_enabled()) { - auto& cluster = thermal.clusters[l]; logs.debug() << "cluster : " << cluster->name(); if ((not cluster->checkMinStablePower()) || (cluster->minStablePower diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 551ae4c9b7..0ae115e4d2 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -84,7 +84,7 @@ void ThermalClusterList::giveIndicesToClusters() enabledCount_ = index; } -unsigned int ThermalClusterList::enabledCount() +unsigned int ThermalClusterList::enabledCount() const { return enabledCount_; } @@ -198,10 +198,8 @@ std::shared_ptr ThermalClusterList::enabledClusterAt(unsigned in // No operator [] was found for std::view (returned by each_enabled()). // The current function is there to replace it. auto it_enabled_cluster = each_enabled().begin(); - for (unsigned int i = 0; i < index; i++) // Compiler won't accept : it_enabled_cluster + n - { + for (unsigned int i = 0; i < index; i++) // Compiler won't accept : it_enabled_cluster + index it_enabled_cluster++; - } return *it_enabled_cluster; } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index f5451f08cf..721175e0ea 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -98,7 +98,7 @@ class ThermalClusterList : public ClusterList void addToCompleteList(std::shared_ptr cluster); void sortCompleteList(); void giveIndicesToClusters(); - unsigned int enabledCount(); + unsigned int enabledCount() const; std::shared_ptr enabledClusterAt(unsigned int index) const; private: diff --git a/src/libs/antares/study/parts/thermal/container.h b/src/libs/antares/study/parts/thermal/container.h index 6a413c479e..f76dfcf693 100644 --- a/src/libs/antares/study/parts/thermal/container.h +++ b/src/libs/antares/study/parts/thermal/container.h @@ -129,12 +129,6 @@ class PartThermal ** thermal clusters in the outputs. */ std::vector clusters; - - // Return unit count - inline size_t clusterCount() const - { - return clusters.size(); - } }; // class PartThermal } // namespace Data diff --git a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp index 026f7f8451..8d5659579d 100644 --- a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp @@ -15,7 +15,7 @@ bool thermalTSNumberData::reset(const Study& study) // If an area is available, it can only be an overlay for thermal timeseries // WARNING: The total number of clusters may vary if used from the // solver or not. - // WARNING: At this point in time, the variable pArea->thermal.clusterCount() + // WARNING: At this point, the variable pArea->thermal.list.size() // might not be valid (because not really initialized yet) uint clusterCount = (study.usedByTheSolver) ? (pArea->thermal.list.size() + pArea->thermal.mustrunList.size()) diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index f61bf1f4ce..ab6bfeb762 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -126,8 +126,6 @@ HydroManagement::HydroManagement(const Data::AreaList& areas, for (uint areaIndex = 0; areaIndex < areas_.size(); ++areaIndex) { auto& area = *areas_.byIndex[areaIndex]; - size_t clusterCount = area.thermal.clusterCount(); - ventilationResults_[areaIndex].HydrauliqueModulableQuotidien.assign(nbDaysPerYear, 0); if (area.hydro.reservoirManagement) diff --git a/src/solver/variable/adequacy/overallCost.h b/src/solver/variable/adequacy/overallCost.h index 3a501d8f71..39be2363dc 100644 --- a/src/solver/variable/adequacy/overallCost.h +++ b/src/solver/variable/adequacy/overallCost.h @@ -264,10 +264,10 @@ class OverallCost : public Variable::IVariable, NextT, VCardO * state.hourlyResults->PompageHoraire[state.hourInTheWeek]); // Thermal costs - for (uint clusterIndex = 0; clusterIndex != area->thermal.clusterCount(); ++clusterIndex) + for (auto cluster : area->thermal.list.each_enabled()) { pValuesForTheCurrentYear[numSpace][state.hourInTheYear] - += thermal[area->index].thermalClustersOperatingCost[clusterIndex]; + += thermal[area->index].thermalClustersOperatingCost[cluster->areaWideIndex]; } // Next variable diff --git a/src/solver/variable/economy/npCostByDispatchablePlant.h b/src/solver/variable/economy/npCostByDispatchablePlant.h index f181bae9db..ee74300d8e 100644 --- a/src/solver/variable/economy/npCostByDispatchablePlant.h +++ b/src/solver/variable/economy/npCostByDispatchablePlant.h @@ -164,7 +164,7 @@ class NonProportionalCostByDispatchablePlant pValuesForTheCurrentYear = new VCardType::IntermediateValuesBaseType[pNbYearsParallel]; // Get the area - pSize = area->thermal.clusterCount(); + pSize = area->thermal.list.enabledCount(); if (pSize) { AncestorType::pResults.resize(pSize); diff --git a/src/solver/variable/economy/productionByDispatchablePlant.h b/src/solver/variable/economy/productionByDispatchablePlant.h index a10fe678bd..ed200ed523 100644 --- a/src/solver/variable/economy/productionByDispatchablePlant.h +++ b/src/solver/variable/economy/productionByDispatchablePlant.h @@ -166,7 +166,7 @@ class ProductionByDispatchablePlant pminOfTheClusterForYear = new double*[pNbYearsParallel]; // Get the area - pSize = area->thermal.clusterCount(); + pSize = area->thermal.list.enabledCount(); if (pSize) { AncestorType::pResults.resize(pSize); diff --git a/src/solver/variable/state.cpp b/src/solver/variable/state.cpp index 0677cacba1..577c8d3329 100644 --- a/src/solver/variable/state.cpp +++ b/src/solver/variable/state.cpp @@ -50,7 +50,7 @@ ThermalState::StateForAnArea& ThermalState::operator[](size_t areaIndex) void ThermalState::StateForAnArea::initializeFromArea(const Data::Area& area) { - const auto count = area.thermal.clusterCount(); + const auto count = area.thermal.list.enabledCount(); thermalClustersProductions.resize(count); numberOfUnitsONbyCluster.resize(count); thermalClustersOperatingCost.resize(count); @@ -75,7 +75,7 @@ void State::initFromThermalClusterIndex(const uint clusterAreaWideIndex) { // asserts assert(area); - assert(clusterAreaWideIndex < area->thermal.clusterCount()); + assert(clusterAreaWideIndex < area->thermal.list.enabledCount()); // alias to the current thermal cluster thermalCluster = area->thermal.list.enabledClusterAt(clusterAreaWideIndex).get(); From c96ae08d9f92b0c4b8b1282ab03dcb68fced2bb1 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 3 Jan 2024 17:11:28 +0100 Subject: [PATCH 28/88] Clean thermal lists : final removal of area.thermal.clusters --- src/libs/antares/study/area/list.cpp | 1 - .../antares/study/parts/thermal/container.cpp | 24 +------------------ .../antares/study/parts/thermal/container.h | 20 ---------------- src/libs/antares/study/runtime/runtime.cpp | 1 - src/libs/antares/study/study.cpp | 1 - src/tests/end-to-end/utils/utils.cpp | 1 - 6 files changed, 1 insertion(+), 47 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 5942afb550..8f33e9b693 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -1101,7 +1101,6 @@ bool AreaList::loadFromFolder(const StudyLoadOptions& options) Area& area = *(i->second); buffer.clear() << pStudy.folderInput << thermalPlant << area.id; ret = area.thermal.list.loadFromFolder(pStudy, buffer.c_str(), &area) && ret; - area.thermal.prepareAreaWideIndexes(); } } diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index 612f0ab1b9..45778c7734 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -63,26 +63,6 @@ PartThermal::~PartThermal() { } -void PartThermal::prepareAreaWideIndexes() -{ - // Copy the list with all thermal clusters - // And init the areaWideIndex (unique index for a given area) - if (list.empty()) - { - clusters.clear(); - return; - } - - clusters.assign(list.size(), nullptr); - - uint idx = 0; - for (const auto& cluster : list) - { - clusters[idx] = cluster.get(); - ++idx; - } -} - uint PartThermal::prepareClustersInMustRunMode() { // nothing to do if there is no cluster available @@ -126,7 +106,6 @@ void PartThermal::reset() mustrunList.clear(); list.clear(); - clusters.clear(); } bool PartThermal::hasForcedTimeseriesGeneration() const @@ -147,8 +126,7 @@ bool PartThermal::hasForcedNoTimeseriesGeneration() const void PartThermal::checkAndCorrectAvailability() { - std::for_each( - clusters.begin(), clusters.end(), std::mem_fn(&ThermalCluster::checkAndCorrectAvailability)); + std::ranges::for_each(list.each_enabled(), &ThermalCluster::checkAndCorrectAvailability); } } // namespace Data diff --git a/src/libs/antares/study/parts/thermal/container.h b/src/libs/antares/study/parts/thermal/container.h index f76dfcf693..28194ad4b1 100644 --- a/src/libs/antares/study/parts/thermal/container.h +++ b/src/libs/antares/study/parts/thermal/container.h @@ -59,16 +59,6 @@ class PartThermal */ void resizeAllTimeseriesNumbers(uint n); - - - /*! - ** \brief Create and initialize the list of all clusters (with the mustrun flag or not) - ** - ** This method must be called before prepareClustersInMustRunMode() - ** to ensure the same order whatever the value of the 'mustrun' flag is. - */ - void prepareAreaWideIndexes(); - /*! ** \brief Prepare all thermal clusters in the 'mustrun' mode ** @@ -119,16 +109,6 @@ class PartThermal //! \warning This list must only be used from the solver ThermalClusterList mustrunList; - /*! - ** \brief All clusters for the area - ** - ** This variable is only available at runtime from the solver. - ** It is initialized in the same time that the runtime data. - ** - ** This list is mainly used to ensure the same order of the - ** thermal clusters in the outputs. - */ - std::vector clusters; }; // class PartThermal } // namespace Data diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index 0f112e9f53..c43047f9dd 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -359,7 +359,6 @@ void StudyRuntimeInfos::initializeThermalClustersInMustRunMode(Study& study) con for (uint a = 0; a != study.areas.size(); ++a) { Area& area = *(study.areas.byIndex[a]); - area.thermal.prepareAreaWideIndexes(); count += area.thermal.prepareClustersInMustRunMode(); } diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index cd8e8b28fc..559b5a69a2 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -1090,7 +1090,6 @@ bool Study::clusterRename(Cluster* cluster, ClusterName newName) break; case kThermal: ret = area.thermal.list.rename(cluster->id(), newName); - area.thermal.prepareAreaWideIndexes(); break; case kUnknown: logs.error() << "Unknown cluster type"; diff --git a/src/tests/end-to-end/utils/utils.cpp b/src/tests/end-to-end/utils/utils.cpp index 676cb984c3..780991af9a 100644 --- a/src/tests/end-to-end/utils/utils.cpp +++ b/src/tests/end-to-end/utils/utils.cpp @@ -25,7 +25,6 @@ std::shared_ptr addClusterToArea(Area* area, const std::string& area->thermal.list.add(cluster); area->thermal.list.addToCompleteList(cluster); - area->thermal.prepareAreaWideIndexes(); area->thermal.list.giveIndicesToClusters(); return cluster; From 7b1089711a9ac19630dcd17b60c66eca947cb3be Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 4 Jan 2024 11:13:34 +0100 Subject: [PATCH 29/88] Clean thermal lists : fix an overlook (in clear()) + change on cluster list filters, to stick to what will be needed in further evolution --- src/libs/antares/study/parts/thermal/cluster.h | 1 + src/libs/antares/study/parts/thermal/cluster_list.h | 9 ++++++++- src/libs/antares/study/parts/thermal/container.cpp | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libs/antares/study/parts/thermal/cluster.h b/src/libs/antares/study/parts/thermal/cluster.h index 68d2050115..89f70b2673 100644 --- a/src/libs/antares/study/parts/thermal/cluster.h +++ b/src/libs/antares/study/parts/thermal/cluster.h @@ -242,6 +242,7 @@ class ThermalCluster final : public Cluster, public std::enable_shared_from_this //! Mustrun bool mustrun; + bool isMustRun() const { return mustrun; } bool isNotMustRun() const { return not mustrun; } bool isEnabled() const { return enabled; } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 721175e0ea..d4a721de3a 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -58,8 +58,15 @@ class ThermalClusterList : public ClusterList */ void enableMustrunForEveryone(); //@} + auto each_enabled() const { return allClusters | std::views::filter(&ThermalCluster::isEnabled); } - auto each_not_mustrun() const { return allClusters | std::views::filter(&ThermalCluster::isNotMustRun); } + + auto each_mustrun_and_enabled() const + { + return allClusters | std::views::filter(&ThermalCluster::isMustRun) + | std::views::filter(&ThermalCluster::isEnabled); + } + auto each_enabled_and_not_mustrun() const { return allClusters | std::views::filter(&ThermalCluster::isEnabled) diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index 45778c7734..c917410486 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -106,6 +106,7 @@ void PartThermal::reset() mustrunList.clear(); list.clear(); + list.allClusters.clear(); // gp : allClusters should be private eventually } bool PartThermal::hasForcedTimeseriesGeneration() const From bd52ad04a313e75937873a8fc0a6afad4c1a9643 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 4 Jan 2024 14:57:23 +0100 Subject: [PATCH 30/88] [TEST] Try short tests on CI --- .github/workflows/ubuntu.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index c733f8bf0d..09b811c943 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -120,6 +120,13 @@ jobs: path: 'simtest.json' prop_path: 'version' + - name: Run short-tests + if: ${{ env.RUN_SIMPLE_TESTS == 'true' }} + uses: ./.github/workflows/run-tests + with: + simtest-tag: ${{steps.simtest-version.outputs.prop}} + batch-name: short-tests + os: ${{ matrix.test-platform }} - name: Run named mps tests if: ${{ env.RUN_SIMPLE_TESTS == 'true' }} @@ -182,13 +189,6 @@ jobs: batch-name: valid-v870 os: ${{ matrix.test-platform }} - - name: Run short-tests - if: ${{ env.RUN_SIMPLE_TESTS == 'true' }} - uses: ./.github/workflows/run-tests - with: - simtest-tag: ${{steps.simtest-version.outputs.prop}} - batch-name: short-tests - os: ${{ matrix.test-platform }} - name: Run mps tests if: ${{ env.RUN_SIMPLE_TESTS == 'true' }} From e7bcae92c3b78b0910548122f3a86df8b56198e4 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 4 Jan 2024 14:58:21 +0100 Subject: [PATCH 31/88] [TEST] Revert CI test order --- .github/workflows/ubuntu.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 09b811c943..c733f8bf0d 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -120,13 +120,6 @@ jobs: path: 'simtest.json' prop_path: 'version' - - name: Run short-tests - if: ${{ env.RUN_SIMPLE_TESTS == 'true' }} - uses: ./.github/workflows/run-tests - with: - simtest-tag: ${{steps.simtest-version.outputs.prop}} - batch-name: short-tests - os: ${{ matrix.test-platform }} - name: Run named mps tests if: ${{ env.RUN_SIMPLE_TESTS == 'true' }} @@ -189,6 +182,13 @@ jobs: batch-name: valid-v870 os: ${{ matrix.test-platform }} + - name: Run short-tests + if: ${{ env.RUN_SIMPLE_TESTS == 'true' }} + uses: ./.github/workflows/run-tests + with: + simtest-tag: ${{steps.simtest-version.outputs.prop}} + batch-name: short-tests + os: ${{ matrix.test-platform }} - name: Run mps tests if: ${{ env.RUN_SIMPLE_TESTS == 'true' }} From d5d796ae23a5887d601542ddcb344f66e4f6b9bb Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 5 Jan 2024 10:30:21 +0100 Subject: [PATCH 32/88] Clean thermal lists : removal of useless features / comments We remove : - logging of loading progression, make code more complicated in cluster list class, for no benefit - useless comments in common cluster list (comment adding nothing to function / variable name) - useless type : Map = std::map --- src/libs/antares/study/area/list.cpp | 25 ------------- src/libs/antares/study/load-options.cpp | 10 ----- src/libs/antares/study/load-options.h | 7 ---- src/libs/antares/study/parts/common/cluster.h | 37 ++++--------------- .../study/parts/common/cluster_list.cpp | 3 -- .../study/parts/thermal/cluster_list.cpp | 4 +- 6 files changed, 8 insertions(+), 78 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 8f33e9b693..2132f0ed89 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -774,14 +774,6 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, StringT& buffer, const StudyLoadOptions& options) { - // Progression - options.progressTicks = 0; - options.progressTickCount - = area.thermal.list.size() * (options.loadOnlyNeeded ? 1 : 2) // prepro+series - + 1 // links - + 4 // load,solar,wind,hydro - + 1; // DSM,misc... - // Reset area.filterSynthesis = filterAll; area.filterYearByYear = filterAll; @@ -820,15 +812,10 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, MatrixTestForPositiveValues_LimitWidth(buffer.c_str(), &area.miscGen, fhhPSP); } - ++options.progressTicks; - options.pushProgressLogs(); - // Links { buffer.clear() << study.folderInput << SEP << "links" << SEP << area.id; ret = AreaLinksLoadFromFolder(study, list, &area, buffer) && ret; - ++options.progressTicks; - options.pushProgressLogs(); } // UI @@ -858,9 +845,6 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, ret = area.load.series.loadFromFile(buffer.c_str(), averageTs) && ret; } - - ++options.progressTicks; - options.pushProgressLogs(); } // Solar @@ -880,9 +864,6 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, && ret; } - - ++options.progressTicks; - options.pushProgressLogs(); } // Hydro @@ -903,9 +884,6 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "series"; ret = area.hydro.series->loadFromFolder(study, area.id, buffer) && ret; } - - ++options.progressTicks; - options.pushProgressLogs(); } // Wind @@ -924,9 +902,6 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, ret = area.wind.series.loadFromFile(buffer.c_str(), averageTs) && ret; } - - ++options.progressTicks; - options.pushProgressLogs(); } // Thermal cluster list diff --git a/src/libs/antares/study/load-options.cpp b/src/libs/antares/study/load-options.cpp index 4cd7281af2..f83b557e25 100644 --- a/src/libs/antares/study/load-options.cpp +++ b/src/libs/antares/study/load-options.cpp @@ -53,16 +53,6 @@ StudyLoadOptions::StudyLoadOptions() : { } -void StudyLoadOptions::pushProgressLogs() const -{ - if (loadOnlyNeeded && progressTicks) - { - uint percent = progressTicks * 100 / progressTickCount; - if (percent < 100) - logs.info() << logMessage << " " << percent << '%'; - } -} - void StudyLoadOptions::checkForceSimulationMode() { const uint number_of_enabled_force_options diff --git a/src/libs/antares/study/load-options.h b/src/libs/antares/study/load-options.h index bce161bfda..2c8e568bde 100644 --- a/src/libs/antares/study/load-options.h +++ b/src/libs/antares/study/load-options.h @@ -44,9 +44,6 @@ class StudyLoadOptions StudyLoadOptions(); //@} - //! Push a new log entry according to the local progress data - void pushProgressLogs() const; - void checkForceSimulationMode(); public: @@ -95,10 +92,6 @@ class StudyLoadOptions //! Temporary string for passing log message mutable Yuni::String logMessage; - //! Porgression, tick count - mutable uint progressTickCount; - //! The current number of ticks - mutable uint progressTicks; //! Display version number and exit bool displayVersion = false; diff --git a/src/libs/antares/study/parts/common/cluster.h b/src/libs/antares/study/parts/common/cluster.h index d552eb54b8..bd36f90691 100644 --- a/src/libs/antares/study/parts/common/cluster.h +++ b/src/libs/antares/study/parts/common/cluster.h @@ -24,37 +24,21 @@ struct CompareClusterName final class Cluster { public: - //! Map of renewable clusters - using Map = std::map; + using Set = std::set; public: Cluster(Area* parent); virtual ~Cluster() = default; - //! Get the cluster ID const ClusterName& id() const; - - //! \name Group - //@{ - //! Get the group of the cluster const ClusterName& group() const; - - //! Get the renewable cluster name const ClusterName& name() const; - - //! Set the name/ID void setName(const AnyString& newname); - //@} - - //! Get the full cluster name Yuni::String getFullName() const; virtual uint groupId() const = 0; - - //! Set the group virtual void setGroup(Data::ClusterName newgrp) = 0; - //@} /*! ** \brief Check and fix all values of a renewable cluster @@ -64,13 +48,13 @@ class Cluster virtual bool integrityCheck() = 0; /*! - ** \brief Get the memory consummed by the renewable cluster (in bytes) + ** \brief Get the memory consummed by the cluster (in bytes) */ virtual uint64_t memoryUsage() const = 0; //@} /*! - ** \brief Invalidate all data associated to the renewable cluster + ** \brief Invalidate all data associated to the cluster */ virtual bool forceReload(bool reload) const = 0; @@ -80,7 +64,7 @@ class Cluster void invalidateArea(); /*! - ** \brief Mark the renewable cluster as modified + ** \brief Mark the cluster as modified */ virtual void markAsModified() const = 0; @@ -97,6 +81,9 @@ class Cluster */ virtual void reset(); + bool saveDataSeriesToFolder(const AnyString& folder) const; + bool loadDataSeriesFromFolder(Study& s, const AnyString& folder); + //! Count of unit uint unitCount; @@ -131,20 +118,10 @@ class Cluster Matrix<> modulation; protected: - //! Name Data::ClusterName pName; - //! ID Data::ClusterName pID; - //! Group Data::ClusterName pGroup; -public: - //! Set of clusters - using Set = std::set; - - bool saveDataSeriesToFolder(const AnyString& folder) const; - bool loadDataSeriesFromFolder(Study& s, const AnyString& folder); - private: virtual unsigned int precision() const = 0; }; diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index de4896d6bd..c3cbb568c1 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -243,9 +243,6 @@ bool ClusterList::loadDataSeriesFromFolder(Study& s, each([&](ClusterT& c) { ret = c.loadDataSeriesFromFolder(s, folder) and ret; - - ++options.progressTicks; - options.pushProgressLogs(); }); return ret; } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 0ae115e4d2..3c38ff9d2d 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -500,9 +500,7 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, Clob buffer; auto hasPrepro = [&](auto c) - { - ++options.progressTicks; - options.pushProgressLogs(); + { return (bool) c->prepro; }; From 5a438df8bf25f45530b97cd7f440dca467e36c74 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 5 Jan 2024 11:24:21 +0100 Subject: [PATCH 33/88] Clean thermal lists : making all thermal cluster list a private data member --- .../antares/study/parts/thermal/cluster_list.cpp | 15 +++++++++++++++ .../antares/study/parts/thermal/cluster_list.h | 9 +++++++-- .../antares/study/parts/thermal/container.cpp | 2 +- src/solver/simulation/solver.hxx | 4 ++-- src/solver/simulation/timeseries-numbers.cpp | 2 +- src/solver/ts-generator/thermal.cpp | 2 +- 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 3c38ff9d2d..854b3dd879 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -203,6 +203,21 @@ std::shared_ptr ThermalClusterList::enabledClusterAt(unsigned in return *it_enabled_cluster; } +void ThermalClusterList::clearAll() +{ + allClusters.clear(); +} + +unsigned int ThermalClusterList::allClustersSize() +{ + return allClusters.size(); +} + +std::vector> ThermalClusterList::all() +{ + return allClusters; +} + static bool ThermalClusterLoadFromProperty(ThermalCluster& cluster, const IniFile::Property* p) { if (p->key.empty()) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index d4a721de3a..7bf052606b 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -73,7 +73,6 @@ class ThermalClusterList : public ClusterList | std::views::filter(&ThermalCluster::isNotMustRun); } - std::vector> allClusters; /*! ** \brief Ensure data for the prepro are initialized @@ -107,10 +106,16 @@ class ThermalClusterList : public ClusterList void giveIndicesToClusters(); unsigned int enabledCount() const; std::shared_ptr enabledClusterAt(unsigned int index) const; + void clearAll(); + unsigned int allClustersSize(); + std::vector> all(); -private: +private: // member functions bool alreadyInAllClusters(std::string clusterName); +private: // member data + std::vector> allClusters; + unsigned int enabledCount_ = 0; }; // class ThermalClusterList } // namespace Data diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index c917410486..d04b4b10fc 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -106,7 +106,7 @@ void PartThermal::reset() mustrunList.clear(); list.clear(); - list.allClusters.clear(); // gp : allClusters should be private eventually + list.clearAll(); } bool PartThermal::hasForcedTimeseriesGeneration() const diff --git a/src/solver/simulation/solver.hxx b/src/solver/simulation/solver.hxx index cd30e24e29..9108082d9a 100644 --- a/src/solver/simulation/solver.hxx +++ b/src/solver/simulation/solver.hxx @@ -627,7 +627,7 @@ void ISimulation::allocateMemoryForRandomNumbers(randomNumbers& randomForP { // logs.info() << " area : " << a << " :"; auto& area = *(study.areas.byIndex[a]); - size_t nbClusters = area.thermal.list.allClusters.size(); + size_t nbClusters = area.thermal.list.allClustersSize(); randomForParallelYears.pYears[y].pThermalNoisesByArea[a] = new double[nbClusters]; randomForParallelYears.pYears[y].pNbClustersByArea[a] = nbClusters; } @@ -691,7 +691,7 @@ void ISimulation::computeRandomNumbers(randomNumbers& randomForYears, // logs.info() << " area : " << a << " :"; auto& area = *(study.areas.byIndex[a]); - for (auto cluster : area.thermal.list.allClusters) + for (auto cluster : area.thermal.list.all()) { uint clusterIndex = cluster->areaWideIndex; double thermalNoise = runtime.random[Data::seedThermalCosts].next(); diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index b559d52220..80529eeea8 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -634,7 +634,7 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i // ------------- indexTS = ts_to_tsIndex.at(timeSeriesThermal); - for (auto cluster : area.thermal.list.allClusters) + for (auto cluster : area.thermal.list.all()) { if (not cluster->enabled) study.runtime->random[seedTimeseriesNumbers].next(); diff --git a/src/solver/ts-generator/thermal.cpp b/src/solver/ts-generator/thermal.cpp index deed83c951..cfd86894dd 100644 --- a/src/solver/ts-generator/thermal.cpp +++ b/src/solver/ts-generator/thermal.cpp @@ -625,7 +625,7 @@ bool GenerateThermalTimeSeries(Data::Study& study, generator->currentYear = year; study.areas.each([&](Data::Area& area) { - for (auto cluster : area.thermal.list.allClusters) + for (auto cluster : area.thermal.list.all()) { if (cluster->doWeGenerateTS(globalThermalTSgeneration) && refreshTSonCurrentYear) { From e72c9347815ebf646316c3628a0a07c34a7b12ae Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 5 Jan 2024 12:02:47 +0100 Subject: [PATCH 34/88] Clean thermal lists : move cluster list containing all clusters to common parent class --- src/libs/antares/study/parts/common/cluster_list.h | 3 ++- src/libs/antares/study/parts/thermal/cluster_list.h | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 5fe13778a9..539d21ab16 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -170,8 +170,9 @@ class ClusterList uint removeDisabledClusters(); protected: - /// The vector containing the clusters + // The vector containing the clusters Vect clusters; + std::vector> allClusters; /// thermal, renewable, etc. virtual std::string typeID() const = 0; diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 7bf052606b..258542272a 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -114,9 +114,8 @@ class ThermalClusterList : public ClusterList bool alreadyInAllClusters(std::string clusterName); private: // member data - std::vector> allClusters; - unsigned int enabledCount_ = 0; + }; // class ThermalClusterList } // namespace Data } // namespace Antares From da7b89f5a1723bad6e4acae61c3b210a405341a9 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 5 Jan 2024 15:13:58 +0100 Subject: [PATCH 35/88] Clean thermal lists : trial to fix a bug on CI only + move enabled filter from thermal list to common list --- src/libs/antares/study/parts/common/cluster.h | 3 +-- src/libs/antares/study/parts/common/cluster_list.h | 5 +++-- src/libs/antares/study/parts/thermal/cluster.h | 1 - src/libs/antares/study/parts/thermal/cluster_list.cpp | 5 +---- src/libs/antares/study/parts/thermal/cluster_list.h | 1 - 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster.h b/src/libs/antares/study/parts/common/cluster.h index bd36f90691..574a774877 100644 --- a/src/libs/antares/study/parts/common/cluster.h +++ b/src/libs/antares/study/parts/common/cluster.h @@ -84,10 +84,9 @@ class Cluster bool saveDataSeriesToFolder(const AnyString& folder) const; bool loadDataSeriesFromFolder(Study& s, const AnyString& folder); - //! Count of unit uint unitCount; - //! Enabled + bool isEnabled() const { return enabled; } bool enabled; //! The associate area (alias) diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 539d21ab16..dbb3d6e90d 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -9,8 +9,7 @@ #include #include #include - - +#include namespace Antares @@ -72,6 +71,8 @@ class ClusterList */ bool exists(const Data::ClusterName& id) const; + auto each_enabled() const { return allClusters | std::views::filter(&ClusterT::isEnabled); } + /*! ** \brief Rename a cluster ** diff --git a/src/libs/antares/study/parts/thermal/cluster.h b/src/libs/antares/study/parts/thermal/cluster.h index 89f70b2673..e7ff7257f2 100644 --- a/src/libs/antares/study/parts/thermal/cluster.h +++ b/src/libs/antares/study/parts/thermal/cluster.h @@ -244,7 +244,6 @@ class ThermalCluster final : public Cluster, public std::enable_shared_from_this bool mustrun; bool isMustRun() const { return mustrun; } bool isNotMustRun() const { return not mustrun; } - bool isEnabled() const { return enabled; } //! Mustrun (as it were at the loading of the data) // diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 854b3dd879..3f78c62953 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -197,10 +197,7 @@ std::shared_ptr ThermalClusterList::enabledClusterAt(unsigned in { // No operator [] was found for std::view (returned by each_enabled()). // The current function is there to replace it. - auto it_enabled_cluster = each_enabled().begin(); - for (unsigned int i = 0; i < index; i++) // Compiler won't accept : it_enabled_cluster + index - it_enabled_cluster++; - return *it_enabled_cluster; + return *(std::views::drop(each_enabled(), index).begin()); } void ThermalClusterList::clearAll() diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 258542272a..435f629e0f 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -1,6 +1,5 @@ #pragma once -#include #include "../common/cluster_list.h" #include "cluster.h" From 7801fd218cdc91b1e19aace53c0ae1074348d4cf Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 5 Jan 2024 15:51:53 +0100 Subject: [PATCH 36/88] Clean thermal lists : remove must-run list - part 1 --- src/solver/simulation/common-eco-adq.cpp | 4 ++-- .../economy/avail-dispatchable-generation.h | 15 +++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index 9dd725e2de..525500ff40 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -131,7 +131,7 @@ void PrepareDataFromClustersInMustrunMode(Data::Study& study, uint numSpace, uin double* mrs = scratchpad.mustrunSum; double* adq = scratchpad.originalMustrunSum; - for (const auto& cluster : area.thermal.mustrunList) + for (const auto& cluster : area.thermal.list.each_mustrun_and_enabled()) { const auto& availableProduction = cluster->series.getColumn(year); if (inAdequacy && cluster->mustrunOrigin) @@ -151,7 +151,7 @@ void PrepareDataFromClustersInMustrunMode(Data::Study& study, uint numSpace, uin if (inAdequacy) { - for (const auto& cluster : area.thermal.mustrunList) + for (const auto& cluster : area.thermal.list.each_mustrun_and_enabled()) { if (!cluster->mustrunOrigin) continue; diff --git a/src/solver/variable/economy/avail-dispatchable-generation.h b/src/solver/variable/economy/avail-dispatchable-generation.h index 9cea0fb713..25bc1d90a6 100644 --- a/src/solver/variable/economy/avail-dispatchable-generation.h +++ b/src/solver/variable/economy/avail-dispatchable-generation.h @@ -192,23 +192,18 @@ class AvailableDispatchGen NextType::simulationEnd(); } - void addThermalClusterList(Data::ThermalClusterList& list, unsigned int year, unsigned int numSpace) + void yearBegin(unsigned int year, unsigned int numSpace) { - for (const auto& cluster : list) + // Somme de toutes les productions disponibles pour l'ensemble des + // paliers thermiques (+must-run) + pValuesForTheCurrentYear[numSpace].reset(); + for (const auto cluster : pArea->thermal.list.each_enabled()) { const auto& availableProduction = cluster->series.getColumn(year); for (unsigned int hour = 0; hour != cluster->series.timeSeries.height; ++hour) pValuesForTheCurrentYear[numSpace].hour[hour] += availableProduction[hour]; } - } - void yearBegin(unsigned int year, unsigned int numSpace) - { - // Somme de toutes les productions disponibles pour l'ensemble des - // paliers thermiques (+must-run) - pValuesForTheCurrentYear[numSpace].reset(); - addThermalClusterList(pArea->thermal.list, year, numSpace); - addThermalClusterList(pArea->thermal.mustrunList, year, numSpace); // Next variable NextType::yearBegin(year, numSpace); From c125adab21d85127dd4be6ec44f1b3eba559b023 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 5 Jan 2024 16:29:54 +0100 Subject: [PATCH 37/88] Clean thermal lists : remove must-run list - part 2 --- src/libs/antares/study/parts/thermal/cluster_list.cpp | 6 ++++-- src/libs/antares/study/runtime/runtime.cpp | 3 --- .../antares/study/scenario-builder/ThermalTSNumberData.cpp | 2 +- src/libs/antares/study/study.importprepro.cpp | 1 - 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 3f78c62953..3ee09c0e65 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -338,12 +338,14 @@ bool ThermalClusterLoadFromSection(const AnyString& filename, void ThermalClusterList::calculationOfSpinning() { - each([&](ThermalCluster& cluster) { cluster.calculationOfSpinning(); }); + for (auto cluster : each_enabled()) + cluster->calculationOfSpinning(); } void ThermalClusterList::reverseCalculationOfSpinning() { - each([&](ThermalCluster& cluster) { cluster.reverseCalculationOfSpinning(); }); + for (auto cluster : each_enabled()) + cluster->reverseCalculationOfSpinning(); } void ThermalClusterList::enableMustrunForEveryone() diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index c43047f9dd..d6217663c9 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -84,10 +84,7 @@ static void StudyRuntimeInfosInitializeAllAreas(Study& study, StudyRuntimeInfos& // Spinning - Economic Only - If no prepro if (!(timeSeriesThermal & study.parameters.timeSeriesToRefresh)) { - // Calculation of the spinning area.thermal.list.calculationOfSpinning(); - // We should not forget the list of clusters in 'must-run' mode - area.thermal.mustrunList.calculationOfSpinning(); } area.scratchpad.reserve(nbYearsInParallel); diff --git a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp index 8d5659579d..8f2176d27d 100644 --- a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp @@ -18,7 +18,7 @@ bool thermalTSNumberData::reset(const Study& study) // WARNING: At this point, the variable pArea->thermal.list.size() // might not be valid (because not really initialized yet) uint clusterCount = (study.usedByTheSolver) - ? (pArea->thermal.list.size() + pArea->thermal.mustrunList.size()) + ? (pArea->thermal.list.enabledCount()) : pArea->thermal.list.size(); // Resize diff --git a/src/libs/antares/study/study.importprepro.cpp b/src/libs/antares/study/study.importprepro.cpp index 1579588b79..3fa815ca7e 100644 --- a/src/libs/antares/study/study.importprepro.cpp +++ b/src/libs/antares/study/study.importprepro.cpp @@ -112,7 +112,6 @@ bool Study::importTimeseriesIntoInput() // Spinning area.thermal.list.reverseCalculationOfSpinning(); - area.thermal.mustrunList.reverseCalculationOfSpinning(); buffer.clear() << folderInput << SEP << "thermal" << SEP << "series"; ret = area.thermal.list.saveDataSeriesToFolder(buffer.c_str(), msg) && ret; From 3bbef8e222328aacb6b9a3ac1db0fb84a1642b1e Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 5 Jan 2024 17:37:22 +0100 Subject: [PATCH 38/88] Clean thermal lists : remove must-run list - part 3 --- .../study/area/store-timeseries-numbers.cpp | 1 - .../study/parts/common/cluster_list.cpp | 18 ++++++++++-------- .../study/parts/thermal/cluster_list.cpp | 8 ++++++++ .../antares/study/parts/thermal/cluster_list.h | 1 + src/libs/antares/study/runtime/runtime.cpp | 2 +- .../antares/study/scenario-builder/rules.cpp | 3 --- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/libs/antares/study/area/store-timeseries-numbers.cpp b/src/libs/antares/study/area/store-timeseries-numbers.cpp index aa207a05ac..0382a0f575 100644 --- a/src/libs/antares/study/area/store-timeseries-numbers.cpp +++ b/src/libs/antares/study/area/store-timeseries-numbers.cpp @@ -90,7 +90,6 @@ void storeTimeseriesNumbersForWind(Solver::IResultWriter& writer, const Area& ar void storeTimeseriesNumbersForThermal(Solver::IResultWriter& writer, const Area& area) { area.thermal.list.storeTimeseriesNumbers(writer); - area.thermal.mustrunList.storeTimeseriesNumbers(writer); } void storeTimeseriesNumbersForRenewable(Solver::IResultWriter& writer, const Area& area) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index c3cbb568c1..24f2e74cb4 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -60,9 +60,10 @@ typename ClusterList::const_iterator ClusterList::end() cons template ClusterT* ClusterList::find(const Data::ClusterName& id) const { - const auto& it = std::ranges::find_if(clusters, [&id](auto& c) { return c->id() == id; }); - - return (it != clusters.end()) ? it->get() : nullptr; + for (auto cluster : each_enabled()) + if (cluster->id() == id) + return cluster.get(); + return nullptr; } template @@ -92,13 +93,14 @@ void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer Clob path; std::string ts_content; - each([&](const Cluster& cluster) { - path.clear() << "ts-numbers" << SEP << typeID() << SEP << cluster.parentArea->id << SEP - << cluster.id() << ".txt"; + for (auto cluster : each_enabled()) + { + path.clear() << "ts-numbers" << SEP << typeID() << SEP << cluster->parentArea->id << SEP + << cluster->id() << ".txt"; ts_content.clear(); // We must clear ts_content here, since saveToBuffer does not do it. - cluster.series.timeseriesNumbers.saveToBuffer(ts_content, 0, true, predicate, true); + cluster->series.timeseriesNumbers.saveToBuffer(ts_content, 0, true, predicate, true); writer.addEntryFromBuffer(path.c_str(), ts_content); - }); + } } template diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 3ee09c0e65..74ad353ca9 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -89,6 +89,14 @@ unsigned int ThermalClusterList::enabledCount() const return enabledCount_; } +unsigned int ThermalClusterList::mustRunAndEnabledCount() const +{ + unsigned int count = 0; + for (auto cluster : each_mustrun_and_enabled()) + count++; + return count; +} + bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, Area* area) { assert(area and "A parent area is required"); diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 435f629e0f..d8df2fefa4 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -104,6 +104,7 @@ class ThermalClusterList : public ClusterList void sortCompleteList(); void giveIndicesToClusters(); unsigned int enabledCount() const; + unsigned int mustRunAndEnabledCount() const; std::shared_ptr enabledClusterAt(unsigned int index) const; void clearAll(); unsigned int allClustersSize(); diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index d6217663c9..4ab16e1957 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -93,7 +93,7 @@ static void StudyRuntimeInfosInitializeAllAreas(Study& study, StudyRuntimeInfos& // statistics r.thermalPlantTotalCount += area.thermal.list.size(); - r.thermalPlantTotalCountMustRun += area.thermal.mustrunList.size(); + r.thermalPlantTotalCountMustRun += area.thermal.list.mustRunAndEnabledCount(); r.shortTermStorageCount += area.shortTermStorage.count(); } diff --git a/src/libs/antares/study/scenario-builder/rules.cpp b/src/libs/antares/study/scenario-builder/rules.cpp index e814468a9a..180777d2d0 100644 --- a/src/libs/antares/study/scenario-builder/rules.cpp +++ b/src/libs/antares/study/scenario-builder/rules.cpp @@ -142,9 +142,6 @@ bool Rules::readThermalCluster(const AreaName::Vector& splitKey, String value, b return false; const ThermalCluster* cluster = area->thermal.list.find(clustername); - if (!cluster) - cluster = area->thermal.mustrunList.find(clustername); - if (cluster) { uint val = fromStringToTSnumber(value); From 986595f4299c0f5f5c5c3737d9b76294b7390282 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 8 Jan 2024 11:39:42 +0100 Subject: [PATCH 39/88] Clean thermal lists : removing thermal/container.hxx (and moving its content to .cpp) --- src/libs/antares/study/CMakeLists.txt | 1 - .../antares/study/parts/thermal/container.cpp | 7 +++ .../antares/study/parts/thermal/container.h | 2 - .../antares/study/parts/thermal/container.hxx | 43 ------------------- 4 files changed, 7 insertions(+), 46 deletions(-) delete mode 100644 src/libs/antares/study/parts/thermal/container.hxx diff --git a/src/libs/antares/study/CMakeLists.txt b/src/libs/antares/study/CMakeLists.txt index 81e40b120f..808f398885 100644 --- a/src/libs/antares/study/CMakeLists.txt +++ b/src/libs/antares/study/CMakeLists.txt @@ -67,7 +67,6 @@ source_group("study\\part\\common" FILES ${SRC_STUDY_PART_COMMON}) set(SRC_STUDY_PART_THERMAL parts/thermal/container.h - parts/thermal/container.hxx parts/thermal/container.cpp parts/thermal/prepro.h parts/thermal/prepro.hxx diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index d04b4b10fc..fe59f3c7c3 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -109,6 +109,13 @@ void PartThermal::reset() list.clearAll(); } +void PartThermal::resizeAllTimeseriesNumbers(uint n) +{ + list.resizeAllTimeseriesNumbers(n); + mustrunList.resizeAllTimeseriesNumbers(n); +} + + bool PartThermal::hasForcedTimeseriesGeneration() const { using Behavior = LocalTSGenerationBehavior; diff --git a/src/libs/antares/study/parts/thermal/container.h b/src/libs/antares/study/parts/thermal/container.h index 28194ad4b1..8cffee7f31 100644 --- a/src/libs/antares/study/parts/thermal/container.h +++ b/src/libs/antares/study/parts/thermal/container.h @@ -114,6 +114,4 @@ class PartThermal } // namespace Data } // namespace Antares -#include "container.hxx" - #endif /* __ANTARES_LIBS_STUDY_PARTS_THERMAL_CONTAINER_H__ */ diff --git a/src/libs/antares/study/parts/thermal/container.hxx b/src/libs/antares/study/parts/thermal/container.hxx deleted file mode 100644 index f4fc746f50..0000000000 --- a/src/libs/antares/study/parts/thermal/container.hxx +++ /dev/null @@ -1,43 +0,0 @@ -/* -** Copyright 2007-2023 RTE -** Authors: 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 __ANTARES_LIBS_STUDY_PARTS_THERMAL_CONTAINER_HXX__ -#define __ANTARES_LIBS_STUDY_PARTS_THERMAL_CONTAINER_HXX__ - -namespace Antares -{ -namespace Data -{ -inline void PartThermal::resizeAllTimeseriesNumbers(uint n) -{ - list.resizeAllTimeseriesNumbers(n); - mustrunList.resizeAllTimeseriesNumbers(n); -} - -} // namespace Data -} // namespace Antares - -#endif // __ANTARES_LIBS_STUDY_PARTS_THERMAL_CONTAINER_HXX__ From cddef42a5eaf221491f715b1ee2c6ea286e7a4fb Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 8 Jan 2024 13:00:29 +0100 Subject: [PATCH 40/88] Clean thermal lists : fix a bug in a unit test --- .../antares/study/parts/renewable/cluster_list.cpp | 13 +++++++++++++ .../antares/study/parts/renewable/cluster_list.h | 5 +++++ .../test-sc-builder-file-read-line.cpp | 1 + 3 files changed, 19 insertions(+) diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index 5e202470dc..8794f3abc8 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -125,6 +125,18 @@ static bool ClusterLoadFromSection(const AnyString& filename, return true; } +bool RenewableClusterList::alreadyInAllClusters(std::string clusterId) +{ + return std::ranges::any_of(allClusters, [&clusterId](const auto& c) { return c->id() == clusterId; }); +} + +void RenewableClusterList::addToCompleteList(std::shared_ptr cluster) +{ + if (alreadyInAllClusters(cluster->id())) + return; + allClusters.push_back(cluster); +} + bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) { assert(area and "A parent area is required"); @@ -161,6 +173,7 @@ bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) // adding the renewable cluster add(cluster); + addToCompleteList(cluster); } } diff --git a/src/libs/antares/study/parts/renewable/cluster_list.h b/src/libs/antares/study/parts/renewable/cluster_list.h index 21f50b3694..2a129d4657 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.h +++ b/src/libs/antares/study/parts/renewable/cluster_list.h @@ -19,6 +19,11 @@ class RenewableClusterList : public ClusterList std::string typeID() const override; bool loadFromFolder(const AnyString& folder, Area* area); bool saveToFolder(const AnyString& folder) const override; + + void addToCompleteList(std::shared_ptr cluster); + +private: // member functions + bool alreadyInAllClusters(std::string clusterName); }; // class RenewableClusterList } // namespace Data } // namespace Antares diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index a1cdfe3f11..127f9191c0 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -25,6 +25,7 @@ void addClusterToAreaList(Area* area, std::shared_ptr cluster) void addClusterToAreaList(Area* area, std::shared_ptr cluster) { area->renewable.list.add(cluster); + area->renewable.list.addToCompleteList(cluster); } template From 5d3099447106c0fa5fcc5ad704594bc03a3e2a07 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 8 Jan 2024 16:46:30 +0100 Subject: [PATCH 41/88] Clean thermal lists : remove must-run list - part 4 : we don't fill the mustrun list anymore --- src/libs/antares/study/parts/common/cluster_list.cpp | 4 ++-- src/libs/antares/study/parts/common/cluster_list.h | 1 - src/libs/antares/study/parts/thermal/cluster_list.cpp | 8 ++++++++ src/libs/antares/study/parts/thermal/cluster_list.h | 1 + src/libs/antares/study/runtime/runtime.cpp | 3 ++- .../study/scenario-builder/test-sc-builder-file-save.cpp | 1 + 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 24f2e74cb4..2fd9529386 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -81,7 +81,8 @@ void ClusterList::clear() template void ClusterList::resizeAllTimeseriesNumbers(uint n) { - each([&](Cluster& cluster) { cluster.series.timeseriesNumbers.resize(1, n); }); + for (auto c : allClusters) + c->series.timeseriesNumbers.resize(1, n); } #define SEP IO::Separator @@ -190,7 +191,6 @@ bool ClusterList::forceReload(bool reload) const return std::ranges::all_of(clusters, [&reload](const auto& c){ return c->forceReload(reload); }); - } template diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index dbb3d6e90d..d2ffc862d0 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -178,7 +178,6 @@ class ClusterList /// thermal, renewable, etc. virtual std::string typeID() const = 0; -private: /// Sort the vector, set index value for each cluster void rebuildIndex(); diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 74ad353ca9..2851b9b46c 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -1,6 +1,7 @@ #include "cluster_list.h" #include "cluster.h" #include "../../study.h" +#include namespace // anonymous { @@ -208,6 +209,13 @@ std::shared_ptr ThermalClusterList::enabledClusterAt(unsigned in return *(std::views::drop(each_enabled(), index).begin()); } +void ThermalClusterList::removeMustRunClusters() +{ + std::erase_if(clusters, [](auto c) { return c->isMustRun(); }); + forceReload(); + rebuildIndex(); +} + void ThermalClusterList::clearAll() { allClusters.clear(); diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index d8df2fefa4..315333aa63 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -106,6 +106,7 @@ class ThermalClusterList : public ClusterList unsigned int enabledCount() const; unsigned int mustRunAndEnabledCount() const; std::shared_ptr enabledClusterAt(unsigned int index) const; + void removeMustRunClusters(); void clearAll(); unsigned int allClustersSize(); std::vector> all(); diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index 4ab16e1957..6e4690ca97 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -356,7 +356,8 @@ void StudyRuntimeInfos::initializeThermalClustersInMustRunMode(Study& study) con for (uint a = 0; a != study.areas.size(); ++a) { Area& area = *(study.areas.byIndex[a]); - count += area.thermal.prepareClustersInMustRunMode(); + count += area.thermal.list.mustRunAndEnabledCount(); + area.thermal.list.removeMustRunClusters(); } switch (count) diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 11ae03aa05..2ba19a5a95 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -66,6 +66,7 @@ void addClusterToAreaList(Area* area, std::shared_ptr cluster) void addClusterToAreaList(Area* area, std::shared_ptr cluster) { area->renewable.list.add(cluster); + area->renewable.list.addToCompleteList(cluster); } template From 5e7a3fb79888ba302e34f8815fc4d1da9b4a7136 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 8 Jan 2024 17:18:27 +0100 Subject: [PATCH 42/88] Clean thermal lists : fix a bug in a unit test + remove unused must-run cluster code --- .../antares/study/parts/thermal/container.cpp | 40 ------------------- .../antares/study/parts/thermal/container.h | 14 +------ .../solver/simulation/tests-ts-numbers.cpp | 1 + 3 files changed, 2 insertions(+), 53 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index fe59f3c7c3..d7c592a06a 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -59,46 +59,6 @@ void PartThermal::markAsModified() const mustrunList.markAsModified(); } -PartThermal::~PartThermal() -{ -} - -uint PartThermal::prepareClustersInMustRunMode() -{ - // nothing to do if there is no cluster available - if (list.empty()) - return 0; - - // the number of clusters in 'must-run' mode - uint count = 0; - bool mustContinue; - do - { - mustContinue = false; - for (auto cluster : list) - { - if (!cluster->mustrun) - continue; - - // Detaching the thermal cluster from the main list... - list.remove(cluster->id()); - if (!cluster->enabled) - continue; - // ...and attaching it into the second list - mustrunList.add(cluster); - ++count; - logs.info() << "enabling 'must-run' mode for the cluster " - << cluster->parentArea->name << "::" << cluster->name(); - - // the iterator has been invalidated, loop again - mustContinue = true; - break; - } - } while (mustContinue); - - return count; -} - void PartThermal::reset() { unsuppliedEnergyCost = 0.; diff --git a/src/libs/antares/study/parts/thermal/container.h b/src/libs/antares/study/parts/thermal/container.h index 8cffee7f31..b92cbfe7e8 100644 --- a/src/libs/antares/study/parts/thermal/container.h +++ b/src/libs/antares/study/parts/thermal/container.h @@ -44,7 +44,7 @@ class PartThermal */ PartThermal(); //! Destructor - ~PartThermal(); + ~PartThermal() = default; //@} /*! @@ -59,18 +59,6 @@ class PartThermal */ void resizeAllTimeseriesNumbers(uint n); - /*! - ** \brief Prepare all thermal clusters in the 'mustrun' mode - ** - ** All clusters with the flag will be moved to the container 'mustrunList'. - ** As a consequence, they will no longer be seen as thermal clusters - ** from the solver's point of view. - ** \warning This method should only be used from the solver - ** - ** \return The number of clusters found in 'must-run' mode - */ - uint prepareClustersInMustRunMode(); - /*! ** \brief Invalidate all JIT data */ diff --git a/src/tests/src/solver/simulation/tests-ts-numbers.cpp b/src/tests/src/solver/simulation/tests-ts-numbers.cpp index d0f9f9d23b..450c9ddbc3 100644 --- a/src/tests/src/solver/simulation/tests-ts-numbers.cpp +++ b/src/tests/src/solver/simulation/tests-ts-numbers.cpp @@ -58,6 +58,7 @@ template<> void addClusterToAreaList(Area* area, std::shared_ptr cluster) { area->renewable.list.add(cluster); + area->renewable.list.addToCompleteList(cluster); } template From e13ed3babebbac9b87a70a1427cdfdd0d0b345b3 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 8 Jan 2024 17:50:26 +0100 Subject: [PATCH 43/88] Clean thermal lists : finally, removing must-run list --- src/libs/antares/study/parts/thermal/container.cpp | 4 ---- src/libs/antares/study/parts/thermal/container.h | 3 --- 2 files changed, 7 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index d7c592a06a..24defce97e 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -49,14 +49,12 @@ bool PartThermal::forceReload(bool reload) const { bool ret = true; ret = list.forceReload(reload) && ret; - ret = mustrunList.forceReload(reload) && ret; return ret; } void PartThermal::markAsModified() const { list.markAsModified(); - mustrunList.markAsModified(); } void PartThermal::reset() @@ -64,7 +62,6 @@ void PartThermal::reset() unsuppliedEnergyCost = 0.; spilledEnergyCost = 0.; - mustrunList.clear(); list.clear(); list.clearAll(); } @@ -72,7 +69,6 @@ void PartThermal::reset() void PartThermal::resizeAllTimeseriesNumbers(uint n) { list.resizeAllTimeseriesNumbers(n); - mustrunList.resizeAllTimeseriesNumbers(n); } diff --git a/src/libs/antares/study/parts/thermal/container.h b/src/libs/antares/study/parts/thermal/container.h index b92cbfe7e8..ec10039a3f 100644 --- a/src/libs/antares/study/parts/thermal/container.h +++ b/src/libs/antares/study/parts/thermal/container.h @@ -93,9 +93,6 @@ class PartThermal //! List of all thermal clusters (enabled and disabled) except must-run clusters ThermalClusterList list; - //! List of all thermal clusters in 'must-run' mode - //! \warning This list must only be used from the solver - ThermalClusterList mustrunList; }; // class PartThermal From 04af0ad78e465a671203e69087e88ddc6d9749f3 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 8 Jan 2024 18:26:27 +0100 Subject: [PATCH 44/88] Clean thermal lists : move up functions to parent class --- .../antares/study/parts/common/cluster_list.cpp | 14 ++++++++++++++ src/libs/antares/study/parts/common/cluster_list.h | 3 +++ .../antares/study/parts/renewable/cluster_list.cpp | 12 ------------ .../antares/study/parts/renewable/cluster_list.h | 4 ---- .../antares/study/parts/thermal/cluster_list.cpp | 12 ------------ .../antares/study/parts/thermal/cluster_list.h | 6 ------ 6 files changed, 17 insertions(+), 34 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 2fd9529386..a0957050cf 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -125,6 +125,20 @@ void ClusterList::add(const SharedPtr newcluster) rebuildIndex(); } +template +bool ClusterList::alreadyInAllClusters(std::string clusterId) +{ + return std::ranges::any_of(allClusters, [&clusterId](const auto& c) { return c->id() == clusterId; }); +} + +template +void ClusterList::addToCompleteList(std::shared_ptr cluster) +{ + if (alreadyInAllClusters(cluster->id())) + return; + allClusters.push_back(cluster); +} + template uint64_t ClusterList::memoryUsage() const { diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index d2ffc862d0..179d844dbb 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -169,6 +169,7 @@ class ClusterList ** \return The number of disabled clusters found */ uint removeDisabledClusters(); + void addToCompleteList(std::shared_ptr cluster); protected: // The vector containing the clusters @@ -180,6 +181,8 @@ class ClusterList /// Sort the vector, set index value for each cluster void rebuildIndex(); +private: + bool alreadyInAllClusters(std::string clusterName); }; // class ClusterList } // namespace Data diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index 8794f3abc8..b637c44999 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -125,18 +125,6 @@ static bool ClusterLoadFromSection(const AnyString& filename, return true; } -bool RenewableClusterList::alreadyInAllClusters(std::string clusterId) -{ - return std::ranges::any_of(allClusters, [&clusterId](const auto& c) { return c->id() == clusterId; }); -} - -void RenewableClusterList::addToCompleteList(std::shared_ptr cluster) -{ - if (alreadyInAllClusters(cluster->id())) - return; - allClusters.push_back(cluster); -} - bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) { assert(area and "A parent area is required"); diff --git a/src/libs/antares/study/parts/renewable/cluster_list.h b/src/libs/antares/study/parts/renewable/cluster_list.h index 2a129d4657..db123657b6 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.h +++ b/src/libs/antares/study/parts/renewable/cluster_list.h @@ -20,10 +20,6 @@ class RenewableClusterList : public ClusterList bool loadFromFolder(const AnyString& folder, Area* area); bool saveToFolder(const AnyString& folder) const override; - void addToCompleteList(std::shared_ptr cluster); - -private: // member functions - bool alreadyInAllClusters(std::string clusterName); }; // class RenewableClusterList } // namespace Data } // namespace Antares diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 2851b9b46c..7ebf63f778 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -42,18 +42,6 @@ static bool ThermalClusterLoadFromSection(const AnyString& filename, ThermalCluster& cluster, const IniFile::Section& section); -bool ThermalClusterList::alreadyInAllClusters(std::string clusterId) -{ - return std::ranges::any_of(allClusters, [&clusterId](const auto& c) { return c->id() == clusterId; }); -} - -void ThermalClusterList::addToCompleteList(std::shared_ptr cluster) -{ - if (alreadyInAllClusters(cluster->id())) - return; - allClusters.push_back(cluster); -} - void ThermalClusterList::sortCompleteList() { std::sort(allClusters.begin(), allClusters.end(), [](const auto& a, const auto& b) { diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 315333aa63..8fdaeecb2d 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -58,8 +58,6 @@ class ThermalClusterList : public ClusterList void enableMustrunForEveryone(); //@} - auto each_enabled() const { return allClusters | std::views::filter(&ThermalCluster::isEnabled); } - auto each_mustrun_and_enabled() const { return allClusters | std::views::filter(&ThermalCluster::isMustRun) @@ -100,7 +98,6 @@ class ThermalClusterList : public ClusterList bool saveToFolder(const AnyString& folder) const override; - void addToCompleteList(std::shared_ptr cluster); void sortCompleteList(); void giveIndicesToClusters(); unsigned int enabledCount() const; @@ -111,9 +108,6 @@ class ThermalClusterList : public ClusterList unsigned int allClustersSize(); std::vector> all(); -private: // member functions - bool alreadyInAllClusters(std::string clusterName); - private: // member data unsigned int enabledCount_ = 0; From 39edc4e7445651649f1d61bb21b56dea3d8d6a02 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Tue, 9 Jan 2024 10:43:45 +0100 Subject: [PATCH 45/88] Clean thermal lists : call addToCompleteList(...) where add(...) We do this so that, at some point, we can easily switch between the 2 underlying lists --- src/tests/src/libs/antares/study/test_study.cpp | 6 ++++++ .../action/handler/antares-study/thermal-cluster/create.cpp | 1 + src/ui/simulator/toolbox/input/renewable-cluster.cpp | 2 ++ src/ui/simulator/toolbox/input/thermal-cluster.cpp | 2 ++ 4 files changed, 11 insertions(+) diff --git a/src/tests/src/libs/antares/study/test_study.cpp b/src/tests/src/libs/antares/study/test_study.cpp index f934754ce5..c71346966f 100644 --- a/src/tests/src/libs/antares/study/test_study.cpp +++ b/src/tests/src/libs/antares/study/test_study.cpp @@ -84,6 +84,7 @@ BOOST_FIXTURE_TEST_CASE(thermal_cluster_delete, OneAreaStudy) disabledCluster->enabled = false; areaA->thermal.list.add(disabledCluster); + areaA->thermal.list.addToCompleteList(disabledCluster); // Check that "Cluster1" is found BOOST_CHECK_EQUAL(areaA->thermal.list.find("cluster1"), disabledCluster.get()); @@ -99,6 +100,7 @@ BOOST_FIXTURE_TEST_CASE(renewable_cluster_delete, OneAreaStudy) disabledCluster->enabled = false; areaA->renewable.list.add(disabledCluster); + areaA->renewable.list.addToCompleteList(disabledCluster); // Check that "Cluster1" is found BOOST_CHECK_EQUAL(areaA->renewable.list.find("cluster1"), disabledCluster.get()); @@ -159,6 +161,7 @@ BOOST_FIXTURE_TEST_CASE(thermal_cluster_add, OneAreaStudy) BOOST_CHECK_EQUAL(newCluster->id(), "cluster"); areaA->thermal.list.add(newCluster); + areaA->thermal.list.addToCompleteList(newCluster); BOOST_CHECK_EQUAL(areaA->thermal.list.find("cluster"), newCluster.get()); BOOST_CHECK_EQUAL(areaA->thermal.list.find("Cluster"), nullptr); } @@ -175,6 +178,7 @@ struct ThermalClusterStudy: public OneAreaStudy auto newCluster = std::make_shared(areaA); newCluster->setName("Cluster"); areaA->thermal.list.add(newCluster); + areaA->thermal.list.addToCompleteList(newCluster); cluster = newCluster.get(); } @@ -208,6 +212,7 @@ BOOST_FIXTURE_TEST_CASE(renewable_cluster_add, OneAreaStudy) BOOST_CHECK(newCluster->id() == "windcluster"); areaA->renewable.list.add(newCluster); + areaA->renewable.list.addToCompleteList(newCluster); BOOST_CHECK(areaA->renewable.list.find("windcluster") == newCluster.get()); BOOST_CHECK(areaA->renewable.list.find("WindCluster") == nullptr); } @@ -226,6 +231,7 @@ struct RenewableClusterStudy : public OneAreaStudy auto newCluster = std::make_shared(areaA); newCluster->setName("WindCluster"); areaA->renewable.list.add(newCluster); + areaA->renewable.list.addToCompleteList(newCluster); cluster = newCluster.get(); } diff --git a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp index 3709ae2985..6cbcc2b2ad 100644 --- a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp +++ b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp @@ -182,6 +182,7 @@ bool Create::performWL(Context& ctx) ctx.cluster->setName(pFuturPlantName); ctx.cluster->reset(); (ctx.area)->thermal.list.add(std::shared_ptr(ctx.cluster)); + (ctx.area)->thermal.list.addToCompleteList(std::shared_ptr(ctx.cluster)); (ctx.area)->thermal.list.giveIndicesToClusters(); } else diff --git a/src/ui/simulator/toolbox/input/renewable-cluster.cpp b/src/ui/simulator/toolbox/input/renewable-cluster.cpp index 08bbb8f748..2432c8bf98 100644 --- a/src/ui/simulator/toolbox/input/renewable-cluster.cpp +++ b/src/ui/simulator/toolbox/input/renewable-cluster.cpp @@ -388,6 +388,7 @@ void RenewableCluster::internalAddPlant(void*) cluster->setName(sFl); cluster->reset(); pArea->renewable.list.add(cluster); + pArea->renewable.list.addToCompleteList(cluster); pArea->renewable.prepareAreaWideIndexes(); // Update the list @@ -465,6 +466,7 @@ void RenewableCluster::internalClonePlant(void*) cluster->copyFrom(selectedPlant); pArea->renewable.list.add(cluster); + pArea->renewable.list.addToCompleteList(cluster); pArea->renewable.prepareAreaWideIndexes(); // Update the list diff --git a/src/ui/simulator/toolbox/input/thermal-cluster.cpp b/src/ui/simulator/toolbox/input/thermal-cluster.cpp index 9b4754de86..97c647b92b 100644 --- a/src/ui/simulator/toolbox/input/thermal-cluster.cpp +++ b/src/ui/simulator/toolbox/input/thermal-cluster.cpp @@ -446,6 +446,7 @@ void ThermalCluster::internalAddPlant(void*) cluster->setName(sFl); cluster->reset(); pArea->thermal.list.add(cluster); + pArea->thermal.list.addToCompleteList(cluster); // Update the list update(); @@ -523,6 +524,7 @@ void ThermalCluster::internalClonePlant(void*) cluster->copyFrom(selectedPlant); pArea->thermal.list.add(cluster); + pArea->thermal.list.addToCompleteList(cluster); // Update the list update(); From 528048149c8747e0e87d0172886a0943dff9cf11 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Tue, 9 Jan 2024 15:33:13 +0100 Subject: [PATCH 46/88] Clean thermal lists : correct a small coding error --- src/solver/simulation/timeseries-numbers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 80529eeea8..4f05e9e198 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -729,7 +729,7 @@ Matrix* getFirstTSnumberInterModalMatrixFoundInArea( else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesHydro)]) tsNumbersMtx = &(area.hydro.series->timeseriesNumbers); else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesThermal)] && - not area.thermal.list.each_enabled().empty() > 0) + not area.thermal.list.each_enabled().empty()) { std::shared_ptr cluster = *(area.thermal.list.each_enabled().begin()); tsNumbersMtx = &(cluster->series.timeseriesNumbers); From 65297d8c571a90f564063ac1b4389160e7ea2e7f Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Tue, 9 Jan 2024 16:29:16 +0100 Subject: [PATCH 47/88] Clean thermal lists : replace a use of list.clusters with a use of filtered list.allClusters --- .../optimisation/post_process_commands.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/solver/optimisation/post_process_commands.cpp b/src/solver/optimisation/post_process_commands.cpp index d1a367e03c..a9c9cf5ba1 100644 --- a/src/solver/optimisation/post_process_commands.cpp +++ b/src/solver/optimisation/post_process_commands.cpp @@ -27,19 +27,16 @@ void DispatchableMarginPostProcessCmd::execute(const optRuntimeData& opt_runtime for (uint h = 0; h != nbHoursInWeek; ++h) dtgmrg[h] = 0.; - if (not area.thermal.list.empty()) - { - auto& hourlyResults = problemeHebdo_->ResultatsHoraires[area.index]; + auto& hourlyResults = problemeHebdo_->ResultatsHoraires[area.index]; - for (const auto& cluster : area.thermal.list) + for (const auto& cluster : area.thermal.list.each_enabled_and_not_mustrun()) + { + const auto& availableProduction = cluster->series.getColumn(year); + for (uint h = 0; h != nbHoursInWeek; ++h) { - const auto& availableProduction = cluster->series.getColumn(year); - for (uint h = 0; h != nbHoursInWeek; ++h) - { - double production = hourlyResults.ProductionThermique[h] - .ProductionThermiqueDuPalier[cluster->index]; - dtgmrg[h] += availableProduction[h + hourInYear] - production; - } + double production = hourlyResults.ProductionThermique[h] + .ProductionThermiqueDuPalier[cluster->index]; + dtgmrg[h] += availableProduction[h + hourInYear] - production; } } }); From f816193595094a643ae71c301a84546f1a759fb0 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 10 Jan 2024 15:34:41 +0100 Subject: [PATCH 48/88] Clean thermal lists : overlooks + small simplifications (see commit message) - GUI : some areaWideIndex rebuilding (that is for enabled clusters) was removed by mistake, we reintroduce it. - small simplifications (easy to understand) --- src/libs/antares/InfoCollection/StudyInfoCollector.cpp | 3 +-- .../antares/study/scenario-builder/ThermalTSNumberData.cpp | 7 ------- src/ui/simulator/toolbox/input/thermal-cluster.cpp | 3 +++ 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp index ba626a59ed..d394be44f3 100644 --- a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp +++ b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp @@ -59,8 +59,7 @@ void StudyInfoCollector::enabledThermalClustersCountToFileContent(FileContent& f for (auto i = study_.areas.begin(); i != end; ++i) { Area& area = *(i->second); - nbEnabledThermalClusters += - std::ranges::count_if(area.thermal.list, [](const auto& c) { return c->enabled; }); + nbEnabledThermalClusters += area.thermal.list.mustRunAndEnabledCount(); } // Adding an item related to number of enabled thermal clusters to the file content diff --git a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp index 8f2176d27d..be2a2a6f72 100644 --- a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp @@ -36,13 +36,6 @@ void thermalTSNumberData::saveToINIFile(const Study& /* study */, if (!pArea) return; -#ifndef NDEBUG - if (pTSNumberRules.width) - { - assert(pTSNumberRules.width == pArea->thermal.list.size()); - } -#endif - // Foreach thermal cluster... for (uint index = 0; index != pTSNumberRules.width; ++index) { diff --git a/src/ui/simulator/toolbox/input/thermal-cluster.cpp b/src/ui/simulator/toolbox/input/thermal-cluster.cpp index 97c647b92b..389aeadb83 100644 --- a/src/ui/simulator/toolbox/input/thermal-cluster.cpp +++ b/src/ui/simulator/toolbox/input/thermal-cluster.cpp @@ -317,6 +317,7 @@ void ThermalCluster::internalDeletePlant(void*) Refresh(); MarkTheStudyAsModified(); updateInnerValues(); + pArea->thermal.list.giveIndicesToClusters(); study->uiinfo->reload(); // delete associated constraints @@ -447,6 +448,7 @@ void ThermalCluster::internalAddPlant(void*) cluster->reset(); pArea->thermal.list.add(cluster); pArea->thermal.list.addToCompleteList(cluster); + pArea->thermal.list.giveIndicesToClusters(); // Update the list update(); @@ -525,6 +527,7 @@ void ThermalCluster::internalClonePlant(void*) pArea->thermal.list.add(cluster); pArea->thermal.list.addToCompleteList(cluster); + pArea->thermal.list.giveIndicesToClusters(); // Update the list update(); From 9c4b01004f9f9a67c77a0cdee044876e006ff8c7 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 10 Jan 2024 17:45:47 +0100 Subject: [PATCH 49/88] Clean thermal lists : specializing or generalizing methods (from child class to parent or reverse side) --- .../study/parts/common/cluster_list.cpp | 12 +- .../antares/study/parts/common/cluster_list.h | 5 +- .../study/parts/renewable/cluster_list.cpp | 9 ++ .../study/parts/renewable/cluster_list.h | 1 + .../study/parts/thermal/cluster_list.cpp | 118 +++++++++--------- .../study/parts/thermal/cluster_list.h | 5 +- src/libs/antares/study/study.cpp | 1 + 7 files changed, 80 insertions(+), 71 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index a0957050cf..57b38fea43 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -24,7 +24,7 @@ using namespace Antares; template inline uint ClusterList::size() const { - return (uint)clusters.size(); + return (uint)clusters.size(); // gp : function not removed because used in GUI where it contains all clusters } template @@ -140,12 +140,12 @@ void ClusterList::addToCompleteList(std::shared_ptr cluster) } template -uint64_t ClusterList::memoryUsage() const +unsigned int ClusterList::enabledCount() const { - uint64_t ret = sizeof(ClusterList) + (2 * sizeof(void*)) * this->size(); - - each([&](const ClusterT& clusters) { ret += clusters.memoryUsage(); }); - return ret; + unsigned int count = 0; + for (auto cluster : each_enabled()) + count++; + return count; } template diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 179d844dbb..0ff79fef78 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -90,7 +90,7 @@ class ClusterList */ virtual bool remove(const Data::ClusterName& id); - //! Get the number of items in the list + // gp : not removed because used in GUI where it contains all clusters uint size() const; //! Return true if the list is empty @@ -131,7 +131,7 @@ class ClusterList ** \brief Get the size (bytes) occupied in memory by a `ClusterList` structure ** \return A size (in bytes) */ - uint64_t memoryUsage() const; + virtual uint64_t memoryUsage() const = 0; /// \name IO functions /// @{ @@ -169,6 +169,7 @@ class ClusterList ** \return The number of disabled clusters found */ uint removeDisabledClusters(); + unsigned int enabledCount() const; void addToCompleteList(std::shared_ptr cluster); protected: diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index b637c44999..d74bb1d7a2 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -17,6 +17,15 @@ std::string RenewableClusterList::typeID() const return "renewables"; } +uint64_t RenewableClusterList::memoryUsage() const +{ + uint64_t ret = sizeof(RenewableClusterList) + (2 * sizeof(void*)) * enabledCount(); + each([&](const RenewableCluster& clusters) { ret += clusters.memoryUsage(); }); + return ret; + +} + + bool RenewableClusterList::saveToFolder(const AnyString& folder) const { // Make sure the folder is created diff --git a/src/libs/antares/study/parts/renewable/cluster_list.h b/src/libs/antares/study/parts/renewable/cluster_list.h index db123657b6..db1849d483 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.h +++ b/src/libs/antares/study/parts/renewable/cluster_list.h @@ -17,6 +17,7 @@ class RenewableClusterList : public ClusterList { public: std::string typeID() const override; + uint64_t memoryUsage() const override; bool loadFromFolder(const AnyString& folder, Area* area); bool saveToFolder(const AnyString& folder) const override; diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 7ebf63f778..f5ef3a5eed 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -38,6 +38,13 @@ std::string ThermalClusterList::typeID() const return "thermal"; } +uint64_t ThermalClusterList::memoryUsage() const +{ + uint64_t ret = sizeof(ThermalClusterList) + (2 * sizeof(void*)) * mustRunAndEnabledCount(); + each([&](const ThermalCluster& clusters) { ret += clusters.memoryUsage(); }); + return ret; +} + static bool ThermalClusterLoadFromSection(const AnyString& filename, ThermalCluster& cluster, const IniFile::Section& section); @@ -69,13 +76,6 @@ void ThermalClusterList::giveIndicesToClusters() c->areaWideIndex = index; index++; } - - enabledCount_ = index; -} - -unsigned int ThermalClusterList::enabledCount() const -{ - return enabledCount_; } unsigned int ThermalClusterList::mustRunAndEnabledCount() const @@ -360,7 +360,7 @@ void ThermalClusterList::enableMustrunForEveryone() void ThermalClusterList::ensureDataPrepro() { - for (const auto& c : clusters) + for (const auto& c : all()) if (!c->prepro) c->prepro = new PreproThermal(c); } @@ -376,96 +376,96 @@ bool ThermalClusterList::saveToFolder(const AnyString& folder) const // Allocate the inifile structure IniFile ini; - // Browse all clusters - each([&](const Data::ThermalCluster& c) { + for (auto c : allClusters) + { // Adding a section to the inifile - IniFile::Section* s = ini.addSection(c.name()); + IniFile::Section* s = ini.addSection(c->name()); // The section must not be empty // This key will be silently ignored the next time - s->add("name", c.name()); + s->add("name", c->name()); - if (not c.group().empty()) - s->add("group", c.group()); - if (not c.enabled) + if (not c->group().empty()) + s->add("group", c->group()); + if (not c->enabled) s->add("enabled", "false"); - if (not Math::Zero(c.unitCount)) - s->add("unitCount", c.unitCount); - if (not Math::Zero(c.nominalCapacity)) - s->add("nominalCapacity", c.nominalCapacity); + if (not Math::Zero(c->unitCount)) + s->add("unitCount", c->unitCount); + if (not Math::Zero(c->nominalCapacity)) + s->add("nominalCapacity", c->nominalCapacity); // TS generation - if (c.tsGenBehavior != LocalTSGenerationBehavior::useGlobalParameter) + if (c->tsGenBehavior != LocalTSGenerationBehavior::useGlobalParameter) { - s->add("gen-ts", c.tsGenBehavior); + s->add("gen-ts", c->tsGenBehavior); } // Min. Stable Power - if (not Math::Zero(c.minStablePower)) - s->add("min-stable-power", c.minStablePower); + if (not Math::Zero(c->minStablePower)) + s->add("min-stable-power", c->minStablePower); // Min up and min down time - if (c.minUpTime != 1) - s->add("min-up-time", c.minUpTime); - if (c.minDownTime != 1) - s->add("min-down-time", c.minDownTime); + if (c->minUpTime != 1) + s->add("min-up-time", c->minUpTime); + if (c->minDownTime != 1) + s->add("min-down-time", c->minDownTime); // must-run - if (c.mustrun) + if (c->mustrun) s->add("must-run", "true"); // spinning - if (not Math::Zero(c.spinning)) - s->add("spinning", c.spinning); + if (not Math::Zero(c->spinning)) + s->add("spinning", c->spinning); // efficiency - if (c.fuelEfficiency != 100.0) - s->add("efficiency", c.fuelEfficiency); + if (c->fuelEfficiency != 100.0) + s->add("efficiency", c->fuelEfficiency); // volatility - if (not Math::Zero(c.forcedVolatility)) - s->add("volatility.forced", Math::Round(c.forcedVolatility, 3)); - if (not Math::Zero(c.plannedVolatility)) - s->add("volatility.planned", Math::Round(c.plannedVolatility, 3)); + if (not Math::Zero(c->forcedVolatility)) + s->add("volatility.forced", Math::Round(c->forcedVolatility, 3)); + if (not Math::Zero(c->plannedVolatility)) + s->add("volatility.planned", Math::Round(c->plannedVolatility, 3)); // laws - if (c.forcedLaw != thermalLawUniform) - s->add("law.forced", c.forcedLaw); - if (c.plannedLaw != thermalLawUniform) - s->add("law.planned", c.plannedLaw); + if (c->forcedLaw != thermalLawUniform) + s->add("law.forced", c->forcedLaw); + if (c->plannedLaw != thermalLawUniform) + s->add("law.planned", c->plannedLaw); // costs - if (c.costgeneration != setManually) - s->add("costgeneration", c.costgeneration); - if (not Math::Zero(c.marginalCost)) - s->add("marginal-cost", Math::Round(c.marginalCost, 3)); - if (not Math::Zero(c.spreadCost)) - s->add("spread-cost", c.spreadCost); - if (not Math::Zero(c.fixedCost)) - s->add("fixed-cost", Math::Round(c.fixedCost, 3)); - if (not Math::Zero(c.startupCost)) - s->add("startup-cost", Math::Round(c.startupCost, 3)); - if (not Math::Zero(c.marketBidCost)) - s->add("market-bid-cost", Math::Round(c.marketBidCost, 3)); - if (!Math::Zero(c.variableomcost)) - s->add("variableomcost", Math::Round(c.variableomcost,3)); + if (c->costgeneration != setManually) + s->add("costgeneration", c->costgeneration); + if (not Math::Zero(c->marginalCost)) + s->add("marginal-cost", Math::Round(c->marginalCost, 3)); + if (not Math::Zero(c->spreadCost)) + s->add("spread-cost", c->spreadCost); + if (not Math::Zero(c->fixedCost)) + s->add("fixed-cost", Math::Round(c->fixedCost, 3)); + if (not Math::Zero(c->startupCost)) + s->add("startup-cost", Math::Round(c->startupCost, 3)); + if (not Math::Zero(c->marketBidCost)) + s->add("market-bid-cost", Math::Round(c->marketBidCost, 3)); + if (!Math::Zero(c->variableomcost)) + s->add("variableomcost", Math::Round(c->variableomcost,3)); //pollutant factor for (auto const& [key, val] : Pollutant::namesToEnum) - s->add(key, c.emissions.factors[val]); + s->add(key, c->emissions.factors[val]); buffer.clear() << folder << SEP << ".." << SEP << ".." << SEP << "prepro" << SEP - << c.parentArea->id << SEP << c.id(); + << c->parentArea->id << SEP << c->id(); if (IO::Directory::Create(buffer)) { buffer.clear() << folder << SEP << ".." << SEP << ".." << SEP << "prepro" << SEP - << c.parentArea->id << SEP << c.id() << SEP << "modulation.txt"; + << c->parentArea->id << SEP << c->id() << SEP << "modulation.txt"; - ret = c.modulation.saveToCSVFile(buffer) and ret; + ret = c->modulation.saveToCSVFile(buffer) and ret; } else ret = 0; - }); + } // Write the ini file buffer.clear() << folder << SEP << "list.ini"; diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 8fdaeecb2d..e14dadac33 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -15,6 +15,7 @@ class ThermalClusterList : public ClusterList { public: std::string typeID() const override; + uint64_t memoryUsage() const override; /*! ** \brief Get the size (bytes) occupied in memory by a `ThermalClusterList` structure @@ -100,7 +101,6 @@ class ThermalClusterList : public ClusterList void sortCompleteList(); void giveIndicesToClusters(); - unsigned int enabledCount() const; unsigned int mustRunAndEnabledCount() const; std::shared_ptr enabledClusterAt(unsigned int index) const; void removeMustRunClusters(); @@ -108,9 +108,6 @@ class ThermalClusterList : public ClusterList unsigned int allClustersSize(); std::vector> all(); -private: // member data - unsigned int enabledCount_ = 0; - }; // class ThermalClusterList } // namespace Data } // namespace Antares diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index 559b5a69a2..58055cc388 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -1090,6 +1090,7 @@ bool Study::clusterRename(Cluster* cluster, ClusterName newName) break; case kThermal: ret = area.thermal.list.rename(cluster->id(), newName); + area.thermal.list.giveIndicesToClusters(); break; case kUnknown: logs.error() << "Unknown cluster type"; From cf44e0b927c339e1115501d1d39c17b2ababa22a Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 10 Jan 2024 18:09:14 +0100 Subject: [PATCH 50/88] Clean thermal lists : remove uses of area.thermal.list.clusters --- .../study/parts/common/cluster_list.cpp | 9 +++--- .../study/parts/thermal/cluster_list.cpp | 30 ++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 57b38fea43..11deb8476a 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -231,7 +231,7 @@ bool ClusterList::remove(const Data::ClusterName& id) template bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) const { - return std::ranges::all_of(clusters, [&folder](const auto& c){ + return std::ranges::all_of(allClusters, [&folder](const auto& c){ return c->saveDataSeriesToFolder(folder); }); } @@ -257,9 +257,10 @@ bool ClusterList::loadDataSeriesFromFolder(Study& s, { bool ret = true; - each([&](ClusterT& c) { - ret = c.loadDataSeriesFromFolder(s, folder) and ret; - }); + for (auto c : allClusters) + { + ret = c->loadDataSeriesFromFolder(s, folder) and ret; + } return ret; } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index f5ef3a5eed..1a871ccf3a 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -354,8 +354,8 @@ void ThermalClusterList::reverseCalculationOfSpinning() void ThermalClusterList::enableMustrunForEveryone() { - // enabling the mustrun mode - each([&](ThermalCluster& cluster) { cluster.mustrun = true; }); + for (auto c : allClusters) + c->mustrun = true; } void ThermalClusterList::ensureDataPrepro() @@ -485,14 +485,15 @@ bool ThermalClusterList::savePreproToFolder(const AnyString& folder) const Clob buffer; bool ret = true; - each([&](const ThermalCluster& c) { - if (c.prepro) + for (auto c : allClusters) + { + if (c->prepro) { - assert(c.parentArea and "cluster: invalid parent area"); - buffer.clear() << folder << SEP << c.parentArea->id << SEP << c.id(); - ret = c.prepro->saveToFolder(buffer) and ret; + assert(c->parentArea and "cluster: invalid parent area"); + buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); + ret = c->prepro->saveToFolder(buffer) and ret; } - }); + } return ret; } @@ -501,11 +502,12 @@ bool ThermalClusterList::saveEconomicCosts(const AnyString& folder) const Clob buffer; bool ret = true; - each([&](const ThermalCluster& c) { - assert(c.parentArea and "cluster: invalid parent area"); - buffer.clear() << folder << SEP << c.parentArea->id << SEP << c.id(); - ret = c.ecoInput.saveToFolder(buffer) && ret; - }); + for (auto c : allClusters) + { + assert(c->parentArea and "cluster: invalid parent area"); + buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); + ret = c->ecoInput.saveToFolder(buffer) && ret; + } return ret; } @@ -536,7 +538,7 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, return result; }; - return std::ranges::all_of(clusters | std::views::filter(hasPrepro), + return std::ranges::all_of(allClusters | std::views::filter(hasPrepro), loadAndCheckPrepro); } From 77e04880cf7eac6f363e804143c7d1dd4fc83560 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 11 Jan 2024 11:26:04 +0100 Subject: [PATCH 51/88] Clean thermal lists : small changes before a bigger commit (about find() function) --- src/libs/antares/study/area/list.cpp | 6 ++---- src/libs/antares/study/cleaner/cleaner-v20.cpp | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 2132f0ed89..aad2900be7 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -1270,7 +1270,6 @@ void AreaListEnsureDataHydroPrepro(AreaList* l) void AreaListEnsureDataThermalPrepro(AreaList* l) { - assert(l && "The area list must not be nullptr"); l->each([&](Data::Area& area) { area.thermal.list.ensureDataPrepro(); }); } @@ -1509,7 +1508,6 @@ ThermalCluster* AreaList::findClusterFromINIKey(const AnyString& key) if (parentArea == nullptr) return nullptr; return parentArea->thermal.list.find(id); - } void AreaList::updateNameIDSet() const @@ -1548,8 +1546,8 @@ void AreaList::removeWindTimeseries() void AreaList::removeThermalTimeseries() { each([](Data::Area& area) { - area.thermal.list.each( - [](Data::ThermalCluster& cluster) { cluster.series.reset(); }); + for (auto c : area.thermal.list.all()) + c->series.reset(); }); } diff --git a/src/libs/antares/study/cleaner/cleaner-v20.cpp b/src/libs/antares/study/cleaner/cleaner-v20.cpp index 5f8e6636e1..3f91fcd7a2 100644 --- a/src/libs/antares/study/cleaner/cleaner-v20.cpp +++ b/src/libs/antares/study/cleaner/cleaner-v20.cpp @@ -135,7 +135,7 @@ static void listOfFilesAnDirectoriesToKeepForArea(PathList& e, PathList& p, cons buffer.clear() << "input/thermal/clusters/" << id << "/list.ini"; e.add(buffer); - for (const auto& cluster : area->thermal.list) + for (const auto cluster : area->thermal.list.all()) { buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster->id(); p.add(buffer); From 1d8a0dfa7cba84238a7caa0c5c0938317bb09ab6 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 11 Jan 2024 13:34:58 +0100 Subject: [PATCH 52/88] Clean thermal lists : fix compilation error --- src/libs/antares/study/cleaner/cleaner-v20.cpp | 2 +- src/libs/antares/study/parts/thermal/cluster_list.cpp | 2 +- src/libs/antares/study/parts/thermal/cluster_list.h | 2 +- src/solver/ts-generator/thermal.cpp | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libs/antares/study/cleaner/cleaner-v20.cpp b/src/libs/antares/study/cleaner/cleaner-v20.cpp index 3f91fcd7a2..38701442bf 100644 --- a/src/libs/antares/study/cleaner/cleaner-v20.cpp +++ b/src/libs/antares/study/cleaner/cleaner-v20.cpp @@ -135,7 +135,7 @@ static void listOfFilesAnDirectoriesToKeepForArea(PathList& e, PathList& p, cons buffer.clear() << "input/thermal/clusters/" << id << "/list.ini"; e.add(buffer); - for (const auto cluster : area->thermal.list.all()) + for (auto cluster : area->thermal.list.all()) { buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster->id(); p.add(buffer); diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 1a871ccf3a..1d9842eeed 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -214,7 +214,7 @@ unsigned int ThermalClusterList::allClustersSize() return allClusters.size(); } -std::vector> ThermalClusterList::all() +std::vector> ThermalClusterList::all() const { return allClusters; } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index e14dadac33..189eeefbe7 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -106,7 +106,7 @@ class ThermalClusterList : public ClusterList void removeMustRunClusters(); void clearAll(); unsigned int allClustersSize(); - std::vector> all(); + std::vector> all() const; }; // class ThermalClusterList } // namespace Data diff --git a/src/solver/ts-generator/thermal.cpp b/src/solver/ts-generator/thermal.cpp index cfd86894dd..b5f0ad5439 100644 --- a/src/solver/ts-generator/thermal.cpp +++ b/src/solver/ts-generator/thermal.cpp @@ -631,7 +631,6 @@ bool GenerateThermalTimeSeries(Data::Study& study, { (*generator)(area, *cluster); } - ++progression; } }); From 7a33389baf29a045df89e7b7f3cd8403692b41d2 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 11 Jan 2024 15:11:09 +0100 Subject: [PATCH 53/88] Clean thermal lists (towards removal of thermal.list.clusters) : change and rename find(...) into findInAll(...) --- src/libs/antares/study/area/list.cpp | 2 +- .../binding_constraint/BindingConstraint.cpp | 4 ++-- .../study/parts/common/cluster_list.cpp | 12 +++++++--- .../antares/study/parts/common/cluster_list.h | 4 +++- .../study/parts/thermal/cluster_list.cpp | 5 ---- .../study/parts/thermal/cluster_list.h | 1 - .../antares/study/scenario-builder/rules.cpp | 4 ++-- src/libs/antares/study/study.cpp | 4 ++-- .../src/libs/antares/study/test_study.cpp | 24 +++++++++---------- .../thermal-price-definition.cpp | 14 +++++------ .../antares-study/thermal-cluster/create.cpp | 12 +++++----- .../toolbox/input/renewable-cluster.cpp | 6 ++--- .../toolbox/input/thermal-cluster.cpp | 6 ++--- 13 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index aad2900be7..9deb3690fd 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -1507,7 +1507,7 @@ ThermalCluster* AreaList::findClusterFromINIKey(const AnyString& key) Area* parentArea = findFromName(parentName); if (parentArea == nullptr) return nullptr; - return parentArea->thermal.list.find(id); + return parentArea->thermal.list.findInAll(id); } void AreaList::updateNameIDSet() const diff --git a/src/libs/antares/study/binding_constraint/BindingConstraint.cpp b/src/libs/antares/study/binding_constraint/BindingConstraint.cpp index f2e49b3c2f..617acf22d4 100644 --- a/src/libs/antares/study/binding_constraint/BindingConstraint.cpp +++ b/src/libs/antares/study/binding_constraint/BindingConstraint.cpp @@ -274,7 +274,7 @@ void BindingConstraint::copyWeights(const Study &study, if (localParent) { const ThermalCluster *localTC - = localParent->thermal.list.find(thermalCluster->id()); + = localParent->thermal.list.findInAll(thermalCluster->id()); if (localTC) pClusterWeights[localTC] = weight; } @@ -335,7 +335,7 @@ void BindingConstraint::copyOffsets(const Study &study, if (localParent) { const ThermalCluster *localTC - = localParent->thermal.list.find(thermalCluster->id()); + = localParent->thermal.list.findInAll(thermalCluster->id()); if (localTC) pClusterOffsets[localTC] = offset; } diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 11deb8476a..9414ceac30 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -58,14 +58,20 @@ typename ClusterList::const_iterator ClusterList::end() cons } template -ClusterT* ClusterList::find(const Data::ClusterName& id) const +ClusterT* ClusterList::findInAll(const Data::ClusterName& id) const { - for (auto cluster : each_enabled()) + for (auto cluster : all()) if (cluster->id() == id) return cluster.get(); return nullptr; } +template +std::vector> ClusterList::all() const +{ + return allClusters; +} + template bool ClusterList::exists(const Data::ClusterName& id) const { @@ -168,7 +174,7 @@ bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName Antares::TransformNameIntoID(newName, newID); // Looking for the renewable clusters in the list - auto* cluster_ptr = this->find(idToFind); + auto* cluster_ptr = this->findInAll(idToFind); if (!cluster_ptr) return true; diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 0ff79fef78..4bd547dbec 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -61,7 +61,7 @@ class ClusterList ** \param id ID of the cluster to find ** \return A pointer to a cluster. nullptr if not found */ - ClusterT* find(const Data::ClusterName& id) const; + ClusterT* findInAll(const Data::ClusterName& id) const; /*! ** \brief Get if a cluster exists @@ -73,6 +73,8 @@ class ClusterList auto each_enabled() const { return allClusters | std::views::filter(&ClusterT::isEnabled); } + std::vector> all() const; + /*! ** \brief Rename a cluster ** diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 1d9842eeed..11fb8cc494 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -214,11 +214,6 @@ unsigned int ThermalClusterList::allClustersSize() return allClusters.size(); } -std::vector> ThermalClusterList::all() const -{ - return allClusters; -} - static bool ThermalClusterLoadFromProperty(ThermalCluster& cluster, const IniFile::Property* p) { if (p->key.empty()) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 189eeefbe7..8c4dd96a24 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -106,7 +106,6 @@ class ThermalClusterList : public ClusterList void removeMustRunClusters(); void clearAll(); unsigned int allClustersSize(); - std::vector> all() const; }; // class ThermalClusterList } // namespace Data diff --git a/src/libs/antares/study/scenario-builder/rules.cpp b/src/libs/antares/study/scenario-builder/rules.cpp index 180777d2d0..fb51898e4c 100644 --- a/src/libs/antares/study/scenario-builder/rules.cpp +++ b/src/libs/antares/study/scenario-builder/rules.cpp @@ -141,7 +141,7 @@ bool Rules::readThermalCluster(const AreaName::Vector& splitKey, String value, b if (!area) return false; - const ThermalCluster* cluster = area->thermal.list.find(clustername); + const ThermalCluster* cluster = area->thermal.list.findInAll(clustername); if (cluster) { uint val = fromStringToTSnumber(value); @@ -177,7 +177,7 @@ bool Rules::readRenewableCluster(const AreaName::Vector& splitKey, String value, if (!area) return false; - const RenewableCluster* cluster = area->renewable.list.find(clustername); + const RenewableCluster* cluster = area->renewable.list.findInAll(clustername); if (cluster) { diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index 58055cc388..f9c7c3d72d 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -1048,12 +1048,12 @@ bool Study::clusterRename(Cluster* cluster, ClusterName newName) if (dynamic_cast(cluster)) { - found = area.thermal.list.find(newID); + found = area.thermal.list.findInAll(newID); type = kThermal; } else if (dynamic_cast(cluster)) { - found = area.renewable.list.find(newID); + found = area.renewable.list.findInAll(newID); type = kRenewable; } diff --git a/src/tests/src/libs/antares/study/test_study.cpp b/src/tests/src/libs/antares/study/test_study.cpp index c71346966f..d90029d578 100644 --- a/src/tests/src/libs/antares/study/test_study.cpp +++ b/src/tests/src/libs/antares/study/test_study.cpp @@ -86,11 +86,11 @@ BOOST_FIXTURE_TEST_CASE(thermal_cluster_delete, OneAreaStudy) areaA->thermal.list.add(disabledCluster); areaA->thermal.list.addToCompleteList(disabledCluster); // Check that "Cluster1" is found - BOOST_CHECK_EQUAL(areaA->thermal.list.find("cluster1"), disabledCluster.get()); + BOOST_CHECK_EQUAL(areaA->thermal.list.findInAll("cluster1"), disabledCluster.get()); study.initializeRuntimeInfos(); // This should remove all disabled thermal clusters // Check that "Cluster1" isn't found - BOOST_CHECK_EQUAL(areaA->thermal.list.find("cluster1"), nullptr); + BOOST_CHECK_EQUAL(areaA->thermal.list.findInAll("cluster1"), nullptr); } BOOST_FIXTURE_TEST_CASE(renewable_cluster_delete, OneAreaStudy) @@ -102,11 +102,11 @@ BOOST_FIXTURE_TEST_CASE(renewable_cluster_delete, OneAreaStudy) areaA->renewable.list.add(disabledCluster); areaA->renewable.list.addToCompleteList(disabledCluster); // Check that "Cluster1" is found - BOOST_CHECK_EQUAL(areaA->renewable.list.find("cluster1"), disabledCluster.get()); + BOOST_CHECK_EQUAL(areaA->renewable.list.findInAll("cluster1"), disabledCluster.get()); study.initializeRuntimeInfos(); // This should remove all disabled renewable clusters // Check that "Cluster1" isn't found - BOOST_CHECK_EQUAL(areaA->renewable.list.find("cluster1"), nullptr); + BOOST_CHECK_EQUAL(areaA->renewable.list.findInAll("cluster1"), nullptr); } BOOST_FIXTURE_TEST_CASE(short_term_storage_delete, OneAreaStudy) @@ -162,8 +162,8 @@ BOOST_FIXTURE_TEST_CASE(thermal_cluster_add, OneAreaStudy) areaA->thermal.list.add(newCluster); areaA->thermal.list.addToCompleteList(newCluster); - BOOST_CHECK_EQUAL(areaA->thermal.list.find("cluster"), newCluster.get()); - BOOST_CHECK_EQUAL(areaA->thermal.list.find("Cluster"), nullptr); + BOOST_CHECK_EQUAL(areaA->thermal.list.findInAll("cluster"), newCluster.get()); + BOOST_CHECK_EQUAL(areaA->thermal.list.findInAll("Cluster"), nullptr); } /*! @@ -194,9 +194,9 @@ BOOST_FIXTURE_TEST_CASE(thermal_cluster_rename, ThermalClusterStudy) BOOST_FIXTURE_TEST_CASE(thermal_cluster_delete, ThermalClusterStudy) { - BOOST_CHECK(areaA->thermal.list.find("cluster") == cluster); + BOOST_CHECK(areaA->thermal.list.findInAll("cluster") == cluster); areaA->thermal.list.remove("cluster"); - BOOST_CHECK(areaA->thermal.list.find("cluster") == nullptr); + BOOST_CHECK(areaA->thermal.list.findInAll("cluster") == nullptr); BOOST_CHECK(areaA->thermal.list.empty()); } @@ -213,8 +213,8 @@ BOOST_FIXTURE_TEST_CASE(renewable_cluster_add, OneAreaStudy) areaA->renewable.list.add(newCluster); areaA->renewable.list.addToCompleteList(newCluster); - BOOST_CHECK(areaA->renewable.list.find("windcluster") == newCluster.get()); - BOOST_CHECK(areaA->renewable.list.find("WindCluster") == nullptr); + BOOST_CHECK(areaA->renewable.list.findInAll("windcluster") == newCluster.get()); + BOOST_CHECK(areaA->renewable.list.findInAll("WindCluster") == nullptr); } @@ -247,9 +247,9 @@ BOOST_FIXTURE_TEST_CASE(renewable_cluster_rename, RenewableClusterStudy) BOOST_FIXTURE_TEST_CASE(renewable_cluster_delete, RenewableClusterStudy) { - BOOST_CHECK(areaA->renewable.list.find("windcluster") == cluster); + BOOST_CHECK(areaA->renewable.list.findInAll("windcluster") == cluster); BOOST_CHECK(areaA->renewable.list.remove("windcluster")); - BOOST_CHECK(areaA->renewable.list.find("windcluster") == nullptr); + BOOST_CHECK(areaA->renewable.list.findInAll("windcluster") == nullptr); BOOST_CHECK(areaA->renewable.list.empty()); } diff --git a/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp b/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp index 3b79f26642..426518405e 100644 --- a/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp +++ b/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp @@ -150,7 +150,7 @@ BOOST_AUTO_TEST_SUITE(s) BOOST_FIXTURE_TEST_CASE(ThermalClusterList_loadFromFolder_basic, FixtureFull) { clusterList.loadFromFolder(*study, folder, area); - auto cluster = clusterList.find("some cluster"); + auto cluster = clusterList.findInAll("some cluster"); BOOST_CHECK(cluster->startupCost == 70000.0); BOOST_CHECK(cluster->costgeneration == useCostTimeseries); @@ -161,7 +161,7 @@ BOOST_FIXTURE_TEST_CASE(ThermalClusterList_loadFromFolder_basic, FixtureFull) BOOST_FIXTURE_TEST_CASE(checkCo2_checkCO2CostColumnNumber_OK, FixtureFull) { area->thermal.list.loadFromFolder(*study, folder, area); - auto cluster = area->thermal.list.find("some cluster"); + auto cluster = area->thermal.list.findInAll("some cluster"); cluster->series.timeSeries.reset(3, 8760); area->thermal.list.giveIndicesToClusters(); @@ -175,7 +175,7 @@ BOOST_FIXTURE_TEST_CASE(checkCo2_checkCO2CostColumnNumber_OK, FixtureFull) BOOST_FIXTURE_TEST_CASE(checkCo2_checkCO2CostColumnNumber_KO, FixtureFull) { area->thermal.list.loadFromFolder(*study, folder, area); - auto cluster = area->thermal.list.find("some cluster"); + auto cluster = area->thermal.list.findInAll("some cluster"); cluster->series.timeSeries.reset(3, 8760); @@ -191,7 +191,7 @@ BOOST_FIXTURE_TEST_CASE(checkCo2_checkCO2CostColumnNumber_KO, FixtureFull) BOOST_FIXTURE_TEST_CASE(checkFuelAndCo2_checkColumnNumber_OK, FixtureFull) { area->thermal.list.loadFromFolder(*study, folder, area); - auto cluster = area->thermal.list.find("some cluster"); + auto cluster = area->thermal.list.findInAll("some cluster"); cluster->series.timeSeries.reset(3, 8760); @@ -207,7 +207,7 @@ BOOST_FIXTURE_TEST_CASE(checkFuelAndCo2_checkColumnNumber_OK, FixtureFull) BOOST_FIXTURE_TEST_CASE(ThermalCluster_costGenManualCalculationOfMarketBidAndMarginalCostPerHour, FixtureFull) { clusterList.loadFromFolder(*study, folder, area); - auto cluster = clusterList.find("some cluster"); + auto cluster = clusterList.findInAll("some cluster"); cluster->costgeneration = Data::setManually; cluster->ComputeCostTimeSeries(); @@ -222,7 +222,7 @@ BOOST_FIXTURE_TEST_CASE(ThermalCluster_costGenTimeSeriesCalculationOfMarketBidAn TimeSeriesFile co2("CO2Cost.txt", 8760); clusterList.loadFromFolder(*study, folder, area); - auto cluster = clusterList.find("some cluster"); + auto cluster = clusterList.findInAll("some cluster"); cluster->modulation.reset(1, 8760); cluster->ecoInput.loadFromFolder(*study, folder); @@ -237,7 +237,7 @@ BOOST_FIXTURE_TEST_CASE(ThermalCluster_costGenTimeSeriesCalculationOfMarketBidAn BOOST_FIXTURE_TEST_CASE(computeMarketBidCost, FixtureFull) { clusterList.loadFromFolder(*study, folder, area); - auto cluster = clusterList.find("some cluster"); + auto cluster = clusterList.findInAll("some cluster"); BOOST_CHECK_CLOSE(cluster->computeMarketBidCost(1, 2, 1), 24.12, 0.001); } diff --git a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp index 6cbcc2b2ad..1439b12ed3 100644 --- a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp +++ b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp @@ -86,7 +86,7 @@ bool Create::prepareWL(Context& ctx) if (suffix == "" || pInfos.behavior == bhMerge) { TransformNameIntoID(pFuturPlantName, id); - clusterFound = area ? area->thermal.list.find(id) : nullptr; + clusterFound = area ? area->thermal.list.findInAll(id) : nullptr; if (clusterFound) { Data::AreaName::Size sepPos = id.find_last_of('-'); @@ -107,7 +107,7 @@ bool Create::prepareWL(Context& ctx) pFuturPlantName.clear() << pTargetPlantName << "-" << indx; id.clear(); TransformNameIntoID(pFuturPlantName, id); - clusterFound = area->thermal.list.find(id); + clusterFound = area->thermal.list.findInAll(id); } while (clusterFound); } } @@ -115,13 +115,13 @@ bool Create::prepareWL(Context& ctx) { pFuturPlantName += suffix; TransformNameIntoID(pFuturPlantName, id); - clusterFound = area ? area->thermal.list.find(id) : nullptr; + clusterFound = area ? area->thermal.list.findInAll(id) : nullptr; } } else { TransformNameIntoID(pFuturPlantName, id); - clusterFound = area ? area->thermal.list.find(id) : nullptr; + clusterFound = area ? area->thermal.list.findInAll(id) : nullptr; } pInfos.caption.clear() << "Plant " << pFuturPlantName; @@ -167,7 +167,7 @@ bool Create::performWL(Context& ctx) if (!source) return false; TransformNameIntoID(pOriginalPlantName, id); - ctx.originalPlant = source->thermal.list.find(id); + ctx.originalPlant = source->thermal.list.findInAll(id); if (!ctx.originalPlant) return false; @@ -175,7 +175,7 @@ bool Create::performWL(Context& ctx) id.clear(); TransformNameIntoID(pFuturPlantName, id); - ctx.cluster = ctx.area->thermal.list.find(id); + ctx.cluster = ctx.area->thermal.list.findInAll(id); if (!ctx.cluster) { ctx.cluster = new Data::ThermalCluster(ctx.area); diff --git a/src/ui/simulator/toolbox/input/renewable-cluster.cpp b/src/ui/simulator/toolbox/input/renewable-cluster.cpp index 2432c8bf98..d32a74821d 100644 --- a/src/ui/simulator/toolbox/input/renewable-cluster.cpp +++ b/src/ui/simulator/toolbox/input/renewable-cluster.cpp @@ -373,7 +373,7 @@ void RenewableCluster::internalAddPlant(void*) // Trying to find an uniq name YString sFl; sFl.clear() << "new cluster"; - while (pArea->renewable.list.find(sFl)) + while (pArea->renewable.list.findInAll(sFl)) { ++indx; sFl.clear() << "new cluster " << indx; @@ -410,7 +410,7 @@ void RenewableCluster::internalClonePlant(void*) if (!pArea || !pLastSelectedRenewableCluster) return; - if (!pArea->renewable.list.find(pLastSelectedRenewableCluster->renewableAggregate()->id())) + if (!pArea->renewable.list.findInAll(pLastSelectedRenewableCluster->renewableAggregate()->id())) { // The selected has been obviously invalidated pLastSelectedRenewableCluster = nullptr; @@ -449,7 +449,7 @@ void RenewableCluster::internalClonePlant(void*) YString sFl; sFl << copy << indx; // lowercase - while (pArea->renewable.list.find(sFl)) + while (pArea->renewable.list.findInAll(sFl)) { ++indx; sFl.clear() << copy << indx; diff --git a/src/ui/simulator/toolbox/input/thermal-cluster.cpp b/src/ui/simulator/toolbox/input/thermal-cluster.cpp index 389aeadb83..e46a886f65 100644 --- a/src/ui/simulator/toolbox/input/thermal-cluster.cpp +++ b/src/ui/simulator/toolbox/input/thermal-cluster.cpp @@ -432,7 +432,7 @@ void ThermalCluster::internalAddPlant(void*) // Trying to find an uniq name YString sFl; sFl.clear() << "new cluster"; - while (pArea->thermal.list.find(sFl)) + while (pArea->thermal.list.findInAll(sFl)) { ++indx; sFl.clear() << "new cluster " << indx; @@ -470,7 +470,7 @@ void ThermalCluster::internalClonePlant(void*) if (!pArea || !pLastSelectedThermalCluster) return; - if (!pArea->thermal.list.find(pLastSelectedThermalCluster->thermalAggregate()->id())) + if (!pArea->thermal.list.findInAll(pLastSelectedThermalCluster->thermalAggregate()->id())) { // The selected has been obviously invalidated pLastSelectedThermalCluster = nullptr; @@ -509,7 +509,7 @@ void ThermalCluster::internalClonePlant(void*) YString sFl; sFl << copy << indx; // lowercase - while (pArea->thermal.list.find(sFl)) + while (pArea->thermal.list.findInAll(sFl)) { ++indx; sFl.clear() << copy << indx; From 86aab4d7809ab959caed6665de38b6eb41e86875 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 11 Jan 2024 16:58:49 +0100 Subject: [PATCH 54/88] Clean thermal lists (towards removal of thermal.list.clusters) : remove size() function --- .../antares/study/parts/common/cluster_list.cpp | 14 +++++++------- .../antares/study/parts/common/cluster_list.h | 4 +--- .../antares/study/parts/thermal/cluster_list.cpp | 15 +++++++++------ .../antares/study/parts/thermal/cluster_list.h | 2 +- src/libs/antares/study/runtime/runtime.cpp | 2 +- .../scenario-builder/RenewableTSNumberData.cpp | 10 +--------- .../scenario-builder/ThermalTSNumberData.cpp | 2 +- src/solver/simulation/common-eco-adq.cpp | 2 +- .../simulation/sim_alloc_probleme_hebdo.cpp | 2 +- src/solver/simulation/sim_calcul_economique.cpp | 7 ++++--- src/solver/simulation/solver.hxx | 2 +- src/solver/simulation/timeseries-numbers.cpp | 7 +++++-- .../variable/economy/productionByRenewablePlant.h | 2 +- .../renderer/area/renewable.areasummary.cpp | 6 +++--- .../renderer/area/renewable.areasummary.h | 2 +- .../renderer/area/thermal.areasummary.cpp | 6 +++--- .../datagrid/renderer/area/thermal.areasummary.h | 2 +- .../scenario-builder-renewable-renderer.cpp | 8 ++++---- .../scenario-builder-thermal-renderer.cpp | 8 ++++---- src/ui/simulator/toolbox/input/area.cpp | 8 ++++---- src/ui/simulator/windows/inspector/frame.cpp | 2 +- 21 files changed, 55 insertions(+), 58 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 9414ceac30..a1974df64c 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -21,12 +21,6 @@ namespace Antares::Data { using namespace Antares; -template -inline uint ClusterList::size() const -{ - return (uint)clusters.size(); // gp : function not removed because used in GUI where it contains all clusters -} - template inline bool ClusterList::empty() const { @@ -154,6 +148,12 @@ unsigned int ClusterList::enabledCount() const return count; } +template +unsigned int ClusterList::allClustersCount() const +{ + return allClusters.size(); +} + template bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName newName) { @@ -249,7 +249,7 @@ bool ClusterList::saveDataSeriesToFolder(const AnyString& folder, cons return std::ranges::all_of(clusters, [&](const auto& c) { - logs.info() << msg << " " << (ticks * 100 / (1 + this->clusters.size())) + logs.info() << msg << " " << (ticks * 100 / (1 + this->allClustersCount())) << "% complete"; ++ticks; return c->saveDataSeriesToFolder(folder); diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 4bd547dbec..182c5e495c 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -92,9 +92,6 @@ class ClusterList */ virtual bool remove(const Data::ClusterName& id); - // gp : not removed because used in GUI where it contains all clusters - uint size() const; - //! Return true if the list is empty bool empty() const; //@} @@ -172,6 +169,7 @@ class ClusterList */ uint removeDisabledClusters(); unsigned int enabledCount() const; + unsigned int allClustersCount() const; void addToCompleteList(std::shared_ptr cluster); protected: diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 11fb8cc494..e6dc8ce817 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -78,6 +78,14 @@ void ThermalClusterList::giveIndicesToClusters() } } +unsigned int ThermalClusterList::enabledAndNotMustRunCount() const +{ + unsigned int count = 0; + for (auto cluster : each_enabled_and_not_mustrun()) + count++; + return count; +} + unsigned int ThermalClusterList::mustRunAndEnabledCount() const { unsigned int count = 0; @@ -209,11 +217,6 @@ void ThermalClusterList::clearAll() allClusters.clear(); } -unsigned int ThermalClusterList::allClustersSize() -{ - return allClusters.size(); -} - static bool ThermalClusterLoadFromProperty(ThermalCluster& cluster, const IniFile::Property* p) { if (p->key.empty()) @@ -337,7 +340,7 @@ bool ThermalClusterLoadFromSection(const AnyString& filename, void ThermalClusterList::calculationOfSpinning() { - for (auto cluster : each_enabled()) + for (auto cluster : each_enabled_and_not_mustrun()) cluster->calculationOfSpinning(); } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 8c4dd96a24..096f147ec0 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -102,10 +102,10 @@ class ThermalClusterList : public ClusterList void sortCompleteList(); void giveIndicesToClusters(); unsigned int mustRunAndEnabledCount() const; + unsigned int enabledAndNotMustRunCount() const; std::shared_ptr enabledClusterAt(unsigned int index) const; void removeMustRunClusters(); void clearAll(); - unsigned int allClustersSize(); }; // class ThermalClusterList } // namespace Data diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index 6e4690ca97..ebbe0ff08d 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -92,7 +92,7 @@ static void StudyRuntimeInfosInitializeAllAreas(Study& study, StudyRuntimeInfos& area.scratchpad.emplace_back(r, area); // statistics - r.thermalPlantTotalCount += area.thermal.list.size(); + r.thermalPlantTotalCount += area.thermal.list.enabledAndNotMustRunCount(); r.thermalPlantTotalCountMustRun += area.thermal.list.mustRunAndEnabledCount(); r.shortTermStorageCount += area.shortTermStorage.count(); diff --git a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp index 808fa9f93b..3d9c557b6e 100644 --- a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp @@ -66,14 +66,6 @@ void renewableTSNumberData::saveToINIFile(const Study& /* study */, if (!pArea) return; -// Foreach year -#ifndef NDEBUG - if (pTSNumberRules.width) - { - assert(pTSNumberRules.width == pArea->renewable.list.size()); - } -#endif - for (uint index = 0; index != pTSNumberRules.width; ++index) { // Foreach renewable cluster... @@ -99,7 +91,7 @@ bool renewableTSNumberData::reset(const Study& study) // solver or not. // WARNING: At this point in time, the variable pArea->renewable.clusterCount() // might not be valid (because not really initialized yet) - const uint clusterCount = pArea->renewable.list.size(); + const uint clusterCount = pArea->renewable.list.allClustersCount(); // Resize pTSNumberRules.reset(clusterCount, nbYears); return true; diff --git a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp index be2a2a6f72..82b84c66de 100644 --- a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp @@ -19,7 +19,7 @@ bool thermalTSNumberData::reset(const Study& study) // might not be valid (because not really initialized yet) uint clusterCount = (study.usedByTheSolver) ? (pArea->thermal.list.enabledCount()) - : pArea->thermal.list.size(); + : pArea->thermal.list.allClustersCount(); // Resize pTSNumberRules.reset(clusterCount, nbYears); diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index 525500ff40..3d4262234c 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -395,7 +395,7 @@ void BuildThermalPartOfWeeklyProblem(Data::Study& study, { auto& area = *study.areas.byIndex[k]; - for (uint l = 0; l != area.thermal.list.size(); ++l) + for (uint l = 0; l != area.thermal.list.enabledAndNotMustRunCount(); ++l) { problem.PaliersThermiquesDuPays[k].PuissanceDisponibleEtCout[l] .PuissanceDisponibleDuPalierThermiqueRef diff --git a/src/solver/simulation/sim_alloc_probleme_hebdo.cpp b/src/solver/simulation/sim_alloc_probleme_hebdo.cpp index 80c5ad5edb..5867cda436 100644 --- a/src/solver/simulation/sim_alloc_probleme_hebdo.cpp +++ b/src/solver/simulation/sim_alloc_probleme_hebdo.cpp @@ -349,7 +349,7 @@ void SIM_AllocateAreas(PROBLEME_HEBDO& problem, for (unsigned k = 0; k < nbPays; k++) { - const uint nbPaliers = study.areas.byIndex[k]->thermal.list.size(); + const uint nbPaliers = study.areas.byIndex[k]->thermal.list.enabledAndNotMustRunCount(); problem.PaliersThermiquesDuPays[k].minUpDownTime.assign(nbPaliers, 0); problem.PaliersThermiquesDuPays[k].PminDuPalierThermiquePendantUneHeure diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 23315d4ef4..962f368291 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -281,9 +281,10 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study, auto& area = *(study.areas.byIndex[i]); auto& pbPalier = problem.PaliersThermiquesDuPays[i]; - pbPalier.NombreDePaliersThermiques = area.thermal.list.size(); + unsigned int clusterCount = area.thermal.list.enabledAndNotMustRunCount(); + pbPalier.NombreDePaliersThermiques = clusterCount; - for (uint clusterIndex = 0; clusterIndex != area.thermal.list.size(); ++clusterIndex) + for (uint clusterIndex = 0; clusterIndex != clusterCount; ++clusterIndex) { auto& cluster = *(area.thermal.list[clusterIndex]); pbPalier.NumeroDuPalierDansLEnsembleDesPaliersThermiques[clusterIndex] @@ -311,7 +312,7 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study, pbPalier.NomsDesPaliersThermiques[clusterIndex] = cluster.name().c_str(); } - NombrePaliers += area.thermal.list.size(); + NombrePaliers += clusterCount; } problem.NombreDePaliersThermiques = NombrePaliers; diff --git a/src/solver/simulation/solver.hxx b/src/solver/simulation/solver.hxx index 9108082d9a..95ee78855c 100644 --- a/src/solver/simulation/solver.hxx +++ b/src/solver/simulation/solver.hxx @@ -627,7 +627,7 @@ void ISimulation::allocateMemoryForRandomNumbers(randomNumbers& randomForP { // logs.info() << " area : " << a << " :"; auto& area = *(study.areas.byIndex[a]); - size_t nbClusters = area.thermal.list.allClustersSize(); + size_t nbClusters = area.thermal.list.allClustersCount(); randomForParallelYears.pYears[y].pThermalNoisesByArea[a] = new double[nbClusters]; randomForParallelYears.pYears[y].pNbClustersByArea[a] = nbClusters; } diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 4f05e9e198..23b8428244 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -735,8 +735,11 @@ Matrix* getFirstTSnumberInterModalMatrixFoundInArea( tsNumbersMtx = &(cluster->series.timeseriesNumbers); } else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)] - && area.renewable.list.size() > 0) - tsNumbersMtx = &(area.renewable.list[0]->series.timeseriesNumbers); + && area.renewable.list.enabledCount() > 0) + { + std::shared_ptr cluster = *(area.renewable.list.each_enabled().begin()); + tsNumbersMtx = &(cluster->series.timeseriesNumbers); + } } assert(tsNumbersMtx); diff --git a/src/solver/variable/economy/productionByRenewablePlant.h b/src/solver/variable/economy/productionByRenewablePlant.h index e1b08a189f..03309e540c 100644 --- a/src/solver/variable/economy/productionByRenewablePlant.h +++ b/src/solver/variable/economy/productionByRenewablePlant.h @@ -159,7 +159,7 @@ class ProductionByRenewablePlant : public Variable::IVariablerenewable.list.size(); + pSize = area->renewable.list.enabledCount(); if (pSize) { AncestorType::pResults.resize(pSize); diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp index db746f9632..7d284b10e4 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp @@ -70,7 +70,7 @@ wxString RenewableClusterSummarySingleArea::columnCaption(int colIndx) const wxString RenewableClusterSummarySingleArea::cellValue(int x, int y) const { - Data::RenewableCluster* cluster = (pArea and (uint) y < pArea->renewable.list.size()) + Data::RenewableCluster* cluster = (pArea and (uint) y < pArea->renewable.list.allClustersCount()) ? pArea->renewable.list[y].get() : nullptr; switch (x) @@ -89,7 +89,7 @@ wxString RenewableClusterSummarySingleArea::cellValue(int x, int y) const double RenewableClusterSummarySingleArea::cellNumericValue(int x, int y) const { - Data::RenewableCluster* cluster = (pArea and (uint) y < pArea->renewable.list.size()) + Data::RenewableCluster* cluster = (pArea and (uint) y < pArea->renewable.list.allClustersCount()) ? pArea->renewable.list[y].get() : nullptr; // gp : do we wish to have the line empty if cluster disabled @@ -111,7 +111,7 @@ double RenewableClusterSummarySingleArea::cellNumericValue(int x, int y) const bool RenewableClusterSummarySingleArea::cellValue(int x, int y, const String& v) { - auto* cluster = (pArea and (uint) y < pArea->renewable.list.size()) + auto* cluster = (pArea and (uint) y < pArea->renewable.list.allClustersCount()) ? pArea->renewable.list[y].get() : nullptr; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.h b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.h index 9a891885a3..cfc212fc3c 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.h +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.h @@ -50,7 +50,7 @@ class RenewableClusterSummarySingleArea : public CommonClusterSummarySingleArea } virtual int height() const { - return (pArea) ? pArea->renewable.list.size() : 0; + return (pArea) ? pArea->renewable.list.allClustersCount() : 0; } virtual wxString columnCaption(int colIndx) const override; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp index ce87ecace2..f82f541080 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp @@ -81,7 +81,7 @@ wxString ThermalClusterSummarySingleArea::columnCaption(int colIndx) const wxString ThermalClusterSummarySingleArea::cellValue(int x, int y) const { - Data::ThermalCluster* cluster = (pArea and (uint) y < pArea->thermal.list.size()) + Data::ThermalCluster* cluster = (pArea and (uint) y < pArea->thermal.list.allClustersCount()) ? pArea->thermal.list[y].get() : nullptr; if (!cluster->enabled) @@ -124,7 +124,7 @@ wxString ThermalClusterSummarySingleArea::cellValue(int x, int y) const double ThermalClusterSummarySingleArea::cellNumericValue(int x, int y) const { - Data::ThermalCluster* cluster = (pArea and (uint) y < pArea->thermal.list.size()) + Data::ThermalCluster* cluster = (pArea and (uint) y < pArea->thermal.list.allClustersCount()) ? pArea->thermal.list[y].get() : nullptr; if (!cluster->enabled) @@ -167,7 +167,7 @@ double ThermalClusterSummarySingleArea::cellNumericValue(int x, int y) const bool ThermalClusterSummarySingleArea::cellValue(int x, int y, const String& v) { - auto* cluster = (pArea and (uint) y < pArea->thermal.list.size()) + auto* cluster = (pArea and (uint) y < pArea->thermal.list.allClustersCount()) ? pArea->thermal.list[y].get() : nullptr; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.h b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.h index 277459598b..e356fbc9f5 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.h +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.h @@ -50,7 +50,7 @@ class ThermalClusterSummarySingleArea : public CommonClusterSummarySingleArea } virtual int height() const override { - return (pArea) ? pArea->thermal.list.size() : 0; + return (pArea) ? pArea->thermal.list.allClustersCount() : 0; } virtual wxString columnCaption(int colIndx) const override; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp index f2af7d9660..2a059c3b6f 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp @@ -43,7 +43,7 @@ int renewableScBuilderRenderer::height() const { if (!(!study) && !(!pRules) && selectedArea()) { - return (int)selectedArea()->renewable.list.size(); + return (int)selectedArea()->renewable.list.allClustersCount(); } return 0; } @@ -51,7 +51,7 @@ int renewableScBuilderRenderer::height() const wxString renewableScBuilderRenderer::rowCaption(int rowIndx) const { if (!(!study) && !(!pRules) && selectedArea() - && (uint)rowIndx < selectedArea()->renewable.list.size()) + && (uint)rowIndx < selectedArea()->renewable.list.allClustersCount()) { return wxString() << wxT( " ") << wxStringFromUTF8(selectedArea()->renewable.list[rowIndx]->name()) @@ -63,7 +63,7 @@ wxString renewableScBuilderRenderer::rowCaption(int rowIndx) const bool renewableScBuilderRenderer::cellValue(int x, int y, const String& value) { if (!(!study) && !(!pRules) && (uint)x < study->parameters.nbYears && selectedArea() - && (uint)y < selectedArea()->renewable.list.size()) + && (uint)y < selectedArea()->renewable.list.allClustersCount()) { assert(selectedArea()->index < pRules->areaCount()); assert((uint)y < pRules->renewable[selectedArea()->index].width()); @@ -79,7 +79,7 @@ bool renewableScBuilderRenderer::cellValue(int x, int y, const String& value) double renewableScBuilderRenderer::cellNumericValue(int x, int y) const { if (!(!study) && !(!pRules) && (uint)x < study->parameters.nbYears && selectedArea() - && (uint)y < selectedArea()->renewable.list.size()) + && (uint)y < selectedArea()->renewable.list.allClustersCount()) { assert((uint)y < pRules->renewable[selectedArea()->index].width()); assert((uint)x < pRules->renewable[selectedArea()->index].height()); diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp index c8e333c1c8..032d1dcaa2 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp @@ -43,7 +43,7 @@ int thermalScBuilderRenderer::height() const { if (!(!study) && !(!pRules) && selectedArea()) { - return (int)selectedArea()->thermal.list.size(); + return (int)selectedArea()->thermal.list.allClustersCount(); } return 0; } @@ -51,7 +51,7 @@ int thermalScBuilderRenderer::height() const wxString thermalScBuilderRenderer::rowCaption(int rowIndx) const { if (!(!study) && !(!pRules) && selectedArea() - && (uint)rowIndx < selectedArea()->thermal.list.size()) + && (uint)rowIndx < selectedArea()->thermal.list.allClustersCount()) { return wxString() << wxT(" ") << wxStringFromUTF8(selectedArea()->thermal.list[rowIndx]->name()) @@ -63,7 +63,7 @@ wxString thermalScBuilderRenderer::rowCaption(int rowIndx) const bool thermalScBuilderRenderer::cellValue(int x, int y, const String& value) { if (!(!study) && !(!pRules) && (uint)x < study->parameters.nbYears && selectedArea() - && (uint)y < selectedArea()->thermal.list.size()) + && (uint)y < selectedArea()->thermal.list.allClustersCount()) { assert(selectedArea()->index < pRules->areaCount()); assert((uint)y < pRules->thermal[selectedArea()->index].width()); @@ -78,7 +78,7 @@ bool thermalScBuilderRenderer::cellValue(int x, int y, const String& value) double thermalScBuilderRenderer::cellNumericValue(int x, int y) const { if (!(!study) && !(!pRules) && (uint)x < study->parameters.nbYears && selectedArea() - && (uint)y < selectedArea()->thermal.list.size()) + && (uint)y < selectedArea()->thermal.list.allClustersCount()) { assert((uint)y < pRules->thermal[selectedArea()->index].width()); assert((uint)x < pRules->thermal[selectedArea()->index].height()); diff --git a/src/ui/simulator/toolbox/input/area.cpp b/src/ui/simulator/toolbox/input/area.cpp index ff6e3d3dd3..a8a8fad7d2 100644 --- a/src/ui/simulator/toolbox/input/area.cpp +++ b/src/ui/simulator/toolbox/input/area.cpp @@ -225,10 +225,10 @@ class SpotlightProviderArea final : public Component::Spotlight::IProvider if (0 != (equipment & Data::timeSeriesThermal)) { - if (area->thermal.list.size() > 0) + if (area->thermal.list.allClustersCount() > 0) { CString<32, false> text; - text << area->thermal.list.size(); + text << area->thermal.list.allClustersCount(); const uint8_t R_COLOR = 210; const uint8_t G_COLOR = 217; const uint8_t B_COLOR = 216; @@ -241,10 +241,10 @@ class SpotlightProviderArea final : public Component::Spotlight::IProvider } if (0 != (equipment & Data::timeSeriesRenewable)) { - if (area->renewable.list.size() > 0) + if (area->renewable.list.allClustersCount() > 0) { CString<32, false> text; - text << area->renewable.list.size(); + text << area->renewable.list.allClustersCount(); item->addRightTag(text, 210, 217, 216); } } diff --git a/src/ui/simulator/windows/inspector/frame.cpp b/src/ui/simulator/windows/inspector/frame.cpp index 7ec3c35df7..7a82e2d292 100644 --- a/src/ui/simulator/windows/inspector/frame.cpp +++ b/src/ui/simulator/windows/inspector/frame.cpp @@ -783,7 +783,7 @@ void Frame::apply(const InspectorData::Ptr& data) { const Data::Area& area = *(*i); nbLinks += (uint)area.links.size(); - nbThermalClusters += area.thermal.list.size(); + nbThermalClusters += area.thermal.list.allClustersCount(); } pPGAreaLinks->SetValueFromInt(nbLinks); pPGAreaPlants->SetValueFromInt(nbThermalClusters); From 7c9ce23d401bf11d30f8efbc44d2aa851b0d58da Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 11 Jan 2024 17:35:30 +0100 Subject: [PATCH 55/88] Clean thermal lists (towards removal of thermal.list.clusters) : some more replacements --- src/libs/antares/study/runtime/runtime.cpp | 9 ++++----- .../study/scenario-builder/ThermalTSNumberData.cpp | 14 ++++++-------- src/libs/antares/study/study.cpp | 9 ++++----- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index ebbe0ff08d..713a203b8c 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -257,11 +257,10 @@ void StudyRuntimeInfos::checkThermalTSGeneration(Study& study) thermalTSRefresh = globalThermalTSgeneration; study.areas.each([this, globalThermalTSgeneration](Data::Area& area) { - area.thermal.list.each( - [this, globalThermalTSgeneration](const Data::ThermalCluster& cluster) { - thermalTSRefresh - = thermalTSRefresh || cluster.doWeGenerateTS(globalThermalTSgeneration); - }); + for (auto c : area.thermal.list.each_enabled_and_not_mustrun()) + { + thermalTSRefresh = thermalTSRefresh || c->doWeGenerateTS(globalThermalTSgeneration); + } }); } diff --git a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp index 82b84c66de..a8ed6b812c 100644 --- a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp @@ -35,19 +35,17 @@ void thermalTSNumberData::saveToINIFile(const Study& /* study */, if (!pArea) return; - - // Foreach thermal cluster... - for (uint index = 0; index != pTSNumberRules.width; ++index) + + for (auto cluster : pArea->thermal.list.all()) { - // Foreach year ... - for (uint y = 0; y != pTSNumberRules.height; ++y) + for (uint year = 0; year != pTSNumberRules.height; ++year) { - const uint val = get(pArea->thermal.list[index].get(), y); + const uint val = get(cluster.get(), year); // Equals to zero means 'auto', which is the default mode if (!val) continue; - file << prefix << pArea->id << "," << y << ',' - << pArea->thermal.list[index]->id() << " = " << val << '\n'; + file << prefix << pArea->id << "," << year << ',' + << cluster->id() << " = " << val << '\n'; } } } diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index f9c7c3d72d..f2b5cf09ea 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -1128,7 +1128,7 @@ void Study::destroyAllWindTSGeneratorData() void Study::destroyAllThermalTSGeneratorData() { areas.each([&](Data::Area& area) { - for (const auto& cluster : area.thermal.list) + for (const auto cluster : area.thermal.list.each_enabled_and_not_mustrun()) FreeAndNil(cluster->prepro); }); } @@ -1414,10 +1414,9 @@ bool Study::checkForFilenameLimits(bool output, const String& chfolder) const auto& cname = clustername; cname.clear(); - area.thermal.list.each([&](const Cluster& cluster) { - if (cluster.id().size() > cname.size()) - cname = cluster.id(); - }); + for (auto cluster : area.thermal.list.all()) + if (cluster->id().size() > cname.size()) + cname = cluster->id(); }); String filename; From f07c4354f3f34b91b4b6bfadd9c4aedc8d5e56a3 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 11 Jan 2024 17:57:19 +0100 Subject: [PATCH 56/88] Clean thermal lists (towards removal of thermal.list.clusters) : some more replacements --- .../study/parts/thermal/cluster_list.cpp | 2 +- src/solver/simulation/common-eco-adq.cpp | 16 +++--- .../simulation/sim_calcul_economique.cpp | 49 +++++++++---------- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index e6dc8ce817..942d27db22 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -346,7 +346,7 @@ void ThermalClusterList::calculationOfSpinning() void ThermalClusterList::reverseCalculationOfSpinning() { - for (auto cluster : each_enabled()) + for (auto cluster : each_enabled_and_not_mustrun()) cluster->reverseCalculationOfSpinning(); } diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index 3d4262234c..900f6cc6dc 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -371,23 +371,23 @@ void BuildThermalPartOfWeeklyProblem(Data::Study& study, for (uint areaIdx = 0; areaIdx < nbPays; ++areaIdx) { auto& area = *study.areas.byIndex[areaIdx]; - area.thermal.list.each([&](const Data::ThermalCluster& cluster) + for (auto cluster : area.thermal.list.each_enabled_and_not_mustrun()) { auto& Pt = problem.PaliersThermiquesDuPays[areaIdx] - .PuissanceDisponibleEtCout[cluster.index]; + .PuissanceDisponibleEtCout[cluster->index]; Pt.CoutHoraireDeProductionDuPalierThermique[hourInWeek] = - cluster.getMarketBidCost(hourInYear, year) - + thermalNoises[areaIdx][cluster.areaWideIndex]; + cluster->getMarketBidCost(hourInYear, year) + + thermalNoises[areaIdx][cluster->areaWideIndex]; Pt.PuissanceDisponibleDuPalierThermique[hourInWeek] - = cluster.series.getCoefficient(year, hourInYear); + = cluster->series.getCoefficient(year, hourInYear); Pt.PuissanceMinDuPalierThermique[hourInWeek] - = (Pt.PuissanceDisponibleDuPalierThermique[hourInWeek] < cluster.PthetaInf[hourInYear]) + = (Pt.PuissanceDisponibleDuPalierThermique[hourInWeek] < cluster->PthetaInf[hourInYear]) ? Pt.PuissanceDisponibleDuPalierThermique[hourInWeek] - : cluster.PthetaInf[hourInYear]; - }); + : cluster->PthetaInf[hourInYear]; + } } } diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 962f368291..a6bd1bf6fd 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -284,32 +284,31 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study, unsigned int clusterCount = area.thermal.list.enabledAndNotMustRunCount(); pbPalier.NombreDePaliersThermiques = clusterCount; - for (uint clusterIndex = 0; clusterIndex != clusterCount; ++clusterIndex) + for (auto cluster : area.thermal.list.each_enabled_and_not_mustrun()) { - auto& cluster = *(area.thermal.list[clusterIndex]); - pbPalier.NumeroDuPalierDansLEnsembleDesPaliersThermiques[clusterIndex] - = NombrePaliers + clusterIndex; - pbPalier.TailleUnitaireDUnGroupeDuPalierThermique[clusterIndex] - = cluster.nominalCapacityWithSpinning; - pbPalier.PminDuPalierThermiquePendantUneHeure[clusterIndex] = cluster.minStablePower; - pbPalier.PminDuPalierThermiquePendantUnJour[clusterIndex] = 0; - pbPalier.minUpDownTime[clusterIndex] = cluster.minUpDownTime; - - pbPalier.CoutDeDemarrageDUnGroupeDuPalierThermique[clusterIndex] = cluster.startupCost; - pbPalier.CoutDArretDUnGroupeDuPalierThermique[clusterIndex] = 0; - pbPalier.CoutFixeDeMarcheDUnGroupeDuPalierThermique[clusterIndex] = cluster.fixedCost; - pbPalier.DureeMinimaleDeMarcheDUnGroupeDuPalierThermique[clusterIndex] - = cluster.minUpTime; - pbPalier.DureeMinimaleDArretDUnGroupeDuPalierThermique[clusterIndex] - = cluster.minDownTime; - - pbPalier.PmaxDUnGroupeDuPalierThermique[clusterIndex] - = cluster.nominalCapacityWithSpinning; - pbPalier.pminDUnGroupeDuPalierThermique[clusterIndex] - = (pbPalier.PmaxDUnGroupeDuPalierThermique[clusterIndex] < cluster.minStablePower) - ? pbPalier.PmaxDUnGroupeDuPalierThermique[clusterIndex] - : cluster.minStablePower; - pbPalier.NomsDesPaliersThermiques[clusterIndex] = cluster.name().c_str(); + pbPalier.NumeroDuPalierDansLEnsembleDesPaliersThermiques[cluster->index] + = NombrePaliers + cluster->index; + pbPalier.TailleUnitaireDUnGroupeDuPalierThermique[cluster->index] + = cluster->nominalCapacityWithSpinning; + pbPalier.PminDuPalierThermiquePendantUneHeure[cluster->index] = cluster->minStablePower; + pbPalier.PminDuPalierThermiquePendantUnJour[cluster->index] = 0; + pbPalier.minUpDownTime[cluster->index] = cluster->minUpDownTime; + + pbPalier.CoutDeDemarrageDUnGroupeDuPalierThermique[cluster->index] = cluster->startupCost; + pbPalier.CoutDArretDUnGroupeDuPalierThermique[cluster->index] = 0; + pbPalier.CoutFixeDeMarcheDUnGroupeDuPalierThermique[cluster->index] = cluster->fixedCost; + pbPalier.DureeMinimaleDeMarcheDUnGroupeDuPalierThermique[cluster->index] + = cluster->minUpTime; + pbPalier.DureeMinimaleDArretDUnGroupeDuPalierThermique[cluster->index] + = cluster->minDownTime; + + pbPalier.PmaxDUnGroupeDuPalierThermique[cluster->index] + = cluster->nominalCapacityWithSpinning; + pbPalier.pminDUnGroupeDuPalierThermique[cluster->index] + = (pbPalier.PmaxDUnGroupeDuPalierThermique[cluster->index] < cluster->minStablePower) + ? pbPalier.PmaxDUnGroupeDuPalierThermique[cluster->index] + : cluster->minStablePower; + pbPalier.NomsDesPaliersThermiques[cluster->index] = cluster->name().c_str(); } NombrePaliers += clusterCount; From b170898634749217827027e34a6f0ac1e063a9a0 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 12 Jan 2024 08:39:14 +0100 Subject: [PATCH 57/88] Clean thermal lists (towards removal of thermal.list.clusters) : replacement and a move of enabledClusterAt to parent class --- src/libs/antares/study/parts/common/cluster_list.cpp | 8 ++++++++ src/libs/antares/study/parts/common/cluster_list.h | 6 ++++-- src/libs/antares/study/parts/thermal/cluster_list.cpp | 7 ------- src/libs/antares/study/parts/thermal/cluster_list.h | 1 - src/solver/variable/surveyresults/reportbuilder.hxx | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index a1974df64c..714367d957 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -51,6 +51,14 @@ typename ClusterList::const_iterator ClusterList::end() cons return std::end(clusters); } +template +std::shared_ptr ClusterList::enabledClusterAt(unsigned int index) const +{ + // No operator [] was found for std::view (returned by each_enabled()). + // The current function is there to replace it. + return *(std::views::drop(each_enabled(), index).begin()); +} + template ClusterT* ClusterList::findInAll(const Data::ClusterName& id) const { diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 182c5e495c..893a8b84bc 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -102,8 +102,10 @@ class ClusterList iterator end(); const_iterator end() const; - SharedPtr operator[](std::size_t idx) { return clusters[idx]; } - const SharedPtr operator[](std::size_t idx) const { return clusters[idx]; } + SharedPtr operator[](std::size_t idx) { return allClusters[idx]; } + const SharedPtr operator[](std::size_t idx) const { return allClusters[idx]; } + + SharedPtr enabledClusterAt(unsigned int index) const; /*! ** \brief Resize all matrices dedicated to the sampled timeseries numbers ** diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 942d27db22..1248852e4d 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -198,13 +198,6 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A return ret; } -std::shared_ptr ThermalClusterList::enabledClusterAt(unsigned int index) const -{ - // No operator [] was found for std::view (returned by each_enabled()). - // The current function is there to replace it. - return *(std::views::drop(each_enabled(), index).begin()); -} - void ThermalClusterList::removeMustRunClusters() { std::erase_if(clusters, [](auto c) { return c->isMustRun(); }); diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 096f147ec0..5c6cd5e4de 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -103,7 +103,6 @@ class ThermalClusterList : public ClusterList void giveIndicesToClusters(); unsigned int mustRunAndEnabledCount() const; unsigned int enabledAndNotMustRunCount() const; - std::shared_ptr enabledClusterAt(unsigned int index) const; void removeMustRunClusters(); void clearAll(); diff --git a/src/solver/variable/surveyresults/reportbuilder.hxx b/src/solver/variable/surveyresults/reportbuilder.hxx index 28e9ef6abe..ec8a808172 100644 --- a/src/solver/variable/surveyresults/reportbuilder.hxx +++ b/src/solver/variable/surveyresults/reportbuilder.hxx @@ -324,7 +324,7 @@ private: if (VariablesStatsByDataLevel::count) { auto& area = *results.data.area; - for (const auto& cluster : area.thermal.list) + for (auto cluster : area.thermal.list.each_enabled_and_not_mustrun()) { results.data.thermalCluster = cluster.get(); From a8a5ea7ff9914789e4a60987aac8262bf1410771 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 12 Jan 2024 12:04:31 +0100 Subject: [PATCH 58/88] Clean thermal lists : fix a bug introduced in the very previous commit --- .../study/scenario-builder/RenewableTSNumberData.cpp | 11 +++++------ .../variable/economy/productionByRenewablePlant.h | 6 +++--- src/solver/variable/info.h | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp index 3d9c557b6e..ea702fc9cd 100644 --- a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp @@ -66,17 +66,16 @@ void renewableTSNumberData::saveToINIFile(const Study& /* study */, if (!pArea) return; - for (uint index = 0; index != pTSNumberRules.width; ++index) + for (auto cluster : pArea->renewable.list.all()) { - // Foreach renewable cluster... - for (uint y = 0; y != pTSNumberRules.height; ++y) + for (uint year = 0; year != pTSNumberRules.height; ++year) { - const uint val = get(pArea->renewable.list[index].get(), y); + const uint val = get(cluster.get(), year); // Equals to zero means 'auto', which is the default mode if (!val) continue; - file << prefix << pArea->id << "," << y << ',' - << pArea->renewable.list[index]->id() << " = " << val << '\n'; + file << prefix << pArea->id << "," << year << ',' + << cluster->id() << " = " << val << '\n'; } } } diff --git a/src/solver/variable/economy/productionByRenewablePlant.h b/src/solver/variable/economy/productionByRenewablePlant.h index 03309e540c..f67f871d55 100644 --- a/src/solver/variable/economy/productionByRenewablePlant.h +++ b/src/solver/variable/economy/productionByRenewablePlant.h @@ -324,12 +324,12 @@ class ProductionByRenewablePlant : public Variable::IVariablerenewable; // Write the data for the current year - for (uint i = 0; i < pSize; ++i) + for (auto cluster : renewable.list.each_enabled()) { // Write the data for the current year - results.variableCaption = renewable.list[i]->name(); + results.variableCaption = cluster->name(); results.variableUnit = VCardType::Unit(); - pValuesForTheCurrentYear[numSpace][i].template buildAnnualSurveyReport( + pValuesForTheCurrentYear[numSpace][cluster->areaWideIndex].template buildAnnualSurveyReport( results, fileLevel, precision); } } diff --git a/src/solver/variable/info.h b/src/solver/variable/info.h index f3b643690b..97301846be 100644 --- a/src/solver/variable/info.h +++ b/src/solver/variable/info.h @@ -407,7 +407,7 @@ struct VariableAccessor if (renewable_details) { auto& renewable = results.data.area->renewable; - results.variableCaption = renewable.list[idx]->name(); + results.variableCaption = renewable.list.enabledClusterAt(idx)->name(); return true; } if (st_storage_details) From 8472b82ce43adadc0b6f6570e8330663ee9ec7a6 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 12 Jan 2024 12:15:37 +0100 Subject: [PATCH 59/88] Clean thermal lists (towards removal of thermal.list.clusters) : remove use of list.begin() or end() --- src/libs/antares/study/parts/common/cluster_list.cpp | 4 ++-- src/libs/antares/study/parts/renewable/container.cpp | 7 ------- src/libs/antares/study/parts/thermal/container.cpp | 4 ++-- .../study/scenario-builder/RenewableTSNumberData.cpp | 8 +++----- src/libs/antares/study/study.cpp | 2 +- .../htmllistbox/datasource/thermal-cluster-order.cpp | 7 ++----- src/ui/simulator/toolbox/components/map/manager.cpp | 7 ++----- 7 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 714367d957..7a298cb097 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -24,7 +24,7 @@ using namespace Antares; template inline bool ClusterList::empty() const { - return clusters.empty(); + return allClusters.empty(); } template @@ -284,7 +284,7 @@ void ClusterList::retrieveTotalCapacityAndUnitCount(double& total, uin total = 0.; unitCount = 0; - for (const auto& c : clusters) + for (const auto& c : all()) { unitCount += c->unitCount; total += c->unitCount * c->nominalCapacity; diff --git a/src/libs/antares/study/parts/renewable/container.cpp b/src/libs/antares/study/parts/renewable/container.cpp index fee7793cdb..c34a32eec0 100644 --- a/src/libs/antares/study/parts/renewable/container.cpp +++ b/src/libs/antares/study/parts/renewable/container.cpp @@ -59,13 +59,6 @@ PartRenewable::~PartRenewable() void PartRenewable::prepareAreaWideIndexes() { - // Copy the list with all renewable clusters - // And init the areaWideIndex (unique index for a given area) - if (list.empty()) - { - return; - } - uint idx = 0; for (const auto& cluster : list) { diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index 24defce97e..f5016040ef 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -75,7 +75,7 @@ void PartThermal::resizeAllTimeseriesNumbers(uint n) bool PartThermal::hasForcedTimeseriesGeneration() const { using Behavior = LocalTSGenerationBehavior; - return std::any_of(list.begin(), list.end(), [](const ThermalClusterList::SharedPtr& cluster) { + return std::ranges::any_of(list.all(), [](const ThermalClusterList::SharedPtr& cluster) { return cluster->tsGenBehavior == Behavior::forceGen; }); } @@ -83,7 +83,7 @@ bool PartThermal::hasForcedTimeseriesGeneration() const bool PartThermal::hasForcedNoTimeseriesGeneration() const { using Behavior = LocalTSGenerationBehavior; - return std::any_of(list.begin(), list.end(), [](const ThermalClusterList::SharedPtr& cluster) { + return std::ranges::any_of(list.all(), [](const ThermalClusterList::SharedPtr& cluster) { return cluster->tsGenBehavior == Behavior::forceNoGen; }); } diff --git a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp index ea702fc9cd..0d86e9b7ec 100644 --- a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp @@ -32,17 +32,15 @@ bool renewableTSNumberData::apply(Study& study) const uint tsGenCountRenewable = get_tsGenCount(study); - uint clusterIndex = 0; - for (const auto& cluster : area.renewable.list) + for (const auto& cluster : area.renewable.list.each_enabled()) { // alias to the current column - assert(clusterIndex < pTSNumberRules.width); - const auto& col = pTSNumberRules[clusterIndex]; + assert(cluster->areaWideIndex < pTSNumberRules.width); + const auto& col = pTSNumberRules[cluster->areaWideIndex]; logprefix.clear() << "Renewable: area '" << area.name << "', cluster: '" << cluster->name() << "': "; ret = ApplyToMatrix(errors, logprefix, cluster->series, col, tsGenCountRenewable) && ret; - clusterIndex++; } return ret; } diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index f2b5cf09ea..ed873fc282 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -1526,7 +1526,7 @@ void Study::computePThetaInfForThermalClusters() const // Alias de la zone courant const auto& area = *(this->areas.byIndex[i]); - for (auto& cluster : area.thermal.list) + for (auto& cluster : area.thermal.list.each_enabled_and_not_mustrun()) { for (uint k = 0; k < HOURS_PER_YEAR; k++) cluster->PthetaInf[k] = cluster->modulation[Data::thermalMinGenModulation][k] diff --git a/src/ui/simulator/toolbox/components/htmllistbox/datasource/thermal-cluster-order.cpp b/src/ui/simulator/toolbox/components/htmllistbox/datasource/thermal-cluster-order.cpp index 52979efd77..b90ccfb8e3 100644 --- a/src/ui/simulator/toolbox/components/htmllistbox/datasource/thermal-cluster-order.cpp +++ b/src/ui/simulator/toolbox/components/htmllistbox/datasource/thermal-cluster-order.cpp @@ -53,16 +53,13 @@ void GetThermalClusterMap(Data::Area* area, ThermalClusterMap& l, const wxString { wxString grp; - const Data::ThermalClusterList::iterator end = area->thermal.list.end(); - for (Data::ThermalClusterList::iterator i = area->thermal.list.begin(); i != end; ++i) + for (auto cluster : area->thermal.list.all()) { - Data::ThermalCluster* cluster = i->get(); - if (search.empty()) { grp = wxStringFromUTF8(cluster->group()); grp.MakeLower(); - l[grp].push_back(cluster); + l[grp].push_back(cluster.get()); } } } diff --git a/src/ui/simulator/toolbox/components/map/manager.cpp b/src/ui/simulator/toolbox/components/map/manager.cpp index d6030be21c..58455da7b7 100644 --- a/src/ui/simulator/toolbox/components/map/manager.cpp +++ b/src/ui/simulator/toolbox/components/map/manager.cpp @@ -764,11 +764,8 @@ void Manager::selectFromBoundingBox(const wxPoint& a, const wxPoint& b, const si j->first->selected(true); if (mouseSelectionPlants) { - Data::ThermalClusterList::iterator tend = area->thermal.list.end(); - for (Data::ThermalClusterList::iterator t = area->thermal.list.begin(); - t != tend; - ++t) - clusterlist.push_back((*t).get()); + for(auto cluster : area->thermal.list.all()) + clusterlist.push_back(cluster.get()); } continue; } From cd001d446306d29fc9710dffe729590556c05f20 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 12 Jan 2024 14:01:05 +0100 Subject: [PATCH 60/88] Clean thermal lists (towards removal of thermal.list.clusters) : remove use of list.begin() or end() --- .../antares/study/cleaner/cleaner-v20.cpp | 2 +- src/solver/simulation/timeseries-numbers.cpp | 32 ++++++++----------- .../economy/productionByRenewablePlant.h | 2 +- .../variable/economy/renewableGeneration.h | 2 +- .../handler/antares-study/area/create.cpp | 2 +- .../datasource/renewable-cluster-order.cpp | 7 ++-- src/ui/simulator/windows/inspector/frame.cpp | 2 +- 7 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/libs/antares/study/cleaner/cleaner-v20.cpp b/src/libs/antares/study/cleaner/cleaner-v20.cpp index 38701442bf..0982a91489 100644 --- a/src/libs/antares/study/cleaner/cleaner-v20.cpp +++ b/src/libs/antares/study/cleaner/cleaner-v20.cpp @@ -164,7 +164,7 @@ static void listOfFilesAnDirectoriesToKeepForArea(PathList& e, PathList& p, cons buffer.clear() << "input/renewables/clusters/" << id << "/list.ini"; e.add(buffer); - for (const auto& cluster : area->renewable.list) + for (const auto cluster : area->renewable.list.all()) { buffer.clear() << "input/renewables/series/" << id << '/' << cluster->id(); p.add(buffer); diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 23b8428244..aa1d0a858f 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -99,7 +99,7 @@ static bool GenerateDeratedMode(Study& study) cluster->series.timeseriesNumbers.zero(); } - for (const auto& cluster : area.renewable.list) + for (const auto cluster : area.renewable.list.each_enabled()) cluster->series.timeseriesNumbers.zero(); }); @@ -223,7 +223,7 @@ class renewClustersAreaNumberOfTSretriever : public areaNumberOfTSretriever std::vector getAreaTimeSeriesNumber(const Area& area) { std::vector to_return; - for (const auto& cluster : area.renewable.list) + for (const auto cluster : area.renewable.list.each_enabled()) { to_return.push_back(cluster->series.timeSeries.width); } @@ -438,7 +438,7 @@ bool checkInterModalConsistencyForArea(Area& area, indexTS = ts_to_tsIndex.at(timeSeriesRenewable); if (isTSintermodal[indexTS]) { - for (const auto& cluster : area.renewable.list) + for (const auto cluster : area.renewable.list.each_enabled()) { uint nbTimeSeries = cluster->series.timeSeries.width; listNumberTsOverArea.push_back(nbTimeSeries); @@ -547,10 +547,9 @@ void storeTSnumbersForIntraModal(const array& intramo if (isTSintramodal[indexTS]) { - for (auto& cluster : area.renewable.list) + for (auto& cluster : area.renewable.list.each_enabled()) { - if (cluster->enabled) - cluster->series.timeseriesNumbers[0][year] = intramodal_draws[indexTS]; + cluster->series.timeseriesNumbers[0][year] = intramodal_draws[indexTS]; } } @@ -655,19 +654,14 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i // -------------------------- indexTS = ts_to_tsIndex.at(timeSeriesRenewable); - for (auto& cluster : area.renewable.list) + for (auto& cluster : area.renewable.list.each_enabled()) { - if (not cluster->enabled) - study.runtime->random[seedTimeseriesNumbers].next(); - else + if (!isTSintramodal[indexTS]) { - if (!isTSintramodal[indexTS]) - { - // There is no TS generation for renewable clusters - uint nbTimeSeries = cluster->series.timeSeries.width; - cluster->series.timeseriesNumbers[0][year] = (uint32_t)( - floor(study.runtime->random[seedTimeseriesNumbers].next() * nbTimeSeries)); - } + // There is no TS generation for renewable clusters + uint nbTimeSeries = cluster->series.timeSeries.width; + cluster->series.timeseriesNumbers[0][year] = (uint32_t)( + floor(study.runtime->random[seedTimeseriesNumbers].next() * nbTimeSeries)); } } @@ -782,7 +776,7 @@ void applyMatrixDrawsToInterModalModesInArea(Matrix* tsNumbersMtx, } if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)]) { - for (const auto& cluster : area.renewable.list) + for (const auto& cluster : area.renewable.list.each_enabled()) { assert(year < cluster->series.timeseriesNumbers.height); cluster->series.timeseriesNumbers[0][year] = draw; @@ -830,7 +824,7 @@ static void fixTSNumbersWhenWidthIsOne(Study& study) } // Renewables - for (const auto& cluster : area.renewable.list) + for (const auto& cluster : area.renewable.list.each_enabled()) fixTSNumbersSingleAreaSingleMode(cluster->series.timeseriesNumbers, cluster->series.timeSeries.width, years); diff --git a/src/solver/variable/economy/productionByRenewablePlant.h b/src/solver/variable/economy/productionByRenewablePlant.h index f67f871d55..89e42a6353 100644 --- a/src/solver/variable/economy/productionByRenewablePlant.h +++ b/src/solver/variable/economy/productionByRenewablePlant.h @@ -277,7 +277,7 @@ class ProductionByRenewablePlant : public Variable::IVariablerenewable.list) + for (const auto renewableCluster : state.area->renewable.list.each_enabled()) { double renewableClusterProduction = renewableCluster->valueAtTimeStep(state.year, state.hourInTheYear); diff --git a/src/solver/variable/economy/renewableGeneration.h b/src/solver/variable/economy/renewableGeneration.h index 5035cb59f4..29658df104 100644 --- a/src/solver/variable/economy/renewableGeneration.h +++ b/src/solver/variable/economy/renewableGeneration.h @@ -267,7 +267,7 @@ class RenewableGeneration void hourForEachArea(State& state, unsigned int numSpace) { - for (const auto& renewableCluster : state.area->renewable.list) + for (const auto renewableCluster : state.area->renewable.list.each_enabled()) { double renewableClusterProduction = renewableCluster->valueAtTimeStep(state.year, state.hourInTheYear); diff --git a/src/ui/action/handler/antares-study/area/create.cpp b/src/ui/action/handler/antares-study/area/create.cpp index e159af140d..f91bda6936 100644 --- a/src/ui/action/handler/antares-study/area/create.cpp +++ b/src/ui/action/handler/antares-study/area/create.cpp @@ -293,7 +293,7 @@ void Create::createActionsForAStandardAreaCopy(Context& ctx, bool copyPosition) auto* root = new RootNodePlant(pOriginalAreaName); // browsing each thermal cluster - for (auto& c : area->thermal.list) + for (auto c : area->thermal.list.all()) *root += StandardActionsToCopyThermalCluster(pOriginalAreaName, c->name()); *this += root; diff --git a/src/ui/simulator/toolbox/components/htmllistbox/datasource/renewable-cluster-order.cpp b/src/ui/simulator/toolbox/components/htmllistbox/datasource/renewable-cluster-order.cpp index d43ea9eb50..88b7134de4 100644 --- a/src/ui/simulator/toolbox/components/htmllistbox/datasource/renewable-cluster-order.cpp +++ b/src/ui/simulator/toolbox/components/htmllistbox/datasource/renewable-cluster-order.cpp @@ -53,16 +53,13 @@ void GetRenewableClusterMap(Data::Area* area, RenewableClusterMap& l, const wxSt { wxString grp; - const Data::RenewableClusterList::iterator end = area->renewable.list.end(); - for (Data::RenewableClusterList::iterator i = area->renewable.list.begin(); i != end; ++i) + for (auto cluster : area->renewable.list.all()) { - Data::RenewableCluster* cluster = i->get(); - if (search.empty()) { grp = wxStringFromUTF8(cluster->group()); grp.MakeLower(); - l[grp].push_back(cluster); + l[grp].push_back(cluster.get()); } } } diff --git a/src/ui/simulator/windows/inspector/frame.cpp b/src/ui/simulator/windows/inspector/frame.cpp index 7a82e2d292..1a754c0dd1 100644 --- a/src/ui/simulator/windows/inspector/frame.cpp +++ b/src/ui/simulator/windows/inspector/frame.cpp @@ -178,7 +178,7 @@ void Frame::onSelectAllPlants(wxCommandEvent&) for (auto i = data->areas.begin(); i != areaEnd; ++i) { Data::Area& area = *(*i); - for (auto& c : area.thermal.list) + for (auto c : area.thermal.list.all()) data->ThClusters.insert(c.get()); } data->areas.clear(); From 2b8c9c0f0c667cc784cca3393fa5432287b14bfb Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 12 Jan 2024 15:06:28 +0100 Subject: [PATCH 61/88] Clean thermal lists (towards removal of thermal.list.clusters) : remove completely list.begin() and list.end() --- .../study/parts/common/cluster_list.cpp | 24 ------------------- .../antares/study/parts/common/cluster_list.h | 6 ----- .../study/parts/renewable/container.cpp | 15 ++++++++---- 3 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 7a298cb097..48ee945a6c 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -27,30 +27,6 @@ inline bool ClusterList::empty() const return allClusters.empty(); } -template -typename ClusterList::iterator ClusterList::begin() -{ - return std::begin(clusters); -} - -template -typename ClusterList::const_iterator ClusterList::begin() const -{ - return std::begin(clusters); -} - -template -typename ClusterList::iterator ClusterList::end() -{ - return std::end(clusters); -} - -template -typename ClusterList::const_iterator ClusterList::end() const -{ - return std::end(clusters); -} - template std::shared_ptr ClusterList::enabledClusterAt(unsigned int index) const { diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 893a8b84bc..2e757f5a07 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -96,12 +96,6 @@ class ClusterList bool empty() const; //@} - iterator begin(); - const_iterator begin() const; - - iterator end(); - const_iterator end() const; - SharedPtr operator[](std::size_t idx) { return allClusters[idx]; } const SharedPtr operator[](std::size_t idx) const { return allClusters[idx]; } diff --git a/src/libs/antares/study/parts/renewable/container.cpp b/src/libs/antares/study/parts/renewable/container.cpp index c34a32eec0..7336b643cd 100644 --- a/src/libs/antares/study/parts/renewable/container.cpp +++ b/src/libs/antares/study/parts/renewable/container.cpp @@ -59,11 +59,18 @@ PartRenewable::~PartRenewable() void PartRenewable::prepareAreaWideIndexes() { - uint idx = 0; - for (const auto& cluster : list) + unsigned int index = 0; + for (auto c : list.all()) { - cluster->areaWideIndex = idx; - ++idx; + c->areaWideIndex = index; + index++; + } + + index = 0; + for (auto c : list.each_enabled()) + { + c->areaWideIndex = index; + index++; } } From c86f5e781aad9b6e67a070457b919a18f3e97b1d Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 12 Jan 2024 16:39:15 +0100 Subject: [PATCH 62/88] Clean thermal lists (towards removal of thermal.list.clusters) : make giveIndicesToClusters() a functions common to thermal and renewable cluster list classes --- src/libs/antares/study/area/list.cpp | 1 - .../study/parts/common/cluster_list.cpp | 23 +++++++++++++++++++ .../antares/study/parts/common/cluster_list.h | 1 + .../study/parts/renewable/cluster_list.cpp | 2 ++ .../study/parts/renewable/container.cpp | 17 -------------- .../antares/study/parts/renewable/container.h | 10 -------- .../study/parts/thermal/cluster_list.cpp | 22 ------------------ .../study/parts/thermal/cluster_list.h | 1 - src/libs/antares/study/runtime/runtime.cpp | 2 +- src/libs/antares/study/study.cpp | 2 +- .../test-sc-builder-file-read-line.cpp | 6 ++--- .../test-sc-builder-file-save.cpp | 6 ++--- .../toolbox/input/renewable-cluster.cpp | 6 ++--- 13 files changed, 37 insertions(+), 62 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 9deb3690fd..b0f0505899 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -1115,7 +1115,6 @@ bool AreaList::loadFromFolder(const StudyLoadOptions& options) Area& area = *(i->second); buffer.clear() << pStudy.folderInput << renewablePlant << area.id; ret = area.renewable.list.loadFromFolder(buffer.c_str(), &area) && ret; - area.renewable.prepareAreaWideIndexes(); } } diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 48ee945a6c..20e6068b39 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -138,6 +138,29 @@ unsigned int ClusterList::allClustersCount() const return allClusters.size(); } +template +void ClusterList::giveIndicesToClusters() +{ + // First, we give an index to every cluster, enabled / must-run or not. + // We do that to : + // - Stick to what was done before and not change the results + // - Avoids seg faults, for instance when storing thermal noises (solver.hxx). + // Indeed : otherwise disabled clusters have an infinite index + unsigned int index = 0; + for (auto c : allClusters) + { + c->areaWideIndex = index; + index++; + } + + index = 0; + for (auto c : each_enabled()) + { + c->areaWideIndex = index; + index++; + } +} + template bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName newName) { diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 2e757f5a07..551a15c422 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -166,6 +166,7 @@ class ClusterList uint removeDisabledClusters(); unsigned int enabledCount() const; unsigned int allClustersCount() const; + void giveIndicesToClusters(); void addToCompleteList(std::shared_ptr cluster); protected: diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index d74bb1d7a2..b625be6be2 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -174,6 +174,8 @@ bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) } } + giveIndicesToClusters(); + return ret; } return false; diff --git a/src/libs/antares/study/parts/renewable/container.cpp b/src/libs/antares/study/parts/renewable/container.cpp index 7336b643cd..cb68a730eb 100644 --- a/src/libs/antares/study/parts/renewable/container.cpp +++ b/src/libs/antares/study/parts/renewable/container.cpp @@ -57,23 +57,6 @@ PartRenewable::~PartRenewable() { } -void PartRenewable::prepareAreaWideIndexes() -{ - unsigned int index = 0; - for (auto c : list.all()) - { - c->areaWideIndex = index; - index++; - } - - index = 0; - for (auto c : list.each_enabled()) - { - c->areaWideIndex = index; - index++; - } -} - void PartRenewable::reset() { list.clear(); diff --git a/src/libs/antares/study/parts/renewable/container.h b/src/libs/antares/study/parts/renewable/container.h index ae4d439608..7928882dec 100644 --- a/src/libs/antares/study/parts/renewable/container.h +++ b/src/libs/antares/study/parts/renewable/container.h @@ -61,16 +61,6 @@ class PartRenewable */ void resizeAllTimeseriesNumbers(uint n); - - - /*! - ** \brief Create and initialize the list of all clusters (with the mustrun flag or not) - ** - ** This method must be called before prepareClustersInMustRunMode() - ** to ensure the same order whatever the value of the 'mustrun' flag is. - */ - void prepareAreaWideIndexes(); - /*! ** \brief Invalidate all JIT data */ diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 1248852e4d..ad576fd343 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -56,28 +56,6 @@ void ThermalClusterList::sortCompleteList() }); } -void ThermalClusterList::giveIndicesToClusters() -{ - // First, we give an index to every cluster, enabled / must-run or not. - // We do that to : - // - Stick to what was done before and not change the results - // - Avoids seg faults, for instance when storing thermal noises (solver.hxx). - // Indeed : otherwise disabled clusters have an infinite index - unsigned int index = 0; - for (auto c : allClusters) - { - c->areaWideIndex = index; - index++; - } - - index = 0; - for (auto c : each_enabled()) - { - c->areaWideIndex = index; - index++; - } -} - unsigned int ThermalClusterList::enabledAndNotMustRunCount() const { unsigned int count = 0; diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 5c6cd5e4de..9728743a4f 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -100,7 +100,6 @@ class ThermalClusterList : public ClusterList bool saveToFolder(const AnyString& folder) const override; void sortCompleteList(); - void giveIndicesToClusters(); unsigned int mustRunAndEnabledCount() const; unsigned int enabledAndNotMustRunCount() const; void removeMustRunClusters(); diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index 713a203b8c..acde8df95d 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -417,7 +417,7 @@ void StudyRuntimeInfos::removeDisabledRenewableClustersFromSolverComputations(St removeClusters(study, "renewable", [](Area& area) { uint ret = area.renewable.list.removeDisabledClusters(); if (ret > 0) - area.renewable.prepareAreaWideIndexes(); + area.renewable.list.giveIndicesToClusters(); return ret; }); } diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index ed873fc282..293b5ef7d3 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -1086,7 +1086,7 @@ bool Study::clusterRename(Cluster* cluster, ClusterName newName) { case kRenewable: ret = area.renewable.list.rename(cluster->id(), newName); - area.renewable.prepareAreaWideIndexes(); + area.renewable.list.giveIndicesToClusters(); break; case kThermal: ret = area.thermal.list.rename(cluster->id(), newName); diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index 127f9191c0..baa306bc8c 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -122,9 +122,9 @@ struct Fixture rnCluster_32->series.timeSeries.resize(9, 1); // Renewable clusters : update areas local numbering for clusters - area_1->renewable.prepareAreaWideIndexes(); - area_2->renewable.prepareAreaWideIndexes(); - area_3->renewable.prepareAreaWideIndexes(); + area_1->renewable.list.giveIndicesToClusters(); + area_2->renewable.list.giveIndicesToClusters(); + area_3->renewable.list.giveIndicesToClusters(); // Resize all TS numbers storage (1 column x nbYears lines) area_1->resizeAllTimeseriesNumbers(study->parameters.nbYears); diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 2ba19a5a95..97944f69a0 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -162,9 +162,9 @@ struct commonFixture rnCluster_32->series.timeSeries.resize(9, 1); // Renewable clusters : update areas local numbering for clusters - area_1->renewable.prepareAreaWideIndexes(); - area_2->renewable.prepareAreaWideIndexes(); - area_3->renewable.prepareAreaWideIndexes(); + area_1->renewable.list.giveIndicesToClusters(); + area_2->renewable.list.giveIndicesToClusters(); + area_3->renewable.list.giveIndicesToClusters(); // Resize all TS numbers storage (1 column x nbYears lines) area_1->resizeAllTimeseriesNumbers(study->parameters.nbYears); diff --git a/src/ui/simulator/toolbox/input/renewable-cluster.cpp b/src/ui/simulator/toolbox/input/renewable-cluster.cpp index d32a74821d..1dd55b16b2 100644 --- a/src/ui/simulator/toolbox/input/renewable-cluster.cpp +++ b/src/ui/simulator/toolbox/input/renewable-cluster.cpp @@ -291,7 +291,7 @@ void RenewableCluster::internalDeletePlant(void*) Refresh(); MarkTheStudyAsModified(); updateInnerValues(); - pArea->renewable.prepareAreaWideIndexes(); + pArea->renewable.list.giveIndicesToClusters(); study->uiinfo->reload(); } else @@ -389,7 +389,7 @@ void RenewableCluster::internalAddPlant(void*) cluster->reset(); pArea->renewable.list.add(cluster); pArea->renewable.list.addToCompleteList(cluster); - pArea->renewable.prepareAreaWideIndexes(); + pArea->renewable.list.giveIndicesToClusters(); // Update the list update(); @@ -467,7 +467,7 @@ void RenewableCluster::internalClonePlant(void*) pArea->renewable.list.add(cluster); pArea->renewable.list.addToCompleteList(cluster); - pArea->renewable.prepareAreaWideIndexes(); + pArea->renewable.list.giveIndicesToClusters(); // Update the list update(); From 55ce3dba7dea17e476669433556b659ac84c6f54 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Sat, 13 Jan 2024 18:37:50 +0100 Subject: [PATCH 63/88] Clean thermal lists : call algorithms instead of our own code --- .../antares/study/parts/common/cluster_list.cpp | 15 +++------------ .../antares/study/parts/thermal/cluster_list.cpp | 10 ++-------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 20e6068b39..6a335f9366 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -126,10 +126,7 @@ void ClusterList::addToCompleteList(std::shared_ptr cluster) template unsigned int ClusterList::enabledCount() const { - unsigned int count = 0; - for (auto cluster : each_enabled()) - count++; - return count; + return std::ranges::count_if(allClusters, &ClusterT::isEnabled); } template @@ -244,7 +241,7 @@ bool ClusterList::remove(const Data::ClusterName& id) template bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) const { - return std::ranges::all_of(allClusters, [&folder](const auto& c){ + return std::ranges::all_of(allClusters, [&folder](const auto c){ return c->saveDataSeriesToFolder(folder); }); } @@ -252,13 +249,7 @@ bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) cons template bool ClusterList::saveDataSeriesToFolder(const AnyString& folder, const String& msg) const { - uint ticks = 0; - - return std::ranges::all_of(clusters, [&](const auto& c) - { - logs.info() << msg << " " << (ticks * 100 / (1 + this->allClustersCount())) - << "% complete"; - ++ticks; + return std::ranges::all_of(clusters, [&](const auto& c) { return c->saveDataSeriesToFolder(folder); }); } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index ad576fd343..33885672d5 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -58,18 +58,12 @@ void ThermalClusterList::sortCompleteList() unsigned int ThermalClusterList::enabledAndNotMustRunCount() const { - unsigned int count = 0; - for (auto cluster : each_enabled_and_not_mustrun()) - count++; - return count; + return std::ranges::count_if(allClusters, [](auto c) { return c->isEnabled() && c->isNotMustRun(); }); } unsigned int ThermalClusterList::mustRunAndEnabledCount() const { - unsigned int count = 0; - for (auto cluster : each_mustrun_and_enabled()) - count++; - return count; + return std::ranges::count_if(allClusters, [](auto c) { return c->isEnabled() && c->isMustRun(); }); } bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, Area* area) From eed3fcdc37579bc9b1bb93e2ee0f935d6a76151b Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Sun, 14 Jan 2024 18:55:50 +0100 Subject: [PATCH 64/88] Clean thermal lists (towards removal of thermal.list.clusters) : renaming --- .../study/parts/common/cluster_list.cpp | 44 +++++++++---------- .../antares/study/parts/common/cluster_list.h | 27 ++++-------- .../study/parts/renewable/cluster_list.cpp | 2 +- .../study/parts/thermal/cluster_list.cpp | 24 +++++----- .../study/parts/thermal/cluster_list.h | 8 ++-- 5 files changed, 47 insertions(+), 58 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 6a335f9366..669fb24573 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -24,7 +24,7 @@ using namespace Antares; template inline bool ClusterList::empty() const { - return allClusters.empty(); + return allClusters_.empty(); } template @@ -47,25 +47,25 @@ ClusterT* ClusterList::findInAll(const Data::ClusterName& id) const template std::vector> ClusterList::all() const { - return allClusters; + return allClusters_; } template bool ClusterList::exists(const Data::ClusterName& id) const { - return std::ranges::any_of(clusters, [&id](const auto& c){ return c->id() == id; }); + return std::ranges::any_of(clusters_, [&id](const auto& c){ return c->id() == id; }); } template void ClusterList::clear() { - clusters.clear(); + clusters_.clear(); } template void ClusterList::resizeAllTimeseriesNumbers(uint n) { - for (auto c : allClusters) + for (auto c : allClusters_) c->series.timeseriesNumbers.resize(1, n); } @@ -91,28 +91,28 @@ void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer template void ClusterList::rebuildIndex() { - std::sort(clusters.begin(), clusters.end(), [](const auto& a, const auto& b){ + std::sort(clusters_.begin(), clusters_.end(), [](const auto& a, const auto& b){ return a->id() < b->id(); }); uint indx = 0; - for (auto& c : clusters) + for (auto& c : clusters_) c->index = indx++; } template -void ClusterList::add(const SharedPtr newcluster) +void ClusterList::add(const SharedPtr cluster) { - if (exists(newcluster->id())) + if (exists(cluster->id())) return; - clusters.push_back(newcluster); + clusters_.push_back(cluster); rebuildIndex(); } template bool ClusterList::alreadyInAllClusters(std::string clusterId) { - return std::ranges::any_of(allClusters, [&clusterId](const auto& c) { return c->id() == clusterId; }); + return std::ranges::any_of(allClusters_, [&clusterId](const auto& c) { return c->id() == clusterId; }); } template @@ -120,19 +120,19 @@ void ClusterList::addToCompleteList(std::shared_ptr cluster) { if (alreadyInAllClusters(cluster->id())) return; - allClusters.push_back(cluster); + allClusters_.push_back(cluster); } template unsigned int ClusterList::enabledCount() const { - return std::ranges::count_if(allClusters, &ClusterT::isEnabled); + return std::ranges::count_if(allClusters_, &ClusterT::isEnabled); } template unsigned int ClusterList::allClustersCount() const { - return allClusters.size(); + return allClusters_.size(); } template @@ -144,7 +144,7 @@ void ClusterList::giveIndicesToClusters() // - Avoids seg faults, for instance when storing thermal noises (solver.hxx). // Indeed : otherwise disabled clusters have an infinite index unsigned int index = 0; - for (auto c : allClusters) + for (auto c : allClusters_) { c->areaWideIndex = index; index++; @@ -212,7 +212,7 @@ bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName template bool ClusterList::forceReload(bool reload) const { - return std::ranges::all_of(clusters, [&reload](const auto& c){ + return std::ranges::all_of(clusters_, [&reload](const auto& c){ return c->forceReload(reload); }); } @@ -220,14 +220,14 @@ bool ClusterList::forceReload(bool reload) const template void ClusterList::markAsModified() const { - for (const auto& c : clusters) + for (const auto& c : clusters_) c->markAsModified(); } template bool ClusterList::remove(const Data::ClusterName& id) { - auto nbDeletion = std::erase_if(clusters, [&id](const SharedPtr& c) { return c->id() == id; }); + auto nbDeletion = std::erase_if(clusters_, [&id](const SharedPtr& c) { return c->id() == id; }); // Invalidating the parent area forceReload(); @@ -241,7 +241,7 @@ bool ClusterList::remove(const Data::ClusterName& id) template bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) const { - return std::ranges::all_of(allClusters, [&folder](const auto c){ + return std::ranges::all_of(allClusters_, [&folder](const auto c){ return c->saveDataSeriesToFolder(folder); }); } @@ -249,7 +249,7 @@ bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) cons template bool ClusterList::saveDataSeriesToFolder(const AnyString& folder, const String& msg) const { - return std::ranges::all_of(clusters, [&](const auto& c) { + return std::ranges::all_of(clusters_, [&](const auto& c) { return c->saveDataSeriesToFolder(folder); }); } @@ -261,7 +261,7 @@ bool ClusterList::loadDataSeriesFromFolder(Study& s, { bool ret = true; - for (auto c : allClusters) + for (auto c : allClusters_) { ret = c->loadDataSeriesFromFolder(s, folder) and ret; } @@ -288,7 +288,7 @@ uint ClusterList::removeDisabledClusters() if (empty()) return 0; - auto count = std::erase_if(clusters, [] (auto& c) { return !c->enabled; }); + auto count = std::erase_if(clusters_, [] (auto& c) { return !c->enabled; }); rebuildIndex(); diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 551a15c422..c8da664594 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -37,26 +37,15 @@ class ClusterList template void each(const PredicateT& predicate) const { - std::ranges::for_each(clusters, [&predicate](const auto& c) { predicate(*c); }); + std::ranges::for_each(clusters_, [&predicate](const auto& c) { predicate(*c); }); } - //! \name clusters management - //@{ - /*! - ** \brief Destroy all clusters - */ void clear(); - /*! - ** \brief Add a cluster in the list - ** - ** \param t The cluster to add - ** \return True if the cluster has been added, false otherwise - */ - void add(const SharedPtr clusters); + void add(const SharedPtr cluster); /*! - ** \brief Try to find a cluster from its id (const) + ** \brief Try to find a cluster from its id (const) in the complete cluster list ** ** \param id ID of the cluster to find ** \return A pointer to a cluster. nullptr if not found @@ -71,7 +60,7 @@ class ClusterList */ bool exists(const Data::ClusterName& id) const; - auto each_enabled() const { return allClusters | std::views::filter(&ClusterT::isEnabled); } + auto each_enabled() const { return allClusters_ | std::views::filter(&ClusterT::isEnabled); } std::vector> all() const; @@ -96,8 +85,8 @@ class ClusterList bool empty() const; //@} - SharedPtr operator[](std::size_t idx) { return allClusters[idx]; } - const SharedPtr operator[](std::size_t idx) const { return allClusters[idx]; } + SharedPtr operator[](std::size_t idx) { return allClusters_[idx]; } + const SharedPtr operator[](std::size_t idx) const { return allClusters_[idx]; } SharedPtr enabledClusterAt(unsigned int index) const; /*! @@ -171,8 +160,8 @@ class ClusterList protected: // The vector containing the clusters - Vect clusters; - std::vector> allClusters; + Vect clusters_; + std::vector> allClusters_; /// thermal, renewable, etc. virtual std::string typeID() const = 0; diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index b625be6be2..c0514995c8 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -20,7 +20,7 @@ std::string RenewableClusterList::typeID() const uint64_t RenewableClusterList::memoryUsage() const { uint64_t ret = sizeof(RenewableClusterList) + (2 * sizeof(void*)) * enabledCount(); - each([&](const RenewableCluster& clusters) { ret += clusters.memoryUsage(); }); + each([&](const RenewableCluster& cluster) { ret += cluster.memoryUsage(); }); return ret; } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 33885672d5..1991af94ba 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -41,7 +41,7 @@ std::string ThermalClusterList::typeID() const uint64_t ThermalClusterList::memoryUsage() const { uint64_t ret = sizeof(ThermalClusterList) + (2 * sizeof(void*)) * mustRunAndEnabledCount(); - each([&](const ThermalCluster& clusters) { ret += clusters.memoryUsage(); }); + each([&](const ThermalCluster& cluster) { ret += cluster.memoryUsage(); }); return ret; } @@ -51,19 +51,19 @@ static bool ThermalClusterLoadFromSection(const AnyString& filename, void ThermalClusterList::sortCompleteList() { - std::sort(allClusters.begin(), allClusters.end(), [](const auto& a, const auto& b) { + std::sort(allClusters_.begin(), allClusters_.end(), [](const auto& a, const auto& b) { return a->id() < b->id(); }); } unsigned int ThermalClusterList::enabledAndNotMustRunCount() const { - return std::ranges::count_if(allClusters, [](auto c) { return c->isEnabled() && c->isNotMustRun(); }); + return std::ranges::count_if(allClusters_, [](auto c) { return c->isEnabled() && c->isNotMustRun(); }); } unsigned int ThermalClusterList::mustRunAndEnabledCount() const { - return std::ranges::count_if(allClusters, [](auto c) { return c->isEnabled() && c->isMustRun(); }); + return std::ranges::count_if(allClusters_, [](auto c) { return c->isEnabled() && c->isMustRun(); }); } bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, Area* area) @@ -172,14 +172,14 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A void ThermalClusterList::removeMustRunClusters() { - std::erase_if(clusters, [](auto c) { return c->isMustRun(); }); + std::erase_if(clusters_, [](auto c) { return c->isMustRun(); }); forceReload(); rebuildIndex(); } void ThermalClusterList::clearAll() { - allClusters.clear(); + allClusters_.clear(); } static bool ThermalClusterLoadFromProperty(ThermalCluster& cluster, const IniFile::Property* p) @@ -317,7 +317,7 @@ void ThermalClusterList::reverseCalculationOfSpinning() void ThermalClusterList::enableMustrunForEveryone() { - for (auto c : allClusters) + for (auto c : allClusters_) c->mustrun = true; } @@ -339,7 +339,7 @@ bool ThermalClusterList::saveToFolder(const AnyString& folder) const // Allocate the inifile structure IniFile ini; - for (auto c : allClusters) + for (auto c : allClusters_) { // Adding a section to the inifile IniFile::Section* s = ini.addSection(c->name()); @@ -448,7 +448,7 @@ bool ThermalClusterList::savePreproToFolder(const AnyString& folder) const Clob buffer; bool ret = true; - for (auto c : allClusters) + for (auto c : allClusters_) { if (c->prepro) { @@ -465,7 +465,7 @@ bool ThermalClusterList::saveEconomicCosts(const AnyString& folder) const Clob buffer; bool ret = true; - for (auto c : allClusters) + for (auto c : allClusters_) { assert(c->parentArea and "cluster: invalid parent area"); buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); @@ -501,13 +501,13 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, return result; }; - return std::ranges::all_of(allClusters | std::views::filter(hasPrepro), + return std::ranges::all_of(allClusters_ | std::views::filter(hasPrepro), loadAndCheckPrepro); } bool ThermalClusterList::loadEconomicCosts(Study& study, const AnyString& folder) { - return std::ranges::all_of(clusters, [&study, folder](const auto& c) + return std::ranges::all_of(clusters_, [&study, folder](const auto& c) { assert(c->parentArea && "cluster: invalid parent area"); Clob buffer; diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 9728743a4f..bb9b469c31 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -61,14 +61,14 @@ class ThermalClusterList : public ClusterList auto each_mustrun_and_enabled() const { - return allClusters | std::views::filter(&ThermalCluster::isMustRun) - | std::views::filter(&ThermalCluster::isEnabled); + return allClusters_ | std::views::filter(&ThermalCluster::isMustRun) + | std::views::filter(&ThermalCluster::isEnabled); } auto each_enabled_and_not_mustrun() const { - return allClusters | std::views::filter(&ThermalCluster::isEnabled) - | std::views::filter(&ThermalCluster::isNotMustRun); + return allClusters_ | std::views::filter(&ThermalCluster::isEnabled) + | std::views::filter(&ThermalCluster::isNotMustRun); } From d8636980594f6d749f15098155907bae386b6ef4 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Sun, 14 Jan 2024 19:37:40 +0100 Subject: [PATCH 65/88] Clean thermal lists (towards removal of thermal.list.clusters) : removing ClusterList::each() --- .../antares/study/parts/common/cluster_list.h | 9 ------ .../study/parts/renewable/cluster_list.cpp | 28 +++++++++---------- .../study/parts/thermal/cluster_list.cpp | 2 +- src/solver/hydro/management/management.cpp | 7 +++-- .../simulation/sim_calcul_economique.cpp | 7 +++-- 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index c8da664594..bb22d44e81 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -31,15 +31,6 @@ class ClusterList using iterator = typename Vect::iterator; using const_iterator = typename Vect::const_iterator; - /*! - ** \brief Iterate through all clusters (const) - */ - template - void each(const PredicateT& predicate) const - { - std::ranges::for_each(clusters_, [&predicate](const auto& c) { predicate(*c); }); - } - void clear(); void add(const SharedPtr cluster); diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index c0514995c8..cdd22418ce 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -20,9 +20,8 @@ std::string RenewableClusterList::typeID() const uint64_t RenewableClusterList::memoryUsage() const { uint64_t ret = sizeof(RenewableClusterList) + (2 * sizeof(void*)) * enabledCount(); - each([&](const RenewableCluster& cluster) { ret += cluster.memoryUsage(); }); + std::ranges::for_each(each_enabled(), [&ret](const auto c) { ret += c->memoryUsage(); }); return ret; - } @@ -38,27 +37,28 @@ bool RenewableClusterList::saveToFolder(const AnyString& folder) const IniFile ini; // Browse all clusters - each([&](const Data::RenewableCluster& c) { + for (auto c : all()) + { // Adding a section to the inifile - IniFile::Section* s = ini.addSection(c.name()); + IniFile::Section* s = ini.addSection(c->name()); // The section must not be empty // This key will be silently ignored the next time - s->add("name", c.name()); + s->add("name", c->name()); - if (not c.group().empty()) - s->add("group", c.group()); - if (not c.enabled) + if (not c->group().empty()) + s->add("group", c->group()); + if (not c->enabled) s->add("enabled", "false"); - if (not Math::Zero(c.nominalCapacity)) - s->add("nominalCapacity", c.nominalCapacity); + if (not Math::Zero(c->nominalCapacity)) + s->add("nominalCapacity", c->nominalCapacity); - if (not Math::Zero(c.unitCount)) - s->add("unitCount", c.unitCount); + if (not Math::Zero(c->unitCount)) + s->add("unitCount", c->unitCount); - s->add("ts-interpretation", c.getTimeSeriesModeAsString()); - }); + s->add("ts-interpretation", c->getTimeSeriesModeAsString()); + } // Write the ini file buffer.clear() << folder << SEP << "list.ini"; diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 1991af94ba..9169176361 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -41,7 +41,7 @@ std::string ThermalClusterList::typeID() const uint64_t ThermalClusterList::memoryUsage() const { uint64_t ret = sizeof(ThermalClusterList) + (2 * sizeof(void*)) * mustRunAndEnabledCount(); - each([&](const ThermalCluster& cluster) { ret += cluster.memoryUsage(); }); + std::ranges::for_each(each_enabled_and_not_mustrun(), [&ret](const auto c) { ret += c->memoryUsage(); }); return ret; } diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index 493a80689b..2b4041aa58 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -409,10 +409,11 @@ void HydroManagement::prepareNetDemand(uint numSpace, uint year, Data::Simulatio - ((mode != Data::SimulationMode::Adequacy) ? scratchpad.mustrunSum[hour] : scratchpad.originalMustrunSum[hour]); - area.renewable.list.each([&](const Antares::Data::RenewableCluster& cluster) { + for (auto c : area.renewable.list.each_enabled()) + { assert(cluster.series.timeSeries.jit == nullptr && "No JIT data from the solver"); - netdemand -= cluster.valueAtTimeStep(year, hour); - }); + netdemand -= c->valueAtTimeStep(year, hour); + } } assert(!Math::NaN(netdemand) diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index a6bd1bf6fd..d06d5d4483 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -605,10 +605,11 @@ void SIM_RenseignementProblemeHebdo(const Study& study, mustRunGen = scratchpad.miscGenSum[hourInYear] + rorSeries + scratchpad.mustrunSum[hourInYear]; - area.renewable.list.each([&](const RenewableCluster& cluster) { + for (auto c : area.renewable.list.each_enabled()) + { assert(cluster.series.timeSeries.jit == nullptr && "No JIT data from the solver"); - mustRunGen += cluster.valueAtTimeStep(year, hourInYear); - }); + mustRunGen += c->valueAtTimeStep(year, hourInYear); + } } assert( From ba18613c1ed00c70e8b5f67130865da060dd52cb Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 15 Jan 2024 11:25:31 +0100 Subject: [PATCH 66/88] Clean thermal lists (towards removal of thermal.list.clusters) : move things from parent/child class to child / parent class (see comment) Move : - cluster->index only applies to thermal clusters, so we move it from generic cluster class to thermal cluster class - the associated rebuildIndex() is also moved from generic cluster list to thermal cluster list - sortCompleteList() applies to generic clusters, so it is moved up to generic cluster list - in cluster classes, we made some simple cleaning : attributes default values are given in the .h, not in the constructor anymore --- .../antares/study/parts/common/cluster.cpp | 9 +---- src/libs/antares/study/parts/common/cluster.h | 11 ++---- .../study/parts/common/cluster_list.cpp | 38 +++++-------------- .../antares/study/parts/common/cluster_list.h | 7 +--- .../antares/study/parts/renewable/cluster.cpp | 4 +- .../antares/study/parts/renewable/cluster.h | 13 +------ .../antares/study/parts/thermal/cluster.cpp | 12 ------ .../antares/study/parts/thermal/cluster.h | 27 +++++++------ .../study/parts/thermal/cluster_list.cpp | 10 ++--- .../study/parts/thermal/cluster_list.h | 4 +- 10 files changed, 45 insertions(+), 90 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster.cpp b/src/libs/antares/study/parts/common/cluster.cpp index 265b8f4d51..010918e0aa 100644 --- a/src/libs/antares/study/parts/common/cluster.cpp +++ b/src/libs/antares/study/parts/common/cluster.cpp @@ -9,13 +9,8 @@ namespace Antares::Data { Cluster::Cluster(Area* parent) : - unitCount(0), - enabled(true), - parentArea(parent), - index(0), - nominalCapacity(0.), - areaWideIndex((uint)-1), - series(tsNumbers) + parentArea(parent), + series(tsNumbers) { } diff --git a/src/libs/antares/study/parts/common/cluster.h b/src/libs/antares/study/parts/common/cluster.h index 574a774877..7d35851d7d 100644 --- a/src/libs/antares/study/parts/common/cluster.h +++ b/src/libs/antares/study/parts/common/cluster.h @@ -84,24 +84,21 @@ class Cluster bool saveDataSeriesToFolder(const AnyString& folder) const; bool loadDataSeriesFromFolder(Study& s, const AnyString& folder); - uint unitCount; + uint unitCount = 0; bool isEnabled() const { return enabled; } - bool enabled; + bool enabled = true; //! The associate area (alias) Area* parentArea; - //! The index of the cluster (within a list) - uint index; - //! Capacity of reference per unit (MW) (pMax) - double nominalCapacity; + double nominalCapacity = 0.; //! The index of the cluster from the area's point of view //! \warning this variable is only valid when used by the solver // (initialized in the same time that the runtime data) - uint areaWideIndex; + uint areaWideIndex = (uint)-1; //! Series TimeSeries series; diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 669fb24573..907355f008 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -53,7 +53,7 @@ std::vector> ClusterList::all() const template bool ClusterList::exists(const Data::ClusterName& id) const { - return std::ranges::any_of(clusters_, [&id](const auto& c){ return c->id() == id; }); + return std::ranges::any_of(allClusters_, [&id](const auto& c){ return c->id() == id; }); } template @@ -88,25 +88,12 @@ void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer } } -template -void ClusterList::rebuildIndex() -{ - std::sort(clusters_.begin(), clusters_.end(), [](const auto& a, const auto& b){ - return a->id() < b->id(); - }); - - uint indx = 0; - for (auto& c : clusters_) - c->index = indx++; -} - template void ClusterList::add(const SharedPtr cluster) { if (exists(cluster->id())) return; clusters_.push_back(cluster); - rebuildIndex(); } template @@ -121,6 +108,13 @@ void ClusterList::addToCompleteList(std::shared_ptr cluster) if (alreadyInAllClusters(cluster->id())) return; allClusters_.push_back(cluster); + sortCompleteList(); +} + +template +void ClusterList::sortCompleteList() +{ + std::ranges::sort(allClusters_, [](const auto a, const auto b) { return a->id() < b->id(); }); } template @@ -204,15 +198,13 @@ bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName if (cluster_ptr->parentArea) (cluster_ptr->parentArea)->invalidateJIT = true; - // Rebuilding the index - rebuildIndex(); return true; } template bool ClusterList::forceReload(bool reload) const { - return std::ranges::all_of(clusters_, [&reload](const auto& c){ + return std::ranges::all_of(allClusters_, [&reload](const auto& c){ return c->forceReload(reload); }); } @@ -220,7 +212,7 @@ bool ClusterList::forceReload(bool reload) const template void ClusterList::markAsModified() const { - for (const auto& c : clusters_) + for (const auto& c : allClusters_) c->markAsModified(); } @@ -232,9 +224,6 @@ bool ClusterList::remove(const Data::ClusterName& id) // Invalidating the parent area forceReload(); - // Rebuilding the index - rebuildIndex(); - return nbDeletion > 0; } @@ -284,14 +273,7 @@ void ClusterList::retrieveTotalCapacityAndUnitCount(double& total, uin template uint ClusterList::removeDisabledClusters() { - // nothing to do if there is no clusters available - if (empty()) - return 0; - auto count = std::erase_if(clusters_, [] (auto& c) { return !c->enabled; }); - - rebuildIndex(); - return count; } // Force template instantiation diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index bb22d44e81..96c6a09530 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -32,7 +32,7 @@ class ClusterList using const_iterator = typename Vect::const_iterator; void clear(); - + bool empty() const; void add(const SharedPtr cluster); /*! @@ -72,8 +72,6 @@ class ClusterList */ virtual bool remove(const Data::ClusterName& id); - //! Return true if the list is empty - bool empty() const; //@} SharedPtr operator[](std::size_t idx) { return allClusters_[idx]; } @@ -148,6 +146,7 @@ class ClusterList unsigned int allClustersCount() const; void giveIndicesToClusters(); void addToCompleteList(std::shared_ptr cluster); + void sortCompleteList(); protected: // The vector containing the clusters @@ -157,8 +156,6 @@ class ClusterList /// thermal, renewable, etc. virtual std::string typeID() const = 0; - /// Sort the vector, set index value for each cluster - void rebuildIndex(); private: bool alreadyInAllClusters(std::string clusterName); diff --git a/src/libs/antares/study/parts/renewable/cluster.cpp b/src/libs/antares/study/parts/renewable/cluster.cpp index ba8d2b6a9d..c148e36ab8 100644 --- a/src/libs/antares/study/parts/renewable/cluster.cpp +++ b/src/libs/antares/study/parts/renewable/cluster.cpp @@ -46,8 +46,8 @@ namespace Antares { namespace Data { -Data::RenewableCluster::RenewableCluster(Area* parent) : - Cluster(parent), groupID(renewableOther1), tsMode(powerGeneration) +Data::RenewableCluster::RenewableCluster(Area* parent) : + Cluster(parent) { // assert assert(parent and "A parent for a renewable dispatchable cluster can not be null"); diff --git a/src/libs/antares/study/parts/renewable/cluster.h b/src/libs/antares/study/parts/renewable/cluster.h index 5ac3d838dc..108b3017f7 100644 --- a/src/libs/antares/study/parts/renewable/cluster.h +++ b/src/libs/antares/study/parts/renewable/cluster.h @@ -38,15 +38,6 @@ namespace Antares { namespace Data { -/* gp : useless in v8.1, could be useful in a further version -enum RenewableModulation -{ - renewableModulationCost = 0, - renewableModulationCapacity, - renewableMinGenModulation, - renewableModulationMax -}; -*/ /* ** \brief A single renewable cluster @@ -162,9 +153,9 @@ class RenewableCluster final : public Cluster ** This value is computed from the field 'group' in 'group() ** \see group() */ - enum RenewableGroup groupID; + enum RenewableGroup groupID = renewableOther1; - enum TimeSeriesMode tsMode; + enum TimeSeriesMode tsMode = powerGeneration; friend class RenewableClusterList; diff --git a/src/libs/antares/study/parts/thermal/cluster.cpp b/src/libs/antares/study/parts/thermal/cluster.cpp index 72548e03fe..4ee971965b 100644 --- a/src/libs/antares/study/parts/thermal/cluster.cpp +++ b/src/libs/antares/study/parts/thermal/cluster.cpp @@ -124,18 +124,6 @@ namespace Data { Data::ThermalCluster::ThermalCluster(Area* parent) : Cluster(parent), - groupID(thermalDispatchGrpOther1), - mustrun(false), - mustrunOrigin(false), - nominalCapacityWithSpinning(0.), - minStablePower(0.), - minUpTime(1), - minDownTime(1), - spinning(0.), - forcedVolatility(0.), - plannedVolatility(0.), - forcedLaw(thermalLawUniform), - plannedLaw(thermalLawUniform), PthetaInf(HOURS_PER_YEAR, 0), costsTimeSeries(1, CostsTimeSeries()) { diff --git a/src/libs/antares/study/parts/thermal/cluster.h b/src/libs/antares/study/parts/thermal/cluster.h index e7ff7257f2..e10c964025 100644 --- a/src/libs/antares/study/parts/thermal/cluster.h +++ b/src/libs/antares/study/parts/thermal/cluster.h @@ -232,16 +232,19 @@ class ThermalCluster final : public Cluster, public std::enable_shared_from_this bool isActive() const; + //! The index of the cluster (within a list) + uint index = 0; + /*! ** \brief The group ID ** ** This value is computed from the field 'group' in 'group() ** \see group() */ - ThermalDispatchableGroup groupID; + ThermalDispatchableGroup groupID = thermalDispatchGrpOther1; //! Mustrun - bool mustrun; + bool mustrun = false; bool isMustRun() const { return mustrun; } bool isNotMustRun() const { return not mustrun; } @@ -250,15 +253,15 @@ class ThermalCluster final : public Cluster, public std::enable_shared_from_this // This value might differ from mustrun, because `mustrun` might be // modified for different reasons. // Only used by the solver in adequacy mode - bool mustrunOrigin; + bool mustrunOrigin = false; //! Nominal capacity - spinning (solver only) - double nominalCapacityWithSpinning; + double nominalCapacityWithSpinning = 0.; //! \name PMin //@{ //! Min. Stable Power (MW) - double minStablePower; + double minStablePower = 0.; struct DivModulation { @@ -274,28 +277,28 @@ class ThermalCluster final : public Cluster, public std::enable_shared_from_this } minDivModulation; //! Min. Up time (1..168) - uint minUpTime; + uint minUpTime = 1; //! Min. Down time (1..168) - uint minDownTime; + uint minDownTime = 1; //! Max entre . minUp/minDown time (1..168) uint minUpDownTime; //@} //! Spinning (%) - double spinning; + double spinning = 0.; //! Efficiency (%) double fuelEfficiency = 100; //! Forced Volatility - double forcedVolatility; + double forcedVolatility = 0.; //! Planned volatility - double plannedVolatility; + double plannedVolatility = 0.; //! Law (ts-generator) - ThermalLaw forcedLaw; + ThermalLaw forcedLaw = thermalLawUniform; //! Law (ts-generator) - ThermalLaw plannedLaw; + ThermalLaw plannedLaw = thermalLawUniform; //! \name Costs // Marginal (€/MWh) MA diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 9169176361..4441e629dd 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -49,11 +49,11 @@ static bool ThermalClusterLoadFromSection(const AnyString& filename, ThermalCluster& cluster, const IniFile::Section& section); -void ThermalClusterList::sortCompleteList() +void ThermalClusterList::rebuildIndex() { - std::sort(allClusters_.begin(), allClusters_.end(), [](const auto& a, const auto& b) { - return a->id() < b->id(); - }); + uint indx = 0; + for (auto& c : each_enabled_and_not_mustrun()) + c->index = indx++; } unsigned int ThermalClusterList::enabledAndNotMustRunCount() const @@ -164,8 +164,8 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A addToCompleteList(cluster); } - sortCompleteList(); giveIndicesToClusters(); + rebuildIndex(); return ret; } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index bb9b469c31..33d15b7c32 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -99,7 +99,9 @@ class ThermalClusterList : public ClusterList bool saveToFolder(const AnyString& folder) const override; - void sortCompleteList(); + /// Sort the vector, set index value for each cluster + void rebuildIndex(); + unsigned int mustRunAndEnabledCount() const; unsigned int enabledAndNotMustRunCount() const; void removeMustRunClusters(); From 822083fb7da0a6d9303bd071556a5def2d3a5508 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 15 Jan 2024 12:14:33 +0100 Subject: [PATCH 67/88] Clean thermal lists (towards removal of thermal.list.clusters) : replace use of old cluster list with use of complete list internally - in loadEconomicCosts(), use of clusters_ with a filtering on complete list - remove() and saveDataSeriesToFolder(...) are only called from GUI, where clusters_ is contains all clusters, so we replace it with allCluster_ --- src/libs/antares/study/parts/common/cluster_list.cpp | 4 ++-- src/libs/antares/study/parts/thermal/cluster_list.cpp | 2 +- src/tests/src/libs/antares/study/test_study.cpp | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 907355f008..6ed8232a35 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -219,7 +219,7 @@ void ClusterList::markAsModified() const template bool ClusterList::remove(const Data::ClusterName& id) { - auto nbDeletion = std::erase_if(clusters_, [&id](const SharedPtr& c) { return c->id() == id; }); + auto nbDeletion = std::erase_if(allClusters_, [&id](const SharedPtr& c) { return c->id() == id; }); // Invalidating the parent area forceReload(); @@ -238,7 +238,7 @@ bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) cons template bool ClusterList::saveDataSeriesToFolder(const AnyString& folder, const String& msg) const { - return std::ranges::all_of(clusters_, [&](const auto& c) { + return std::ranges::all_of(allClusters_, [&](const auto& c) { return c->saveDataSeriesToFolder(folder); }); } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 4441e629dd..d65efab2b5 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -507,7 +507,7 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, bool ThermalClusterList::loadEconomicCosts(Study& study, const AnyString& folder) { - return std::ranges::all_of(clusters_, [&study, folder](const auto& c) + return std::ranges::all_of(each_enabled_and_not_mustrun(), [&study, folder](const auto& c) { assert(c->parentArea && "cluster: invalid parent area"); Clob buffer; diff --git a/src/tests/src/libs/antares/study/test_study.cpp b/src/tests/src/libs/antares/study/test_study.cpp index d90029d578..59256e919c 100644 --- a/src/tests/src/libs/antares/study/test_study.cpp +++ b/src/tests/src/libs/antares/study/test_study.cpp @@ -194,6 +194,7 @@ BOOST_FIXTURE_TEST_CASE(thermal_cluster_rename, ThermalClusterStudy) BOOST_FIXTURE_TEST_CASE(thermal_cluster_delete, ThermalClusterStudy) { + // gp : remove() only used in GUI (will go away when removing the GUI) BOOST_CHECK(areaA->thermal.list.findInAll("cluster") == cluster); areaA->thermal.list.remove("cluster"); BOOST_CHECK(areaA->thermal.list.findInAll("cluster") == nullptr); @@ -247,6 +248,7 @@ BOOST_FIXTURE_TEST_CASE(renewable_cluster_rename, RenewableClusterStudy) BOOST_FIXTURE_TEST_CASE(renewable_cluster_delete, RenewableClusterStudy) { + // gp : remove() only used in GUI (will go away when removing the GUI) BOOST_CHECK(areaA->renewable.list.findInAll("windcluster") == cluster); BOOST_CHECK(areaA->renewable.list.remove("windcluster")); BOOST_CHECK(areaA->renewable.list.findInAll("windcluster") == nullptr); From 405483fe729260673509c7224cc1f5d8f97ee495 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 15 Jan 2024 12:29:14 +0100 Subject: [PATCH 68/88] Clean thermal lists : correct a mistake + cleaning - loadEconomicCosts is actually called when list clusters_ is contains all clusters, so we replace use of each_enabled_and_not_mustrun() with allClusters_ - uses of algorithms instead of loops --- .../antares/study/parts/common/cluster_list.cpp | 14 ++++---------- .../antares/study/parts/thermal/cluster_list.cpp | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 6ed8232a35..ba42f8a9fd 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -238,9 +238,8 @@ bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) cons template bool ClusterList::saveDataSeriesToFolder(const AnyString& folder, const String& msg) const { - return std::ranges::all_of(allClusters_, [&](const auto& c) { - return c->saveDataSeriesToFolder(folder); - }); + return std::ranges::all_of(allClusters_, + [&](const auto& c) { return c->saveDataSeriesToFolder(folder); }); } template @@ -248,13 +247,8 @@ bool ClusterList::loadDataSeriesFromFolder(Study& s, const StudyLoadOptions& options, const AnyString& folder) { - bool ret = true; - - for (auto c : allClusters_) - { - ret = c->loadDataSeriesFromFolder(s, folder) and ret; - } - return ret; + return std::ranges::all_of(allClusters_, + [&](auto c) { return c->loadDataSeriesFromFolder(s, folder); }); } template diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index d65efab2b5..f1139bf4a4 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -507,7 +507,7 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, bool ThermalClusterList::loadEconomicCosts(Study& study, const AnyString& folder) { - return std::ranges::all_of(each_enabled_and_not_mustrun(), [&study, folder](const auto& c) + return std::ranges::all_of(allClusters_, [&study, folder](const auto& c) { assert(c->parentArea && "cluster: invalid parent area"); Clob buffer; From 1ff3065e71430fc97d9492de259b93dab807bddd Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 15 Jan 2024 13:26:37 +0100 Subject: [PATCH 69/88] Clean thermal lists (towards removal of thermal.list.clusters) : removing 2 functions that use old list clusters_ --- .../antares/study/cleaner/cleaner-v20.cpp | 2 +- .../study/parts/common/cluster_list.cpp | 10 ++------- .../antares/study/parts/common/cluster_list.h | 13 +----------- .../study/parts/renewable/container.cpp | 2 +- .../study/parts/thermal/cluster_list.cpp | 8 +------ .../study/parts/thermal/cluster_list.h | 1 - .../antares/study/parts/thermal/container.cpp | 1 - src/libs/antares/study/runtime/runtime.cpp | 21 ------------------- src/libs/antares/study/runtime/runtime.h | 2 -- .../thermal-cluster/root-node.cpp | 2 +- 10 files changed, 7 insertions(+), 55 deletions(-) diff --git a/src/libs/antares/study/cleaner/cleaner-v20.cpp b/src/libs/antares/study/cleaner/cleaner-v20.cpp index 0982a91489..8f2124a442 100644 --- a/src/libs/antares/study/cleaner/cleaner-v20.cpp +++ b/src/libs/antares/study/cleaner/cleaner-v20.cpp @@ -353,7 +353,7 @@ bool listOfFilesAnDirectoriesToKeep(StudyCleaningInfos* infos) // Exclude listOfFilesAnDirectoriesToKeepForArea(e, p, area, buffer); // Clear the memory used by the thermal clusters of the area - area->thermal.list.clear(); + area->thermal.list.clearAll(); // Interconnections { diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index ba42f8a9fd..7152d59fa1 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -57,9 +57,9 @@ bool ClusterList::exists(const Data::ClusterName& id) const } template -void ClusterList::clear() +void ClusterList::clearAll() { - clusters_.clear(); + allClusters_.clear(); } template @@ -264,12 +264,6 @@ void ClusterList::retrieveTotalCapacityAndUnitCount(double& total, uin } } -template -uint ClusterList::removeDisabledClusters() -{ - auto count = std::erase_if(clusters_, [] (auto& c) { return !c->enabled; }); - return count; -} // Force template instantiation template class ClusterList; template class ClusterList; diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 96c6a09530..b0697c5ac5 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -31,7 +31,7 @@ class ClusterList using iterator = typename Vect::iterator; using const_iterator = typename Vect::const_iterator; - void clear(); + void clearAll(); bool empty() const; void add(const SharedPtr cluster); @@ -131,17 +131,6 @@ class ClusterList */ void retrieveTotalCapacityAndUnitCount(double& total, uint& unitCount) const; - /*! - ** \brief Removes disabled clusters - ** - ** All clusters with the flag 'enabled' turned to false will be removed from 'list'. - ** As a consequence, they will no longer be seen as thermal clusters - ** from the solver's point of view. - ** \warning This method should only be used from the solver - ** - ** \return The number of disabled clusters found - */ - uint removeDisabledClusters(); unsigned int enabledCount() const; unsigned int allClustersCount() const; void giveIndicesToClusters(); diff --git a/src/libs/antares/study/parts/renewable/container.cpp b/src/libs/antares/study/parts/renewable/container.cpp index cb68a730eb..f2ecc6c644 100644 --- a/src/libs/antares/study/parts/renewable/container.cpp +++ b/src/libs/antares/study/parts/renewable/container.cpp @@ -59,7 +59,7 @@ PartRenewable::~PartRenewable() void PartRenewable::reset() { - list.clear(); + list.clearAll(); } } // namespace Data diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index f1139bf4a4..9960dbc6ab 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -27,8 +27,7 @@ ThermalClusterList::ThermalClusterList() ThermalClusterList::~ThermalClusterList() { - // deleting all thermal clusters - clear(); + clearAll(); } #define SEP IO::Separator @@ -177,11 +176,6 @@ void ThermalClusterList::removeMustRunClusters() rebuildIndex(); } -void ThermalClusterList::clearAll() -{ - allClusters_.clear(); -} - static bool ThermalClusterLoadFromProperty(ThermalCluster& cluster, const IniFile::Property* p) { if (p->key.empty()) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 33d15b7c32..84fe187420 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -105,7 +105,6 @@ class ThermalClusterList : public ClusterList unsigned int mustRunAndEnabledCount() const; unsigned int enabledAndNotMustRunCount() const; void removeMustRunClusters(); - void clearAll(); }; // class ThermalClusterList } // namespace Data diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index f5016040ef..fbb1f071d1 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -62,7 +62,6 @@ void PartThermal::reset() unsuppliedEnergyCost = 0.; spilledEnergyCost = 0.; - list.clear(); list.clearAll(); } diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index acde8df95d..3fdfcb7c54 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -286,17 +286,12 @@ bool StudyRuntimeInfos::loadFromStudy(Study& study) study.calendarOutput.reset({gd.dayOfThe1stJanuary, gd.firstWeekday, gd.firstMonthInYear, gd.leapYear}); initializeRangeLimits(study, rangeLimits); - // Removing disabled thermal clusters from solver computations - removeDisabledThermalClustersFromSolverComputations(study); - // Removing disabled short-term storage objects from solver computations removeDisabledShortTermStorageClustersFromSolverComputations(study); switch (gd.renewableGeneration()) { case rgClusters: - // Removing disabled renewable clusters from solver computations - removeDisabledRenewableClustersFromSolverComputations(study); break; case rgAggregated: // Removing all renewable clusters from solver computations @@ -406,22 +401,6 @@ static void removeClusters(Study& study, } } -void StudyRuntimeInfos::removeDisabledThermalClustersFromSolverComputations(Study& study) -{ - removeClusters( - study, "thermal", [](Area& area) { return area.thermal.list.removeDisabledClusters(); }); -} - -void StudyRuntimeInfos::removeDisabledRenewableClustersFromSolverComputations(Study& study) -{ - removeClusters(study, "renewable", [](Area& area) { - uint ret = area.renewable.list.removeDisabledClusters(); - if (ret > 0) - area.renewable.list.giveIndicesToClusters(); - return ret; - }); -} - void StudyRuntimeInfos::removeDisabledShortTermStorageClustersFromSolverComputations(Study& study) { removeClusters( diff --git a/src/libs/antares/study/runtime/runtime.h b/src/libs/antares/study/runtime/runtime.h index e70f9f223a..f85cfb6dd1 100644 --- a/src/libs/antares/study/runtime/runtime.h +++ b/src/libs/antares/study/runtime/runtime.h @@ -136,8 +136,6 @@ class StudyRuntimeInfos void initializeRangeLimits(const Study& study, StudyRangeLimits& limits); //! Prepare all thermal clusters in 'must-run' mode 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); diff --git a/src/ui/action/handler/antares-study/thermal-cluster/root-node.cpp b/src/ui/action/handler/antares-study/thermal-cluster/root-node.cpp index ab183e7ba4..a14ab9cb00 100644 --- a/src/ui/action/handler/antares-study/thermal-cluster/root-node.cpp +++ b/src/ui/action/handler/antares-study/thermal-cluster/root-node.cpp @@ -86,7 +86,7 @@ bool RootNode::performWL(Context& ctx) { // bool forcePlantCreate = ctx.clusterForceCreate[pOriginalAreaName]; if (pInfos.behavior == bhOverwrite) - ctx.area->thermal.list.clear(); + ctx.area->thermal.list.clearAll(); return true; } return false; From 2c1101814fd99ef857f608063e9244c8e3f29180 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 15 Jan 2024 14:00:45 +0100 Subject: [PATCH 70/88] Clean thermal lists (towards removal of thermal.list.clusters) : removing must-run cluster removal from clusters_ --- .../study/parts/thermal/cluster_list.cpp | 7 ---- .../study/parts/thermal/cluster_list.h | 1 - src/libs/antares/study/runtime/runtime.cpp | 34 ------------------- 3 files changed, 42 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 9960dbc6ab..06287565c1 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -169,13 +169,6 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A return ret; } -void ThermalClusterList::removeMustRunClusters() -{ - std::erase_if(clusters_, [](auto c) { return c->isMustRun(); }); - forceReload(); - rebuildIndex(); -} - static bool ThermalClusterLoadFromProperty(ThermalCluster& cluster, const IniFile::Property* p) { if (p->key.empty()) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 84fe187420..7bf9e57991 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -104,7 +104,6 @@ class ThermalClusterList : public ClusterList unsigned int mustRunAndEnabledCount() const; unsigned int enabledAndNotMustRunCount() const; - void removeMustRunClusters(); }; // class ThermalClusterList } // namespace Data diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index 3fdfcb7c54..99b5b72657 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -303,9 +303,6 @@ bool StudyRuntimeInfos::loadFromStudy(Study& study) break; } - // Must-run mode - initializeThermalClustersInMustRunMode(study); - // Areas StudyRuntimeInfosInitializeAllAreas(study, *this); @@ -338,37 +335,6 @@ uint StudyRuntimeInfos::interconnectionsCount() const return static_cast(areaLink.size()); } -void StudyRuntimeInfos::initializeThermalClustersInMustRunMode(Study& study) const -{ - logs.info(); - logs.info() << "Optimizing the thermal clusters in 'must-run' mode..."; - - // The number of thermal clusters in 'must-run' mode - uint count = 0; - - // each area... - for (uint a = 0; a != study.areas.size(); ++a) - { - Area& area = *(study.areas.byIndex[a]); - count += area.thermal.list.mustRunAndEnabledCount(); - area.thermal.list.removeMustRunClusters(); - } - - switch (count) - { - case 0: - logs.info() << "No thermal cluster in 'must-run' mode"; - break; - case 1: - logs.info() << "Found 1 thermal cluster in 'must-run' mode"; - break; - default: - logs.info() << "Found " << count << " thermal clusters in 'must-run' mode"; - } - // space - logs.info(); -} - static void removeClusters(Study& study, const char* type, std::function eachArea, From e5a9ebb3389e1bc369f30c9588e23ad1bd09f0fa Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 15 Jan 2024 14:32:39 +0100 Subject: [PATCH 71/88] Clean thermal lists : completely remove list.clusters_ --- src/libs/antares/study/parts/common/cluster_list.cpp | 8 -------- src/libs/antares/study/parts/common/cluster_list.h | 5 ----- src/libs/antares/study/parts/renewable/cluster_list.cpp | 4 ---- src/libs/antares/study/parts/thermal/cluster_list.cpp | 3 --- 4 files changed, 20 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 7152d59fa1..5f4d9732fb 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -88,14 +88,6 @@ void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer } } -template -void ClusterList::add(const SharedPtr cluster) -{ - if (exists(cluster->id())) - return; - clusters_.push_back(cluster); -} - template bool ClusterList::alreadyInAllClusters(std::string clusterId) { diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index b0697c5ac5..480624ade3 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -27,13 +27,9 @@ class ClusterList { public: using SharedPtr = typename std::shared_ptr; - using Vect = typename std::vector; - using iterator = typename Vect::iterator; - using const_iterator = typename Vect::const_iterator; void clearAll(); bool empty() const; - void add(const SharedPtr cluster); /*! ** \brief Try to find a cluster from its id (const) in the complete cluster list @@ -139,7 +135,6 @@ class ClusterList protected: // The vector containing the clusters - Vect clusters_; std::vector> allClusters_; /// thermal, renewable, etc. diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index cdd22418ce..b2d363ab3d 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -165,11 +165,7 @@ bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) continue; } - // Check the data integrity of the cluster cluster->integrityCheck(); - - // adding the renewable cluster - add(cluster); addToCompleteList(cluster); } } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 06287565c1..ada5215da3 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -157,9 +157,6 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A // Check the data integrity of the cluster cluster->integrityCheck(); - - // adding the thermal cluster - add(cluster); addToCompleteList(cluster); } From 242ba0fdd4d3888833834bd36d0dd7bf6b5f88fd Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 15 Jan 2024 15:10:54 +0100 Subject: [PATCH 72/88] Clean thermal lists : fix a compilation error --- src/tests/end-to-end/utils/utils.cpp | 1 - .../test-sc-builder-file-read-line.cpp | 2 -- .../scenario-builder/test-sc-builder-file-save.cpp | 2 -- src/tests/src/libs/antares/study/test_study.cpp | 10 ++-------- src/tests/src/solver/simulation/tests-ts-numbers.cpp | 2 -- .../handler/antares-study/thermal-cluster/create.cpp | 1 - src/ui/simulator/toolbox/input/renewable-cluster.cpp | 2 -- src/ui/simulator/toolbox/input/thermal-cluster.cpp | 2 -- 8 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/tests/end-to-end/utils/utils.cpp b/src/tests/end-to-end/utils/utils.cpp index 780991af9a..b9c652fd81 100644 --- a/src/tests/end-to-end/utils/utils.cpp +++ b/src/tests/end-to-end/utils/utils.cpp @@ -23,7 +23,6 @@ std::shared_ptr addClusterToArea(Area* area, const std::string& cluster->setName(clusterName); cluster->reset(); - area->thermal.list.add(cluster); area->thermal.list.addToCompleteList(cluster); area->thermal.list.giveIndicesToClusters(); diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index baa306bc8c..0f76631782 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -18,13 +18,11 @@ using namespace Antares::Data; void addClusterToAreaList(Area* area, std::shared_ptr cluster) { - area->thermal.list.add(cluster); area->thermal.list.addToCompleteList(cluster); } void addClusterToAreaList(Area* area, std::shared_ptr cluster) { - area->renewable.list.add(cluster); area->renewable.list.addToCompleteList(cluster); } diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 97944f69a0..0920067095 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -59,13 +59,11 @@ void referenceScBuilderFile::write() void addClusterToAreaList(Area* area, std::shared_ptr cluster) { - area->thermal.list.add(cluster); area->thermal.list.addToCompleteList(cluster); } void addClusterToAreaList(Area* area, std::shared_ptr cluster) { - area->renewable.list.add(cluster); area->renewable.list.addToCompleteList(cluster); } diff --git a/src/tests/src/libs/antares/study/test_study.cpp b/src/tests/src/libs/antares/study/test_study.cpp index 59256e919c..aa543593e6 100644 --- a/src/tests/src/libs/antares/study/test_study.cpp +++ b/src/tests/src/libs/antares/study/test_study.cpp @@ -82,9 +82,8 @@ BOOST_FIXTURE_TEST_CASE(thermal_cluster_delete, OneAreaStudy) auto disabledCluster = std::make_shared(areaA); disabledCluster->setName("Cluster1"); disabledCluster->enabled = false; - - areaA->thermal.list.add(disabledCluster); areaA->thermal.list.addToCompleteList(disabledCluster); + // Check that "Cluster1" is found BOOST_CHECK_EQUAL(areaA->thermal.list.findInAll("cluster1"), disabledCluster.get()); @@ -98,9 +97,8 @@ BOOST_FIXTURE_TEST_CASE(renewable_cluster_delete, OneAreaStudy) auto disabledCluster = std::make_shared(areaA); disabledCluster->setName("Cluster1"); disabledCluster->enabled = false; - - areaA->renewable.list.add(disabledCluster); areaA->renewable.list.addToCompleteList(disabledCluster); + // Check that "Cluster1" is found BOOST_CHECK_EQUAL(areaA->renewable.list.findInAll("cluster1"), disabledCluster.get()); @@ -160,7 +158,6 @@ BOOST_FIXTURE_TEST_CASE(thermal_cluster_add, OneAreaStudy) BOOST_CHECK_EQUAL(newCluster->name(), "Cluster"); BOOST_CHECK_EQUAL(newCluster->id(), "cluster"); - areaA->thermal.list.add(newCluster); areaA->thermal.list.addToCompleteList(newCluster); BOOST_CHECK_EQUAL(areaA->thermal.list.findInAll("cluster"), newCluster.get()); BOOST_CHECK_EQUAL(areaA->thermal.list.findInAll("Cluster"), nullptr); @@ -177,7 +174,6 @@ struct ThermalClusterStudy: public OneAreaStudy { auto newCluster = std::make_shared(areaA); newCluster->setName("Cluster"); - areaA->thermal.list.add(newCluster); areaA->thermal.list.addToCompleteList(newCluster); cluster = newCluster.get(); } @@ -212,7 +208,6 @@ BOOST_FIXTURE_TEST_CASE(renewable_cluster_add, OneAreaStudy) BOOST_CHECK(newCluster->name() == "WindCluster"); BOOST_CHECK(newCluster->id() == "windcluster"); - areaA->renewable.list.add(newCluster); areaA->renewable.list.addToCompleteList(newCluster); BOOST_CHECK(areaA->renewable.list.findInAll("windcluster") == newCluster.get()); BOOST_CHECK(areaA->renewable.list.findInAll("WindCluster") == nullptr); @@ -231,7 +226,6 @@ struct RenewableClusterStudy : public OneAreaStudy areaA = study.areaAdd("A"); auto newCluster = std::make_shared(areaA); newCluster->setName("WindCluster"); - areaA->renewable.list.add(newCluster); areaA->renewable.list.addToCompleteList(newCluster); cluster = newCluster.get(); } diff --git a/src/tests/src/solver/simulation/tests-ts-numbers.cpp b/src/tests/src/solver/simulation/tests-ts-numbers.cpp index 450c9ddbc3..f3f4368ece 100644 --- a/src/tests/src/solver/simulation/tests-ts-numbers.cpp +++ b/src/tests/src/solver/simulation/tests-ts-numbers.cpp @@ -50,14 +50,12 @@ void addClusterToAreaList(Area* area, std::shared_ptr cluster); template<> void addClusterToAreaList(Area* area, std::shared_ptr cluster) { - area->thermal.list.add(cluster); area->thermal.list.addToCompleteList(cluster); } template<> void addClusterToAreaList(Area* area, std::shared_ptr cluster) { - area->renewable.list.add(cluster); area->renewable.list.addToCompleteList(cluster); } diff --git a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp index 1439b12ed3..584a60474b 100644 --- a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp +++ b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp @@ -181,7 +181,6 @@ bool Create::performWL(Context& ctx) ctx.cluster = new Data::ThermalCluster(ctx.area); ctx.cluster->setName(pFuturPlantName); ctx.cluster->reset(); - (ctx.area)->thermal.list.add(std::shared_ptr(ctx.cluster)); (ctx.area)->thermal.list.addToCompleteList(std::shared_ptr(ctx.cluster)); (ctx.area)->thermal.list.giveIndicesToClusters(); } diff --git a/src/ui/simulator/toolbox/input/renewable-cluster.cpp b/src/ui/simulator/toolbox/input/renewable-cluster.cpp index 1dd55b16b2..d9f07bd1a7 100644 --- a/src/ui/simulator/toolbox/input/renewable-cluster.cpp +++ b/src/ui/simulator/toolbox/input/renewable-cluster.cpp @@ -387,7 +387,6 @@ void RenewableCluster::internalAddPlant(void*) logs.info() << "adding new renewable cluster " << pArea->id << '.' << sFl; cluster->setName(sFl); cluster->reset(); - pArea->renewable.list.add(cluster); pArea->renewable.list.addToCompleteList(cluster); pArea->renewable.list.giveIndicesToClusters(); @@ -465,7 +464,6 @@ void RenewableCluster::internalClonePlant(void*) // Reset to default values cluster->copyFrom(selectedPlant); - pArea->renewable.list.add(cluster); pArea->renewable.list.addToCompleteList(cluster); pArea->renewable.list.giveIndicesToClusters(); diff --git a/src/ui/simulator/toolbox/input/thermal-cluster.cpp b/src/ui/simulator/toolbox/input/thermal-cluster.cpp index e46a886f65..e3edde5c82 100644 --- a/src/ui/simulator/toolbox/input/thermal-cluster.cpp +++ b/src/ui/simulator/toolbox/input/thermal-cluster.cpp @@ -446,7 +446,6 @@ void ThermalCluster::internalAddPlant(void*) logs.info() << "adding new thermal cluster " << pArea->id << '.' << sFl; cluster->setName(sFl); cluster->reset(); - pArea->thermal.list.add(cluster); pArea->thermal.list.addToCompleteList(cluster); pArea->thermal.list.giveIndicesToClusters(); @@ -525,7 +524,6 @@ void ThermalCluster::internalClonePlant(void*) // Reset to default values cluster->copyFrom(selectedPlant); - pArea->thermal.list.add(cluster); pArea->thermal.list.addToCompleteList(cluster); pArea->thermal.list.giveIndicesToClusters(); From 119746e5fc09508387cef85df9d5751cddc6cd67 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 15 Jan 2024 16:22:22 +0100 Subject: [PATCH 73/88] Clean cluster lists : make giveIndicesToClusters() a protected member functions --- src/libs/antares/study/parts/common/cluster_list.cpp | 1 + src/libs/antares/study/parts/common/cluster_list.h | 6 +++--- src/libs/antares/study/parts/thermal/cluster_list.h | 7 ++++--- src/libs/antares/study/study.cpp | 2 -- src/tests/end-to-end/utils/utils.cpp | 1 - .../test-sc-builder-file-read-line.cpp | 11 ----------- .../scenario-builder/test-sc-builder-file-save.cpp | 10 ---------- .../thermal-price-definition.cpp | 5 ----- .../handler/antares-study/thermal-cluster/create.cpp | 1 - src/ui/simulator/toolbox/input/renewable-cluster.cpp | 3 --- src/ui/simulator/toolbox/input/thermal-cluster.cpp | 3 --- 11 files changed, 8 insertions(+), 42 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 5f4d9732fb..5ecba778a1 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -101,6 +101,7 @@ void ClusterList::addToCompleteList(std::shared_ptr cluster) return; allClusters_.push_back(cluster); sortCompleteList(); + giveIndicesToClusters(); } template diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 480624ade3..a0f917bd62 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -129,17 +129,17 @@ class ClusterList unsigned int enabledCount() const; unsigned int allClustersCount() const; - void giveIndicesToClusters(); void addToCompleteList(std::shared_ptr cluster); void sortCompleteList(); protected: - // The vector containing the clusters std::vector> allClusters_; - /// thermal, renewable, etc. virtual std::string typeID() const = 0; + // Give a special index to enabled clusters (thermal / renewable) + void giveIndicesToClusters(); + private: bool alreadyInAllClusters(std::string clusterName); diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 7bf9e57991..6b440d4985 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -99,12 +99,13 @@ class ThermalClusterList : public ClusterList bool saveToFolder(const AnyString& folder) const override; - /// Sort the vector, set index value for each cluster - void rebuildIndex(); - unsigned int mustRunAndEnabledCount() const; unsigned int enabledAndNotMustRunCount() const; +private: + // Give a special index to enbled and not must-run THERMAL clusters + void rebuildIndex(); + }; // class ThermalClusterList } // namespace Data } // namespace Antares diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index 293b5ef7d3..bc8a279b78 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -1086,11 +1086,9 @@ bool Study::clusterRename(Cluster* cluster, ClusterName newName) { case kRenewable: ret = area.renewable.list.rename(cluster->id(), newName); - area.renewable.list.giveIndicesToClusters(); break; case kThermal: ret = area.thermal.list.rename(cluster->id(), newName); - area.thermal.list.giveIndicesToClusters(); break; case kUnknown: logs.error() << "Unknown cluster type"; diff --git a/src/tests/end-to-end/utils/utils.cpp b/src/tests/end-to-end/utils/utils.cpp index b9c652fd81..0056f72939 100644 --- a/src/tests/end-to-end/utils/utils.cpp +++ b/src/tests/end-to-end/utils/utils.cpp @@ -24,7 +24,6 @@ std::shared_ptr addClusterToArea(Area* area, const std::string& cluster->reset(); area->thermal.list.addToCompleteList(cluster); - area->thermal.list.giveIndicesToClusters(); return cluster; } diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp index 0f76631782..eb146667a8 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-read-line.cpp @@ -103,12 +103,6 @@ struct Fixture thCluster_12->series.timeSeries.resize(14, 1); thCluster_31->series.timeSeries.resize(14, 1); - // Thermal clusters : update areas local numbering for clusters - area_1->thermal.list.giveIndicesToClusters(); - area_2->thermal.list.giveIndicesToClusters(); - area_3->thermal.list.giveIndicesToClusters(); - - // Add renewable clusters rnCluster_21 = addClusterToArea(area_2, "rn-cluster-21"); rnCluster_31 = addClusterToArea(area_3, "rn-cluster-31"); @@ -119,11 +113,6 @@ struct Fixture rnCluster_31->series.timeSeries.resize(9, 1); rnCluster_32->series.timeSeries.resize(9, 1); - // Renewable clusters : update areas local numbering for clusters - area_1->renewable.list.giveIndicesToClusters(); - area_2->renewable.list.giveIndicesToClusters(); - area_3->renewable.list.giveIndicesToClusters(); - // Resize all TS numbers storage (1 column x nbYears lines) area_1->resizeAllTimeseriesNumbers(study->parameters.nbYears); area_2->resizeAllTimeseriesNumbers(study->parameters.nbYears); diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 0920067095..fa5dee9673 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -144,11 +144,6 @@ struct commonFixture thCluster_12->series.timeSeries.resize(14, 1); thCluster_31->series.timeSeries.resize(14, 1); - // Thermal clusters : update areas local numbering for clusters - area_1->thermal.list.giveIndicesToClusters(); - area_2->thermal.list.giveIndicesToClusters(); - area_3->thermal.list.giveIndicesToClusters(); - // Add renewable clusters rnCluster_21 = addClusterToArea(area_2, "rn-cluster-21"); rnCluster_31 = addClusterToArea(area_3, "rn-cluster-31"); @@ -159,11 +154,6 @@ struct commonFixture rnCluster_31->series.timeSeries.resize(9, 1); rnCluster_32->series.timeSeries.resize(9, 1); - // Renewable clusters : update areas local numbering for clusters - area_1->renewable.list.giveIndicesToClusters(); - area_2->renewable.list.giveIndicesToClusters(); - area_3->renewable.list.giveIndicesToClusters(); - // Resize all TS numbers storage (1 column x nbYears lines) area_1->resizeAllTimeseriesNumbers(study->parameters.nbYears); area_2->resizeAllTimeseriesNumbers(study->parameters.nbYears); diff --git a/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp b/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp index 426518405e..eaf12c2466 100644 --- a/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp +++ b/src/tests/src/libs/antares/study/thermal-price-definition/thermal-price-definition.cpp @@ -164,7 +164,6 @@ BOOST_FIXTURE_TEST_CASE(checkCo2_checkCO2CostColumnNumber_OK, FixtureFull) auto cluster = area->thermal.list.findInAll("some cluster"); cluster->series.timeSeries.reset(3, 8760); - area->thermal.list.giveIndicesToClusters(); auto& ecoInput = cluster->ecoInput; ecoInput.co2cost.reset(3, 8760); @@ -179,8 +178,6 @@ BOOST_FIXTURE_TEST_CASE(checkCo2_checkCO2CostColumnNumber_KO, FixtureFull) cluster->series.timeSeries.reset(3, 8760); - area->thermal.list.giveIndicesToClusters(); - auto& ecoInput = cluster->ecoInput; ecoInput.co2cost.reset(2, 8760); @@ -195,8 +192,6 @@ BOOST_FIXTURE_TEST_CASE(checkFuelAndCo2_checkColumnNumber_OK, FixtureFull) cluster->series.timeSeries.reset(3, 8760); - area->thermal.list.giveIndicesToClusters(); - cluster->ecoInput.fuelcost.reset(3, 8760); cluster->ecoInput.co2cost.reset(3, 8760); diff --git a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp index 584a60474b..07793cab2a 100644 --- a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp +++ b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp @@ -182,7 +182,6 @@ bool Create::performWL(Context& ctx) ctx.cluster->setName(pFuturPlantName); ctx.cluster->reset(); (ctx.area)->thermal.list.addToCompleteList(std::shared_ptr(ctx.cluster)); - (ctx.area)->thermal.list.giveIndicesToClusters(); } else { diff --git a/src/ui/simulator/toolbox/input/renewable-cluster.cpp b/src/ui/simulator/toolbox/input/renewable-cluster.cpp index d9f07bd1a7..05112d5205 100644 --- a/src/ui/simulator/toolbox/input/renewable-cluster.cpp +++ b/src/ui/simulator/toolbox/input/renewable-cluster.cpp @@ -291,7 +291,6 @@ void RenewableCluster::internalDeletePlant(void*) Refresh(); MarkTheStudyAsModified(); updateInnerValues(); - pArea->renewable.list.giveIndicesToClusters(); study->uiinfo->reload(); } else @@ -388,7 +387,6 @@ void RenewableCluster::internalAddPlant(void*) cluster->setName(sFl); cluster->reset(); pArea->renewable.list.addToCompleteList(cluster); - pArea->renewable.list.giveIndicesToClusters(); // Update the list update(); @@ -465,7 +463,6 @@ void RenewableCluster::internalClonePlant(void*) cluster->copyFrom(selectedPlant); pArea->renewable.list.addToCompleteList(cluster); - pArea->renewable.list.giveIndicesToClusters(); // Update the list update(); diff --git a/src/ui/simulator/toolbox/input/thermal-cluster.cpp b/src/ui/simulator/toolbox/input/thermal-cluster.cpp index e3edde5c82..b3a0afec85 100644 --- a/src/ui/simulator/toolbox/input/thermal-cluster.cpp +++ b/src/ui/simulator/toolbox/input/thermal-cluster.cpp @@ -317,7 +317,6 @@ void ThermalCluster::internalDeletePlant(void*) Refresh(); MarkTheStudyAsModified(); updateInnerValues(); - pArea->thermal.list.giveIndicesToClusters(); study->uiinfo->reload(); // delete associated constraints @@ -447,7 +446,6 @@ void ThermalCluster::internalAddPlant(void*) cluster->setName(sFl); cluster->reset(); pArea->thermal.list.addToCompleteList(cluster); - pArea->thermal.list.giveIndicesToClusters(); // Update the list update(); @@ -525,7 +523,6 @@ void ThermalCluster::internalClonePlant(void*) cluster->copyFrom(selectedPlant); pArea->thermal.list.addToCompleteList(cluster); - pArea->thermal.list.giveIndicesToClusters(); // Update the list update(); From 9c321ddff7ca74b9e2e52bc0dbdcade848fabfdd Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 18 Jan 2024 17:37:59 +0100 Subject: [PATCH 74/88] Clean thermal lists : correction of an error --- src/libs/antares/study/parts/thermal/cluster_list.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index ada5215da3..dd4b9b8316 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -289,13 +289,13 @@ bool ThermalClusterLoadFromSection(const AnyString& filename, void ThermalClusterList::calculationOfSpinning() { - for (auto cluster : each_enabled_and_not_mustrun()) + for (auto cluster : each_enabled()) cluster->calculationOfSpinning(); } void ThermalClusterList::reverseCalculationOfSpinning() { - for (auto cluster : each_enabled_and_not_mustrun()) + for (auto cluster : each_enabled()) cluster->reverseCalculationOfSpinning(); } From beecabc7c580601e1cd9f3fa5cfd0d02c32b14ca Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 19 Jan 2024 10:17:13 +0100 Subject: [PATCH 75/88] Clean thermal lists : correcting an error --- src/libs/antares/InfoCollection/StudyInfoCollector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp index d394be44f3..dd44b8a739 100644 --- a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp +++ b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp @@ -59,7 +59,7 @@ void StudyInfoCollector::enabledThermalClustersCountToFileContent(FileContent& f for (auto i = study_.areas.begin(); i != end; ++i) { Area& area = *(i->second); - nbEnabledThermalClusters += area.thermal.list.mustRunAndEnabledCount(); + nbEnabledThermalClusters += area.thermal.list.enabledAndNotMustRunCount(); } // Adding an item related to number of enabled thermal clusters to the file content From fcc3ee862f3d52325c704bc1ff2758259a971f51 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 15 Feb 2024 16:08:15 +0100 Subject: [PATCH 76/88] renamed giveIndicesToClusters --- .../antares/study/parts/common/cluster_list.cpp | 4 ++-- src/libs/antares/study/parts/common/cluster_list.h | 2 +- .../antares/study/parts/renewable/cluster_list.cpp | 14 +++++++------- .../antares/study/parts/thermal/cluster_list.cpp | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 5ecba778a1..e0bb693a9e 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -101,7 +101,7 @@ void ClusterList::addToCompleteList(std::shared_ptr cluster) return; allClusters_.push_back(cluster); sortCompleteList(); - giveIndicesToClusters(); + rebuildIndexes(); } template @@ -123,7 +123,7 @@ unsigned int ClusterList::allClustersCount() const } template -void ClusterList::giveIndicesToClusters() +void ClusterList::rebuildIndexes() { // First, we give an index to every cluster, enabled / must-run or not. // We do that to : diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index a0f917bd62..f1c907d33c 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -138,7 +138,7 @@ class ClusterList virtual std::string typeID() const = 0; // Give a special index to enabled clusters (thermal / renewable) - void giveIndicesToClusters(); + void rebuildIndexes(); private: bool alreadyInAllClusters(std::string clusterName); diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index b2d363ab3d..3c3215b99b 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -46,15 +46,15 @@ bool RenewableClusterList::saveToFolder(const AnyString& folder) const // This key will be silently ignored the next time s->add("name", c->name()); - if (not c->group().empty()) + if (!c->group().empty()) s->add("group", c->group()); - if (not c->enabled) + if (!c->enabled) s->add("enabled", "false"); - if (not Math::Zero(c->nominalCapacity)) + if (!Math::Zero(c->nominalCapacity)) s->add("nominalCapacity", c->nominalCapacity); - if (not Math::Zero(c->unitCount)) + if (!Math::Zero(c->unitCount)) s->add("unitCount", c->unitCount); s->add("ts-interpretation", c->getTimeSeriesModeAsString()); @@ -123,7 +123,7 @@ static bool ClusterLoadFromSection(const AnyString& filename, << "`: Invalid key/value"; continue; } - if (not ClusterLoadFromProperty(cluster, property)) + if (!ClusterLoadFromProperty(cluster, property)) { logs.warning() << '`' << filename << "`: `" << section.name << "`/`" << property->key << "`: The property is unknown and ignored"; @@ -160,7 +160,7 @@ bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) auto cluster = std::make_shared(area); // Load data of a renewable cluster from a ini file section - if (not ClusterLoadFromSection(buffer, *cluster, *section)) + if (!ClusterLoadFromSection(buffer, *cluster, *section)) { continue; } @@ -170,7 +170,7 @@ bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) } } - giveIndicesToClusters(); + rebuildIndexes(); return ret; } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index dd4b9b8316..e39990ba80 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -160,7 +160,7 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A addToCompleteList(cluster); } - giveIndicesToClusters(); + rebuildIndexes(); rebuildIndex(); return ret; From 08b28c78ad19f3b5875f751c8df06e27b632ce10 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 15 Feb 2024 17:21:12 +0100 Subject: [PATCH 77/88] remove isNotMustRun, remove assert not compiling, remove unused args from functions --- src/libs/antares/study/area/list.cpp | 6 +++--- .../antares/study/parts/common/cluster_list.cpp | 14 +++----------- .../antares/study/parts/common/cluster_list.h | 3 --- src/libs/antares/study/parts/thermal/cluster.h | 1 - .../antares/study/parts/thermal/cluster_list.cpp | 3 +-- .../antares/study/parts/thermal/cluster_list.h | 15 ++++++++------- src/libs/antares/study/study.importprepro.cpp | 2 +- src/solver/hydro/management/management.cpp | 3 --- src/solver/simulation/sim_calcul_economique.cpp | 3 --- 9 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index b0f0505899..cb89b5a218 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -907,9 +907,9 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, // Thermal cluster list { buffer.clear() << study.folderInput << SEP << "thermal" << SEP << "prepro"; - ret = area.thermal.list.loadPreproFromFolder(study, options, buffer) && ret; + ret = area.thermal.list.loadPreproFromFolder(study, buffer) && ret; buffer.clear() << study.folderInput << SEP << "thermal" << SEP << "series"; - ret = area.thermal.list.loadDataSeriesFromFolder(study, options, buffer) && ret; + ret = area.thermal.list.loadDataSeriesFromFolder(study, buffer) && ret; ret = area.thermal.list.loadEconomicCosts(study, buffer) && ret; // In adequacy mode, all thermal clusters must be in 'mustrun' mode @@ -931,7 +931,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, if (study.header.version >= 810) { buffer.clear() << study.folderInput << SEP << "renewables" << SEP << "series"; - ret = area.renewable.list.loadDataSeriesFromFolder(study, options, buffer) && ret; + ret = area.renewable.list.loadDataSeriesFromFolder(study, buffer) && ret; } // Adequacy patch diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index e0bb693a9e..35de0e31fb 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -31,7 +31,7 @@ template std::shared_ptr ClusterList::enabledClusterAt(unsigned int index) const { // No operator [] was found for std::view (returned by each_enabled()). - // The current function is there to replace it. + // The current function is there to replace it. return *(std::views::drop(each_enabled(), index).begin()); } @@ -78,7 +78,7 @@ void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer Clob path; std::string ts_content; - for (auto cluster : each_enabled()) + for (auto cluster : each_enabled()) { path.clear() << "ts-numbers" << SEP << typeID() << SEP << cluster->parentArea->id << SEP << cluster->id() << ".txt"; @@ -228,19 +228,11 @@ bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) cons }); } -template -bool ClusterList::saveDataSeriesToFolder(const AnyString& folder, const String& msg) const -{ - return std::ranges::all_of(allClusters_, - [&](const auto& c) { return c->saveDataSeriesToFolder(folder); }); -} - template bool ClusterList::loadDataSeriesFromFolder(Study& s, - const StudyLoadOptions& options, const AnyString& folder) { - return std::ranges::all_of(allClusters_, + return std::ranges::all_of(allClusters_, [&](auto c) { return c->loadDataSeriesFromFolder(s, folder); }); } diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index f1c907d33c..dda29a8168 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -105,13 +105,10 @@ class ClusterList /// \name IO functions /// @{ bool loadDataSeriesFromFolder(Study& study, - const StudyLoadOptions& options, const AnyString& folder); bool saveDataSeriesToFolder(const AnyString& folder) const; - bool saveDataSeriesToFolder(const AnyString& folder, const YString& msg) const; - virtual bool saveToFolder(const AnyString& folder) const = 0; ///@} diff --git a/src/libs/antares/study/parts/thermal/cluster.h b/src/libs/antares/study/parts/thermal/cluster.h index e10c964025..6e1edfe79d 100644 --- a/src/libs/antares/study/parts/thermal/cluster.h +++ b/src/libs/antares/study/parts/thermal/cluster.h @@ -246,7 +246,6 @@ class ThermalCluster final : public Cluster, public std::enable_shared_from_this //! Mustrun bool mustrun = false; bool isMustRun() const { return mustrun; } - bool isNotMustRun() const { return not mustrun; } //! Mustrun (as it were at the loading of the data) // diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index e39990ba80..4297df9015 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -57,7 +57,7 @@ void ThermalClusterList::rebuildIndex() unsigned int ThermalClusterList::enabledAndNotMustRunCount() const { - return std::ranges::count_if(allClusters_, [](auto c) { return c->isEnabled() && c->isNotMustRun(); }); + return std::ranges::count_if(allClusters_, [](auto c) { return c->isEnabled() && !c->isMustRun(); }); } unsigned int ThermalClusterList::mustRunAndEnabledCount() const @@ -459,7 +459,6 @@ bool ThermalClusterList::saveEconomicCosts(const AnyString& folder) const } bool ThermalClusterList::loadPreproFromFolder(Study& study, - const StudyLoadOptions& options, const AnyString& folder) { const bool globalThermalTSgeneration diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 6b440d4985..f5871e6e24 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -1,5 +1,6 @@ #pragma once +#include #include "../common/cluster_list.h" #include "cluster.h" @@ -59,16 +60,16 @@ class ThermalClusterList : public ClusterList void enableMustrunForEveryone(); //@} - auto each_mustrun_and_enabled() const - { + auto each_mustrun_and_enabled() const + { return allClusters_ | std::views::filter(&ThermalCluster::isMustRun) | std::views::filter(&ThermalCluster::isEnabled); } - auto each_enabled_and_not_mustrun() const - { + auto each_enabled_and_not_mustrun() const + { return allClusters_ | std::views::filter(&ThermalCluster::isEnabled) - | std::views::filter(&ThermalCluster::isNotMustRun); + | std::views::filter(std::not_fn(&ThermalCluster::isMustRun)); } @@ -90,7 +91,7 @@ class ThermalClusterList : public ClusterList ** \param folder The target folder ** \return A non-zero value if the operation succeeded, 0 otherwise */ - bool loadPreproFromFolder(Study& s, const StudyLoadOptions& options, const AnyString& folder); + bool loadPreproFromFolder(Study& s, const AnyString& folder); bool loadEconomicCosts(Study& s, const AnyString& folder); @@ -103,7 +104,7 @@ class ThermalClusterList : public ClusterList unsigned int enabledAndNotMustRunCount() const; private: - // Give a special index to enbled and not must-run THERMAL clusters + // Give a special index to enbled and not must-run THERMAL clusters void rebuildIndex(); }; // class ThermalClusterList diff --git a/src/libs/antares/study/study.importprepro.cpp b/src/libs/antares/study/study.importprepro.cpp index 3fa815ca7e..0a577b301d 100644 --- a/src/libs/antares/study/study.importprepro.cpp +++ b/src/libs/antares/study/study.importprepro.cpp @@ -114,7 +114,7 @@ bool Study::importTimeseriesIntoInput() area.thermal.list.reverseCalculationOfSpinning(); buffer.clear() << folderInput << SEP << "thermal" << SEP << "series"; - ret = area.thermal.list.saveDataSeriesToFolder(buffer.c_str(), msg) && ret; + ret = area.thermal.list.saveDataSeriesToFolder(buffer.c_str()) && ret; ++progression; }); } diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index 2b4041aa58..15e3c06a92 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -410,10 +410,7 @@ void HydroManagement::prepareNetDemand(uint numSpace, uint year, Data::Simulatio : scratchpad.originalMustrunSum[hour]); for (auto c : area.renewable.list.each_enabled()) - { - assert(cluster.series.timeSeries.jit == nullptr && "No JIT data from the solver"); netdemand -= c->valueAtTimeStep(year, hour); - } } assert(!Math::NaN(netdemand) diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index d06d5d4483..9a0e058020 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -606,10 +606,7 @@ void SIM_RenseignementProblemeHebdo(const Study& study, + scratchpad.mustrunSum[hourInYear]; for (auto c : area.renewable.list.each_enabled()) - { - assert(cluster.series.timeSeries.jit == nullptr && "No JIT data from the solver"); mustRunGen += c->valueAtTimeStep(year, hourInYear); - } } assert( From d2c6f3bef7db879547b5f3e7ca21b4667fd47497 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 16 Feb 2024 11:40:35 +0100 Subject: [PATCH 78/88] rename enabledAndMustRunCount --- src/libs/antares/study/parts/thermal/cluster_list.cpp | 4 ++-- src/libs/antares/study/parts/thermal/cluster_list.h | 2 +- src/libs/antares/study/runtime/runtime.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 4297df9015..6174fdb080 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -39,7 +39,7 @@ std::string ThermalClusterList::typeID() const uint64_t ThermalClusterList::memoryUsage() const { - uint64_t ret = sizeof(ThermalClusterList) + (2 * sizeof(void*)) * mustRunAndEnabledCount(); + uint64_t ret = sizeof(ThermalClusterList) + (2 * sizeof(void*)) * enabledAndMustRunCount(); std::ranges::for_each(each_enabled_and_not_mustrun(), [&ret](const auto c) { ret += c->memoryUsage(); }); return ret; } @@ -60,7 +60,7 @@ unsigned int ThermalClusterList::enabledAndNotMustRunCount() const return std::ranges::count_if(allClusters_, [](auto c) { return c->isEnabled() && !c->isMustRun(); }); } -unsigned int ThermalClusterList::mustRunAndEnabledCount() const +unsigned int ThermalClusterList::enabledAndMustRunCount() const { return std::ranges::count_if(allClusters_, [](auto c) { return c->isEnabled() && c->isMustRun(); }); } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index f5871e6e24..d09c3983bc 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -100,7 +100,7 @@ class ThermalClusterList : public ClusterList bool saveToFolder(const AnyString& folder) const override; - unsigned int mustRunAndEnabledCount() const; + unsigned int enabledAndMustRunCount() const; unsigned int enabledAndNotMustRunCount() const; private: diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index 99b5b72657..d549b8cc08 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -93,7 +93,7 @@ static void StudyRuntimeInfosInitializeAllAreas(Study& study, StudyRuntimeInfos& // statistics r.thermalPlantTotalCount += area.thermal.list.enabledAndNotMustRunCount(); - r.thermalPlantTotalCountMustRun += area.thermal.list.mustRunAndEnabledCount(); + r.thermalPlantTotalCountMustRun += area.thermal.list.enabledAndMustRunCount(); r.shortTermStorageCount += area.shortTermStorage.count(); } From 3689c46746cafb5bb0cc1099ebeac57e5ea1fc22 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 16 Feb 2024 11:45:06 +0100 Subject: [PATCH 79/88] activate sonarcloud --- .github/workflows/sonarcloud.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 44908b595c..7e8df4d671 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -6,6 +6,9 @@ on: - main - develop - release/* + - fix/* + - feature/* + pull_request: jobs: From 00a911bf9bf5b39c47f29d4929cb5f31f13747f1 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 16 Feb 2024 16:48:46 +0100 Subject: [PATCH 80/88] fix compile --- .gitignore | 1 + src/libs/antares/study/CMakeLists.txt | 1 - .../study/parts/renewable/cluster_list.h | 1 + .../study/parts/renewable/cluster_list.h | 28 ------------------- src/solver/simulation/timeseries-numbers.cpp | 2 +- src/solver/ts-generator/generator.cpp | 4 +-- 6 files changed, 5 insertions(+), 32 deletions(-) delete mode 100644 src/libs/antares/study/parts/renewable/cluster_list.h diff --git a/.gitignore b/.gitignore index 1afaf89c00..e9566a3906 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ Makefile src/.vs src/config.h +src/config/include # Yuni src/ext/yuni/src/ProfileBuild.cmake diff --git a/src/libs/antares/study/CMakeLists.txt b/src/libs/antares/study/CMakeLists.txt index 08620864ec..2f61b665d2 100644 --- a/src/libs/antares/study/CMakeLists.txt +++ b/src/libs/antares/study/CMakeLists.txt @@ -67,7 +67,6 @@ source_group("study\\part\\common" FILES ${SRC_STUDY_PART_COMMON}) set(SRC_STUDY_PART_THERMAL include/antares/study/parts/thermal/container.h - include/antares/study/parts/thermal/container.hxx parts/thermal/container.cpp include/antares/study/parts/thermal/prepro.h include/antares/study/parts/thermal/prepro.hxx diff --git a/src/libs/antares/study/include/antares/study/parts/renewable/cluster_list.h b/src/libs/antares/study/include/antares/study/parts/renewable/cluster_list.h index bdbaab971c..de45a30811 100644 --- a/src/libs/antares/study/include/antares/study/parts/renewable/cluster_list.h +++ b/src/libs/antares/study/include/antares/study/parts/renewable/cluster_list.h @@ -38,6 +38,7 @@ class RenewableClusterList : public ClusterList { public: std::string typeID() const override; + uint64_t memoryUsage() const override; bool loadFromFolder(const AnyString& folder, Area* area); bool saveToFolder(const AnyString& folder) const override; }; // class RenewableClusterList diff --git a/src/libs/antares/study/parts/renewable/cluster_list.h b/src/libs/antares/study/parts/renewable/cluster_list.h deleted file mode 100644 index db1849d483..0000000000 --- a/src/libs/antares/study/parts/renewable/cluster_list.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __ANTARES_LIBS_STUDY_PARTS_RENEWABLE_CLUSTER_LIST_H__ -#define __ANTARES_LIBS_STUDY_PARTS_RENEWABLE_CLUSTER_LIST_H__ - -#include "../../fwd.h" -#include "cluster.h" -#include "../common/cluster_list.h" - -namespace Antares -{ -namespace Data -{ -/*! -** \brief List of renewable clusters -** \ingroup renewableclusters -*/ -class RenewableClusterList : public ClusterList -{ -public: - std::string typeID() const override; - uint64_t memoryUsage() const override; - bool loadFromFolder(const AnyString& folder, Area* area); - bool saveToFolder(const AnyString& folder) const override; - -}; // class RenewableClusterList -} // namespace Data -} // namespace Antares - -#endif /* __ANTARES_LIBS_STUDY_PARTS_RENEWABLE_CLUSTER_LIST_H__ */ diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 5803368f3d..2a8290659c 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -300,7 +300,7 @@ bool checkInterModalConsistencyForArea(Area& area, if (isTSintermodal[indexTS]) { for (auto cluster : area.thermal.list.each_enabled()) - listNumberTsOverArea.push_back(cluster.series.timeSeries.width); + listNumberTsOverArea.push_back(cluster->series.timeSeries.width); } // Renewable clusters : Add renewable's number of TS of each cluster in area ... diff --git a/src/solver/ts-generator/generator.cpp b/src/solver/ts-generator/generator.cpp index 82f25d1b95..fd40b286a2 100644 --- a/src/solver/ts-generator/generator.cpp +++ b/src/solver/ts-generator/generator.cpp @@ -54,7 +54,7 @@ void ResizeGeneratedTimeSeries(Data::AreaList& areas, Data::Parameters& params) // Thermal bool globalThermalTSgeneration = params.timeSeriesToGenerate & Data::timeSeriesThermal; - for (auto [_, cluster] : area.thermal.list.mapping) + for (auto& cluster : area.thermal.list.each_enabled()) { if (cluster->doWeGenerateTS(globalThermalTSgeneration)) cluster->series.timeSeries.reset(params.nbTimeSeriesThermal, HOURS_PER_YEAR); @@ -71,4 +71,4 @@ void DestroyAll(Data::Study& study) Destroy(study, (uint)-1); } -} // Antares::TSGenerator \ No newline at end of file +} // Antares::TSGenerator From 4c47d7d2db875abf441e00146d6f4ce94bcf73b4 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 19 Feb 2024 10:23:18 +0100 Subject: [PATCH 81/88] use all() to reset TS --- src/solver/ts-generator/generator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/ts-generator/generator.cpp b/src/solver/ts-generator/generator.cpp index fd40b286a2..c56ec94ea1 100644 --- a/src/solver/ts-generator/generator.cpp +++ b/src/solver/ts-generator/generator.cpp @@ -54,7 +54,7 @@ void ResizeGeneratedTimeSeries(Data::AreaList& areas, Data::Parameters& params) // Thermal bool globalThermalTSgeneration = params.timeSeriesToGenerate & Data::timeSeriesThermal; - for (auto& cluster : area.thermal.list.each_enabled()) + for (auto& cluster : area.thermal.list.all()) { if (cluster->doWeGenerateTS(globalThermalTSgeneration)) cluster->series.timeSeries.reset(params.nbTimeSeriesThermal, HOURS_PER_YEAR); From f3f73c1e169895c231c5112c11b80b0733963c6c Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 19 Feb 2024 10:46:28 +0100 Subject: [PATCH 82/88] code smells 1 --- .../InfoCollection/StudyInfoCollector.cpp | 2 +- .../antares/study/parts/common/cluster_list.h | 4 +- .../antares/study/parts/thermal/cluster.h | 2 +- .../study/parts/thermal/cluster_list.h | 2 +- .../antares/study/parts/thermal/container.h | 2 +- .../study/parts/common/cluster_list.cpp | 2 +- .../antares/study/parts/thermal/cluster.cpp | 6 +- .../study/parts/thermal/cluster_list.cpp | 218 +++++++++--------- .../antares/study/parts/thermal/container.cpp | 2 +- .../scenario-builder/ThermalTSNumberData.cpp | 4 +- .../antares/study/scenario-builder/rules.cpp | 3 +- src/solver/simulation/common-eco-adq.cpp | 2 +- .../antares/solver/simulation/solver.hxx | 2 +- 13 files changed, 124 insertions(+), 127 deletions(-) diff --git a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp index 781eb303a9..20a1672b74 100644 --- a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp +++ b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp @@ -78,7 +78,7 @@ void StudyInfoCollector::enabledThermalClustersCountToFileContent(FileContent& f auto end = study_.areas.end(); for (auto i = study_.areas.begin(); i != end; ++i) { - Area& area = *(i->second); + const Area& area = *(i->second); nbEnabledThermalClusters += area.thermal.list.enabledAndNotMustRunCount(); } diff --git a/src/libs/antares/study/include/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/include/antares/study/parts/common/cluster_list.h index 4e401d2ab5..20493bc0cb 100644 --- a/src/libs/antares/study/include/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/include/antares/study/parts/common/cluster_list.h @@ -91,7 +91,7 @@ class ClusterList //@} SharedPtr operator[](std::size_t idx) { return allClusters_[idx]; } - const SharedPtr operator[](std::size_t idx) const { return allClusters_[idx]; } + SharedPtr operator[](std::size_t idx) const { return allClusters_[idx]; } SharedPtr enabledClusterAt(unsigned int index) const; /*! @@ -99,7 +99,7 @@ class ClusterList ** ** \param n A number of years */ - void resizeAllTimeseriesNumbers(uint n); + void resizeAllTimeseriesNumbers(uint n) const; void storeTimeseriesNumbers(Solver::IResultWriter& writer) const; diff --git a/src/libs/antares/study/include/antares/study/parts/thermal/cluster.h b/src/libs/antares/study/include/antares/study/parts/thermal/cluster.h index 6986a07d5c..3b32763d51 100644 --- a/src/libs/antares/study/include/antares/study/parts/thermal/cluster.h +++ b/src/libs/antares/study/include/antares/study/parts/thermal/cluster.h @@ -211,7 +211,7 @@ class ThermalCluster final : public Cluster, public std::enable_shared_from_this /*! ** \brief Check the validity of Min Stable Power with a new modulation value */ - bool checkMinStablePowerWithNewModulation(uint index, double value); + bool checkMinStablePowerWithNewModulation(uint idx, double value); //@} bool doWeGenerateTS(bool globalTSgeneration) const; diff --git a/src/libs/antares/study/include/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/include/antares/study/parts/thermal/cluster_list.h index 3df5bb030d..5bd3cda4e5 100644 --- a/src/libs/antares/study/include/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/include/antares/study/parts/thermal/cluster_list.h @@ -125,7 +125,7 @@ class ThermalClusterList : public ClusterList private: // Give a special index to enbled and not must-run THERMAL clusters - void rebuildIndex(); + void rebuildIndex() const; }; // class ThermalClusterList } // namespace Data diff --git a/src/libs/antares/study/include/antares/study/parts/thermal/container.h b/src/libs/antares/study/include/antares/study/parts/thermal/container.h index f96de181dd..fb6ea8d251 100644 --- a/src/libs/antares/study/include/antares/study/parts/thermal/container.h +++ b/src/libs/antares/study/include/antares/study/parts/thermal/container.h @@ -77,7 +77,7 @@ class PartThermal // Check & correct availability timeseries for thermal availability // Only applies if time-series are ready-made - void checkAndCorrectAvailability(); + void checkAndCorrectAvailability() const; public: //! The unsupplied energy cost (Euros/MWh) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 64030352c4..1cb99b9a5d 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -83,7 +83,7 @@ void ClusterList::clearAll() } template -void ClusterList::resizeAllTimeseriesNumbers(uint n) +void ClusterList::resizeAllTimeseriesNumbers(uint n) const { for (auto c : allClusters_) c->series.timeseriesNumbers.reset(1, n); diff --git a/src/libs/antares/study/parts/thermal/cluster.cpp b/src/libs/antares/study/parts/thermal/cluster.cpp index 0d0aad1841..e3b206b3ab 100644 --- a/src/libs/antares/study/parts/thermal/cluster.cpp +++ b/src/libs/antares/study/parts/thermal/cluster.cpp @@ -671,9 +671,9 @@ bool ThermalCluster::checkMinStablePower() return true; } -bool ThermalCluster::checkMinStablePowerWithNewModulation(uint index, double value) +bool ThermalCluster::checkMinStablePowerWithNewModulation(uint idx, double value) { - if (not minDivModulation.isCalculated || index == minDivModulation.index) + if (not minDivModulation.isCalculated || idx == minDivModulation.index) calculatMinDivModulation(); else { @@ -681,7 +681,7 @@ bool ThermalCluster::checkMinStablePowerWithNewModulation(uint index, double val if (div < minDivModulation.value) { minDivModulation.value = div; - minDivModulation.index = index; + minDivModulation.index = idx; } } diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index d5de8b4c5b..09ba0b3123 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -69,7 +69,7 @@ static bool ThermalClusterLoadFromSection(const AnyString& filename, ThermalCluster& cluster, const IniFile::Section& section); -void ThermalClusterList::rebuildIndex() +void ThermalClusterList::rebuildIndex() const { uint indx = 0; for (auto& c : each_enabled_and_not_mustrun()) @@ -88,7 +88,7 @@ unsigned int ThermalClusterList::enabledAndMustRunCount() const bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, Area* area) { - assert(area and "A parent area is required"); + assert(area && "A parent area is required"); // logs logs.info() << "Loading thermal configuration for the area " << area->name; @@ -114,7 +114,7 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A auto cluster = std::make_shared(area); // Load data of a thermal cluster from a ini file section - if (not ThermalClusterLoadFromSection(study.buffer, *cluster, *section)) + if (!ThermalClusterLoadFromSection(study.buffer, *cluster, *section)) { continue; } @@ -147,20 +147,20 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A }; bool r = cluster->modulation.loadFromCSVFile( modulationFile, thermalModulationMax, HOURS_PER_YEAR, options); - if (not r and study.usedByTheSolver) + if (!r && study.usedByTheSolver) { cluster->modulation.reset(thermalModulationMax, HOURS_PER_YEAR); cluster->modulation.fill(1.); cluster->modulation.fillColumn(thermalMinGenModulation, 0.); } - ret = ret and r; + ret = ret && r; // Special operations when not ran from the interface (aka solver) if (study.usedByTheSolver) { - if (not study.parameters.include.thermal.minStablePower) + if (!study.parameters.include.thermal.minStablePower) cluster->minStablePower = 0.; - if (not study.parameters.include.thermal.minUPTime) + if (!study.parameters.include.thermal.minUPTime) { cluster->minUpDownTime = 1; cluster->minUpTime = 1; @@ -170,7 +170,7 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A cluster->minUpDownTime = Math::Max(cluster->minUpTime, cluster->minDownTime); - if (not study.parameters.include.reserve.spinning) + if (!study.parameters.include.reserve.spinning) cluster->spinning = 0; cluster->nominalCapacityWithSpinning = cluster->nominalCapacity; @@ -336,116 +336,114 @@ void ThermalClusterList::ensureDataPrepro() bool ThermalClusterList::saveToFolder(const AnyString& folder) const { // Make sure the folder is created - if (IO::Directory::Create(folder)) + if (!IO::Directory::Create(folder)) { - Clob buffer; - bool ret = true; + logs.error() << "I/O Error: impossible to create '" << folder << "'"; + return false; + } - // Allocate the inifile structure - IniFile ini; + bool ret = true; + Clob buffer; + // Allocate the inifile structure + IniFile ini; - for (auto c : allClusters_) + for (auto c : allClusters_) + { + // Adding a section to the inifile + IniFile::Section* s = ini.addSection(c->name()); + + // The section must not be empty + // This key will be silently ignored the next time + s->add("name", c->name()); + + if (!c->group().empty()) + s->add("group", c->group()); + if (!c->enabled) + s->add("enabled", "false"); + if (!Math::Zero(c->unitCount)) + s->add("unitCount", c->unitCount); + if (!Math::Zero(c->nominalCapacity)) + s->add("nominalCapacity", c->nominalCapacity); + // TS generation + if (c->tsGenBehavior != LocalTSGenerationBehavior::useGlobalParameter) + { + s->add("gen-ts", c->tsGenBehavior); + } + // Min. Stable Power + if (!Math::Zero(c->minStablePower)) + s->add("min-stable-power", c->minStablePower); + + // Min up and min down time + if (c->minUpTime != 1) + s->add("min-up-time", c->minUpTime); + if (c->minDownTime != 1) + s->add("min-down-time", c->minDownTime); + + // must-run + if (c->mustrun) + s->add("must-run", "true"); + + // spinning + if (!Math::Zero(c->spinning)) + s->add("spinning", c->spinning); + + // efficiency + if (c->fuelEfficiency != 100.0) + s->add("efficiency", c->fuelEfficiency); + + // volatility + if (!Math::Zero(c->forcedVolatility)) + s->add("volatility.forced", Math::Round(c->forcedVolatility, 3)); + if (!Math::Zero(c->plannedVolatility)) + s->add("volatility.planned", Math::Round(c->plannedVolatility, 3)); + + // laws + if (c->forcedLaw != thermalLawUniform) + s->add("law.forced", c->forcedLaw); + if (c->plannedLaw != thermalLawUniform) + s->add("law.planned", c->plannedLaw); + + // costs + if (c->costgeneration != setManually) + s->add("costgeneration", c->costgeneration); + if (!Math::Zero(c->marginalCost)) + s->add("marginal-cost", Math::Round(c->marginalCost, 3)); + if (!Math::Zero(c->spreadCost)) + s->add("spread-cost", c->spreadCost); + if (!Math::Zero(c->fixedCost)) + s->add("fixed-cost", Math::Round(c->fixedCost, 3)); + if (!Math::Zero(c->startupCost)) + s->add("startup-cost", Math::Round(c->startupCost, 3)); + if (!Math::Zero(c->marketBidCost)) + s->add("market-bid-cost", Math::Round(c->marketBidCost, 3)); + if (!Math::Zero(c->variableomcost)) + s->add("variableomcost", Math::Round(c->variableomcost,3)); + + + //pollutant factor + for (auto const& [key, val] : Pollutant::namesToEnum) + s->add(key, c->emissions.factors[val]); + + + buffer.clear() << folder << SEP << ".." << SEP << ".." << SEP << "prepro" << SEP + << c->parentArea->id << SEP << c->id(); + if (IO::Directory::Create(buffer)) { - // Adding a section to the inifile - IniFile::Section* s = ini.addSection(c->name()); - - // The section must not be empty - // This key will be silently ignored the next time - s->add("name", c->name()); - - if (not c->group().empty()) - s->add("group", c->group()); - if (not c->enabled) - s->add("enabled", "false"); - if (not Math::Zero(c->unitCount)) - s->add("unitCount", c->unitCount); - if (not Math::Zero(c->nominalCapacity)) - s->add("nominalCapacity", c->nominalCapacity); - // TS generation - if (c->tsGenBehavior != LocalTSGenerationBehavior::useGlobalParameter) - { - s->add("gen-ts", c->tsGenBehavior); - } - // Min. Stable Power - if (not Math::Zero(c->minStablePower)) - s->add("min-stable-power", c->minStablePower); - - // Min up and min down time - if (c->minUpTime != 1) - s->add("min-up-time", c->minUpTime); - if (c->minDownTime != 1) - s->add("min-down-time", c->minDownTime); - - // must-run - if (c->mustrun) - s->add("must-run", "true"); - - // spinning - if (not Math::Zero(c->spinning)) - s->add("spinning", c->spinning); - - // efficiency - if (c->fuelEfficiency != 100.0) - s->add("efficiency", c->fuelEfficiency); - - // volatility - if (not Math::Zero(c->forcedVolatility)) - s->add("volatility.forced", Math::Round(c->forcedVolatility, 3)); - if (not Math::Zero(c->plannedVolatility)) - s->add("volatility.planned", Math::Round(c->plannedVolatility, 3)); - - // laws - if (c->forcedLaw != thermalLawUniform) - s->add("law.forced", c->forcedLaw); - if (c->plannedLaw != thermalLawUniform) - s->add("law.planned", c->plannedLaw); - - // costs - if (c->costgeneration != setManually) - s->add("costgeneration", c->costgeneration); - if (not Math::Zero(c->marginalCost)) - s->add("marginal-cost", Math::Round(c->marginalCost, 3)); - if (not Math::Zero(c->spreadCost)) - s->add("spread-cost", c->spreadCost); - if (not Math::Zero(c->fixedCost)) - s->add("fixed-cost", Math::Round(c->fixedCost, 3)); - if (not Math::Zero(c->startupCost)) - s->add("startup-cost", Math::Round(c->startupCost, 3)); - if (not Math::Zero(c->marketBidCost)) - s->add("market-bid-cost", Math::Round(c->marketBidCost, 3)); - if (!Math::Zero(c->variableomcost)) - s->add("variableomcost", Math::Round(c->variableomcost,3)); - - - //pollutant factor - for (auto const& [key, val] : Pollutant::namesToEnum) - s->add(key, c->emissions.factors[val]); - - buffer.clear() << folder << SEP << ".." << SEP << ".." << SEP << "prepro" << SEP - << c->parentArea->id << SEP << c->id(); - if (IO::Directory::Create(buffer)) - { - buffer.clear() << folder << SEP << ".." << SEP << ".." << SEP << "prepro" << SEP - << c->parentArea->id << SEP << c->id() << SEP << "modulation.txt"; + << c->parentArea->id << SEP << c->id() << SEP << "modulation.txt"; - ret = c->modulation.saveToCSVFile(buffer) and ret; - } - else - ret = 0; + ret = c->modulation.saveToCSVFile(buffer) && ret; } + else + ret = false; + // Write the ini file buffer.clear() << folder << SEP << "list.ini"; - ret = ini.save(buffer) and ret; - } - else - { - logs.error() << "I/O Error: impossible to create '" << folder << "'"; - return false; + ret = ini.save(buffer) && ret; } - return true; + return ret; } bool ThermalClusterList::savePreproToFolder(const AnyString& folder) const @@ -453,13 +451,13 @@ bool ThermalClusterList::savePreproToFolder(const AnyString& folder) const Clob buffer; bool ret = true; - for (auto c : allClusters_) + for (auto c : allClusters_) { if (c->prepro) { - assert(c->parentArea and "cluster: invalid parent area"); + assert(c->parentArea && "cluster: invalid parent area"); buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); - ret = c->prepro->saveToFolder(buffer) and ret; + ret = c->prepro->saveToFolder(buffer) && ret; } } return ret; @@ -472,7 +470,7 @@ bool ThermalClusterList::saveEconomicCosts(const AnyString& folder) const for (auto c : allClusters_) { - assert(c->parentArea and "cluster: invalid parent area"); + assert(c->parentArea && "cluster: invalid parent area"); buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); ret = c->ecoInput.saveToFolder(buffer) && ret; } diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index 7ef2fdc77e..2db38a90cb 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -81,7 +81,7 @@ bool PartThermal::hasForcedNoTimeseriesGeneration() const }); } -void PartThermal::checkAndCorrectAvailability() +void PartThermal::checkAndCorrectAvailability() const { std::ranges::for_each(list.each_enabled(), &ThermalCluster::checkAndCorrectAvailability); } diff --git a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp index b612819370..58007ebb7e 100644 --- a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp @@ -55,7 +55,7 @@ void thermalTSNumberData::saveToINIFile(const Study& /* study */, if (!pArea) return; - + for (auto cluster : pArea->thermal.list.all()) { for (uint year = 0; year != pTSNumberRules.height; ++year) @@ -89,7 +89,7 @@ bool thermalTSNumberData::apply(Study& study) // Alias to the current area assert(pArea != nullptr); assert(pArea->index < study.areas.size()); - Area& area = *(study.areas.byIndex[pArea->index]); + const Area& area = *(study.areas.byIndex[pArea->index]); const uint tsGenCountThermal = get_tsGenCount(study); diff --git a/src/libs/antares/study/scenario-builder/rules.cpp b/src/libs/antares/study/scenario-builder/rules.cpp index c4b8a075bc..3840117f6f 100644 --- a/src/libs/antares/study/scenario-builder/rules.cpp +++ b/src/libs/antares/study/scenario-builder/rules.cpp @@ -131,8 +131,7 @@ bool Rules::readThermalCluster(const AreaName::Vector& splitKey, String value, b if (!area) return false; - const ThermalCluster* cluster = area->thermal.list.findInAll(clustername); - if (cluster) + if (const ThermalCluster* cluster = area->thermal.list.findInAll(clustername); cluster) { uint val = fromStringToTSnumber(value); thermal[area->index].setTSnumber(cluster, year, val); diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index 0528d5161c..a00e2a21c5 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -222,7 +222,7 @@ void PrepareRandomNumbers(Data::Study& study, yearRandomNumbers& randomForYear) { uint indexArea = 0; - study.areas.each([&](Data::Area& area) { + study.areas.each([&](const Data::Area& area) { double rnd = 0.; rnd = randomForYear.pUnsuppliedEnergy[indexArea]; diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.hxx b/src/solver/simulation/include/antares/solver/simulation/solver.hxx index 7448af909b..7c475f0f9c 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.hxx +++ b/src/solver/simulation/include/antares/solver/simulation/solver.hxx @@ -688,7 +688,7 @@ void ISimulation::computeRandomNumbers(randomNumbers& random for (unsigned int a = 0; a != nbAreas; ++a) { // logs.info() << " area : " << a << " :"; - auto& area = *(study.areas.byIndex[a]); + const auto& area = *(study.areas.byIndex[a]); for (auto cluster : area.thermal.list.all()) { From 3790f82f385f9392a256f5963a1def8d5a086222 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 19 Feb 2024 10:52:58 +0100 Subject: [PATCH 83/88] code smells 2 --- src/solver/simulation/sim_calcul_economique.cpp | 2 +- src/solver/simulation/timeseries-numbers.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 2f7e9cb8b4..2ace94c543 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -277,7 +277,7 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study, NombrePaliers = 0; for (uint i = 0; i < study.areas.size(); ++i) { - auto& area = *(study.areas.byIndex[i]); + const auto& area = *(study.areas.byIndex[i]); auto& pbPalier = problem.PaliersThermiquesDuPays[i]; unsigned int clusterCount = area.thermal.list.enabledAndNotMustRunCount(); diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 2a8290659c..8d32fcca68 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -257,7 +257,7 @@ bool checkIntraModalConsistency(array& nbTimeseriesByMode return true; } -bool checkInterModalConsistencyForArea(Area& area, +bool checkInterModalConsistencyForArea(const Area& area, const array& isTSintermodal) { // 1. Making a list of TS numbers : From 973572ea5a824d2d605f44834c0358ddca107c67 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 19 Feb 2024 11:18:30 +0100 Subject: [PATCH 84/88] update test_study to account for new enabled behavior --- .../src/libs/antares/study/test_study.cpp | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/tests/src/libs/antares/study/test_study.cpp b/src/tests/src/libs/antares/study/test_study.cpp index 2a334a53f4..aa596d4dad 100644 --- a/src/tests/src/libs/antares/study/test_study.cpp +++ b/src/tests/src/libs/antares/study/test_study.cpp @@ -79,14 +79,16 @@ BOOST_FIXTURE_TEST_CASE(thermal_cluster_delete, OneAreaStudy) auto disabledCluster = std::make_shared(areaA); disabledCluster->setName("Cluster1"); disabledCluster->enabled = false; - areaA->thermal.list.addToCompleteList(disabledCluster); + auto enabledCluster = std::make_shared(areaA); + enabledCluster->setName("Cluster2"); + enabledCluster->enabled = true; - // Check that "Cluster1" is found - BOOST_CHECK_EQUAL(areaA->thermal.list.findInAll("cluster1"), disabledCluster.get()); + areaA->thermal.list.addToCompleteList(disabledCluster); + areaA->thermal.list.addToCompleteList(enabledCluster); - study->initializeRuntimeInfos(); // This should remove all disabled thermal clusters // Check that "Cluster1" isn't found - BOOST_CHECK_EQUAL(areaA->thermal.list.findInAll("cluster1"), nullptr); + for (const auto c : areaA->thermal.list.each_enabled()) + BOOST_CHECK(c->name() != "Cluster1"); } BOOST_FIXTURE_TEST_CASE(renewable_cluster_delete, OneAreaStudy) @@ -94,14 +96,16 @@ BOOST_FIXTURE_TEST_CASE(renewable_cluster_delete, OneAreaStudy) auto disabledCluster = std::make_shared(areaA); disabledCluster->setName("Cluster1"); disabledCluster->enabled = false; - areaA->renewable.list.addToCompleteList(disabledCluster); + auto enabledCluster = std::make_shared(areaA); + enabledCluster->setName("Cluster2"); + enabledCluster->enabled = true; - // Check that "Cluster1" is found - BOOST_CHECK_EQUAL(areaA->renewable.list.findInAll("cluster1"), disabledCluster.get()); + areaA->renewable.list.addToCompleteList(disabledCluster); + areaA->renewable.list.addToCompleteList(enabledCluster); - study->initializeRuntimeInfos(); // This should remove all disabled renewable clusters // Check that "Cluster1" isn't found - BOOST_CHECK_EQUAL(areaA->renewable.list.findInAll("cluster1"), nullptr); + for (const auto c : areaA->renewable.list.each_enabled()) + BOOST_CHECK(c->name() != "Cluster1"); } BOOST_FIXTURE_TEST_CASE(short_term_storage_delete, OneAreaStudy) From 8e804308bbf0c399d694bd37481776501102e41b Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 19 Feb 2024 11:29:14 +0100 Subject: [PATCH 85/88] fix compile --- src/tests/src/libs/antares/study/test_study.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/src/libs/antares/study/test_study.cpp b/src/tests/src/libs/antares/study/test_study.cpp index aa596d4dad..1474f85178 100644 --- a/src/tests/src/libs/antares/study/test_study.cpp +++ b/src/tests/src/libs/antares/study/test_study.cpp @@ -96,7 +96,7 @@ BOOST_FIXTURE_TEST_CASE(renewable_cluster_delete, OneAreaStudy) auto disabledCluster = std::make_shared(areaA); disabledCluster->setName("Cluster1"); disabledCluster->enabled = false; - auto enabledCluster = std::make_shared(areaA); + auto enabledCluster = std::make_shared(areaA); enabledCluster->setName("Cluster2"); enabledCluster->enabled = true; From 59d249f6aa14ea55ae21ee609de582826f896d5e Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 19 Feb 2024 13:58:29 +0100 Subject: [PATCH 86/88] code smells 3 --- src/libs/antares/checks/checkLoadedInputData.cpp | 2 +- .../antares/study/parts/thermal/container.h | 2 +- src/libs/antares/study/parts/thermal/cluster.cpp | 14 +++++++------- src/libs/antares/study/parts/thermal/container.cpp | 2 +- src/solver/simulation/timeseries-numbers.cpp | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/libs/antares/checks/checkLoadedInputData.cpp b/src/libs/antares/checks/checkLoadedInputData.cpp index ced8521a63..f13c8f2011 100644 --- a/src/libs/antares/checks/checkLoadedInputData.cpp +++ b/src/libs/antares/checks/checkLoadedInputData.cpp @@ -143,7 +143,7 @@ void checkMinStablePower(bool tsGenThermal, const Antares::Data::AreaList& areas } else { - areas.each([](Antares::Data::Area& area) { area.thermal.checkAndCorrectAvailability(); }); + areas.each([](const auto& area) { area.thermal.checkAndCorrectAvailability(); }); } } diff --git a/src/libs/antares/study/include/antares/study/parts/thermal/container.h b/src/libs/antares/study/include/antares/study/parts/thermal/container.h index fb6ea8d251..f9053706bf 100644 --- a/src/libs/antares/study/include/antares/study/parts/thermal/container.h +++ b/src/libs/antares/study/include/antares/study/parts/thermal/container.h @@ -51,7 +51,7 @@ class PartThermal ** ** \param n A number of years */ - void resizeAllTimeseriesNumbers(uint n); + void resizeAllTimeseriesNumbers(uint n) const; /*! ** \brief Invalidate all JIT data diff --git a/src/libs/antares/study/parts/thermal/cluster.cpp b/src/libs/antares/study/parts/thermal/cluster.cpp index e3b206b3ab..5608e0a5f9 100644 --- a/src/libs/antares/study/parts/thermal/cluster.cpp +++ b/src/libs/antares/study/parts/thermal/cluster.cpp @@ -192,7 +192,7 @@ void Data::ThermalCluster::copyFrom(const ThermalCluster& cluster) // Making sure that the data related to the prepro and timeseries are present // prepro - if (not prepro) + if (!prepro) prepro = new PreproThermal(this->weak_from_this()); prepro->copyFrom(*cluster.prepro); @@ -273,7 +273,7 @@ void Data::ThermalCluster::calculationOfSpinning() // Nothing to do if the spinning is equal to zero // because it will the same multiply all entries of the matrix by 1. - if (not Math::Zero(spinning)) + if (!Math::Zero(spinning)) { logs.debug() << " Calculation of spinning... " << parentArea->name << "::" << pName; @@ -393,7 +393,7 @@ void Data::ThermalCluster::reverseCalculationOfSpinning() { // Nothing to do if the spinning is equal to zero // because it will the same multiply all entries of the matrix by 1. - if (not Math::Zero(spinning)) + if (!Math::Zero(spinning)) { logs.debug() << " Calculation of spinning (reverse)... " << parentArea->name << "::" << pName; @@ -458,7 +458,7 @@ void Data::ThermalCluster::reset() // warning: the variables `prepro` and `series` __must__ not be destroyed // since the interface may still have a pointer to them. // we must simply reset their content. - if (not prepro) + if (!prepro) prepro = new PreproThermal(this->weak_from_this()); prepro->reset(); ecoInput.reset(); @@ -466,7 +466,7 @@ void Data::ThermalCluster::reset() bool Data::ThermalCluster::integrityCheck() { - if (not parentArea) + if (!parentArea) { logs.error() << "Thermal cluster " << pName << ": The parent area is missing"; return false; @@ -643,7 +643,7 @@ void ThermalCluster::calculatMinDivModulation() bool ThermalCluster::checkMinStablePower() { - if (not minDivModulation.isCalculated) // not has been initialized + if (!minDivModulation.isCalculated) // not has been initialized calculatMinDivModulation(); if (minDivModulation.value < 0) @@ -673,7 +673,7 @@ bool ThermalCluster::checkMinStablePower() bool ThermalCluster::checkMinStablePowerWithNewModulation(uint idx, double value) { - if (not minDivModulation.isCalculated || idx == minDivModulation.index) + if (!minDivModulation.isCalculated || idx == minDivModulation.index) calculatMinDivModulation(); else { diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index 2db38a90cb..ff0f2803f0 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -59,7 +59,7 @@ void PartThermal::reset() list.clearAll(); } -void PartThermal::resizeAllTimeseriesNumbers(uint n) +void PartThermal::resizeAllTimeseriesNumbers(uint n) const { list.resizeAllTimeseriesNumbers(n); } diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 8d32fcca68..700637ea72 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -488,7 +488,7 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i for (auto cluster : area.thermal.list.all()) { - if (not cluster->enabled) + if (!cluster->enabled) study.runtime->random[seedTimeseriesNumbers].next(); else { @@ -563,7 +563,7 @@ Matrix* getFirstTSnumberInterModalMatrixFoundInArea( else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesHydro)]) tsNumbersMtx = &(area.hydro.series->timeseriesNumbers); else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesThermal)] && - not area.thermal.list.each_enabled().empty()) + !area.thermal.list.each_enabled().empty()) { std::shared_ptr cluster = *(area.thermal.list.each_enabled().begin()); tsNumbersMtx = &(cluster->series.timeseriesNumbers); @@ -659,7 +659,7 @@ bool TimeSeriesNumbers::Generate(Study& study) array intramodal_draws; std::fill(intramodal_draws.begin(), intramodal_draws.end(), 0); - if (not checkIntraModalConsistency(nbTimeseriesByMode, isTSintramodal, study)) + if (!checkIntraModalConsistency(nbTimeseriesByMode, isTSintramodal, study)) return false; for (uint year = 0; year < years; ++year) From 106db374bed9c0df857dd9100e76c09ca3585eda Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 19 Feb 2024 15:31:37 +0100 Subject: [PATCH 87/88] code smells 4 --- .../study/include/antares/study/parts/common/cluster_list.h | 2 +- src/libs/antares/study/parts/common/cluster_list.cpp | 2 +- src/libs/antares/study/parts/thermal/cluster_list.cpp | 4 ++-- src/solver/ts-generator/generator.cpp | 2 +- src/ui/simulator/toolbox/input/renewable-cluster.cpp | 4 ++-- src/ui/simulator/toolbox/input/thermal-cluster.cpp | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libs/antares/study/include/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/include/antares/study/parts/common/cluster_list.h index 20493bc0cb..40a083be83 100644 --- a/src/libs/antares/study/include/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/include/antares/study/parts/common/cluster_list.h @@ -57,7 +57,7 @@ class ClusterList ** \param id ID of the cluster to find ** \return A pointer to a cluster. nullptr if not found */ - ClusterT* findInAll(const Data::ClusterName& id) const; + ClusterT* findInAll(std::string_view id) const; /*! ** \brief Get if a cluster exists diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 1cb99b9a5d..818fa9a85f 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -56,7 +56,7 @@ std::shared_ptr ClusterList::enabledClusterAt(unsigned int i } template -ClusterT* ClusterList::findInAll(const Data::ClusterName& id) const +ClusterT* ClusterList::findInAll(std::string_view id) const { for (auto cluster : all()) if (cluster->id() == id) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 09ba0b3123..b782ee2e9a 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -484,9 +484,9 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, = study.parameters.timeSeriesToGenerate & timeSeriesThermal; Clob buffer; - auto hasPrepro = [&](auto c) { return (bool) c->prepro; }; + auto hasPrepro = [](auto c) { return (bool) c->prepro; }; - auto loadAndCheckPrepro = [&](auto c) + auto loadAndCheckPrepro = [&buffer, &folder, &study, &globalThermalTSgeneration](auto c) { assert(c->parentArea && "cluster: invalid parent area"); buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); diff --git a/src/solver/ts-generator/generator.cpp b/src/solver/ts-generator/generator.cpp index c56ec94ea1..7db121112c 100644 --- a/src/solver/ts-generator/generator.cpp +++ b/src/solver/ts-generator/generator.cpp @@ -54,7 +54,7 @@ void ResizeGeneratedTimeSeries(Data::AreaList& areas, Data::Parameters& params) // Thermal bool globalThermalTSgeneration = params.timeSeriesToGenerate & Data::timeSeriesThermal; - for (auto& cluster : area.thermal.list.all()) + for (const auto& cluster : area.thermal.list.all()) { if (cluster->doWeGenerateTS(globalThermalTSgeneration)) cluster->series.timeSeries.reset(params.nbTimeSeriesThermal, HOURS_PER_YEAR); diff --git a/src/ui/simulator/toolbox/input/renewable-cluster.cpp b/src/ui/simulator/toolbox/input/renewable-cluster.cpp index 12ae24257d..8f9c60b318 100644 --- a/src/ui/simulator/toolbox/input/renewable-cluster.cpp +++ b/src/ui/simulator/toolbox/input/renewable-cluster.cpp @@ -366,7 +366,7 @@ void RenewableCluster::internalAddPlant(void*) // Trying to find an uniq name YString sFl; sFl.clear() << "new cluster"; - while (pArea->renewable.list.findInAll(sFl)) + while (pArea->renewable.list.findInAll(sFl.c_str())) { ++indx; sFl.clear() << "new cluster " << indx; @@ -440,7 +440,7 @@ void RenewableCluster::internalClonePlant(void*) YString sFl; sFl << copy << indx; // lowercase - while (pArea->renewable.list.findInAll(sFl)) + while (pArea->renewable.list.findInAll(sFl.c_str())) { ++indx; sFl.clear() << copy << indx; diff --git a/src/ui/simulator/toolbox/input/thermal-cluster.cpp b/src/ui/simulator/toolbox/input/thermal-cluster.cpp index be5eac364a..8939dc7242 100644 --- a/src/ui/simulator/toolbox/input/thermal-cluster.cpp +++ b/src/ui/simulator/toolbox/input/thermal-cluster.cpp @@ -425,7 +425,7 @@ void ThermalCluster::internalAddPlant(void*) // Trying to find an uniq name YString sFl; sFl.clear() << "new cluster"; - while (pArea->thermal.list.findInAll(sFl)) + while (pArea->thermal.list.findInAll(sFl.c_str())) { ++indx; sFl.clear() << "new cluster " << indx; @@ -500,7 +500,7 @@ void ThermalCluster::internalClonePlant(void*) YString sFl; sFl << copy << indx; // lowercase - while (pArea->thermal.list.findInAll(sFl)) + while (pArea->thermal.list.findInAll(sFl.c_str())) { ++indx; sFl.clear() << copy << indx; From 00471021e44ac1dbb915106b1bf2fbd203cce798 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 19 Feb 2024 16:17:54 +0100 Subject: [PATCH 88/88] remove double sonar job --- .github/workflows/sonarcloud.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 0ef6d231e5..c5cba3e87e 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -9,8 +9,6 @@ on: - fix/* - feature/* - pull_request: - jobs: sonarcloud: name: SonarCloud