Antares Simulator
Power System Simulator
study.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 __ANTARES_LIBS_STUDY_STUDY_H__
22 #define __ANTARES_LIBS_STUDY_STUDY_H__
23 
24 #include <memory>
25 
26 #include <yuni/yuni.h>
27 #include <yuni/core/noncopyable.h>
28 #include <yuni/job/queue/service.h>
29 
30 #include <antares/correlation/correlation.h>
31 #include <antares/date/date.h>
32 #include <antares/solver/modeler/data.h>
33 #include <antares/study/runtime/runtime.h>
34 #include <antares/writer/i_writer.h>
35 #include "antares/study/binding_constraint/BindingConstraintGroupRepository.h"
36 #include "antares/study/binding_constraint/BindingConstraintsRepository.h"
37 
38 #include "area/store-timeseries-numbers.h"
39 #include "binding_constraint/BindingConstraint.h"
40 #include "fwd.h"
41 #include "header.h"
42 #include "layerdata.h"
43 #include "parameters.h"
44 #include "progression/progression.h"
45 #include "sets.h"
46 #include "simulation.h"
47 
48 namespace Antares::Data
49 {
54 class UIRuntimeInfo;
55 
56 class Study: public Yuni::NonCopyable<Study>, public LayerData
57 {
58 public:
59  using Ptr = std::shared_ptr<Study>;
61  using Set = std::set<Ptr>;
63  using List = std::list<Ptr>;
64 
67 
69  using FileExtension = std::string;
70 
79  static bool TitleFromStudyFolder(const AnyString& folder, YString& out, bool warnings = false);
80 
87  static bool IsRootStudy(const AnyString& folder);
88 
96  static bool IsRootStudy(const AnyString& folder, YString& buffer);
97 
110  static bool IsInsideStudyFolder(const AnyString& path, YString& location, YString& title);
111 
113 
114 
120  Study(bool forTheSolver = false);
122  virtual ~Study();
124 
126 
127 
130  void createAsNew();
131 
138  void relocate(const std::filesystem::path& newFolder);
139 
146  bool loadFromFolder(const std::string& path, const StudyLoadOptions& options);
147 
151  void clear();
152 
156  void reloadCorrelation();
157 
161  bool reloadXCastData();
162 
169  bool saveToFolder(const AnyString& newfolder);
170 
176  bool resetFolderIcon() const;
178 
180 
181 
187  bool forceReload(bool reload = false) const;
188 
192  void markAsModified() const;
194 
196 
197 
204  bool modifyAreaNameIfAlreadyTaken(AreaName& out, const AreaName& basename);
205 
214  // TODO no need for the 2nd argument, remove it after the GUI has been removed, keeping the
215  // default value
216  Area* areaAdd(const AreaName& name, bool update = false);
217 
218 #ifdef BUILD_UI
226  bool areaRename(Area* area, AreaName newName);
227 
235  bool areaDelete(Area* area);
236 
246  void areaDelete(Area::Vector& area);
248 
250 
251 
259  bool linkDelete(AreaLink* lnk);
261 
263 
264 
270  bool clusterRename(Cluster* cluster, std::string newName);
272 
274 
275 
278  bool readonly() const;
279 
281 #endif
282 
284 
285 
290  void resizeAllTimeseriesNumbers(uint n);
291 
298  template<TimeSeriesType TimeSeriesT>
300  {
301  storeTimeseriesNumbers<TimeSeriesT>(resultWriter, areas);
302  }
303 
305 
307 
308 
315 
319  bool initializeRuntimeInfos();
320 
324  void prepareOutput();
325 
326  void saveAboutTheStudy(Solver::IResultWriter& resultWriter);
327 
331  void initializeProgressMeter(bool tsGeneratorOnly);
332 
334 
336 
337 
340  template<TimeSeriesType TS>
342  {
343  }
344 
359 
361 
362 
369  void scenarioRulesCreate();
370 
374  void scenarioRulesDestroy();
376 
378 
379 
387  unsigned getNumberOfCoresPerMode(unsigned nbLogicalCores, int ncMode);
388 
395  void getNumberOfCores(const bool forceParallel, const uint nbYearsParallelForced);
396 
402 
404 
405 
414  bool checkForFilenameLimits(bool output, const YString& chfolder = nullptr) const;
416 
418 
419 
425 
427 
428 
431  void importLogsToOutputFolder(Solver::IResultWriter& resultWriter) const;
433 
435 
441 
444 
446 
447  std::filesystem::path folder;
450  std::filesystem::path folderInput;
452  std::filesystem::path folderOutput;
454  std::filesystem::path folderSettings;
456 
458 
459  // TODO VP: remove with GUI
462 
463  int64_t pStartTime;
464  // Used in GUI and solver
465  // ----------------------
466  // Maximum number of years in a set of parallel years.
467  // It is a possible reduction of the raw number of cores set by user (simulation cores level).
468  // This raw number of cores is possibly reduced by the smallest TS refresh span or the total
469  // number of MC years. In GUI, used for RAM estimation only. In solver, it is the max number of
470  // years (actually run, not skipped) a set of parallel years can contain.
471  uint maxNbYearsInParallel = 1;
472 
473  // Used in GUI only.
474  // ----------------
475  // Allows storing the maximum number of years in a set of parallel years.
476  // Useful to estimate the RAM when the run window's parallel mode is chosen.
477  uint maxNbYearsInParallel_save = 0;
478 
479  // Used in GUI and solver.
480  // ----------------------
481  // Raw numbers of cores (== nb of MC years run in parallel) based on the number
482  // of cores level (see advanced parameters).
483  uint nbYearsParallelRaw = 1;
484 
485  // Used in GUI only.
486  // -----------------
487  // Minimum number of years in a set of parallel years.
488  // It is a possible reduction of the raw number of cores set by user (simulation cores level).
489  // This raw number of cores can be reduced :
490  // - by the smallest TS refresh span
491  // - by the smallest interval between TS refreshes
492  // - In the Run window, if either Default or swap support mode is enabled, then parallel
493  // computation is disabled, and the number of cores is 1
494  // Useful to populate the run window's simulation cores field.
495  uint minNbYearsInParallel = 0;
496 
497  // Used in GUI only.
498  // ----------------
499  // Allows storing the minimum number of years in a set of parallel years.
500  // Useful to populate the run window's simulation cores field.
501  uint minNbYearsInParallel_save = 0;
502 
505 
520 
522 
523  AreaList areas;
526 
528 
531  BindingConstraintGroupRepository bindingConstraintsGroups;
533 
535 
545 
547 
551 
553 
554  std::unique_ptr<ScenarioBuilder::Sets> scenarioRules;
557 
558  TimeSeries::TS scenarioInitialHydroLevels;
559  // Hydro Final Levels
560  TimeSeries::TS scenarioFinalHydroLevels;
567 
568  // Antares::Solver::Variable::State* state;
569 
573  UIRuntimeInfo* uiinfo = nullptr;
574 
582 
585 
593  mutable YString buffer;
597  mutable YString bufferLoadingTS;
599 
601  std::shared_ptr<Yuni::Job::QueueService> pQueueService;
602 
604 
605 
609  void* cacheTSGenerator[timeSeriesCount];
611 
618  const bool usedByTheSolver;
619 
620  Antares::Modeler::Data* getModelerData() const
621  {
622  return modelerInput_.get();
623  }
624 
625 protected:
627 
628  bool internalLoadFromFolder(const std::filesystem::path& path, const StudyLoadOptions& options);
631  bool internalLoadHeader(const std::filesystem::path& folder);
635  virtual bool internalLoadBindingConstraints(const StudyLoadOptions& options);
637  bool internalLoadSets();
639 
640  bool internalLoadIni(const std::filesystem::path& path, const StudyLoadOptions& options);
641 
643  void loadModelerComponents();
644  void checkModelerDataCompatibility() const;
645 
646  void parameterFiller(const StudyLoadOptions& options);
647 
649 
650  void reduceMemoryUsage();
653 
654 private:
655  std::unique_ptr<Modeler::Data> modelerInput_;
656 }; // class Study
657 
661 extern YString StudyIconFile;
662 
663 std::filesystem::path StudyCreateOutputPath(SimulationMode mode,
664  ResultFormat fmt,
665  const std::filesystem::path& folder,
666  const std::string& label,
667  const std::tm& startTime);
668 } // namespace Antares::Data
669 
670 #endif /* __ANTARES_LIBS_STUDY_STUDY_H__ */
A list of areas.
Definition: area.h:365
Definition for a single area.
Definition: area.h:51
Definition: BindingConstraintGroupRepository.h:41
Definition: BindingConstraintsRepository.h:36
Definition: cluster.h:46
Definition: correlation.h:35
Antares Study.
Definition: layerdata.h:37
General data for a study.
Definition: parameters.h:51
Definition: sets.h:40
Set of settings for a simulation.
Definition: simulation.h:38
Header of a study.
Definition: header.h:46
Definition: load-options.h:34
Runtime informations.
Definition: runtime.h:69
Definition: study.h:57
bool saveToFolder(const AnyString &newfolder)
Save the study into a folder.
bool resetFolderIcon() const
Reset the folder icon (Windows only)
std::filesystem::path folder
The source folder of the study.
Definition: study.h:448
bool reloadXCastData()
Reload all XCast Data.
Definition: load.cpp:350
Parameters parameters
Parameters.
Definition: study.h:504
void scenarioRulesLoadIfNotAvailable()
Load the data related to the scenario builder if not available.
Definition: study.extra.cpp:50
bool internalLoadCorrelationMatrices(const StudyLoadOptions &options)
Load all correlation matrices.
Definition: load.cpp:273
Date::Calendar calendar
Calendar.
Definition: study.h:512
static bool IsRootStudy(const AnyString &folder, YString &buffer)
Get if a folder if a study.
BindingConstraintsRepository bindingConstraints
Binding constraints.
Definition: study.h:530
void scenarioRulesCreate()
Re-Initialize/Re-Load the scenario builder data.
Definition: study.extra.cpp:35
void prepareOutput()
Prepare the output where the results of the simulation will be written.
Definition: study.cpp:373
bool internalLoadFromFolder(const std::filesystem::path &path, const StudyLoadOptions &options)
Load a study from a folder.
Definition: load.cpp:166
bool internalLoadSets()
Load all set of areas and links.
Definition: load.cpp:318
bool initializeRuntimeInfos()
Initialize runtime informations required by the solver.
Definition: study.cpp:260
virtual bool internalLoadBindingConstraints(const StudyLoadOptions &options)
Load all binding constraints.
Definition: load.cpp:305
unsigned getNumberOfCoresPerMode(unsigned nbLogicalCores, int ncMode)
Computes a raw number of cores table.
Definition: study.cpp:191
void removeTimeseriesIfTSGeneratorEnabled()
Remove timeseries if ts-generator is enabled.
Definition: study.cpp:1208
std::string FileExtension
Extension filename.
Definition: study.h:69
void checkModelerDataCompatibility() const
Definition: load.cpp:254
void importLogsToOutputFolder(Solver::IResultWriter &resultWriter) const
Copy the log file from the 'logs' folder to the current output folder.
Definition: importlogs.cpp:34
void relocate(const std::filesystem::path &newFolder)
Relocate the study into a new folder.
Definition: study.cpp:986
std::filesystem::path folderOutput
The output folder.
Definition: study.h:452
void createAsNew()
Create a clean study.
Definition: study.cpp:135
YString buffer
A buffer for temporary operations on filename.
Definition: study.h:593
Solver::Progression progression
Progression about the current action performed on the study.
Definition: study.h:584
UIRuntimeInfo * uiinfo
Specific data related to the User Interface.
Definition: study.h:573
void ensureDataAreLoadedForAllBindingConstraints()
Load all matrices within the binding constraints if not already done.
Definition: study.cpp:852
FileExtension inputExtension
The file extension for file within the input ('txt' or 'csv')
Definition: study.h:581
bool modifyAreaNameIfAlreadyTaken(AreaName &out, const AreaName &basename)
Try to find a name for a new area.
Definition: study.extra.cpp:60
bool loadFromFolder(const std::string &path, const StudyLoadOptions &options)
Load a study from a folder.
Definition: load.cpp:52
void loadModelerComponents()
Load extra modeler components for hybrid studies and verify compatibility.
Definition: load.cpp:226
static bool TitleFromStudyFolder(const AnyString &folder, YString &out, bool warnings=false)
Extract the title of a study.
Definition: study.extra.cpp:86
SimulationComments simulationComments
The current Simulation.
Definition: study.h:461
void storeTimeSeriesNumbers(Solver::IResultWriter &resultWriter) const
Store the timeseries numbers.
Definition: study.h:299
bool checkForFilenameLimits(bool output, const YString &chfolder=nullptr) const
Check for filename limits restriction on some platforms.
Definition: study.cpp:1002
void markAsModified() const
Mark the whole study as modified.
Definition: study.cpp:972
StudyHeader header
Header (general information about the study)
Definition: study.h:443
bool importTimeseriesIntoInput()
Import all time-series into the input folder.
Definition: study.importprepro.cpp:34
void destroyTSGeneratorData()
Destroy all data of the TS generator '@TS'.
Definition: study.h:341
static bool IsInsideStudyFolder(const AnyString &path, YString &location, YString &title)
Check if a path is within a study folder.
Definition: study.extra.cpp:114
Date::Calendar calendarOutput
Calendar output.
Definition: study.h:518
void getNumberOfCores(const bool forceParallel, const uint nbYearsParallelForced)
Computes number of cores.
Definition: study.cpp:220
bool forceReload(bool reload=false) const
Invalidate the whole study.
Definition: study.cpp:954
Correlation preproSolarCorrelation
Correlation matrix for the solar time series generated by the prepro.
Definition: study.h:539
std::unique_ptr< ScenarioBuilder::Sets > scenarioRules
Rules for building scenarios (can be null)
Definition: study.h:555
SetsOfAreas setsOfAreas
Sets of areas.
Definition: study.h:549
std::filesystem::path folderSettings
The settings folder.
Definition: study.h:454
void * cacheTSGenerator[timeSeriesCount]
Time-series generators used by the solver.
Definition: study.h:609
Correlation preproLoadCorrelation
Correlation matrix for the load time series generated by the prepro.
Definition: study.h:537
std::shared_ptr< Yuni::Job::QueueService > pQueueService
The queue service that runs every set of parallel years.
Definition: study.h:601
Study(bool forTheSolver=false)
Default Constructor.
Definition: study.cpp:70
std::set< Ptr > Set
Set of studies.
Definition: study.h:61
StudyRuntimeInfos runtime
Runtime informations.
Definition: study.h:566
void clear()
Clear all ressources held by the study.
Definition: study.cpp:107
Area * areaAdd(const AreaName &name, bool update=false)
Add an area and make all required initialization.
Definition: study.cpp:464
static bool IsRootStudy(const AnyString &folder)
Get if a folder if a study.
Definition: study.extra.cpp:100
Matrix ::BufferType dataBuffer
A buffer for temporary operations on large amount of data.
Definition: study.h:595
Correlation preproHydroCorrelation
Correlation matrix for the hydro time series generated by the prepro.
Definition: study.h:543
AreaList areas
All available areas.
Definition: study.h:524
void scenarioRulesDestroy()
Release the scenario builder.
Definition: study.extra.cpp:45
YString bufferLoadingTS
A buffer used when loading time-series for dealing with filenames (prepro/series only)
Definition: study.h:597
void performTransformationsBeforeLaunchingSimulation()
Perform several modifications required when launching a simulation (like computing the DSM values)
Definition: study.cpp:265
void reduceMemoryUsage()
Release all unnecessary buffers.
Definition: study.cpp:184
std::filesystem::path folderInput
The input folder.
Definition: study.h:450
virtual ~Study()
Destructor.
Definition: study.cpp:102
void reloadCorrelation()
Reload all correlation.
Definition: load.cpp:342
const bool usedByTheSolver
A non-zero value when the study will be used by the solver.
Definition: study.h:618
void initializeProgressMeter(bool tsGeneratorOnly)
Initialize the progress meter.
Definition: study.cpp:888
void computePThetaInfForThermalClusters() const
Check validity between Min Stable Power and capacity modulation for each thermal cluster in the all a...
Definition: study.cpp:1235
void resizeAllTimeseriesNumbers(uint n)
Resize all matrices dedicated to the sampled timeseries numbers.
Definition: study.cpp:994
Correlation preproWindCorrelation
Correlation matrix for the wind time series generated by the prepro.
Definition: study.h:541
std::list< Ptr > List
List of studies.
Definition: study.h:63
bool internalLoadHeader(const std::filesystem::path &folder)
Load the study header.
Definition: load.cpp:33
Definition: ui-runtimeinfos.h:36
Definition: date.h:180
A n-by-n matrix.
Definition: matrix.h:44
Yuni::Clob BufferType
A buffer, for large amount of data.
Definition: matrix.h:65
Definition: i_writer.h:32
Progress meter about any operation performed on the attached study.
Definition: progression.h:44
Definition: data.h:38