Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 47 additions & 42 deletions src/solver/simulation/common-eco-adq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,31 @@
const std::vector<AvgExchangeResults*>& balance,
int PasDeTempsDebut)
{
for (uint i = 0; i < (uint)problem.NombreDePasDeTemps; i++)
const uint linkCount = study.runtime.interconnectionsCount();
const uint hourCount = static_cast<uint>(problem.NombreDePasDeTemps);

// The average NTC only depends on the link and on the hour, not on the time step being filled
// in : compute it once per link for the whole week.
std::vector<std::vector<double>> avgDirect(linkCount);
std::vector<std::vector<double>> avgIndirect(linkCount);
for (uint j = 0; j < linkCount; ++j)
{
const auto* link = study.runtime.areaLink[j];
retrieveAverageNTC(study,
link->directCapacities.timeSeries,
link->timeseriesNumbers,
PasDeTempsDebut,

Check warning on line 38 in src/solver/simulation/common-eco-adq.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int')

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZ9bdKOYTXuGxIxuescp&open=AZ9bdKOYTXuGxIxuescp&pullRequest=3805
hourCount,
avgDirect[j]);
retrieveAverageNTC(study,
link->indirectCapacities.timeSeries,
link->timeseriesNumbers,
PasDeTempsDebut,

Check warning on line 44 in src/solver/simulation/common-eco-adq.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int')

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZ9bdKOYTXuGxIxuescq&open=AZ9bdKOYTXuGxIxuescq&pullRequest=3805
hourCount,
avgIndirect[j]);
}

for (uint i = 0; i < hourCount; i++)

Check warning on line 49 in src/solver/simulation/common-eco-adq.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use prefix increment.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZ9bdKOYTXuGxIxuescr&open=AZ9bdKOYTXuGxIxuescr&pullRequest=3805
{
auto& ntcValues = problem.ValeursDeNTC[i];
uint decalPasDeTemps = PasDeTempsDebut + i;
Expand All @@ -43,32 +67,12 @@
}
}

std::vector<double> avgDirect;
std::vector<double> avgIndirect;
for (uint j = 0; j < study.runtime.interconnectionsCount(); ++j)
for (uint j = 0; j < linkCount; ++j)
{
auto* link = study.runtime.areaLink[j];
int ret = retrieveAverageNTC(study,
link->directCapacities.timeSeries,
link->timeseriesNumbers,
avgDirect);

ret = retrieveAverageNTC(study,
link->indirectCapacities.timeSeries,
link->timeseriesNumbers,
avgIndirect)
&& ret;
if (!ret)
{
ntcValues.ValeurDeNTCOrigineVersExtremite[j] = avgDirect[decalPasDeTemps];
ntcValues.ValeurDeNTCExtremiteVersOrigine[j] = avgIndirect[decalPasDeTemps];
}
else
{
assert(false && "invalid NTC");
}
ntcValues.ValeurDeNTCOrigineVersExtremite[j] = avgDirect[j][i];
ntcValues.ValeurDeNTCExtremiteVersOrigine[j] = avgIndirect[j][i];

auto& mtxParamaters = link->parameters;
const auto& mtxParamaters = study.runtime.areaLink[j]->parameters;
ntcValues.ResistanceApparente[j] = mtxParamaters[Data::fhlImpedances][decalPasDeTemps];
}
}
Expand Down Expand Up @@ -394,49 +398,50 @@
}
}

int retrieveAverageNTC(const Data::Study& study,
const Matrix<>& capacities,
const Data::TimeSeriesNumbers& tsNumbers,
std::vector<double>& avg)
void retrieveAverageNTC(const Data::Study& study,
const Matrix<>& capacities,
const Data::TimeSeriesNumbers& tsNumbers,
uint firstHour,
uint hourCount,
std::vector<double>& avg)
{
const auto& parameters = study.parameters;

const auto& yearsWeight = parameters.getYearsWeight();
const auto& yearsWeightSum = parameters.getYearsWeightSum();
const auto yearsWeightSum = parameters.getYearsWeightSum();
const auto& yearsFilter = parameters.yearsFilter;
const auto width = capacities.width;
avg.assign(HOURS_PER_YEAR, 0);
const bool singleTS = (capacities.width == 1);

avg.assign(hourCount, 0.);

std::map<uint32_t, double> weightOfTS;

for (uint y = 0; y < study.parameters.nbYears; y++)
for (uint y = 0; y < parameters.nbYears; y++)

Check warning on line 419 in src/solver/simulation/common-eco-adq.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use prefix increment.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZ9bdKOYTXuGxIxuescs&open=AZ9bdKOYTXuGxIxuescs&pullRequest=3805
{
if (!yearsFilter[y])
{
continue;
}

uint32_t tsIndex = (width == 1) ? 0 : tsNumbers[y];
uint32_t tsIndex = singleTS ? 0 : tsNumbers[y];
weightOfTS[tsIndex] += yearsWeight[y];
}

// No need for the year number, only the TS index is required
for (const auto& it: weightOfTS)
for (const auto& [tsIndex, weight]: weightOfTS)
{
const uint32_t tsIndex = it.first;
const double weight = it.second;
const auto* column = capacities[tsIndex];

for (uint h = 0; h < HOURS_PER_YEAR; h++)
for (uint h = 0; h < hourCount; h++)
{
avg[h] += capacities[tsIndex][h] * weight;
avg[h] += column[firstHour + h] * weight;
}
}

for (uint h = 0; h < HOURS_PER_YEAR; h++)
for (auto& value: avg)
{
avg[h] /= yearsWeightSum;
value /= yearsWeightSum;
}
return 0;
}

void finalizeOptimizationStatistics(PROBLEME_HEBDO& problem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,21 @@ void interpolateWaterValue(const Data::AreaList& areas,
void updatingWeeklyFinalHydroLevel(const Data::AreaList& areas, PROBLEME_HEBDO& problem);

/*
** \brief Compute the weighted average NTC for a link
** \brief Compute the MC-years weighted average NTC of a link, over a range of hours
**
** \param areas : the areas of study
** \param link The link
** \param Weighted average NTC for the direct direction
** \param Weighted average NTC for the indirect direction
** \param study The study
** \param capacities NTC time series of the link, for one direction
** \param tsNumbers TS numbers of the link
** \param firstHour First hour of the range, in [0, HOURS_PER_YEAR[
** \param hourCount Number of hours of the range
** \param avg Weighted average NTC, resized to hourCount. avg[h] refers to hour firstHour + h
*/
int retrieveAverageNTC(const Data::Study& study,
const Matrix<>& capacities,
const Data::TimeSeriesNumbers& tsNumbers,
std::vector<double>& avg);
void retrieveAverageNTC(const Data::Study& study,
const Matrix<>& capacities,
const Data::TimeSeriesNumbers& tsNumbers,
uint firstHour,
uint hourCount,
std::vector<double>& avg);

void finalizeOptimizationStatistics(PROBLEME_HEBDO& problem,
Antares::Solver::Variable::State& state);
Expand Down
Loading