Skip to content

Commit

Permalink
Add getValue for thermal clusters, remove State::timeSeriesIndex (#1644)
Browse files Browse the repository at this point in the history
* Ramove global NumeroChroniquesTireesParPays : removing from class State

* Move DataSeriesMemoryUsage to series.cpp

* Move DataSeriesMemoryUsage to class

* Use DataSeriesCommon::getValue for thermal

* Fix index

* Remove some uses of ThermiqueParPalier

* [DEV] Add arg year in prepareClustersInMustRunMode

* [FIX] Segfault by using getValue()

* [DEV] Renamed getValue by getAvailablePower

* [DEV] Add getSeriesIndex

* [FIX] segfault with getSeriesIndex

* [FIX] getseriesindex

* [DEV] getMarketBidCost now takes hour and year

* [DEV] use correct size, remove numspace from args

* [FIX] size

* [DEV] private getSeriesIndex

* [DEV] remove ThermiqueParPalier

* [FIX] post_process

---------

Co-authored-by: Florian OMNES <[email protected]>
Co-authored-by: Vincent Payet <[email protected]>
  • Loading branch information
3 people authored Sep 28, 2023
1 parent 62f6abe commit f23b312
Show file tree
Hide file tree
Showing 25 changed files with 72 additions and 160 deletions.
1 change: 0 additions & 1 deletion src/libs/antares/study/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ source_group("study\\area\\ui" FILES ${SRC_STUDY_AREA_UI})

set(SRC_STUDY_PART_COMMON
parts/common/series.h
parts/common/series.hxx
parts/common/series.cpp
parts/common/cluster.cpp
parts/common/cluster.h
Expand Down
16 changes: 16 additions & 0 deletions src/libs/antares/study/parts/common/series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ void DataSeriesCommon::markAsModified() const
timeSeries.markAsModified();
}

uint64_t DataSeriesCommon::memoryUsage() const
{
return timeSeries.memoryUsage();
}

double DataSeriesCommon::getAvailablePower(unsigned int hour, unsigned int year) const
{
return timeSeries[getSeriesIndex(year)][hour];
}
uint DataSeriesCommon::getSeriesIndex(unsigned int year) const
{
if (timeSeries.width == 1)
return 0;
else
return timeseriesNumbers[0][year];
}

} // namespace Antares::Data

17 changes: 9 additions & 8 deletions src/libs/antares/study/parts/common/series.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
#include <antares/array/matrix.h>
#include "../../fwd.h"

namespace Antares
{
namespace Data
namespace Antares::Data
{
/*!
** \brief Data series (Common)
Expand All @@ -44,7 +42,10 @@ class DataSeriesCommon

void markAsModified() const;

public:
uint64_t memoryUsage() const;

double getAvailablePower(unsigned int hour, unsigned int year) const;

/*!
** \brief Series (MW)
**
Expand All @@ -56,10 +57,10 @@ class DataSeriesCommon
** \brief Monte-Carlo
*/
Matrix<uint32_t> timeseriesNumbers;
}; // class DataSeriesCommon
} // namespace Data
} // namespace Antares

#include "series.hxx"
private:
uint getSeriesIndex(unsigned int year) const;

}; // class DataSeriesCommon
} // namespace Antares::Data
#endif /* __ANTARES_LIBS_STUDY_PARTS_COMMON_TIMESERIES_H__ */
42 changes: 0 additions & 42 deletions src/libs/antares/study/parts/common/series.hxx

This file was deleted.

2 changes: 1 addition & 1 deletion src/libs/antares/study/parts/renewable/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ uint64_t RenewableCluster::memoryUsage() const
{
uint64_t amount = sizeof(RenewableCluster);
if (series)
amount += DataSeriesMemoryUsage(series);
amount += series->memoryUsage();
return amount;
}

Expand Down
6 changes: 4 additions & 2 deletions src/libs/antares/study/parts/thermal/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ uint64_t ThermalCluster::memoryUsage() const
if (prepro)
amount += prepro->memoryUsage();
if (series)
amount += DataSeriesMemoryUsage(series);
amount += series->memoryUsage();
amount += ecoInput.memoryUsage();
return amount;
}
Expand Down Expand Up @@ -770,8 +770,10 @@ double ThermalCluster::getMarginalCost(uint serieIndex, uint hourInTheYear) cons
inside -> that is used for all (e.g.10) TS*/
}

double ThermalCluster::getMarketBidCost(uint serieIndex, uint hourInTheYear) const
double ThermalCluster::getMarketBidCost(uint hourInTheYear, uint year) const
{
uint serieIndex = (series->timeSeries.width == 1) ? 0 : series->timeseriesNumbers[0][year];

double mod = modulation[thermalModulationMarketBid][serieIndex];

if (costgeneration == Data::setManually)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/parts/thermal/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class ThermalCluster final : public Cluster, public std::enable_shared_from_this

double getOperatingCost(uint tsIndex, uint hourInTheYear) const;
double getMarginalCost(uint tsIndex, uint hourInTheYear) const;
double getMarketBidCost(uint tsIndex, uint hourInTheYear) const;
double getMarketBidCost(uint hourInTheYear, uint year) const;

// Check & correct availability timeseries for thermal availability
// Only applies if time-series are ready-made
Expand Down
24 changes: 0 additions & 24 deletions src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,6 @@ void ApplyRandomTSnumbers(const Study& study,
: 0; // zero-based
}
}

// Thermal
{
auto end = area.thermal.list.mapping.end();
for (auto it = area.thermal.list.mapping.begin(); it != end; ++it)
{
ThermalClusterList::SharedPtr cluster = it->second;

if (!cluster->enabled)
{
continue;
}

const auto& data = *cluster->series;
assert(year < data.timeseriesNumbers.height);
unsigned int clusterIndex = cluster->areaWideIndex;

// the matrix data.series should be properly initialized at this stage
// because the ts-generator has already been launched
ptchro.ThermiqueParPalier[clusterIndex] = (data.timeSeries.width != 1)
? (long)data.timeseriesNumbers[0][year]
: 0; // zero-based
}
} // thermal
} // each area

// ------------------------------
Expand Down
14 changes: 4 additions & 10 deletions src/solver/optimisation/post_process_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DispatchableMarginPostProcessCmd::DispatchableMarginPostProcessCmd(PROBLEME_HEBD
void DispatchableMarginPostProcessCmd::execute(const optRuntimeData& opt_runtime_data)
{
unsigned int hourInYear = opt_runtime_data.hourInTheYear;

unsigned int year = opt_runtime_data.year;
area_list_.each([&](Data::Area& area) {
double* dtgmrg = area.scratchpad[thread_number_].dispatchableGenerationMargin;
for (uint h = 0; h != nbHoursInWeek; ++h)
Expand All @@ -30,23 +30,17 @@ void DispatchableMarginPostProcessCmd::execute(const optRuntimeData& opt_runtime
if (not area.thermal.list.empty())
{
auto& hourlyResults = problemeHebdo_->ResultatsHoraires[area.index];
auto end = area.thermal.list.end();

auto end = area.thermal.list.end();
for (auto i = area.thermal.list.begin(); i != end; ++i)
{
auto& cluster = *(i->second);
uint chro = NumeroChroniquesTireesParPays[thread_number_][area.index]
.ThermiqueParPalier[cluster.areaWideIndex];
auto& matrix = cluster.series->timeSeries;
assert(chro < matrix.width);
auto& column = matrix.entry[chro];
assert(hourInYear + nbHoursInWeek <= matrix.height && "index out of bounds");

for (uint h = 0; h != nbHoursInWeek; ++h)
{
double production = hourlyResults.ProductionThermique[h]
.ProductionThermiqueDuPalier[cluster.index];
dtgmrg[h] += column[h + hourInYear] - production;
double availability = cluster.series->getAvailablePower(h + hourInYear, year);
dtgmrg[h] += availability - production;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/solver/simulation/adequacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ bool Adequacy::year(Progression::Task& progression,
numSpace, hourInTheYear, hydroVentilationResults);

BuildThermalPartOfWeeklyProblem(study, pProblemesHebdo[numSpace],
numSpace, hourInTheYear, randomForYear.pThermalNoisesByArea);
hourInTheYear, randomForYear.pThermalNoisesByArea, state.year);

// Reinit optimisation if needed
pProblemesHebdo[numSpace].ReinitOptimisation = reinitOptim;
Expand Down Expand Up @@ -386,9 +386,9 @@ void Adequacy::simulationEnd()
}
}

void Adequacy::prepareClustersInMustRunMode(uint numSpace)
void Adequacy::prepareClustersInMustRunMode(uint numSpace, uint year)
{
PrepareDataFromClustersInMustrunMode(study, numSpace);
PrepareDataFromClustersInMustrunMode(study, numSpace, year);
}

} // namespace Antares::Solver::Simulation
2 changes: 1 addition & 1 deletion src/solver/simulation/adequacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Adequacy
/*!
** \brief Prepare clusters in 'must-run' mode
*/
void prepareClustersInMustRunMode(uint numSpace);
void prepareClustersInMustRunMode(uint numSpace, uint year);

void initializeState(Variable::State& state, uint numSpace);

Expand Down
39 changes: 12 additions & 27 deletions src/solver/simulation/common-eco-adq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static void RecalculDesEchangesMoyens(Data::Study& study,
}
}

void PrepareDataFromClustersInMustrunMode(Data::Study& study, uint numSpace)
void PrepareDataFromClustersInMustrunMode(Data::Study& study, uint numSpace, uint year)
{
bool inAdequacy = (study.parameters.mode == Data::stdmAdequacy);

Expand All @@ -130,7 +130,6 @@ void PrepareDataFromClustersInMustrunMode(Data::Study& study, uint numSpace)
if (inAdequacy)
memset(scratchpad.originalMustrunSum, 0, sizeof(double) * HOURS_PER_YEAR);

auto& PtChro = NumeroChroniquesTireesParPays[numSpace][i];
double* mrs = scratchpad.mustrunSum;
double* adq = scratchpad.originalMustrunSum;

Expand All @@ -140,25 +139,19 @@ void PrepareDataFromClustersInMustrunMode(Data::Study& study, uint numSpace)
for (auto i = area.thermal.mustrunList.begin(); i != end; ++i)
{
auto& cluster = *(i->second);
auto& series = cluster.series->timeSeries;
uint tsIndex = static_cast<uint>(PtChro.ThermiqueParPalier[cluster.areaWideIndex]);
if (tsIndex >= series.width)
tsIndex = 0;

auto& column = series[tsIndex];

if (inAdequacy && cluster.mustrunOrigin)
{
for (uint h = 0; h != series.height; ++h)
for (uint h = 0; h != cluster.series->timeSeries.height; ++h)
{
mrs[h] += column[h];
adq[h] += column[h];
mrs[h] += cluster.series->getAvailablePower(h, year);
adq[h] += cluster.series->getAvailablePower(h, year);
}
}
else
{
for (uint h = 0; h != series.height; ++h)
mrs[h] += column[h];
for (uint h = 0; h != cluster.series->timeSeries.height; ++h)
mrs[h] += cluster.series->getAvailablePower(h, year);
}
}
}
Expand All @@ -172,14 +165,8 @@ void PrepareDataFromClustersInMustrunMode(Data::Study& study, uint numSpace)
if (!cluster.mustrunOrigin)
continue;

auto& series = cluster.series->timeSeries;
uint tsIndex = static_cast<uint>(PtChro.ThermiqueParPalier[cluster.areaWideIndex]);
if (tsIndex >= series.width)
tsIndex = 0;

auto& column = series[tsIndex];
for (uint h = 0; h != series.height; ++h)
adq[h] += column[h];
for (uint h = 0; h != cluster.series->timeSeries.height; ++h)
adq[h] += cluster.series->getAvailablePower(h, year);
}
}
}
Expand Down Expand Up @@ -385,9 +372,9 @@ void PrepareRandomNumbers(Data::Study& study,

void BuildThermalPartOfWeeklyProblem(Data::Study& study,
PROBLEME_HEBDO& problem,
uint numSpace,
const int PasDeTempsDebut,
double** thermalNoises)
double** thermalNoises,
unsigned int year)
{
int hourInYear = PasDeTempsDebut;
const uint nbPays = study.areas.size();
Expand All @@ -396,19 +383,17 @@ void BuildThermalPartOfWeeklyProblem(Data::Study& study,
for (uint areaIdx = 0; areaIdx < nbPays; ++areaIdx)
{
auto& area = *study.areas.byIndex[areaIdx];
auto& tsIndex = NumeroChroniquesTireesParPays[numSpace][areaIdx];
area.thermal.list.each([&](const Data::ThermalCluster& cluster)
{
auto& Pt = problem.PaliersThermiquesDuPays[areaIdx]
.PuissanceDisponibleEtCout[cluster.index];

Pt.CoutHoraireDeProductionDuPalierThermique[hourInWeek] =
cluster.getMarketBidCost(tsIndex.ThermiqueParPalier[cluster.areaWideIndex], hourInYear)
cluster.getMarketBidCost(hourInYear, year)
+ thermalNoises[areaIdx][cluster.areaWideIndex];

Pt.PuissanceDisponibleDuPalierThermique[hourInWeek]
= cluster.series
->timeSeries[tsIndex.ThermiqueParPalier[cluster.areaWideIndex]][hourInYear];
= cluster.series->getAvailablePower(hourInYear, year);

Pt.PuissanceMinDuPalierThermique[hourInWeek]
= (Pt.PuissanceDisponibleDuPalierThermique[hourInWeek] < cluster.PthetaInf[hourInYear])
Expand Down
6 changes: 3 additions & 3 deletions src/solver/simulation/common-eco-adq.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ void PrepareRandomNumbers(Data::Study& study,

void BuildThermalPartOfWeeklyProblem(Data::Study& study,
PROBLEME_HEBDO& problem,
uint numSpace,
const int PasDeTempsDebut,
double** thermalNoises);
double** thermalNoises,
unsigned int year);

/*!
** \brief Prepare data from clusters in mustrun mode (eco+adq)
*/
void PrepareDataFromClustersInMustrunMode(Data::Study& study, uint numSpace);
void PrepareDataFromClustersInMustrunMode(Data::Study& study, uint numSpace, uint year);

/*!
** \brief Get if the quadratic optimization should be used according
Expand Down
6 changes: 3 additions & 3 deletions src/solver/simulation/economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool Economy::year(Progression::Task& progression,
numSpace, hourInTheYear, hydroVentilationResults);

BuildThermalPartOfWeeklyProblem(study, pProblemesHebdo[numSpace],
numSpace, hourInTheYear, randomForYear.pThermalNoisesByArea);
hourInTheYear, randomForYear.pThermalNoisesByArea, state.year);

// Reinit optimisation if needed
pProblemesHebdo[numSpace].ReinitOptimisation = reinitOptim;
Expand Down Expand Up @@ -264,9 +264,9 @@ void Economy::simulationEnd()
}
}

void Economy::prepareClustersInMustRunMode(uint numSpace)
void Economy::prepareClustersInMustRunMode(uint numSpace, uint year)
{
PrepareDataFromClustersInMustrunMode(study, numSpace);
PrepareDataFromClustersInMustrunMode(study, numSpace, year);
}

} // namespace Antares::Solver::Simulation
2 changes: 1 addition & 1 deletion src/solver/simulation/economy.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Economy
/*!
** \brief Prepare clusters in 'must-run' mode
*/
void prepareClustersInMustRunMode(uint numSpace);
void prepareClustersInMustRunMode(uint numSpace, uint year);

void initializeState(Variable::State& state, uint numSpace);

Expand Down
Loading

0 comments on commit f23b312

Please sign in to comment.