From 207f376e8fb848a80465be8f3322ee7b021cf869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=A8=D9=84=D8=A7=D9=84=20=D9=85=D8=B3=D9=84=D9=88=D8=A8?= Date: Thu, 8 Aug 2024 17:29:17 +0200 Subject: [PATCH] Remove duplication in simulation run : first trial (#282) Co-authored-by: Guillaume PIERRE --- src/api/API.cpp | 7 +++--- src/solver/application/application.cpp | 10 +++++---- .../include/antares/application/application.h | 22 +++++++++++++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/api/API.cpp b/src/api/API.cpp index 38e9778eab..d102c8ca10 100644 --- a/src/api/API.cpp +++ b/src/api/API.cpp @@ -62,8 +62,6 @@ SimulationResults APIInternal::execute() const return {.simulationPath{}, .antares_problems{}, .error = err}; } - study_->computePThetaInfForThermalClusters(); - // Only those two fields are used un simulation Settings settings; settings.tsGeneratorsOnly = false; @@ -77,6 +75,9 @@ SimulationResults APIInternal::execute() const auto resultWriter = Solver::resultWriterFactory( study_->parameters.resultFormat, study_->folderOutput, ioQueueService, durationCollector); SimulationObserver simulationObserver; + + study_->computePThetaInfForThermalClusters(); + // Run the simulation switch (study_->runtime->mode) { @@ -104,8 +105,6 @@ SimulationResults APIInternal::execute() const // Importing Time-Series if asked study_->importTimeseriesIntoInput(); - // Stop the display of the progression - study_->progression.stop(); return { .simulationPath = study_->folderOutput.c_str(), diff --git a/src/solver/application/application.cpp b/src/solver/application/application.cpp index c65e849a15..b13f53c5ef 100644 --- a/src/solver/application/application.cpp +++ b/src/solver/application/application.cpp @@ -20,7 +20,6 @@ */ #include "antares/application/application.h" -#include #include #include @@ -30,7 +29,6 @@ #include #include #include -#include #include #include #include "antares/antares/version.h" @@ -44,6 +42,10 @@ #include "antares/solver/utils/ortools_utils.h" #include "antares/study/simulation.h" +#include "antares/solver/simulation/economy.h" +#include "antares/solver/simulation/adequacy.h" +#include "antares/solver/simulation/solver.h" + using namespace Antares::Check; namespace fs = std::filesystem; @@ -395,10 +397,10 @@ void Application::execute() { case Data::SimulationMode::Economy: case Data::SimulationMode::Expansion: - runSimulationInEconomicMode(); + runSimulation>(); break; case Data::SimulationMode::Adequacy: - runSimulationInAdequacyMode(); + runSimulation>(); break; default: break; diff --git a/src/solver/application/include/antares/application/application.h b/src/solver/application/include/antares/application/application.h index be114f2d88..a97171a03c 100644 --- a/src/solver/application/include/antares/application/application.h +++ b/src/solver/application/include/antares/application/application.h @@ -29,6 +29,7 @@ #include #include "antares/infoCollection/StudyInfoCollector.h" #include "antares/solver/misc/options.h" +#include "antares/solver/simulation/ISimulationObserver.h" namespace Antares::Solver { @@ -95,6 +96,9 @@ class Application final: public Yuni::IEventObserver + void runSimulation(); + void onLogMessage(int level, const std::string& message); //! The settings given from the command line @@ -132,4 +136,22 @@ class Application final: public Yuni::IEventObserver +void Application::runSimulation() +{ + Simulation::NullSimulationObserver observer; + simulationType simulation(*pStudy, pSettings, pDurationCollector, *resultWriter, observer); + simulation.checkWriter(); + simulation.run(); + + if (!(pSettings.noOutput || pSettings.tsGeneratorsOnly)) + { + pDurationCollector("synthesis_export") + << [&simulation] { simulation.writeResults(/*synthesis:*/ true); }; + + pOptimizationInfo = simulation.getOptimizationInfo(); + } +}; + } // namespace Antares::Solver