From 063ae29a56ec7fb556408fd8071f64bb0a075f99 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 19 Jul 2024 18:14:18 +0200 Subject: [PATCH] Remove duplication in simulation run : first trial --- 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 a76eb934ec..5520323cd0 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 334e8f86d7..552b6fd56e 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; @@ -394,10 +396,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