Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
progression.h
1/*
2** Copyright 2007-2024, 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 __ANTARES_LIBS_SOLVER_SIMULATION_PROGRESSION_H__
22#define __ANTARES_LIBS_SOLVER_SIMULATION_PROGRESSION_H__
23
24#include <atomic>
25#include <list>
26#include <map>
27#include <mutex>
28#include <vector>
29
30#include <yuni/core/singleton.h>
31#include <yuni/io/file.h>
32#include <yuni/thread/timer.h>
33
34#include <antares/writer/i_writer.h>
35
36#include "../fwd.h"
37
38namespace Antares
39{
40namespace Solver
41{
45class Progression final
46{
47public:
48 enum Section
49 {
50 sectYear = 0,
51 sectOutput,
52 sectTSGLoad,
53 sectTSGSolar,
54 sectTSGWind,
55 sectTSGHydro,
56 sectTSGThermal,
57 sectImportTS,
58 sectMax
59 };
60
61 enum
62 {
63 npos = (uint)-1,
64 };
65
66 const char* SectionToCStr(Section section);
67
68private:
69 class Part final
70 {
71 public:
72 using MapPerSection = std::map<Section, Part>;
73 using Map = std::map<uint, MapPerSection>;
74 // using ListRef = Yuni::LinkedList<Part*>;
75 using ListRef = std::list<Part*>;
76
77 public:
79 unsigned maxTickCount;
81 std::atomic<unsigned> tickCount;
83 unsigned lastTickCount;
84 // Caption to use when displaying logs
85 // Example: 'year: 10000, task: thermal'
86 Yuni::CString<40, false> caption;
87 };
88
89public:
90 class Task final
91 {
92 public:
93 Task(const Antares::Data::Study& study, Section section);
94 Task(const Antares::Data::Study& study, uint year, Section section);
95
96 ~Task()
97 {
98 pProgression.end(pPart);
99 }
100
101 Task& operator++()
102 {
103 ++pPart.tickCount;
104 return *this;
105 }
106
107 Task& operator+=(unsigned value)
108 {
109 pPart.tickCount += value;
110 return *this;
111 }
112
113 private:
114 Progression& pProgression;
115 Part& pPart;
116 };
117
118public:
120
121
124 Progression();
128 ~Progression();
130
141 void add(uint year, Section section, unsigned nbTicks);
142
143 void add(Section section, int nbTicks);
144
145 bool saveToFile(const Yuni::String& filename, IResultWriter& writer);
146
147 void setNumberOfParallelYears(uint nb);
148
150
151
154 void start();
155
159 void stop();
161
162protected:
163 Part& begin(uint year, Section section);
164 void end(Part& part);
165
166private:
167 class Meter final: public Yuni::Thread::Timer
168 {
169 public:
170 Meter();
171
172 virtual ~Meter() = default;
173
177 void taskCount(uint n);
178
179 protected:
180 virtual bool onInterval(uint) override;
181
182 public:
183 Progression::Part::Map parts;
184 Part::ListRef inUse;
185 std::mutex mutex;
186 uint nbParallelYears;
187
188 std::vector<Yuni::CString<256, false>> logsContainer;
189
190 }; // class Meter
191
192private:
194 Meter pProgressMeter;
196 // This variable has no need to be thread-safe because initialized at the very beginning
197 bool pStarted;
198 // Friend
199 friend class Task;
200
201}; // class Progression
202
203} // namespace Solver
204} // namespace Antares
205
206#include "progression.hxx"
207
208#endif // __ANTARES_LIBS_SOLVER_SIMULATION_PROGRESSION_H__
Definition study.h:61
Definition i_writer.h:34
Definition progression.h:91
Progress meter about any operation performed on the attached study.
Definition progression.h:46
void start()
Start the thread dedicated to the progress notification.
Definition progression.cpp:192
void add(uint year, Section section, unsigned nbTicks)
Declare a new part of the progression.
Definition progression.cpp:45
~Progression()
Destructor.
Definition progression.cpp:157
void stop()
Stop the thread dedicated to the progress notification.
Definition progression.cpp:199