Antares Simulator
Power System Simulator
solver.h
1 /*
2  * Copyright 2007-2025, RTE (https://www.rte-france.com)
3  * See AUTHORS.txt
4  * SPDX-License-Identifier: MPL-2.0
5  * This file is part of Antares-Simulator,
6  * Adequacy and Performance assessment for interconnected energy networks.
7  *
8  * Antares_Simulator is free software: you can redistribute it and/or modify
9  * it under the terms of the Mozilla Public Licence 2.0 as published by
10  * the Mozilla Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Antares_Simulator is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * Mozilla Public Licence 2.0 for more details.
17  *
18  * You should have received a copy of the Mozilla Public Licence 2.0
19  * along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20  */
21 #ifndef __SOLVER_SIMULATION_SOLVER_H__
22 #define __SOLVER_SIMULATION_SOLVER_H__
23 
24 #include <stdexcept>
25 
26 #include <yuni/job/queue/service.h>
27 
28 #include <antares/benchmarking/DurationCollector.h>
29 #include <antares/logs/logs.h>
30 #include <antares/solver/simulation/ISimulationObserver.h>
31 #include <antares/study/study.h>
32 #include <antares/writer/writer_factory.h>
33 #include "antares/solver/hydro/management/management.h"
34 #include "antares/solver/misc/options.h"
35 #include "antares/solver/simulation/solver_utils.h"
36 #include "antares/solver/variable/state.h"
37 
39 
40 namespace Antares::Solver::Simulation
41 {
42 template<class Impl>
43 class yearJob;
44 
45 template<class Impl>
46 class ISimulation: public Impl
47 {
48  friend class yearJob<Impl>;
49 
50 public:
52 
53 
57  const ::Settings& settings,
58  Benchmarking::DurationCollector& duration_collector,
59  IResultWriter& resultWriter,
60  Simulation::ISimulationObserver& simulationObserver);
62  ~ISimulation();
64 
65  // Check that the writer is valid
66  void checkWriter() const;
67 
71  void run();
72 
80  void writeResults(bool synthesis, uint year = 0, uint numSpace = 9999);
81 
85  const ::Settings& settings;
86 
87 private:
98  void computeAnnualCostsStatistics(Variable::State state);
99 
106  void loopThroughYears(uint firstYear, uint endYear, std::vector<Variable::State>& state);
107 
109  uint pNbYearsReallyPerformed;
111  uint pNbMaxPerformedYearsInParallel;
113  bool pYearByYear;
114 
116  annualCostsStatistics pAnnualStatistics;
117 
118  // Collecting durations inside the simulation
119  Benchmarking::DurationCollector& pDurationCollector;
120 
121  std::map<uint, std::pair<std::string, std::string>> yearSimulationBuffers_;
122  std::mutex buffersMutex_;
123 
124 public:
126  std::shared_ptr<Yuni::Job::QueueService> pQueueService = nullptr;
129 
130  std::reference_wrapper<ISimulationObserver> simulationObserver_;
131  void storeYearBuffers(uint year, std::string&& firstBuffer, std::string&& secondBuffer);
132  void aggregateAndWriteSimulationTables();
133 
134  OptimisationsSimulationTable& getSimulationTable(uint numSpace);
135 }; // class ISimulation
136 } // namespace Antares::Solver::Simulation
137 
138 #include "solver.hxx"
139 
140 #endif // __SOLVER_SIMULATION_SOLVER_H__
Definition: study.h:57
Definition: i_writer.h:32
The ISimulationObserver class is an interface for observing the simulation.
Definition: ISimulationObserver.h:36
const ::Settings & settings
The global settings.
Definition: solver.h:85
void writeResults(bool synthesis, uint year=0, uint numSpace=9999)
Export the results to disk.
Definition: solver.hxx:366
Antares::Solver::IResultWriter & pResultWriter
Result writer.
Definition: solver.h:128
ISimulation(Data::Study &study, const ::Settings &settings, Benchmarking::DurationCollector &duration_collector, IResultWriter &resultWriter, Simulation::ISimulationObserver &simulationObserver)
Constructor (with a given study)
Definition: solver.hxx:237
void run()
Run the simulation.
Definition: solver.hxx:283
Data::Study & study
Reference to the current study.
Definition: solver.h:83
std::shared_ptr< Yuni::Job::QueueService > pQueueService
The queue service that runs every set of parallel years.
Definition: solver.h:126
~ISimulation()
Destructor.
Definition: solver.hxx:278
Definition: solver.hxx:46
Definition: state.h:71
Definition: DurationCollector.h:36
Definition: OptimisationsSimulationTable.h:31