From 15b9285f020f97f407a51a0bdeb1d5017ef86788 Mon Sep 17 00:00:00 2001 From: guilpier-code <62292552+guilpier-code@users.noreply.github.com> Date: Tue, 12 Sep 2023 12:15:04 +0200 Subject: [PATCH] Move economic thermal costs input files into "series" directory (#1616) * Move economic thermal costs input files into series directory * Move economic thermal costs input files into series directory : oops, forgot to implement the saving * Move economic thermal costs input files into series directory : small simplifications --- src/libs/antares/study/area/list.cpp | 2 + .../study/parts/common/cluster_list.cpp | 30 ++------ .../study/parts/thermal/cluster_list.cpp | 69 ++++++++++++------- .../study/parts/thermal/cluster_list.h | 3 + 4 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index f3c897016d..ee7750bb8c 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -287,6 +287,7 @@ static bool AreaListSaveToFolderSingleArea(const Area& area, Clob& buffer, const ret = area.thermal.list.savePreproToFolder(buffer) && ret; buffer.clear() << folder << SEP << "input" << SEP << "thermal" << SEP << "series"; ret = area.thermal.list.saveDataSeriesToFolder(buffer) && ret; + ret = area.thermal.list.saveEconomicCosts(buffer) && ret; } // Renewable cluster list @@ -944,6 +945,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, ret = area.thermal.list.loadPreproFromFolder(study, options, buffer) && ret; buffer.clear() << study.folderInput << SEP << "thermal" << SEP << "series"; ret = area.thermal.list.loadDataSeriesFromFolder(study, options, buffer) && ret; + ret = area.thermal.list.loadEconomicCosts(study, buffer) && ret; // In adequacy mode, all thermal clusters must be in 'mustrun' mode if (study.usedByTheSolver && study.parameters.mode == stdmAdequacy) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 0ba7cf2afb..7c8adf4616 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -370,17 +370,17 @@ int ClusterList::saveDataSeriesToFolder(const AnyString& folder, const return ret; } -template<> -int ClusterList::loadDataSeriesFromFolder(Study& s, - const StudyLoadOptions& options, - const AnyString& folder) +template +int ClusterList::loadDataSeriesFromFolder(Study& s, + const StudyLoadOptions& options, + const AnyString& folder) { if (empty()) return 1; int ret = 1; - each([&ret, &options, &s, &folder](ThermalCluster& c) { + each([&](ClusterT& c) { if (c.series) ret = c.loadDataSeriesFromFolder(s, folder) and ret; @@ -390,26 +390,6 @@ int ClusterList::loadDataSeriesFromFolder(Study& s, return ret; } -template<> -int ClusterList::loadDataSeriesFromFolder(Study& s, - const StudyLoadOptions& options, - const AnyString& folder) -{ - if (empty()) - return 1; - - int ret = 1; - - each([&](Cluster& cluster) { - if (cluster.series) - ret = cluster.loadDataSeriesFromFolder(s, folder) and ret; - - ++options.progressTicks; - options.pushProgressLogs(); - }); - return ret; -} - template void ClusterList::ensureDataTimeSeries() { diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index b313932991..2b00545cc9 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -470,18 +470,29 @@ bool ThermalClusterList::savePreproToFolder(const AnyString& folder) const Clob buffer; bool ret = true; - each([&](const Data::ThermalCluster& c) { + each([&](const ThermalCluster& c) { 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.ecoInput.saveToFolder(buffer) && ret; - } + }); + return ret; +} + +bool ThermalClusterList::saveEconomicCosts(const AnyString& folder) const +{ + if (empty()) + return true; + + 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; }); return ret; } @@ -499,39 +510,51 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, Clob buffer; bool ret = true; - for (auto it = begin(); it != end(); ++it) + for (auto& [name, c] : cluster) { - auto& c = *(it->second); - if (c.prepro) + if (c->prepro) { - assert(c.parentArea and "cluster: invalid parent area"); - buffer.clear() << folder << SEP << c.parentArea->id << SEP << c.id(); + assert(c->parentArea and "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)) + if (result && study.usedByTheSolver && c->doWeGenerateTS(globalThermalTSgeneration)) { // checking NPO max - result = c.prepro->normalizeAndCheckNPO(); + result = c->prepro->normalizeAndCheckNPO(); } ret = result and ret; } - { - assert(c.parentArea and "cluster: invalid parent area"); - buffer.clear() << folder << SEP << c.parentArea->id << SEP << c.id(); - - bool result = c.ecoInput.loadFromFolder(study, buffer); - c.ComputeCostTimeSeries(); - - ret = result && ret; - } ++options.progressTicks; options.pushProgressLogs(); } return ret; } + +bool ThermalClusterList::loadEconomicCosts(Study& study, const AnyString& folder) +{ + if (empty()) + return true; + + Clob buffer; + bool ret = true; + + for (auto& [name, c] : cluster) + { + assert(c->parentArea and "cluster: invalid parent area"); + buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); + + bool result = c->ecoInput.loadFromFolder(study, buffer); + c->ComputeCostTimeSeries(); + + ret = result && ret; + } + return ret; +} + } // namespace Data } // namespace Antares diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 1365e97262..56969a00a4 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -84,7 +84,10 @@ class ThermalClusterList : public ClusterList */ bool loadPreproFromFolder(Study& s, const StudyLoadOptions& options, const AnyString& folder); + bool loadEconomicCosts(Study& s, const AnyString& folder); + bool savePreproToFolder(const AnyString& folder) const; + bool saveEconomicCosts(const AnyString& folder) const; bool saveToFolder(const AnyString& folder) const override; }; // class ThermalClusterList