From c4cd709bf4906b075a9e5543de4b015dad42c353 Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Mon, 18 Dec 2023 21:46:51 +0100 Subject: [PATCH] Small code improvement for ramping --- .../antares/study/parts/thermal/cluster.cpp | 8 +++++++ .../antares/study/parts/thermal/cluster.h | 1 + .../variable/surveyresults/surveyresults.cpp | 21 ++++++++----------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster.cpp b/src/libs/antares/study/parts/thermal/cluster.cpp index 4ade08ae1f7..094f16d43ea 100644 --- a/src/libs/antares/study/parts/thermal/cluster.cpp +++ b/src/libs/antares/study/parts/thermal/cluster.cpp @@ -875,5 +875,13 @@ bool ThermalCluster::Ramping::checkValidity(Area* parentArea, Data::ClusterName return ret; } +std::ostream& ThermalCluster::Ramping::operator<<(std::ostream& os) const +{ + return os << powerIncreaseCost << '\t' + << powerDecreaseCost << '\t' + << maxUpwardPowerRampingRate << '\t' + << maxDownwardPowerRampingRate << '\n'; +} + } // namespace Data } // namespace Antares diff --git a/src/libs/antares/study/parts/thermal/cluster.h b/src/libs/antares/study/parts/thermal/cluster.h index c27e70473d4..91735f88a87 100644 --- a/src/libs/antares/study/parts/thermal/cluster.h +++ b/src/libs/antares/study/parts/thermal/cluster.h @@ -362,6 +362,7 @@ class ThermalCluster final : public Cluster, public std::enable_shared_from_this void reset(); bool checkValidity(Area* area, Data::ClusterName clusterName); + std::ostream& operator<<(std::ostream&) const; }; Ramping ramping; diff --git a/src/solver/variable/surveyresults/surveyresults.cpp b/src/solver/variable/surveyresults/surveyresults.cpp index 45558ab1721..00f89d01ec7 100644 --- a/src/solver/variable/surveyresults/surveyresults.cpp +++ b/src/solver/variable/surveyresults/surveyresults.cpp @@ -32,6 +32,7 @@ #include #include #include +#include using namespace Yuni; using namespace Antares; @@ -115,9 +116,7 @@ static void ExportGridInfosAreas(const Data::Study& study, const Yuni::String& originalOutput, IResultWriter& writer) { - Clob out; - Clob outLinks; - Clob outThermal; + std::ostringstream out, outLinks, outThermal; out << "id\tname\n"; outLinks << "upstream\tdownstream\n"; @@ -158,23 +157,21 @@ static void ExportGridInfosAreas(const Data::Study& study, outThermal << cluster.fixedCost << '\t'; outThermal << cluster.startupCost << '\t'; outThermal << cluster.marketBidCost << '\t'; - outThermal << cluster.spreadCost << '\n'; - outThermal << cluster.ramping.powerIncreaseCost << '\n'; - outThermal << cluster.ramping.powerDecreaseCost << '\n'; - outThermal << cluster.ramping.maxUpwardPowerRampingRate << '\n'; - outThermal << cluster.ramping.maxDownwardPowerRampingRate << '\n'; + outThermal << cluster.spreadCost << '\t'; + outThermal << cluster.ramping; } // each thermal cluster }); // each area - auto add = [&writer, &originalOutput](const YString& filename, Clob&& buffer) { + // buffer must be copied since addEntryFromBuffer has no std::string&& variant, unfortunately + auto add = [&writer, &originalOutput](const YString& filename, std::string buffer) { YString path; path << originalOutput << SEP << "grid" << SEP << filename; writer.addEntryFromBuffer(path.c_str(), buffer); }; - add("areas.txt", std::move(out)); - add("links.txt", std::move(outLinks)); - add("thermal.txt", std::move(outThermal)); + add("areas.txt", out.str()); + add("links.txt", outLinks.str()); + add("thermal.txt", outThermal.str()); } SurveyResultsData::SurveyResultsData(const Data::Study& s, const String& o) :