Antares Simulator
Power System Simulator
rules.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 __LIBS_STUDY_SCENARIO_BUILDER_RULES_H__
22 #define __LIBS_STUDY_SCENARIO_BUILDER_RULES_H__
23 
24 #include <map>
25 #include <memory>
26 
27 #include <yuni/yuni.h>
28 #include <yuni/core/string.h>
29 
30 #include "../fwd.h"
31 #include "BindingConstraintsTSNumbersData.h"
32 #include "HydroTSNumberData.h"
33 #include "LoadTSNumberData.h"
34 #include "NTCTSNumberData.h"
35 #include "RenewableTSNumberData.h"
36 #include "ShortTermAdditionalConstraintsTSNumberData.h"
37 #include "ShortTermInflowsTSNumberData.h"
38 #include "TSnumberData.h"
39 #include "ThermalTSNumberData.h"
40 #include "WindTSNumberData.h"
41 #include "hydroLevelsData.h"
42 #include "solarTSNumberData.h"
43 
44 namespace Antares::Data::ScenarioBuilder
45 {
49 class Rules final: private Yuni::NonCopyable<Rules>
50 {
51 public:
53  using Ptr = std::shared_ptr<Rules>;
55  using Map = std::map<RulesScenarioName, Ptr>;
57  using MappingID = std::map<int, Ptr>;
58 
60 
61 
66  explicit Rules(Study& study);
68  ~Rules() = default;
70 
72 
73 
76  bool reset();
77 
81  bool readLine(const AreaName::Vector& splitKey, const String& value, bool updaterMode = false);
82 
83 #ifdef BUILD_UI
87  void saveToINIFile(Yuni::IO::File::Stream& file) const;
89 #endif
90 
92  uint areaCount() const;
93 
95  const RulesScenarioName& name() const;
96  void setName(RulesScenarioName name);
97 
103  bool apply();
104 
105  // When current rule is the active one, sends warnings for disabled clusters.
106  void sendWarningsForDisabledClusters();
107 
116 
118  std::vector<thermalTSNumberData> thermal;
120  std::vector<renewableTSNumberData> renewable;
121 
123  hydroLevelsData hydroInitialLevels = {"hl,", initLevelApply};
125  hydroLevelsData hydroFinalLevels = {"hfl,", finalLevelApply};
126 
127  // Links NTC
128  std::vector<ntcTSNumberData> linksNTC;
129 
130  BindingConstraintsTSNumberData binding_constraints;
131 
132  std::vector<ShortTermInflowsTSNumberData> shortTermStorageInflows;
133  std::vector<ShortTermAdditionalConstraintsTSNumberData> shortTermStorageAdditionalConstraints;
134 
135 private:
136  // Member methods
137  bool readThermalCluster(const AreaName::Vector& instrs, const String& value, bool updaterMode);
138  bool readRenewableCluster(const AreaName::Vector& instrs,
139  const String& value,
140  bool updaterMode);
141  bool readLoad(const AreaName::Vector& instrs, const String& value, bool updaterMode);
142  bool readWind(const AreaName::Vector& instrs, const String& value, bool updaterMode);
143  bool readHydro(const AreaName::Vector& instrs, const String& value, bool updaterMode);
144  bool readSolar(const AreaName::Vector& instrs, const String& value, bool updaterMode);
145  bool readInitialHydroLevels(const AreaName::Vector& instrs,
146  const String& value,
147  bool updaterMode);
148  bool readFinalHydroLevels(const AreaName::Vector& instrs,
149  const String& value,
150  bool updaterMode);
151  bool readLink(const AreaName::Vector& instrs, const String& value, bool updaterMode);
152  bool readBindingConstraints(const AreaName::Vector& splitKey, const String& value);
153 
154  bool readShortTermStorageInflows(const AreaName::Vector& splitKey,
155  const String& value,
156  bool updaterMode);
157 
158  bool readShortTermStorageAdditionalConstraints(const AreaName::Vector& splitKey,
159  const String& value,
160  bool updaterMode);
161 
162  Data::Area* getArea(const AreaName& areaname, bool updaterMode);
163  Data::AreaLink* getLink(const AreaName& fromAreaName,
164  const AreaName& toAreaName,
165  bool updaterMode);
166  bool checkGroupExists(const std::string& groupName) const;
167 
168  // Member data
169  Study& study_;
171  uint pAreaCount;
173  RulesScenarioName pName;
174  // Disabled clusters when current rule is active (useful for sending warnings)
175  std::map<std::string, std::vector<uint>> disabledClustersOnRuleActive;
176 
177 }; // class Rules
178 
179 } // namespace Antares::Data::ScenarioBuilder
180 
181 #include "rules.hxx"
182 
183 #endif // __LIBS_STUDY_SCENARIO_BUILDER_RULES_H__
Definition for a single area.
Definition: area.h:51
Definition: BindingConstraintsTSNumbersData.h:32
Rules for TS numbers, for all years and a single timeseries.
Definition: rules.h:50
std::vector< renewableTSNumberData > renewable
Renewable (array [0..pAreaCount - 1])
Definition: rules.h:120
std::vector< thermalTSNumberData > thermal
Thermal (array [0..pAreaCount - 1])
Definition: rules.h:118
Rules(Study &study)
Default constructor.
Definition: rules.cpp:51
loadTSNumberData load
Load.
Definition: rules.h:109
hydroTSNumberData hydro
Hydro.
Definition: rules.h:113
bool reset()
Initialize data from the study.
Definition: rules.cpp:89
std::map< RulesScenarioName, Ptr > Map
Map.
Definition: rules.h:55
bool apply()
Apply the changes to the timeseries number matrices.
Definition: rules.cpp:537
bool readLine(const AreaName::Vector &splitKey, const String &value, bool updaterMode=false)
Load information from a single line (extracted from an INI file)
Definition: rules.cpp:472
solarTSNumberData solar
Solar.
Definition: rules.h:111
hydroLevelsData hydroFinalLevels
hydro final levels
Definition: rules.h:125
hydroLevelsData hydroInitialLevels
hydro initial levels
Definition: rules.h:123
const RulesScenarioName & name() const
Name of the rules set.
Definition: rules.hxx:31
std::shared_ptr< Rules > Ptr
Smart pointer.
Definition: rules.h:53
std::map< int, Ptr > MappingID
Map ID.
Definition: rules.h:57
uint areaCount() const
Get the number of areas.
Definition: rules.hxx:26
windTSNumberData wind
Wind.
Definition: rules.h:115
Rules for hydro levels, for all years and areas.
Definition: hydroLevelsData.h:34
Definition: HydroTSNumberData.h:29
Definition: LoadTSNumberData.h:29
Definition: solarTSNumberData.h:33
Definition: WindTSNumberData.h:29
Definition: study.h:57