Antares Simulator
Power System Simulator
application.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 #pragma once
22 
23 #include <yuni/core/string.h>
24 
25 #include <antares/benchmarking/DurationCollector.h>
26 #include <antares/benchmarking/timer.h>
27 #include <antares/study/load-options.h>
28 #include <antares/study/study.h>
29 #include <antares/writer/i_writer.h>
30 #include "antares/infoCollection/StudyInfoCollector.h"
31 #include "antares/solver/misc/options.h"
32 #include "antares/solver/simulation/ISimulationObserver.h"
33 
34 namespace Antares::Solver
35 {
36 class Application final: public Yuni::IEventObserver<Application, Yuni::Policy::SingleThreaded>
37 {
38 public:
40 
41 
44  Application();
48  ~Application() override;
50 
51  Application(const Application&) = delete;
52 
53  Application& operator=(const Application&) = delete;
54 
60  void prepare(int argc, const char* argv[]);
61 
67  void execute();
68 
72  void resetProcessPriority() const;
73 
74  void writeExectutionInfo();
75 
80  std::unique_ptr<Data::Study> acquireStudy()
81  {
82  return std::move(pStudy);
83  }
84 
85 private:
86  enum class LogType
87  {
88  Warning,
89  Error
90  };
91 
95  void resetLogFilename() const;
96 
100  void readDataForTheStudy(Antares::Data::StudyLoadOptions& options);
101 
102  void onLogMessage(int level, const std::string& message);
103 
105  Settings pSettings;
107  std::unique_ptr<Antares::Data::Study> pStudy;
109  Antares::Data::Parameters* pParameters = nullptr;
111  uint pErrorCount = 0;
113  uint pWarningCount = 0;
114 
115  int pArgc = 0;
116  const char** pArgv = nullptr;
117 
118  // Benchmarking
119  Benchmarking::DurationCollector pDurationCollector;
120  Benchmarking::OptimizationInfo pOptimizationInfo;
121 
122  std::shared_ptr<Yuni::Job::QueueService> ioQueueService;
123  IResultWriter::Ptr resultWriter = nullptr;
124  std::vector<std::pair<LogType, std::string>> messagesStack;
125 
126  void prepareWriter(const Antares::Data::Study& study,
127  Benchmarking::DurationCollector& duration_collector);
128 
129  void writeComment(Data::Study& study);
130  void readStudy_makeChecks_and_printThings(Data::StudyLoadOptions& options);
131  // Return false if the user requested the version ,available solvers, etc, true otherwise
132  bool handleOptions(const Data::StudyLoadOptions& options);
133  void LogMessageStack(std::vector<std::pair<LogType, std::string>>& stack);
134  // Return false if the user requested help, true otherwise
135  bool parseCommandLine(Data::StudyLoadOptions& options);
136  void postParametersChecks() const;
137 }; // class Application
138 
139 } // namespace Antares::Solver
General data for a study.
Definition: parameters.h:51
Definition: load-options.h:34
Definition: study.h:57
Definition: application.h:37
std::unique_ptr< Data::Study > acquireStudy()
/!\ Acquire the study. Leave Application object in an invalid state.
Definition: application.h:80
Application()
Default Constructor.
Definition: application.cpp:64
void resetProcessPriority() const
Reset the process priority (Windows only)
Definition: process-priority.cpp:38
void prepare(int argc, const char *argv[])
Initialize data before launching the simulation.
Definition: application.cpp:333
~Application() override
Destructor.
Definition: application.cpp:551
void execute()
Execute the simulation.
Definition: application.cpp:415
Definition: DurationCollector.h:36
Command line settings for launching the simulation.
Definition: options.h:36
Definition: StudyInfoCollector.h:61