Antares Simulator
Power System Simulator
area.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_AREAS_H__
22 #define __ANTARES_LIBS_STUDY_AREAS_H__
23 
24 #include <filesystem>
25 #include <set>
26 #include <stdlib.h>
27 #include <vector>
28 //
29 #include "antares/study/parts/parts.h"
30 //
31 #include <yuni/yuni.h>
32 #include <yuni/core/noncopyable.h>
33 #include <yuni/core/string.h>
34 
35 #include <antares/array/matrix.h>
36 #include <antares/study/parameters/adq-patch-params.h>
37 #include "antares/study/filter.h"
38 
39 #include "constants.h"
40 #include "links.h"
41 #include "ui.h"
42 
43 namespace Antares::Data
44 {
45 struct CompareAreaName;
46 
50 class Area final: private Yuni::NonCopyable<Area>
51 {
52 public:
53  using NameSet = std::set<AreaName>;
54  using Set = std::set<Area*, CompareAreaName>;
55  using LinkMap = std::map<Area*, AreaLink::Set, CompareAreaName>;
56  using Map = std::map<AreaName, Area*>;
57  using Vector = std::vector<Area*>;
58  using VectorConst = std::vector<const Area*>;
59  using List = std::list<Area*>;
60  using ScratchMap = std::map<const Area*, AreaScratchpad&>;
62  using NameMapping = std::map<AreaName, AreaName>;
63 
64 public:
66 
67 
70  Area();
76  explicit Area(const AnyString& name);
83  Area(const AnyString& name, const AnyString& id);
87  ~Area();
88 
90 
91  // !\name isVisibleOnLayer
93 
96  bool isVisibleOnLayer(const size_t& layerID) const
97  {
98  if (ui == nullptr)
99  {
100  return false;
101  }
102 
103  std::vector<size_t>& layerList = ui->mapLayersVisibilityList;
104  std::vector<size_t>::iterator layerPosition = std::find(layerList.begin(),
105  layerList.end(),
106  layerID);
107  return layerPosition != layerList.end();
108  }
109 
111 
112 
115  void clearAllLinks();
116 
122  void detachAllLinks();
123 
127  AreaLink* findLinkByID(const AreaName& id);
128  const AreaLink* findLinkByID(const AreaName& id) const;
129 
133  void detachLinkFromID(const AreaName& id);
134 
135  static void detachLink(const AreaLink* lnk);
136 
140  void detachLinkFromItsPointer(const AreaLink* lnk);
142 
143  void buildLinksIndexes();
147  void createMissingData();
148 
152  void resetToDefaultValues();
153 
159  void resizeAllTimeseriesNumbers(uint nbYears);
160 
168  const AreaLink* findExistingLinkWith(const Area& with) const;
169 
171 
172 
183  bool forceReload(bool reload = false) const;
184 
188  void markAsModified() const;
189 
191 
192 
197  bool thermalClustersMinStablePowerValidity(std::vector<YString>& output) const;
199 
203  template<enum TimeSeriesType T>
204  XCast* xcastData();
205  template<enum TimeSeriesType T>
206  const XCast* xcastData() const;
207 
208 public:
210 
211  AreaName name;
214  AreaName id;
216  uint index = (uint)(-1);
218  AdequacyPatch::AdequacyPatchMode adequacyPatchMode = AdequacyPatch::physicalAreaOutsideAdqPatch;
222 
223 
236  Matrix<> miscGen; // [fhhMax][HOURS_PER_YEAR]
238 
240 
241  Load::Container load;
243 
245 
246  Solar::Container solar;
248 
250 
251  PartHydro hydro;
253 
255 
259 
261 
262  PartThermal thermal;
264 
266 
267  PartRenewable renewable;
269 
270  ShortTermStorage::STStorageInput shortTermStorage;
271 
273 
277 
279 
280  uint nodalOptimization = anoAll;
283 
285 
286  double spreadUnsuppliedEnergyCost = 0.;
291 
293 
294  uint filterSynthesis = filterAll;
297  uint filterYearByYear = filterAll;
299 
301 
302  std::unique_ptr<AreaUI> ui;
305 
307 
308 
311  mutable std::vector<AreaScratchpad> scratchpad;
313 
315 
316 
322  mutable bool invalidateJIT = false;
324 
325 private:
326  void internalInitialize();
327  void createMissingTimeSeries();
328  void createMissingPrepros();
329 
330 }; // class Area
331 
332 bool saveAreaOptimisationIniFile(const Area& area, const Yuni::Clob& buffer);
333 
334 bool saveAreaAdequacyPatchIniFile(const Area& area, const Yuni::Clob& buffer);
335 
364 class AreaList final: public Yuni::NonCopyable<AreaList>
365 {
366 public:
368  using iterator = Area::Map::iterator;
370  using const_iterator = Area::Map::const_iterator;
372  using reverse_iterator = Area::Map::reverse_iterator;
374  using const_reverse_iterator = Area::Map::const_reverse_iterator;
376  using value_type = Area::Map::value_type;
377 
378 public:
380 
381 
384  explicit AreaList(Study& study);
386  ~AreaList();
388 
390 
391 
394  template<class PredicateT>
395  void each(const PredicateT& predicate);
399  template<class PredicateT>
400  void each(const PredicateT& predicate) const;
401 
402  iterator begin();
403  const_iterator begin() const;
404  const_iterator cbegin() const;
405 
406  iterator end();
407  const_iterator end() const;
408  const_iterator cend() const;
409 
410  reverse_iterator rbegin();
411  const_reverse_iterator rbegin() const;
412 
413  reverse_iterator rend();
414  const_reverse_iterator rend() const;
415 
417 
418 
425  void ensureDataIsInitialized(Parameters& params, bool loadOnlyNeeded);
427 
429 
430 
436  bool loadFromFolder(const StudyLoadOptions& options);
437 
447  bool loadListFromFile(const std::filesystem::path& filename);
448 
449 #ifdef BUILD_UI
456  bool saveToFolder(const AnyString& folder) const;
457 
466  bool saveListToFile(const AnyString& filename) const;
467 #endif
468 
484  void saveLinkListToBuffer(Yuni::Clob& buffer) const;
485 
491  bool preloadAndMarkAsModifiedAllInvalidatedAreas(uint* invalidateCount = nullptr) const;
493 
495 
496 
499  Area* add(Area* a);
500 
504  Area* find(const AreaName& id);
508  const Area* find(const AreaName& id) const;
509 
513  Area* findFromName(const AreaName& name);
514 
515  Area* findFromPosition(const int x, const int y) const;
516 
520  const Area* findFromName(const AreaName& name) const;
521 
527  void resizeAllTimeseriesNumbers(uint n);
528 
532  void clear();
533 
535  bool empty() const;
536 
543  bool forceReload(bool reload = false) const;
544 
548  void markAsModified() const;
549 
556  void rebuildIndexes();
557 
565  bool remove(const AnyString& id);
566 
578  bool renameArea(const AreaName& oldid, const AreaName& newName);
579 
592  bool renameArea(const AreaName& oldid, const AreaName& newid, const AreaName& newName);
593 
597  uint size() const;
599 
601 
602 
608  AreaLink* findLink(const AreaName& area, const AreaName& with);
609  const AreaLink* findLink(const AreaName& area, const AreaName& with) const;
610 
614  AreaLink* findLinkFromINIKey(const AnyString& key);
615 
619  ThermalCluster* findClusterFromINIKey(const AnyString& key);
620 
624  uint areaLinkCount() const;
626 
628 
629 
633 
635  void removeLoadTimeseries();
637  void removeHydroTimeseries();
639  void removeSolarTimeseries();
641  void removeWindTimeseries();
645 
647  Area::ScratchMap buildScratchMap(uint numspace);
648 
652  void updateNameIDSet() const;
654 
656 
657 
660  Area* operator[](uint i);
661  const Area* operator[](uint i) const;
663 
664 public:
666  std::vector<Area*> byIndex;
668  Area::Map areas;
669 
671  // used by the copy/paste
672  mutable Area::NameSet nameidSet;
673 
674 private:
676  Study& pStudy;
677 
678 }; // class AreaList
679 
680 void AreaListDeleteLinkFromAreaPtr(AreaList* l, const Area* a);
681 
692 AreaLink* AreaAddLinkBetweenAreas(Area* area, Area* with, bool warning = true);
693 
701 bool AreaLinksLoadFromFolder(Study& s,
702  AreaList* l,
703  Area* area,
704  const std::filesystem::path& folder);
705 
706 #ifdef BUILD_UI
714 bool AreaLinksSaveToFolder(const Area* area, const char* const folder);
715 
716 // Save a given area's interconnexions configuration file into a folder
717 bool saveAreaLinksConfigurationFileToFolder(const Area* area, const char* const folder);
718 #endif
719 
723 int AreaLinkClear(AreaList* l, Area* area);
724 
728 void AreaLinkRemove(AreaLink* lnk);
729 
737 Area* AreaListLFind(AreaList* l, const char lname[]);
738 
746 Area* AreaListFindPtr(AreaList* l, const Area* ptr);
747 
755 Area* addAreaToListOfAreas(AreaList& list, const AnyString& name);
756 
765 Area* AreaListAddFromNames(AreaList& list, const AnyString& name, const AnyString& lname);
766 
774 AreaLink* AreaListAddLink(AreaList* l, const char area[], const char with[], bool warning = true);
775 
776 void AreaListClearAllLinks(AreaList* l);
777 
781 void AreaListEnsureDataLoadPrepro(AreaList* l);
782 
786 void AreaListEnsureDataSolarPrepro(AreaList* l);
787 
791 void AreaListEnsureDataWindPrepro(AreaList* l);
792 
796 void AreaListEnsureDataHydroTimeSeries(AreaList* l);
797 
801 void AreaListEnsureDataHydroPrepro(AreaList* l);
802 
806 void AreaListEnsureDataThermalPrepro(AreaList* l);
807 
811 inline bool CheckForbiddenCharacterInAreaName(const AnyString& name)
812 {
813  return name.contains('*');
814 }
815 
816 } // namespace Antares::Data
817 
818 #include "../load-options.h"
819 #include "area.hxx"
820 
821 #endif // __ANTARES_LIBS_STUDY_AREAS_H__
A list of areas.
Definition: area.h:365
bool remove(const AnyString &id)
Remove an area from its ID.
Definition: list.cpp:1627
Area::Map::value_type value_type
Key-value type.
Definition: area.h:376
void rebuildIndexes()
Rebuild the indexes for accessing areas.
Definition: list.cpp:470
void saveLinkListToBuffer(Yuni::Clob &buffer) const
Write the list of all links into a file.
Definition: list.cpp:600
void removeSolarTimeseries()
Remove all solar timeseries.
Definition: list.cpp:1712
bool preloadAndMarkAsModifiedAllInvalidatedAreas(uint *invalidateCount=nullptr) const
Preload all areas which have been invalidated.
Definition: list.cpp:656
bool renameArea(const AreaName &oldid, const AreaName &newName)
Rename an area.
Definition: list.cpp:1458
AreaLink * findLink(const AreaName &area, const AreaName &with)
Find an interconnection between two areas.
Definition: list.cpp:428
Area::Map areas
All areas in the list.
Definition: area.h:668
AreaLink * findLinkFromINIKey(const AnyString &key)
Try to find the link from a given INI key (<area1>%<area2>)
Definition: list.cpp:1653
void markAsModified() const
Mark all data as modified.
Definition: list.cpp:680
void clear()
Remove all elements in the container.
Definition: list.cpp:456
bool loadFromFolder(const StudyLoadOptions &options)
Load all informations about areas from a folder (-> input/generalData)
Definition: list.cpp:1178
Area::ScratchMap buildScratchMap(uint numspace)
create a map with the corresponding scratchpad for each area link to this numspace
Definition: list.cpp:1734
void removeLoadTimeseries()
Remove all load timeseries.
Definition: list.cpp:1702
bool forceReload(bool reload=false) const
Invalidate all areas.
Definition: list.cpp:1568
Area::Map::const_reverse_iterator const_reverse_iterator
A const iterator.
Definition: area.h:374
Area * operator[](uint i)
Get an area from its index.
Definition: area.hxx:36
void updateNameIDSet() const
Update the name id set.
Definition: list.cpp:1691
Area * find(const AreaName &id)
Find an area from its unique string id.
Definition: list.cpp:1285
Area::Map::reverse_iterator reverse_iterator
An iterator.
Definition: area.h:372
void fixOrientationForAllInterconnections(BindingConstraintsRepository &bindingconstraints)
Fix all invalid orientations.
Definition: list.cpp:1582
bool empty() const
Get if the container is empty.
Definition: list.cpp:394
Area::NameSet nameidSet
Name set (must be updated by updateNameSet)
Definition: area.h:672
uint areaLinkCount() const
Get the total number of interconnections between all areas.
Definition: list.cpp:1438
bool loadListFromFile(const std::filesystem::path &filename)
Fill the list of areas from an input file.
Definition: list.cpp:540
Area::Map::const_iterator const_iterator
A const iterator.
Definition: area.h:370
AreaList(Study &study)
Default constructor.
Definition: list.cpp:384
void removeThermalTimeseries()
Remove all thermal timeseries.
Definition: list.cpp:1722
void resizeAllTimeseriesNumbers(uint n)
Resize all matrices dedicated to the sampled timeseries numbers.
Definition: list.cpp:1575
void ensureDataIsInitialized(Parameters &params, bool loadOnlyNeeded)
Ensure data for time series/prepro are initalized if they should be.
Definition: list.cpp:1139
Area * findFromName(const AreaName &name)
Find an area from its name.
Definition: list.cpp:1297
std::vector< Area * > byIndex
All areas by their index.
Definition: area.h:666
void removeWindTimeseries()
Remove all wind timeseries.
Definition: list.cpp:1717
void removeHydroTimeseries()
Remove all hydro timeseries.
Definition: list.cpp:1707
~AreaList()
Destructor.
Definition: list.cpp:389
Area::Map::iterator iterator
An iterator.
Definition: area.h:368
uint size() const
Get the total number of areas.
Definition: area.hxx:108
Area * add(Area *a)
Add an area in the container.
Definition: list.cpp:486
void each(const PredicateT &predicate)
Iterate through all areas.
Definition: area.hxx:87
ThermalCluster * findClusterFromINIKey(const AnyString &key)
Try to find the cluster from a given INI key (<area>.<cluster>)
Definition: list.cpp:1670
Definition for a single area.
Definition: area.h:51
bool isVisibleOnLayer(const size_t &layerID) const
check visibility on layer
Definition: area.h:96
uint filterYearByYear
Print results for the area in the year-by-year mode.
Definition: area.h:297
AreaLink::Map links
All connections with this area.
Definition: area.h:275
double spreadUnsuppliedEnergyCost
Spread for the unsupplied energy cost.
Definition: area.h:287
uint filterSynthesis
Print results for the area in the simulation synthesis.
Definition: area.h:295
void createMissingData()
Ensure all data are created.
Definition: area.cpp:167
bool forceReload(bool reload=false) const
Load all data not already loaded.
Definition: area.cpp:271
AreaName name
Name of the area.
Definition: area.h:212
bool thermalClustersMinStablePowerValidity(std::vector< YString > &output) const
Check the validity of min stable power for all thermal clusters.
Definition: area.cpp:254
void markAsModified() const
Mark all areas as modified.
Definition: area.cpp:315
uint index
Index of the area - only valid when already added to an area list.
Definition: area.h:216
std::unique_ptr< AreaUI > ui
Information for the UI.
Definition: area.h:303
void resetToDefaultValues()
Reset all values to their default one.
Definition: area.cpp:202
void detachLinkFromItsPointer(const AreaLink *lnk)
Remove a link from its raw pointer.
Definition: list.cpp:1445
AreaLink * findExistingLinkWith(Area &with)
Check if a link with another area is already established.
Definition: area.cpp:106
Area()
Default constructor.
Definition: area.cpp:47
Matrix miscGen
Misc Gen.
Definition: area.h:236
void detachAllLinks()
Properly detach all links attached to an area.
Definition: area.cpp:98
std::map< AreaName, AreaName > NameMapping
Name mapping -> must be replaced by AreaNameMapping.
Definition: area.h:62
void resizeAllTimeseriesNumbers(uint nbYears)
Resize all matrices dedicated to the sampled timeseries numbers.
Definition: area.cpp:236
~Area()
Destructor.
Definition: area.cpp:70
std::vector< AreaScratchpad > scratchpad
Scratchpad used temporary calculations (solver only)
Definition: area.h:311
void clearAllLinks()
Destroy all links.
Definition: area.cpp:81
AdequacyPatch::AdequacyPatchMode adequacyPatchMode
Use adequacy patch for this area.
Definition: area.h:218
bool invalidateJIT
Invalidate (JIT)
Definition: area.h:322
XCast * xcastData()
Get the XCast data according a given time-series type.
Definition: area.hxx:49
AreaLink * findLinkByID(const AreaName &id)
Try to find the attached link from another area id.
Definition: area.cpp:367
void detachLinkFromID(const AreaName &id)
Detach any link connected from this area to the given area.
Definition: area.cpp:349
Wind::Container wind
Wind time-series and Wind prepro data.
Definition: area.h:257
uint nodalOptimization
Nodal optimization (see AreaNodalOptimization)
Definition: area.h:281
double spreadSpilledEnergyCost
Spread for the spilled energy cost.
Definition: area.h:289
Matrix reserves
Reserves.
Definition: area.h:229
AreaName id
Name of the area in lowercase format.
Definition: area.h:214
Definition: BindingConstraintsRepository.h:36
Definition: container.h:34
General data for a study.
Definition: parameters.h:51
Hydro for a single area.
Definition: container.h:86
Definition: container.h:33
Definition: container.h:31
Definition: container.h:31
Definition: load-options.h:34
Definition: study.h:57
A single thermal cluster.
Definition: cluster.h:76
Definition: container.h:31
Definition: xcast.h:35
A n-by-n matrix.
Definition: matrix.h:44