Skip to content

Commit

Permalink
Split TS generation into files : simplifying and renaming function wr…
Browse files Browse the repository at this point in the history
…iteResultsToDisk which now does exactly what its name says it does
  • Loading branch information
guilpier-code committed Jun 25, 2024
1 parent 2710aa4 commit f842001
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/solver/ts-generator/availability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,23 +612,17 @@ std::vector<Data::ThermalCluster*> getAllClustersToGen(const Data::AreaList& are
return clusters;
}

void writeResultsToDisk(const Data::Study& study,
Solver::IResultWriter& writer,
const Matrix<>& series,
const std::string& savePath)
void writeTStoDisk(Solver::IResultWriter& writer,
const Matrix<>& series,
const std::string& savePath)
{
if (study.parameters.noOutput)
{
return;
}

std::string buffer;
series.saveToBuffer(buffer, 0);
writer.addEntryFromBuffer(savePath, buffer);
}

void writeResultsToDisk(const Matrix<>& series,
const std::filesystem::path savePath)
void writeTStoDisk(const Matrix<>& series,
const std::filesystem::path savePath)
{
std::string buffer;
series.saveToBuffer(buffer, 0);
Expand All @@ -650,6 +644,12 @@ bool generateThermalTimeSeries(Data::Study& study,
logs.info() << "Generating the thermal time-series";

bool archive = study.parameters.timeSeriesToArchive & Data::timeSeriesThermal;
bool doWeWrite = archive && !study.parameters.noOutput;
if (! doWeWrite)
{
logs.info() << "Study parammeters such that we don't write thermal TS.";
return true;
}

auto generator = AvailabilityTSgenerator(study,
study.parameters.nbTimeSeriesThermal,
Expand All @@ -660,12 +660,9 @@ bool generateThermalTimeSeries(Data::Study& study,
AvailabilityTSGeneratorData tsGenerationData(cluster);
generator.run(tsGenerationData);

if (archive) // For compatibilty with in memory thermal TS generation
{
std::string filePath = savePath + SEP + cluster->parentArea->id + SEP + cluster->id()
+ ".txt";
writeResultsToDisk(study, writer, cluster->series.timeSeries, filePath);
}
std::string filePath = savePath + SEP + cluster->parentArea->id + SEP + cluster->id()
+ ".txt";
writeTStoDisk(writer, cluster->series.timeSeries, filePath);
}

return true;
Expand Down Expand Up @@ -704,7 +701,7 @@ bool generateLinkTimeSeries(std::vector<LinkTSgenerationParams>& links,

std::string filePath = savePath + SEP + link.namesPair.first + SEP + link.namesPair.second
+ "_direct.txt";
writeResultsToDisk(ts.timeSeries, filePath);
writeTStoDisk(ts.timeSeries, filePath);

// INDIRECT
AvailabilityTSGeneratorData tsConfigDataIndirect(link, ts, link.modulationCapacityIndirect, link.namesPair.second);
Expand All @@ -713,7 +710,7 @@ bool generateLinkTimeSeries(std::vector<LinkTSgenerationParams>& links,

filePath = savePath + SEP + link.namesPair.first + SEP + link.namesPair.second
+ "_indirect.txt";
writeResultsToDisk(ts.timeSeries, filePath);
writeTStoDisk(ts.timeSeries, filePath);
}

return true;
Expand Down

0 comments on commit f842001

Please sign in to comment.