Antares Simulator
Power System Simulator
component.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 #pragma once
22 
23 #include <map>
24 #include <optional>
25 
26 #include <antares/expressions/nodes/PortFieldNode.h>
27 #include "antares/study/system-model/connection.h"
28 
29 #include "model.h"
30 #include "variabilityType.h"
31 
32 namespace Antares::ModelerStudy::SystemModel
33 {
34 
35 // this struct contains more or less the same infos as the one in system.h
37 {
38  std::string id;
40  std::string value;
41 };
42 
47 class ComponentData final
48 {
49 public:
50  std::string id;
51  const Model* model = nullptr;
52  std::map<std::string, ParameterTypeAndValue> parameter_values;
53  std::string scenario_group_id;
54  unsigned index = 0;
55 
56  void reset()
57  {
58  id.clear();
59  model = nullptr;
60  parameter_values.clear();
61  scenario_group_id.clear();
62  }
63 };
64 
68 class Component final
69 {
70 public:
71  // Only allowing one private constructor (see below) to forbid empty Components
72  Component() = delete;
73 
74  const std::string& Id() const
75  {
76  return data_.id;
77  }
78 
79  const Model* getModel() const
80  {
81  return data_.model;
82  }
83 
84  const std::map<std::string, ParameterTypeAndValue>& getParameterValues() const
85  {
86  return data_.parameter_values;
87  }
88 
89  std::string getParameterValue(const std::string& parameter_id) const
90  {
91  if (!data_.parameter_values.contains(parameter_id))
92  {
93  throw std::invalid_argument("Parameter '" + parameter_id + "' not found in component '"
94  + data_.id + "'");
95  }
96  return data_.parameter_values.at(parameter_id).value;
97  }
98 
99  std::string getScenarioGroupId() const
100  {
101  return data_.scenario_group_id;
102  }
103 
104  void addComponentConnection(const std::string localPortId, ConnectionEnd&& connection);
105  std::vector<ConnectionEnd> componentConnectionsViaPort(const std::string& portId) const;
106 
107  Expressions::Nodes::Node* nodeAtPortField(const std::string& portId,
108  const std::string& fieldId) const;
109 
110  const Expression& expressionAtPortField(const std::string& portId,
111  const std::string& fieldId) const;
112 
113  void addAreaConnection(const std::string& localPortId, const std::string& areaId);
114 
115  std::optional<std::string> areaConnectedToPort(const std::string& portId) const;
116 
117  const std::map<std::string, std::string>& portToAreaConnections() const;
118 
119  unsigned int Index() const
120  {
121  return data_.index;
122  }
123 
124 private:
125  // Only ComponentBuilder is allowed to build Component instances
126  friend class ComponentBuilder;
127  explicit Component(const ComponentData& component_data);
128  std::map<std::string, std::vector<ConnectionEnd>> componentConnectionEnds_;
129  std::map<std::string, std::string> portToAreaConnections_;
130  ComponentData data_;
131 };
132 
133 class ComponentBuilder final
134 {
135 public:
136  ComponentBuilder& withId(std::string_view id);
137  ComponentBuilder& withModel(const Model* model);
138  ComponentBuilder& withIndex(unsigned int index);
140  std::map<std::string, ParameterTypeAndValue> parameter_values);
141  ComponentBuilder& withScenarioGroupId(const std::string& scenario_group_id);
142  Component build();
143 
144 private:
145  ComponentData data_;
146 };
147 
148 } // namespace Antares::ModelerStudy::SystemModel
Base class for nodes in a syntax tree.
Definition: Node.h:30
ComponentBuilder & withScenarioGroupId(const std::string &scenario_group_id)
Sets the ID of the scenario group to which the component belongs.
Definition: component.cpp:236
ComponentBuilder & withModel(const Model *model)
Sets the model of the component.
Definition: component.cpp:204
Component build()
Builds and returns the Component object.
Definition: component.cpp:247
ComponentBuilder & withId(std::string_view id)
Sets the ID of the component.
Definition: component.cpp:192
ComponentBuilder & withParameterValues(std::map< std::string, ParameterTypeAndValue > parameter_values)
Sets the parameter values of the component. The parameters included should be all of the model's para...
Definition: component.cpp:223
VariabilityType
Represents the time and scenario variation of a value.
Definition: variabilityType.h:29