From feaeeb7301f93ee08f586059165a9afe4a82186d Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 29 May 2024 19:11:12 +0200 Subject: [PATCH 1/5] Remove some numspace : we don't need the number of parallel year inside one year --- .../hydro/include/antares/solver/hydro/management/management.h | 1 - src/solver/hydro/management/management.cpp | 2 -- .../simulation/include/antares/solver/simulation/solver.hxx | 1 - 3 files changed, 4 deletions(-) diff --git a/src/solver/hydro/include/antares/solver/hydro/management/management.h b/src/solver/hydro/include/antares/solver/hydro/management/management.h index 29f64fbd93..77f7b70b46 100644 --- a/src/solver/hydro/include/antares/solver/hydro/management/management.h +++ b/src/solver/hydro/include/antares/solver/hydro/management/management.h @@ -107,7 +107,6 @@ class HydroManagement final HydroManagement(const Data::AreaList& areas, const Data::Parameters& params, const Date::Calendar& calendar, - unsigned int maxNbYearsInParallel, Solver::IResultWriter& resultWriter); //! Perform the hydro ventilation diff --git a/src/solver/hydro/management/management.cpp b/src/solver/hydro/management/management.cpp index 5d8fb79d47..0308bfe608 100644 --- a/src/solver/hydro/management/management.cpp +++ b/src/solver/hydro/management/management.cpp @@ -117,12 +117,10 @@ double BetaVariable(double a, double b, MersenneTwister& random) HydroManagement::HydroManagement(const Data::AreaList& areas, const Data::Parameters& params, const Date::Calendar& calendar, - unsigned int maxNbYearsInParallel, Solver::IResultWriter& resultWriter): areas_(areas), calendar_(calendar), parameters_(params), - maxNbYearsInParallel_(maxNbYearsInParallel), resultWriter_(resultWriter) { // Ventilation results memory allocation diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.hxx b/src/solver/simulation/include/antares/solver/simulation/solver.hxx index 70d88c47af..ec2716da2f 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.hxx +++ b/src/solver/simulation/include/antares/solver/simulation/solver.hxx @@ -75,7 +75,6 @@ public: hydroManagement(study.areas, study.parameters, study.calendar, - study.maxNbYearsInParallel, resultWriter) { hydroHotStart = (study.parameters.initialReservoirLevels.iniLevels == Data::irlHotStart); From 3807f79614a0c565b1a609fddb2fa2ae2de12159 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 29 May 2024 19:31:59 +0200 Subject: [PATCH 2/5] Remove some numspace : state > using state instead of state[numSpace] --- .../antares/solver/simulation/solver.hxx | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.hxx b/src/solver/simulation/include/antares/solver/simulation/solver.hxx index ec2716da2f..a59229aebb 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.hxx +++ b/src/solver/simulation/include/antares/solver/simulation/solver.hxx @@ -55,7 +55,7 @@ public: randomNumbers& pRandomForParallelYears, bool pPerformCalculations, Data::Study& pStudy, - std::vector& pState, + Variable::State& pState, bool pYearByYear, Benchmarking::DurationCollector& durationCollector, IResultWriter& resultWriter): @@ -95,7 +95,7 @@ private: randomNumbers& randomForParallelYears; bool performCalculations; Data::Study& study; - std::vector& state; + Variable::State& state; bool yearByYear; bool hydroHotStart; Benchmarking::DurationCollector& pDurationCollector; @@ -154,8 +154,7 @@ public: // 1 - Applying random levels for current year if (hydroHotStart && firstSetParallelWithAPerformedYearWasRun) { - randomReservoirLevel = state[numSpace] - .problemeHebdo->previousYearFinalLevels.data(); + randomReservoirLevel = state.problemeHebdo->previousYearFinalLevels.data(); } else { @@ -171,13 +170,13 @@ public: // 4 - Hydraulic ventilation pDurationCollector("hydro_ventilation") << [&] { hydroManagement.makeVentilation(randomReservoirLevel, - state[numSpace], + state, y, scratchmap); }; // Updating the state - state[numSpace].year = y; + state.year = y; // 5 - Resetting all variables for the output simulation_->variables.yearBegin(y, numSpace); @@ -189,7 +188,7 @@ public: OptimizationStatisticsWriter optWriter(pResultWriter, y); yearFailed[y] = !simulation_->year(progression, - state[numSpace], + state, numSpace, randomForCurrentYear, failedWeekList, @@ -201,7 +200,7 @@ public: // Log failing weeks logFailedWeek(y, study, failedWeekList); - simulation_->variables.yearEndBuild(state[numSpace], y, numSpace); + simulation_->variables.yearEndBuild(state, y, numSpace); // 7 - End of the year, this is the last stade where the variables can retrieve // their data for this year. @@ -1059,19 +1058,19 @@ void ISimulation::loopThroughYears(uint firstYear, // continue; auto task = std::make_shared>( - this, - y, - set_it->yearFailed, - set_it->isFirstPerformedYearOfASet, - pFirstSetParallelWithAPerformedYearWasRun, - numSpace, - randomForParallelYears, - performCalculations, - study, - state, - pYearByYear, - pDurationCollector, - pResultWriter); + this, + y, + set_it->yearFailed, + set_it->isFirstPerformedYearOfASet, + pFirstSetParallelWithAPerformedYearWasRun, + numSpace, + randomForParallelYears, + performCalculations, + study, + state[numSpace], + pYearByYear, + pDurationCollector, + pResultWriter); results.add(Concurrency::AddTask(*pQueueService, task)); } // End loop over years of the current set of parallel years From 50d2e06477cbdbb611aeb71fbf735ed7c10e95b9 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 30 May 2024 14:59:41 +0200 Subject: [PATCH 3/5] Remove some numspace : simplify functions prepareClustersInMustRunMode --- src/solver/simulation/adequacy.cpp | 30 +++++++++- src/solver/simulation/common-eco-adq.cpp | 59 ------------------- src/solver/simulation/economy.cpp | 16 ++++- .../solver/simulation/common-eco-adq.h | 7 --- 4 files changed, 43 insertions(+), 69 deletions(-) diff --git a/src/solver/simulation/adequacy.cpp b/src/solver/simulation/adequacy.cpp index 5d3a54b261..ab51b59056 100644 --- a/src/solver/simulation/adequacy.cpp +++ b/src/solver/simulation/adequacy.cpp @@ -411,7 +411,33 @@ void Adequacy::simulationEnd() void Adequacy::prepareClustersInMustRunMode(Data::Area::ScratchMap& scratchmap, uint year) { - PrepareDataFromClustersInMustrunMode(study, scratchmap, year); -} + for (uint i = 0; i < study.areas.size(); ++i) + { + auto &area = *study.areas[i]; + auto &scratchpad = scratchmap.at(&area); + + memset(scratchpad.mustrunSum, 0, sizeof(double) * HOURS_PER_YEAR); + memset(scratchpad.originalMustrunSum, 0, sizeof(double) * HOURS_PER_YEAR); + + double *mrs = scratchpad.mustrunSum; + double *adq = scratchpad.originalMustrunSum; + + for (const auto &cluster: area.thermal.list.each_mustrun_and_enabled()) + { + const auto &availableProduction = cluster->series.getColumn(year); + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) + { + mrs[h] += availableProduction[h]; + } + if (cluster->mustrunOrigin) + { + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) + { + adq[h] += 2 * availableProduction[h]; // Why do we add the available production twice ? + } + } + } + } +} } // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index 8abcb0cb98..5dcff82ae3 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -113,65 +113,6 @@ static void RecalculDesEchangesMoyens(Data::Study& study, } } -void PrepareDataFromClustersInMustrunMode(Data::Study& study, - Data::Area::ScratchMap& scratchmap, - uint year) -{ - bool inAdequacy = (study.parameters.mode == Data::SimulationMode::Adequacy); - - for (uint i = 0; i < study.areas.size(); ++i) - { - auto& area = *study.areas[i]; - auto& scratchpad = scratchmap.at(&area); - - memset(scratchpad.mustrunSum, 0, sizeof(double) * HOURS_PER_YEAR); - if (inAdequacy) - { - memset(scratchpad.originalMustrunSum, 0, sizeof(double) * HOURS_PER_YEAR); - } - - double* mrs = scratchpad.mustrunSum; - double* adq = scratchpad.originalMustrunSum; - - for (const auto& cluster: area.thermal.list.each_mustrun_and_enabled()) - { - const auto& availableProduction = cluster->series.getColumn(year); - if (inAdequacy && cluster->mustrunOrigin) - { - for (uint h = 0; h != cluster->series.timeSeries.height; ++h) - { - mrs[h] += availableProduction[h]; - adq[h] += availableProduction[h]; - } - } - else - { - for (uint h = 0; h != cluster->series.timeSeries.height; ++h) - { - mrs[h] += availableProduction[h]; - } - } - } - - if (inAdequacy) - { - for (const auto& cluster: area.thermal.list.each_mustrun_and_enabled()) - { - if (!cluster->mustrunOrigin) - { - continue; - } - - const auto& availableProduction = cluster->series.getColumn(year); - for (uint h = 0; h != cluster->series.timeSeries.height; ++h) - { - adq[h] += availableProduction[h]; - } - } - } - } -} - bool ShouldUseQuadraticOptimisation(const Data::Study& study) { const bool flowQuadEnabled = study.parameters.variablesPrintInfo.isPrinted("FLOW QUAD."); diff --git a/src/solver/simulation/economy.cpp b/src/solver/simulation/economy.cpp index 558c4f2095..72d5497295 100644 --- a/src/solver/simulation/economy.cpp +++ b/src/solver/simulation/economy.cpp @@ -272,7 +272,21 @@ void Economy::simulationEnd() void Economy::prepareClustersInMustRunMode(Data::Area::ScratchMap& scratchmap, uint year) { - PrepareDataFromClustersInMustrunMode(study, scratchmap, year); + for (uint i = 0; i < study.areas.size(); ++i) + { + auto& area = *study.areas[i]; + auto& scratchpad = scratchmap.at(&area); + memset(scratchpad.mustrunSum, 0, sizeof(double) * HOURS_PER_YEAR); + double* mrs = scratchpad.mustrunSum; + for (const auto& cluster: area.thermal.list.each_mustrun_and_enabled()) + { + const auto& availableProduction = cluster->series.getColumn(year); + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) + { + mrs[h] += availableProduction[h]; + } + } + } } } // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h b/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h index 2110c4cbe9..fc8a338cfd 100644 --- a/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h +++ b/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h @@ -62,13 +62,6 @@ void BuildThermalPartOfWeeklyProblem(Data::Study& study, double** thermalNoises, unsigned int year); -/*! -** \brief Prepare data from clusters in mustrun mode (eco+adq) -*/ -void PrepareDataFromClustersInMustrunMode(Data::Study& study, - Data::Area::ScratchMap& scratchmap, - uint year); - /*! ** \brief Get if the quadratic optimization should be used according ** to the input data (eco+adq) From 6cb037dce299171f126f0d7f254cc2bf591de28d Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 30 May 2024 16:52:40 +0200 Subject: [PATCH 4/5] Remove some numspace : simplification on the fly : why use a hard coded value and check its value right after ? --- src/solver/simulation/adequacy.cpp | 10 +--------- src/solver/simulation/economy.cpp | 8 +------- .../include/antares/solver/simulation/simulation.h | 2 +- src/solver/simulation/sim_calcul_economique.cpp | 2 +- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/solver/simulation/adequacy.cpp b/src/solver/simulation/adequacy.cpp index ab51b59056..33a9319490 100644 --- a/src/solver/simulation/adequacy.cpp +++ b/src/solver/simulation/adequacy.cpp @@ -68,15 +68,7 @@ bool Adequacy::simulationBegin() pProblemesHebdo.resize(pNbMaxPerformedYearsInParallel); for (uint numSpace = 0; numSpace < pNbMaxPerformedYearsInParallel; numSpace++) { - SIM_InitialisationProblemeHebdo(study, pProblemesHebdo[numSpace], 168, numSpace); - - assert((uint)nbHoursInAWeek == (uint)pProblemesHebdo[numSpace].NombreDePasDeTemps - && "inconsistency"); - if ((uint)nbHoursInAWeek != (uint)pProblemesHebdo[numSpace].NombreDePasDeTemps) - { - logs.fatal() << "internal error"; - return false; - } + SIM_InitialisationProblemeHebdo(study, pProblemesHebdo[numSpace], nbHoursInAWeek, numSpace); } } diff --git a/src/solver/simulation/economy.cpp b/src/solver/simulation/economy.cpp index 72d5497295..0cf2989304 100644 --- a/src/solver/simulation/economy.cpp +++ b/src/solver/simulation/economy.cpp @@ -73,13 +73,7 @@ bool Economy::simulationBegin() for (uint numSpace = 0; numSpace < pNbMaxPerformedYearsInParallel; numSpace++) { - SIM_InitialisationProblemeHebdo(study, pProblemesHebdo[numSpace], 168, numSpace); - - if ((uint)nbHoursInAWeek != (uint)pProblemesHebdo[numSpace].NombreDePasDeTemps) - { - logs.fatal() << "internal error"; - return false; - } + SIM_InitialisationProblemeHebdo(study, pProblemesHebdo[numSpace], nbHoursInAWeek, numSpace); auto options = createOptimizationOptions(study); weeklyOptProblems_[numSpace] = Antares::Solver::Optimization::WeeklyOptimization:: diff --git a/src/solver/simulation/include/antares/solver/simulation/simulation.h b/src/solver/simulation/include/antares/solver/simulation/simulation.h index 6d814157d1..bf214beff6 100644 --- a/src/solver/simulation/include/antares/solver/simulation/simulation.h +++ b/src/solver/simulation/include/antares/solver/simulation/simulation.h @@ -45,7 +45,7 @@ void SIM_AllocationProblemeHebdo(const Antares::Data::Study& study, */ void SIM_InitialisationProblemeHebdo(Antares::Data::Study& study, PROBLEME_HEBDO& problem, - int NombreDePasDeTemps, + unsigned int NombreDePasDeTemps, uint numspace); void SIM_RenseignementProblemeHebdo(const Antares::Data::Study& study, diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 8b921dfec3..c51d8283dc 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -71,7 +71,7 @@ static void importShortTermStorages( void SIM_InitialisationProblemeHebdo(Data::Study& study, PROBLEME_HEBDO& problem, - int NombreDePasDeTemps, + unsigned int NombreDePasDeTemps, uint numspace) { int NombrePaliers; From 89a058145d26468c07d2b87a3589b7c52b7db6fb Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Fri, 14 Jun 2024 14:53:47 +0200 Subject: [PATCH 5/5] Revert "Remove some numspace : simplify functions prepareClustersInMustRunMode" This reverts commit 50d2e06477cbdbb611aeb71fbf735ed7c10e95b9. --- src/solver/simulation/adequacy.cpp | 30 +--------- src/solver/simulation/common-eco-adq.cpp | 59 +++++++++++++++++++ src/solver/simulation/economy.cpp | 16 +---- .../solver/simulation/common-eco-adq.h | 7 +++ 4 files changed, 69 insertions(+), 43 deletions(-) diff --git a/src/solver/simulation/adequacy.cpp b/src/solver/simulation/adequacy.cpp index 33a9319490..82c48bd709 100644 --- a/src/solver/simulation/adequacy.cpp +++ b/src/solver/simulation/adequacy.cpp @@ -403,33 +403,7 @@ void Adequacy::simulationEnd() void Adequacy::prepareClustersInMustRunMode(Data::Area::ScratchMap& scratchmap, uint year) { - for (uint i = 0; i < study.areas.size(); ++i) - { - auto &area = *study.areas[i]; - auto &scratchpad = scratchmap.at(&area); - - memset(scratchpad.mustrunSum, 0, sizeof(double) * HOURS_PER_YEAR); - memset(scratchpad.originalMustrunSum, 0, sizeof(double) * HOURS_PER_YEAR); - - double *mrs = scratchpad.mustrunSum; - double *adq = scratchpad.originalMustrunSum; - - for (const auto &cluster: area.thermal.list.each_mustrun_and_enabled()) - { - const auto &availableProduction = cluster->series.getColumn(year); - for (uint h = 0; h != cluster->series.timeSeries.height; ++h) - { - mrs[h] += availableProduction[h]; - } - - if (cluster->mustrunOrigin) - { - for (uint h = 0; h != cluster->series.timeSeries.height; ++h) - { - adq[h] += 2 * availableProduction[h]; // Why do we add the available production twice ? - } - } - } - } + PrepareDataFromClustersInMustrunMode(study, scratchmap, year); } + } // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index 5dcff82ae3..8abcb0cb98 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -113,6 +113,65 @@ static void RecalculDesEchangesMoyens(Data::Study& study, } } +void PrepareDataFromClustersInMustrunMode(Data::Study& study, + Data::Area::ScratchMap& scratchmap, + uint year) +{ + bool inAdequacy = (study.parameters.mode == Data::SimulationMode::Adequacy); + + for (uint i = 0; i < study.areas.size(); ++i) + { + auto& area = *study.areas[i]; + auto& scratchpad = scratchmap.at(&area); + + memset(scratchpad.mustrunSum, 0, sizeof(double) * HOURS_PER_YEAR); + if (inAdequacy) + { + memset(scratchpad.originalMustrunSum, 0, sizeof(double) * HOURS_PER_YEAR); + } + + double* mrs = scratchpad.mustrunSum; + double* adq = scratchpad.originalMustrunSum; + + for (const auto& cluster: area.thermal.list.each_mustrun_and_enabled()) + { + const auto& availableProduction = cluster->series.getColumn(year); + if (inAdequacy && cluster->mustrunOrigin) + { + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) + { + mrs[h] += availableProduction[h]; + adq[h] += availableProduction[h]; + } + } + else + { + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) + { + mrs[h] += availableProduction[h]; + } + } + } + + if (inAdequacy) + { + for (const auto& cluster: area.thermal.list.each_mustrun_and_enabled()) + { + if (!cluster->mustrunOrigin) + { + continue; + } + + const auto& availableProduction = cluster->series.getColumn(year); + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) + { + adq[h] += availableProduction[h]; + } + } + } + } +} + bool ShouldUseQuadraticOptimisation(const Data::Study& study) { const bool flowQuadEnabled = study.parameters.variablesPrintInfo.isPrinted("FLOW QUAD."); diff --git a/src/solver/simulation/economy.cpp b/src/solver/simulation/economy.cpp index 0cf2989304..f86fb885c3 100644 --- a/src/solver/simulation/economy.cpp +++ b/src/solver/simulation/economy.cpp @@ -266,21 +266,7 @@ void Economy::simulationEnd() void Economy::prepareClustersInMustRunMode(Data::Area::ScratchMap& scratchmap, uint year) { - for (uint i = 0; i < study.areas.size(); ++i) - { - auto& area = *study.areas[i]; - auto& scratchpad = scratchmap.at(&area); - memset(scratchpad.mustrunSum, 0, sizeof(double) * HOURS_PER_YEAR); - double* mrs = scratchpad.mustrunSum; - for (const auto& cluster: area.thermal.list.each_mustrun_and_enabled()) - { - const auto& availableProduction = cluster->series.getColumn(year); - for (uint h = 0; h != cluster->series.timeSeries.height; ++h) - { - mrs[h] += availableProduction[h]; - } - } - } + PrepareDataFromClustersInMustrunMode(study, scratchmap, year); } } // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h b/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h index fc8a338cfd..2110c4cbe9 100644 --- a/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h +++ b/src/solver/simulation/include/antares/solver/simulation/common-eco-adq.h @@ -62,6 +62,13 @@ void BuildThermalPartOfWeeklyProblem(Data::Study& study, double** thermalNoises, unsigned int year); +/*! +** \brief Prepare data from clusters in mustrun mode (eco+adq) +*/ +void PrepareDataFromClustersInMustrunMode(Data::Study& study, + Data::Area::ScratchMap& scratchmap, + uint year); + /*! ** \brief Get if the quadratic optimization should be used according ** to the input data (eco+adq)