DPsim
Attributes.cpp
1 /* Copyright 2017-2022 Institute for Automation of Complex Power Systems,
2  * EONERC, RWTH Aachen University
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7  *********************************************************************************/
8 
9 #include <DPsim.h>
10 #include <dpsim-models/CSVReader.h>
11 #include <dpsim-models/IdentifiedObject.h>
12 #include <dpsim/RealTimeSimulation.h>
13 #include <dpsim/Simulation.h>
14 #include <dpsim/pybind/BaseComponents.h>
15 #include <dpsim/pybind/Utils.h>
16 
17 PYBIND11_DECLARE_HOLDER_TYPE(T, CPS::AttributePointer<T>);
18 
19 namespace py = pybind11;
20 using namespace pybind11::literals;
21 
22 void addAttributes(py::module_ m) {
23 
24  py::class_<CPS::AttributeBase, CPS::AttributePointer<CPS::AttributeBase>>(
25  m, "Attribute")
26  .def("__str__", &CPS::AttributeBase::toString)
27  .def("__repr__", &CPS::AttributeBase::toString);
28 
29  // Class bindings for the most common attribute types. Allows for the usage of the `get` and `set` methods in Python.
30 
31  py::class_<CPS::Attribute<CPS::Real>,
33  CPS::AttributeBase>(m, "AttributeReal")
34  .def("get", &CPS::Attribute<CPS::Real>::get)
35  .def("set", &CPS::Attribute<CPS::Real>::set)
36  .def("derive_scaled", &CPS::Attribute<CPS::Real>::deriveScaled);
37 
38  py::class_<CPS::AttributeStatic<CPS::Real>,
40  CPS::Attribute<CPS::Real>>(m, "AttributeRealStat");
41  py::class_<CPS::AttributeDynamic<CPS::Real>,
43  CPS::Attribute<CPS::Real>>(m, "AttributeRealDyn")
44  .def("set_reference", &CPS::AttributeDynamic<CPS::Real>::setReference);
45 
46  py::class_<CPS::Attribute<CPS::Complex>,
48  CPS::AttributeBase>(m, "AttributeComplex")
51  .def("derive_real", &CPS::Attribute<CPS::Complex>::deriveReal)
52  .def("derive_imag", &CPS::Attribute<CPS::Complex>::deriveImag)
53  .def("derive_mag", &CPS::Attribute<CPS::Complex>::deriveMag)
54  .def("derive_phase", &CPS::Attribute<CPS::Complex>::derivePhase)
55  .def("derive_scaled", &CPS::Attribute<CPS::Complex>::deriveScaled);
56 
57  py::class_<CPS::AttributeStatic<CPS::Complex>,
59  CPS::Attribute<CPS::Complex>>(m, "AttributeComplexStat");
60  py::class_<CPS::AttributeDynamic<CPS::Complex>,
62  CPS::Attribute<CPS::Complex>>(m, "AttributeComplexDyn")
64 
65  py::class_<CPS::Attribute<CPS::Matrix>,
67  CPS::AttributeBase>(m, "AttributeMatrix")
70  .def("derive_coeff",
72 
73  py::class_<CPS::AttributeStatic<CPS::Matrix>,
75  CPS::Attribute<CPS::Matrix>>(m, "AttributeMatrixStat");
76  py::class_<CPS::AttributeDynamic<CPS::Matrix>,
78  CPS::Attribute<CPS::Matrix>>(m, "AttributeMatrixDyn")
80 
81  py::class_<CPS::Attribute<CPS::MatrixComp>,
83  CPS::AttributeBase>(m, "AttributeMatrixComp")
86  .def("derive_coeff",
88 
89  py::class_<CPS::AttributeStatic<CPS::MatrixComp>,
91  CPS::Attribute<CPS::MatrixComp>>(m, "AttributeMatrixCompStat");
92  py::class_<CPS::AttributeDynamic<CPS::MatrixComp>,
94  CPS::Attribute<CPS::MatrixComp>>(m, "AttributeMatrixCompDyn")
95  .def("set_reference",
97 
98  py::class_<CPS::Attribute<CPS::String>,
100  CPS::AttributeBase>(m, "AttributeString")
102  .def("set", &CPS::Attribute<CPS::String>::set);
103 
104  py::class_<CPS::AttributeStatic<CPS::String>,
106  CPS::Attribute<CPS::String>>(m, "AttributeStringStat");
107  py::class_<CPS::AttributeDynamic<CPS::String>,
109  CPS::Attribute<CPS::String>>(m, "AttributeStringDyn")
110  .def("set_reference", &CPS::AttributeDynamic<CPS::String>::setReference);
111 }
virtual String toString()=0