Skip to content

Commit

Permalink
Remove duplication in simulation run : first trial (#282)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume PIERRE <[email protected]>
  • Loading branch information
meslubi2021 and guilpier-code authored Aug 8, 2024
1 parent 714274d commit 207f376
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/api/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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(),
Expand Down
10 changes: 6 additions & 4 deletions src/solver/application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
#include "antares/application/application.h"

#include <yuni/datetime/timestamp.h>

#include <antares/antares/fatal-error.h>
#include <antares/application/ScenarioBuilderOwner.h>
Expand All @@ -30,7 +29,6 @@
#include <antares/infoCollection/StudyInfoCollector.h>
#include <antares/logs/hostinfo.h>
#include <antares/resources/resources.h>
#include <antares/study/version.h>
#include <antares/sys/policy.h>
#include <antares/writer/writer_factory.h>
#include "antares/antares/version.h"
Expand All @@ -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;
Expand Down Expand Up @@ -395,10 +397,10 @@ void Application::execute()
{
case Data::SimulationMode::Economy:
case Data::SimulationMode::Expansion:
runSimulationInEconomicMode();
runSimulation<Solver::Simulation::ISimulation<Solver::Simulation::Economy>>();
break;
case Data::SimulationMode::Adequacy:
runSimulationInAdequacyMode();
runSimulation<Solver::Simulation::ISimulation<Solver::Simulation::Adequacy>>();
break;
default:
break;
Expand Down
22 changes: 22 additions & 0 deletions src/solver/application/include/antares/application/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <antares/writer/i_writer.h>
#include "antares/infoCollection/StudyInfoCollector.h"
#include "antares/solver/misc/options.h"
#include "antares/solver/simulation/ISimulationObserver.h"

namespace Antares::Solver
{
Expand Down Expand Up @@ -95,6 +96,9 @@ class Application final: public Yuni::IEventObserver<Application, Yuni::Policy::
void runSimulationInAdequacyMode();
void runSimulationInEconomicMode();

template<class simulationType>
void runSimulation();

void onLogMessage(int level, const std::string& message);

//! The settings given from the command line
Expand Down Expand Up @@ -132,4 +136,22 @@ class Application final: public Yuni::IEventObserver<Application, Yuni::Policy::
void postParametersChecks() const;

}; // class Application

template<class simulationType>
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

0 comments on commit 207f376

Please sign in to comment.