From 9672206eb89a1c969e8b77b17f12c2ac7a3008e1 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 27 Jun 2024 17:30:32 +0200 Subject: [PATCH] Split thermal TS generation : raised an error if a prepro file does not exist Not just ignore it, as code used to do. --- .../antares/solver/ts-generator/generator.h | 2 +- src/tools/ts-generator/linksTSgenerator.cpp | 74 ++++++++++--------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/solver/ts-generator/include/antares/solver/ts-generator/generator.h b/src/solver/ts-generator/include/antares/solver/ts-generator/generator.h index b6746bbb37f..ef55c2a9647 100644 --- a/src/solver/ts-generator/include/antares/solver/ts-generator/generator.h +++ b/src/solver/ts-generator/include/antares/solver/ts-generator/generator.h @@ -50,7 +50,7 @@ struct LinkTSgenerationParams { LinkPair namesPair; - unsigned unitCount = 0; + unsigned unitCount = 1; double nominalCapacity = 0; double forcedVolatility = 0.; diff --git a/src/tools/ts-generator/linksTSgenerator.cpp b/src/tools/ts-generator/linksTSgenerator.cpp index 129604c3d2d..62940cd3778 100644 --- a/src/tools/ts-generator/linksTSgenerator.cpp +++ b/src/tools/ts-generator/linksTSgenerator.cpp @@ -166,52 +166,56 @@ void readIniProperties(std::vector& linkList, fs::path t } } - bool readLinkPreproTimeSeries(LinkTSgenerationParams& link, - fs::path sourceAreaDir) - { - bool to_return = true; - const auto preproId = link.namesPair.first + "/" + link.namesPair.second; - link.prepro = std::make_unique(preproId, link.unitCount); +fs::path makePreproFile(const fs::path& preproFilePath, const std::string& changingEnd) +{ + auto to_return = preproFilePath; + to_return += changingEnd + ".txt"; + return to_return; +} - auto preproFileRoot = sourceAreaDir / "prepro" / link.namesPair.second; +bool readLinkPreproTimeSeries(LinkTSgenerationParams& link, + fs::path sourceAreaDir) +{ + bool to_return = true; + const auto preproId = link.namesPair.first + "/" + link.namesPair.second; + link.prepro = std::make_unique(preproId, link.unitCount); + + auto preproFileRoot = sourceAreaDir / "prepro" / link.namesPair.second; + + // Testing files existence + auto preproFile = makePreproFile(preproFileRoot, ""); + auto modulationDirectFile = makePreproFile(preproFileRoot, "_mod_direct"); + auto modulationIndirectFile = makePreproFile(preproFileRoot, "_mod_indirect"); + std::vector paths {preproFile, modulationDirectFile, modulationIndirectFile}; + if (std::any_of(paths.begin(), paths.end(), [](auto& path) {return ! fs::exists(path);})) + { + link.hasValidData = false; + return false; + } - auto preproFile = preproFileRoot; - preproFile += ".txt"; - if (fs::exists(preproFile)) - { - to_return = link.prepro->data.loadFromCSVFile( + // Files loading + to_return = link.prepro->data.loadFromCSVFile( preproFile.string(), Data::PreproAvailability::preproAvailabilityMax, DAYS_PER_YEAR) - && link.prepro->validate() - && to_return; - } + && link.prepro->validate() + && to_return; - auto modulationFileDirect = preproFileRoot; - modulationFileDirect += "_mod_direct.txt"; - if (fs::exists(modulationFileDirect)) - { - to_return = link.modulationCapacityDirect.loadFromCSVFile( - modulationFileDirect.string(), + to_return = link.modulationCapacityDirect.loadFromCSVFile( + modulationDirectFile.string(), 1, HOURS_PER_YEAR) - && to_return; - } + && to_return; - auto modulationFileIndirect = preproFileRoot; - modulationFileIndirect += "_mod_indirect.txt"; - if (fs::exists(modulationFileIndirect)) - { - to_return = link.modulationCapacityIndirect.loadFromCSVFile( - modulationFileIndirect.string(), + to_return = link.modulationCapacityIndirect.loadFromCSVFile( + modulationIndirectFile.string(), 1, HOURS_PER_YEAR) - && to_return; - } - // Makes it possible to skip a link's TS generation when time comes - link.hasValidData = link.hasValidData && to_return; - return to_return; - } + && to_return; + + link.hasValidData = link.hasValidData && to_return; + return to_return; +} void readPreproTimeSeries(std::vector& linkList, fs::path toLinksDir)