Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
area.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_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 <yuni/yuni.h>
30#include <yuni/core/noncopyable.h>
31#include <yuni/core/string.h>
32
33#include <antares/array/matrix.h>
34#include <antares/study/parameters/adq-patch-params.h>
35#include "antares/study/filter.h"
36#include "antares/study/parts/parts.h"
37
38#include "constants.h"
39#include "links.h"
40#include "ui.h"
41
42namespace Antares
43{
44namespace Data
45{
46struct CompareAreaName;
47
51class Area final: private Yuni::NonCopyable<Area>
52{
53public:
54 using NameSet = std::set<AreaName>;
55 using Set = std::set<Area*, CompareAreaName>;
56 using LinkMap = std::map<Area*, AreaLink::Set, CompareAreaName>;
57 using Map = std::map<AreaName, Area*>;
58 using Vector = std::vector<Area*>;
59 using VectorConst = std::vector<const Area*>;
60 using List = std::list<Area*>;
61 using ScratchMap = std::map<const Area*, AreaScratchpad&>;
63 using NameMapping = std::map<AreaName, AreaName>;
64
65public:
67
68
71 Area();
77 explicit Area(const AnyString& name);
84 Area(const AnyString& name, const AnyString& id);
88 ~Area();
89
91
92 // !\name isVisibleOnLayer
94
97 bool isVisibleOnLayer(const size_t& layerID) const
98 {
99 if (ui == nullptr)
100 {
101 return false;
102 }
103
104 std::vector<size_t>& layerList = ui->mapLayersVisibilityList;
105 std::vector<size_t>::iterator layerPosition = std::find(layerList.begin(),
106 layerList.end(),
107 layerID);
108 return layerPosition != layerList.end();
109 }
110
112
113
116 void clearAllLinks();
117
123 void detachAllLinks();
124
128 AreaLink* findLinkByID(const AreaName& id);
129 const AreaLink* findLinkByID(const AreaName& id) const;
130
134 void detachLinkFromID(const AreaName& id);
135
136 static void detachLink(const AreaLink* lnk);
137
141 void detachLinkFromItsPointer(const AreaLink* lnk);
143
144 void buildLinksIndexes();
148 void createMissingData();
149
154
160 void resizeAllTimeseriesNumbers(uint nbYears);
161
169 const AreaLink* findExistingLinkWith(const Area& with) const;
170
172
173
184 bool forceReload(bool reload = false) const;
185
189 void markAsModified() const;
190
192
193
198 bool thermalClustersMinStablePowerValidity(std::vector<YString>& output) const;
200
204 template<enum TimeSeriesType T>
205 XCast* xcastData();
206 template<enum TimeSeriesType T>
207 const XCast* xcastData() const;
208
209public:
211
212
213 AreaName name;
215 AreaName id;
217 uint index = (uint)(-1);
219 AdequacyPatch::AdequacyPatchMode adequacyPatchMode = AdequacyPatch::physicalAreaOutsideAdqPatch;
223
224
237 Matrix<> miscGen; // [fhhMax][HOURS_PER_YEAR]
239
241
242 Load::Container load;
244
246
247 Solar::Container solar;
249
251
252 PartHydro hydro;
254
256
257
260
262
263 PartThermal thermal;
265
267
268 PartRenewable renewable;
270
271 ShortTermStorage::STStorageInput shortTermStorage;
272
274
275
278
280
281
282 uint nodalOptimization = anoAll;
284
286
287
292
294
295
296 uint filterSynthesis = filterAll;
298 uint filterYearByYear = filterAll;
300
302
303
304 std::unique_ptr<AreaUI> ui;
306
308
309
312 mutable std::vector<AreaScratchpad> scratchpad;
314
316
317
323 mutable bool invalidateJIT = false;
325
326private:
327 void internalInitialize();
328 void createMissingTimeSeries();
329 void createMissingPrepros();
330
331}; // class Area
332
333bool saveAreaOptimisationIniFile(const Area& area, const Yuni::Clob& buffer);
334
335bool saveAreaAdequacyPatchIniFile(const Area& area, const Yuni::Clob& buffer);
336
365class AreaList final: public Yuni::NonCopyable<AreaList>
366{
367public:
369 using iterator = Area::Map::iterator;
371 using const_iterator = Area::Map::const_iterator;
373 using reverse_iterator = Area::Map::reverse_iterator;
375 using const_reverse_iterator = Area::Map::const_reverse_iterator;
377 using value_type = Area::Map::value_type;
378
379public:
381
382
385 explicit AreaList(Study& study);
387 ~AreaList();
389
391
392
395 template<class PredicateT>
396 void each(const PredicateT& predicate);
400 template<class PredicateT>
401 void each(const PredicateT& predicate) const;
402
403 iterator begin();
404 const_iterator begin() const;
405 const_iterator cbegin() const;
406
407 iterator end();
408 const_iterator end() const;
409 const_iterator cend() const;
410
411 reverse_iterator rbegin();
412 const_reverse_iterator rbegin() const;
413
414 reverse_iterator rend();
415 const_reverse_iterator rend() const;
416
418
419
426 void ensureDataIsInitialized(Parameters& params, bool loadOnlyNeeded);
428
430
431
437 bool loadFromFolder(const StudyLoadOptions& options);
438
448 bool loadListFromFile(const std::filesystem::path& filename);
449
456 bool saveToFolder(const AnyString& folder) const;
457
466 bool saveListToFile(const AnyString& filename) const;
467
483 void saveLinkListToBuffer(Yuni::Clob& buffer) const;
484
490 bool preloadAndMarkAsModifiedAllInvalidatedAreas(uint* invalidateCount = nullptr) const;
492
494
495
498 Area* add(Area* a);
499
503 Area* find(const AreaName& id);
507 const Area* find(const AreaName& id) const;
508
512 Area* findFromName(const AreaName& name);
513
514 Area* findFromPosition(const int x, const int y) const;
515
519 const Area* findFromName(const AreaName& name) const;
520
526 void resizeAllTimeseriesNumbers(uint n);
527
531 void clear();
532
534 bool empty() const;
535
542 bool forceReload(bool reload = false) const;
543
547 void markAsModified() const;
548
555 void rebuildIndexes();
556
564 bool remove(const AnyString& id);
565
577 bool renameArea(const AreaName& oldid, const AreaName& newName);
578
591 bool renameArea(const AreaName& oldid, const AreaName& newid, const AreaName& newName);
592
596 uint size() const;
598
600
601
607 AreaLink* findLink(const AreaName& area, const AreaName& with);
608 const AreaLink* findLink(const AreaName& area, const AreaName& with) const;
609
613 AreaLink* findLinkFromINIKey(const AnyString& key);
614
618 ThermalCluster* findClusterFromINIKey(const AnyString& key);
619
623 uint areaLinkCount() const;
625
627
628
632
644
646 Area::ScratchMap buildScratchMap(uint numspace);
647
651 void updateNameIDSet() const;
653
655
656
659 Area* operator[](uint i);
660 const Area* operator[](uint i) const;
662
663public:
665 std::vector<Area*> byIndex;
667 Area::Map areas;
668
670 // used by the copy/paste
671 mutable Area::NameSet nameidSet;
672
673private:
675 Study& pStudy;
676
677}; // class AreaList
678
679void AreaListDeleteLinkFromAreaPtr(AreaList* l, const Area* a);
680
691AreaLink* AreaAddLinkBetweenAreas(Area* area, Area* with, bool warning = true);
692
700bool AreaLinksLoadFromFolder(Study& s,
701 AreaList* l,
702 Area* area,
703 const std::filesystem::path& folder);
704
712bool AreaLinksSaveToFolder(const Area* area, const char* const folder);
713
714// Save a given area's interconnexions configuration file into a folder
715bool saveAreaLinksConfigurationFileToFolder(const Area* area, const char* const folder);
716
720int AreaLinkClear(AreaList* l, Area* area);
721
725void AreaLinkRemove(AreaLink* lnk);
726
734Area* AreaListLFind(AreaList* l, const char lname[]);
735
743Area* AreaListFindPtr(AreaList* l, const Area* ptr);
744
752Area* addAreaToListOfAreas(AreaList& list, const AnyString& name);
753
762Area* AreaListAddFromNames(AreaList& list, const AnyString& name, const AnyString& lname);
763
771AreaLink* AreaListAddLink(AreaList* l, const char area[], const char with[], bool warning = true);
772
773void AreaListClearAllLinks(AreaList* l);
774
778void AreaListEnsureDataLoadPrepro(AreaList* l);
779
783void AreaListEnsureDataSolarPrepro(AreaList* l);
784
788void AreaListEnsureDataWindPrepro(AreaList* l);
789
793void AreaListEnsureDataHydroTimeSeries(AreaList* l);
794
798void AreaListEnsureDataHydroPrepro(AreaList* l);
799
803void AreaListEnsureDataThermalPrepro(AreaList* l);
804
808inline bool CheckForbiddenCharacterInAreaName(const AnyString& name)
809{
810 return name.contains('*');
811}
812
813} // namespace Data
814} // namespace Antares
815
816#include "../load-options.h"
817#include "area.hxx"
818
819#endif // __ANTARES_LIBS_STUDY_AREAS_H__
A list of areas.
Definition area.h:366
bool remove(const AnyString &id)
Remove an area from its ID.
Definition list.cpp:1608
Area::Map::value_type value_type
Key-value type.
Definition area.h:377
void rebuildIndexes()
Rebuild the indexes for accessing areas.
Definition list.cpp:467
void saveLinkListToBuffer(Yuni::Clob &buffer) const
Write the list of all links into a file.
Definition list.cpp:601
bool saveToFolder(const AnyString &folder) const
Save all informations about areas into a folder (-> input/generalData)
Definition list.cpp:684
void removeSolarTimeseries()
Remove all solar timeseries.
Definition list.cpp:1693
bool preloadAndMarkAsModifiedAllInvalidatedAreas(uint *invalidateCount=nullptr) const
Preload all areas which have been invalidated.
Definition list.cpp:655
bool renameArea(const AreaName &oldid, const AreaName &newName)
Rename an area.
Definition list.cpp:1435
AreaLink * findLink(const AreaName &area, const AreaName &with)
Find an interconnection between two areas.
Definition list.cpp:425
Area::Map areas
All areas in the list.
Definition area.h:667
AreaLink * findLinkFromINIKey(const AnyString &key)
Try to find the link from a given INI key (<area1>%<area2>)
Definition list.cpp:1634
void markAsModified() const
Mark all data as modified.
Definition list.cpp:679
void clear()
Remove all elements in the container.
Definition list.cpp:453
bool loadFromFolder(const StudyLoadOptions &options)
Load all informations about areas from a folder (-> input/generalData)
Definition list.cpp:1155
Area::ScratchMap buildScratchMap(uint numspace)
create a map with the corresponding scratchpad for each area link to this numspace
Definition list.cpp:1715
void removeLoadTimeseries()
Remove all load timeseries.
Definition list.cpp:1683
bool forceReload(bool reload=false) const
Invalidate all areas.
Definition list.cpp:1549
Area::Map::const_reverse_iterator const_reverse_iterator
A const iterator.
Definition area.h:375
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:1672
Area * find(const AreaName &id)
Find an area from its unique string id.
Definition list.cpp:1262
Area::Map::reverse_iterator reverse_iterator
An iterator.
Definition area.h:373
void fixOrientationForAllInterconnections(BindingConstraintsRepository &bindingconstraints)
Fix all invalid orientations.
Definition list.cpp:1563
bool empty() const
Get if the container is empty.
Definition list.cpp:391
Area::NameSet nameidSet
Name set (must be updated by updateNameSet)
Definition area.h:671
uint areaLinkCount() const
Get the total number of interconnections between all areas.
Definition list.cpp:1415
bool loadListFromFile(const std::filesystem::path &filename)
Fill the list of areas from an input file.
Definition list.cpp:541
Area::Map::const_iterator const_iterator
A const iterator.
Definition area.h:371
AreaList(Study &study)
Default constructor.
Definition list.cpp:381
void removeThermalTimeseries()
Remove all thermal timeseries.
Definition list.cpp:1703
void resizeAllTimeseriesNumbers(uint n)
Resize all matrices dedicated to the sampled timeseries numbers.
Definition list.cpp:1556
void ensureDataIsInitialized(Parameters &params, bool loadOnlyNeeded)
Ensure data for time series/prepro are initalized if they should be.
Definition list.cpp:1116
Area * findFromName(const AreaName &name)
Find an area from its name.
Definition list.cpp:1274
std::vector< Area * > byIndex
All areas by their index.
Definition area.h:665
void removeWindTimeseries()
Remove all wind timeseries.
Definition list.cpp:1698
void removeHydroTimeseries()
Remove all hydro timeseries.
Definition list.cpp:1688
~AreaList()
Destructor.
Definition list.cpp:386
bool saveListToFile(const AnyString &filename) const
Write the list of areas into a file.
Definition list.cpp:615
Area::Map::iterator iterator
An iterator.
Definition area.h:369
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:483
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:1651
Definition for a single area.
Definition area.h:52
bool isVisibleOnLayer(const size_t &layerID) const
check visibility on layer
Definition area.h:97
uint filterYearByYear
Print results for the area in the year-by-year mode.
Definition area.h:298
AreaLink::Map links
All connections with this area.
Definition area.h:276
double spreadUnsuppliedEnergyCost
Spread for the unsupplied energy cost.
Definition area.h:288
uint filterSynthesis
Print results for the area in the simulation synthesis.
Definition area.h:296
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:213
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:217
std::unique_ptr< AreaUI > ui
Information for the UI.
Definition area.h:304
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:1422
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:237
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:63
void resizeAllTimeseriesNumbers(uint nbYears)
Resize all matrices dedicated to the sampled timeseries numbers.
Definition area.cpp:237
~Area()
Destructor.
Definition area.cpp:70
std::vector< AreaScratchpad > scratchpad
Scratchpad used temporary calculations (solver only)
Definition area.h:312
void clearAllLinks()
Destroy all links.
Definition area.cpp:81
AdequacyPatch::AdequacyPatchMode adequacyPatchMode
Use adequacy patch for this area.
Definition area.h:219
bool invalidateJIT
Invalidate (JIT)
Definition area.h:323
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:258
uint nodalOptimization
Nodal optimization (see AreaNodalOptimization)
Definition area.h:282
double spreadSpilledEnergyCost
Spread for the spilled energy cost.
Definition area.h:290
Matrix reserves
Reserves.
Definition area.h:230
AreaName id
Name of the area in lowercase format.
Definition area.h:215
Definition BindingConstraintsRepository.h:36
Definition container.h:38
General data for a study.
Definition parameters.h:51
Hydro for a single area.
Definition container.h:91
Definition container.h:35
Definition container.h:33
Definition container.h:35
Definition load-options.h:36
Definition study.h:61
A single thermal cluster.
Definition cluster.h:78
Definition container.h:35
Definition xcast.h:35
A n-by-n matrix.
Definition jit.h:30