Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
component.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#pragma once
22
23#include <map>
24
25#include <antares/expressions/visitors/EvaluationContext.h>
26
27#include "model.h"
28
29namespace Antares::Study::SystemModel
30{
31
37{
38public:
39 std::string id;
40 const Model* model = nullptr;
41 std::map<std::string, Expressions::Visitors::ParameterTypeAndValue> parameter_values;
42 std::string scenario_group_id;
43
44 void reset()
45 {
46 id.clear();
47 model = nullptr;
48 parameter_values.clear();
49 scenario_group_id.clear();
50 }
51};
52
57{
58public:
59 // Only allowing one private constructor (see below) to forbid empty Components
60 Component() = delete;
61
62 const std::string& Id() const
63 {
64 return data_.id;
65 }
66
67 const Model* getModel() const
68 {
69 return data_.model;
70 }
71
72 const std::map<std::string, Expressions::Visitors::ParameterTypeAndValue>& getParameterValues()
73 const
74 {
75 return data_.parameter_values;
76 }
77
78 std::string getParameterValue(const std::string& parameter_id) const
79 {
80 if (!data_.parameter_values.contains(parameter_id))
81 {
82 throw std::invalid_argument("Parameter '" + parameter_id + "' not found in component '"
83 + data_.id + "'");
84 }
85 return data_.parameter_values.at(parameter_id).value;
86 }
87
88 std::string getScenarioGroupId() const
89 {
90 return data_.scenario_group_id;
91 }
92
93private:
94 // Only ComponentBuilder is allowed to build Component instances
95 friend class ComponentBuilder;
96 explicit Component(const ComponentData& component_data);
97 ComponentData data_;
98};
99
101{
102public:
103 ComponentBuilder& withId(std::string_view id);
104 ComponentBuilder& withModel(const Model* model);
106 std::map<std::string, Expressions::Visitors::ParameterTypeAndValue> parameter_values);
107 ComponentBuilder& withScenarioGroupId(const std::string& scenario_group_id);
109
110private:
111 ComponentData data_;
112};
113
114} // namespace Antares::Study::SystemModel
ComponentBuilder & withId(std::string_view id)
Sets the ID of the component.
Definition component.cpp:73
ComponentBuilder & withModel(const Model *model)
Sets the model of the component.
Definition component.cpp:85
ComponentBuilder & withParameterValues(std::map< std::string, Expressions::Visitors::ParameterTypeAndValue > parameter_values)
Sets the parameter values of the component. The parameters included should be all of the model's para...
Definition component.cpp:98
ComponentBuilder & withScenarioGroupId(const std::string &scenario_group_id)
Sets the ID of the scenario group to which the component belongs.
Definition component.cpp:111
Component build()
Builds and returns the Component object.
Definition component.cpp:122