Skip to content

Commit

Permalink
Split thermal TS generation : make TS generator's run method return a…
Browse files Browse the repository at this point in the history
… TS matrix
  • Loading branch information
guilpier-code committed Jun 28, 2024
1 parent 5486b05 commit cdd57e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
43 changes: 16 additions & 27 deletions src/solver/ts-generator/availability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ AvailabilityTSGeneratorData::AvailabilityTSGeneratorData(Data::ThermalCluster* c
forcedLaw(cluster->forcedLaw),
plannedLaw(cluster->plannedLaw),
prepro(cluster->prepro),
series(cluster->series.timeSeries),
modulationCapacity(cluster->modulation[Data::thermalModulationCapacity]),
name(cluster->name())
{
}

AvailabilityTSGeneratorData::AvailabilityTSGeneratorData(LinkTSgenerationParams& source,
Data::TimeSeries& capacity,
Matrix<>& modulation,
const std::string& areaDestName):
unitCount(source.unitCount),
Expand All @@ -56,7 +54,6 @@ AvailabilityTSGeneratorData::AvailabilityTSGeneratorData(LinkTSgenerationParams&
forcedLaw(source.forcedLaw),
plannedLaw(source.plannedLaw),
prepro(source.prepro.get()),
series(capacity.timeSeries),
modulationCapacity(modulation[0]),
name(areaDestName)
{
Expand All @@ -69,7 +66,7 @@ class AvailabilityTSgenerator final
public:
explicit AvailabilityTSgenerator(bool, unsigned, MersenneTwister&);

void run(AvailabilityTSGeneratorData&) const;
Matrix<double> run(AvailabilityTSGeneratorData&) const;

private:
bool derated;
Expand Down Expand Up @@ -181,13 +178,16 @@ int AvailabilityTSgenerator::durationGenerator(Data::StatisticalLaw law,
return 0;
}

void AvailabilityTSgenerator::run(AvailabilityTSGeneratorData& tsGenerationData) const
Matrix<double> AvailabilityTSgenerator::run(AvailabilityTSGeneratorData& tsGenerationData) const
{
assert(tsGenerationData.prepro);

Matrix<double> to_return;
to_return.reset(nbOfSeriesToGen_, 24 * DAYS_PER_YEAR);

if (0 == tsGenerationData.unitCount || 0 == tsGenerationData.nominalCapacity)
{
return;
return to_return;
}

const auto& preproData = *(tsGenerationData.prepro);
Expand Down Expand Up @@ -301,18 +301,11 @@ void AvailabilityTSgenerator::run(AvailabilityTSGeneratorData& tsGenerationData)
double last = 0;

auto& modulation = tsGenerationData.modulationCapacity;
double* dstSeries = nullptr;

const uint tsCount = nbOfSeriesToGen_ + 2;
for (uint tsIndex = 0; tsIndex != tsCount; ++tsIndex)
{
uint hour = 0;

if (tsIndex > 1)
{
dstSeries = tsGenerationData.series[tsIndex - 2];
}

for (uint dayInTheYear = 0; dayInTheYear < DAYS_PER_YEAR; ++dayInTheYear)
{
assert(dayInTheYear < 366);
Expand Down Expand Up @@ -562,7 +555,7 @@ void AvailabilityTSgenerator::run(AvailabilityTSGeneratorData& tsGenerationData)
double AVPDayInTheYear = AVP[dayInTheYear];
for (uint h = 0; h != 24; ++h)
{
dstSeries[hour] = std::round(AVPDayInTheYear * modulation[hour]);
to_return[tsIndex - 2][hour] = std::round(AVPDayInTheYear * modulation[hour]);
++hour;
}
}
Expand All @@ -571,8 +564,9 @@ void AvailabilityTSgenerator::run(AvailabilityTSGeneratorData& tsGenerationData)

if (derated)
{
tsGenerationData.series.averageTimeseries();
to_return.averageTimeseries();
}
return to_return;
}
} // namespace

Expand Down Expand Up @@ -623,9 +617,8 @@ bool generateThermalTimeSeries(Data::Study& study,

for (auto* cluster: clusters)
{
cluster->series.timeSeries.reset(study.parameters.nbTimeSeriesThermal, HOURS_PER_YEAR);
AvailabilityTSGeneratorData tsGenerationData(cluster);
generator.run(tsGenerationData);
cluster->series.timeSeries = generator.run(tsGenerationData);
}

return true;
Expand Down Expand Up @@ -666,23 +659,19 @@ bool generateLinkTimeSeries(std::vector<LinkTSgenerationParams>& links,
if (link.forceNoGeneration)
continue; // Skipping the link

Data::TimeSeriesNumbers fakeTSnumbers; // gp : to quickly get rid of
Data::TimeSeries ts(fakeTSnumbers);
ts.resize(generalParams.nbLinkTStoGenerate, HOURS_PER_YEAR);

// === DIRECT =======================
AvailabilityTSGeneratorData tsConfigDataDirect(link, ts, link.modulationCapacityDirect, link.namesPair.second);
generator.run(tsConfigDataDirect);
AvailabilityTSGeneratorData tsConfigDataDirect(link, link.modulationCapacityDirect, link.namesPair.second);
auto generated_ts = generator.run(tsConfigDataDirect);

auto filePath = savePath / link.namesPair.first / link.namesPair.second += "_direct.txt";
writeTStoDisk(ts.timeSeries, filePath);
writeTStoDisk(generated_ts, filePath);

// === INDIRECT =======================
AvailabilityTSGeneratorData tsConfigDataIndirect(link, ts, link.modulationCapacityIndirect, link.namesPair.second);
generator.run(tsConfigDataIndirect);
AvailabilityTSGeneratorData tsConfigDataIndirect(link, link.modulationCapacityIndirect, link.namesPair.second);
generated_ts = generator.run(tsConfigDataIndirect);

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

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class AvailabilityTSGeneratorData
explicit AvailabilityTSGeneratorData(Data::ThermalCluster*);

AvailabilityTSGeneratorData(LinkTSgenerationParams&,
Data::TimeSeries&,
Matrix<>& modulation,
const std::string& name);

Expand All @@ -90,8 +89,6 @@ class AvailabilityTSGeneratorData

Data::PreproAvailability* prepro;

Matrix<>& series;

Matrix<>::ColumnType& modulationCapacity;

const std::string& name;
Expand Down

0 comments on commit cdd57e8

Please sign in to comment.