Skip to content

Commit

Permalink
Split thermal TS generation : we don't execute not required TS genera…
Browse files Browse the repository at this point in the history
…tion code
  • Loading branch information
guilpier-code committed Jun 28, 2024
1 parent 2e40e8d commit fdf0ec4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ bool parseOptions(int, char*[], Settings&);
std::unique_ptr<Yuni::GetOpt::Parser> createTsGeneratorParser(Settings&);

bool checkOptions(Settings& options);
bool linkTSrequired(Settings& options);
bool thermalTSrequired(Settings& options);
}
2 changes: 1 addition & 1 deletion src/tools/ts-generator/linksTSgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void readPreproTimeSeries(std::vector<LinkTSgenerationParams>& linkList,
fs::path sourceAreaDir = toLinksDir / sourceAreaName;
if (! readLinkPreproTimeSeries(link, sourceAreaDir))
{
logs.warning() << "Could not load all prepro data for link '"
logs.warning() << "Could not load all prepro/modulation data for link '"
<< link.namesPair.first << "." << link.namesPair.second << "'";
}
}
Expand Down
73 changes: 39 additions & 34 deletions src/tools/ts-generator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,44 +76,49 @@ int main(int argc, char* argv[])
if (! checkOptions(settings))
return 1;

// ============ THERMAL : Getting data for generating time-series =========
auto study = std::make_shared<Data::Study>(true);
Data::StudyLoadOptions studyOptions;
if (!study->loadFromFolder(settings.studyFolder, studyOptions))
{
logs.error() << "Invalid study given to the generator";
return 1;
}
bool return_code {true};

std::vector<Data::ThermalCluster*> clusters;
if (settings.allThermal)
{
clusters = getAllClustersToGen(study->areas, true);
}
else if (!settings.thermalListToGen.empty())
if (thermalTSrequired(settings))
{
clusters = getClustersToGen(study->areas, settings.thermalListToGen);
}
// ========================================================================

LinksTSgenerator linksTSgenerator(settings);
linksTSgenerator.extractData();

// ============ TS Generation =============================================
MersenneTwister thermalRandom;
thermalRandom.reset(study->parameters.seed[Data::seedTsGenThermal]);

bool ret = TSGenerator::generateThermalTimeSeries(*study,
clusters,
thermalRandom);
// === Data for TS generation ===
auto study = std::make_shared<Data::Study>(true);
Data::StudyLoadOptions studyOptions;
if (!study->loadFromFolder(settings.studyFolder, studyOptions))
{
logs.error() << "Invalid study given to the generator";
return 1;
}

auto thermalSavePath = fs::path(settings.studyFolder) / "output" / FormattedTime("%Y%m%d-%H%M");
thermalSavePath /= "ts-generator";
thermalSavePath /= "thermal";
std::vector<Data::ThermalCluster*> clusters;
if (settings.allThermal)
{
clusters = getAllClustersToGen(study->areas, true);
}
else if (!settings.thermalListToGen.empty())
{
clusters = getClustersToGen(study->areas, settings.thermalListToGen);
}

writeThermalTimeSeries(clusters, thermalSavePath);
// === TS generation ===
MersenneTwister thermalRandom;
thermalRandom.reset(study->parameters.seed[Data::seedTsGenThermal]);
return_code = TSGenerator::generateThermalTimeSeries(*study,
clusters,
thermalRandom);

// === Writing generated TS on disk ===
auto thermalSavePath = fs::path(settings.studyFolder) / "output" / FormattedTime("%Y%m%d-%H%M");
thermalSavePath /= "ts-generator";
thermalSavePath /= "thermal";
writeThermalTimeSeries(clusters, thermalSavePath);
}

ret = linksTSgenerator.generate() && ret;
if (linkTSrequired(settings))
{
LinksTSgenerator linksTSgenerator(settings);
linksTSgenerator.extractData();
return_code = linksTSgenerator.generate() && return_code;
}

return !ret; // return 0 for success
return !return_code; // return 0 for success
}
8 changes: 8 additions & 0 deletions src/tools/ts-generator/tsGenerationOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,12 @@ bool checkOptions(Settings& options)
return true;
}

bool linkTSrequired(Settings& options)
{
return options.allLinks || !options.linksListToGen.empty();
}
bool thermalTSrequired(Settings& options)
{
return options.allThermal || !options.thermalListToGen.empty();
}
}

0 comments on commit fdf0ec4

Please sign in to comment.