DPsim
Loading...
Searching...
No Matches
EMTComponents.cpp
1/* Copyright 2017-2021 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/EMTComponents.h>
15#include <dpsim/pybind/Utils.h>
16
17#ifdef WITH_JSON
18#include <nlohmann/json.hpp>
19using json = nlohmann::json;
20#endif
21
22namespace py = pybind11;
23using namespace pybind11::literals;
24
25void addEMTComponents(py::module_ mEMT) {
26 py::class_<CPS::EMT::SimNode, std::shared_ptr<CPS::EMT::SimNode>,
27 CPS::TopologicalNode>(mEMT, "SimNode", py::module_local())
28 .def(py::init<std::string>())
29 .def(py::init<std::string, CPS::PhaseType>())
30 .def(py::init<std::string, CPS::PhaseType,
31 const std::vector<CPS::Complex>>())
32 .def("set_initial_voltage",
33 py::overload_cast<CPS::MatrixComp>(
34 &CPS::EMT::SimNode::setInitialVoltage, py::const_))
35 .def("set_initial_voltage",
36 py::overload_cast<CPS::Complex>(
37 &CPS::EMT::SimNode::setInitialVoltage, py::const_))
38 .def("set_initial_voltage",
39 py::overload_cast<CPS::Complex, int>(
40 &CPS::EMT::SimNode::setInitialVoltage, py::const_))
41 .def_readonly_static("gnd", &CPS::EMT::SimNode::GND);
42
43 py::module mEMTPh1 = mEMT.def_submodule(
44 "ph1", "single phase electromagnetic-transient models");
45 addEMTPh1Components(mEMTPh1);
46 py::module mEMTPh3 =
47 mEMT.def_submodule("ph3", "three phase electromagnetic-transient models");
48 addEMTPh3Components(mEMTPh3);
49}
50
51void addEMTPh1Components(py::module_ mEMTPh1) {
53 std::shared_ptr<CPS::EMT::Ph1::CurrentSource>,
54 CPS::SimPowerComp<CPS::Real>>(mEMTPh1, "CurrentSource",
55 py::multiple_inheritance())
56 .def(py::init<std::string>())
57 .def(py::init<std::string, CPS::Logger::Level>())
58 .def("set_parameters", &CPS::EMT::Ph1::CurrentSource::setParameters,
59 "I_ref"_a, "f_src"_a = -1)
61 .def_property("I_ref", createAttributeGetter<CPS::Complex>("I_ref"),
62 createAttributeSetter<CPS::Complex>("I_ref"))
63 .def_property("f_src", createAttributeGetter<CPS::Real>("f_src"),
64 createAttributeSetter<CPS::Real>("f_src"));
65
67 std::shared_ptr<CPS::EMT::Ph1::VoltageSource>,
68 CPS::SimPowerComp<CPS::Real>>(mEMTPh1, "VoltageSource",
69 py::multiple_inheritance())
70 .def(py::init<std::string>())
71 .def(py::init<std::string, CPS::Logger::Level>())
72 .def("set_parameters", &CPS::EMT::Ph1::VoltageSource::setParameters,
73 "V_ref"_a, "f_src"_a = -1)
75 .def_property("V_ref", createAttributeGetter<CPS::Complex>("V_ref"),
76 createAttributeSetter<CPS::Complex>("V_ref"))
77 .def_property("f_src", createAttributeGetter<CPS::Real>("f_src"),
78 createAttributeSetter<CPS::Real>("f_src"));
79
80 py::class_<CPS::EMT::Ph1::Resistor, std::shared_ptr<CPS::EMT::Ph1::Resistor>,
81 CPS::SimPowerComp<CPS::Real>>(mEMTPh1, "Resistor",
82 py::multiple_inheritance())
83 .def(py::init<std::string>())
84 .def(py::init<std::string, CPS::Logger::Level>())
85 .def("set_parameters", &CPS::EMT::Ph1::Resistor::setParameters, "R"_a)
86 .def("connect", &CPS::EMT::Ph1::Resistor::connect)
87 .def_property("R", createAttributeGetter<CPS::Real>("R"),
88 createAttributeSetter<CPS::Real>("R"));
89
90 py::class_<CPS::EMT::Ph1::Capacitor,
91 std::shared_ptr<CPS::EMT::Ph1::Capacitor>,
92 CPS::SimPowerComp<CPS::Real>>(mEMTPh1, "Capacitor",
93 py::multiple_inheritance())
94 .def(py::init<std::string>())
95 .def(py::init<std::string, CPS::Logger::Level>())
96 .def("set_parameters", &CPS::EMT::Ph1::Capacitor::setParameters, "C"_a)
97 .def("connect", &CPS::EMT::Ph1::Capacitor::connect)
98 .def_property("C", createAttributeGetter<CPS::Real>("C"),
99 createAttributeSetter<CPS::Real>("C"));
100
101 py::class_<CPS::EMT::Ph1::Inductor, std::shared_ptr<CPS::EMT::Ph1::Inductor>,
102 CPS::SimPowerComp<CPS::Real>>(mEMTPh1, "Inductor",
103 py::multiple_inheritance())
104 .def(py::init<std::string>())
105 .def(py::init<std::string, CPS::Logger::Level>())
106 .def("set_parameters", &CPS::EMT::Ph1::Inductor::setParameters, "L"_a)
107 .def("connect", &CPS::EMT::Ph1::Inductor::connect)
108 .def_property("L", createAttributeGetter<CPS::Real>("L"),
109 createAttributeSetter<CPS::Real>("L"));
110
111 py::class_<CPS::EMT::Ph1::Switch, std::shared_ptr<CPS::EMT::Ph1::Switch>,
113 mEMTPh1, "Switch", py::multiple_inheritance())
114 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
115 "loglevel"_a = CPS::Logger::Level::off)
116 .def("set_parameters", &CPS::EMT::Ph1::Switch::setParameters,
117 "open_resistance"_a, "closed_resistance"_a,
118 "closed"_a = false) // cppcheck-suppress assignBoolToPointer
119 .def("open", &CPS::EMT::Ph1::Switch::open)
120 .def("close", &CPS::EMT::Ph1::Switch::close)
121 .def("connect", &CPS::EMT::Ph1::Switch::connect);
122
124 std::shared_ptr<CPS::EMT::Ph1::SSN::Full_Serial_RLC>,
125 CPS::SimPowerComp<CPS::Real>>(mEMTPh1, "Full_Serial_RLC",
126 py::multiple_inheritance())
127 .def(py::init<std::string>())
128 .def(py::init<std::string, CPS::Logger::Level>())
129 .def("set_parameters",
130 &CPS::EMT::Ph1::SSN::Full_Serial_RLC::setParameters, "R"_a, "L"_a,
131 "C"_a)
133 .def_property("R", createAttributeGetter<CPS::Real>("R"),
134 createAttributeSetter<CPS::Real>("R"))
135 .def_property("L", createAttributeGetter<CPS::Real>("L"),
136 createAttributeSetter<CPS::Real>("L"))
137 .def_property("C", createAttributeGetter<CPS::Real>("C"),
138 createAttributeSetter<CPS::Real>("C"));
139
140 py::class_<CPS::EMT::Ph1::SSNTypeI2T,
141 std::shared_ptr<CPS::EMT::Ph1::SSNTypeI2T>,
142 CPS::SimPowerComp<CPS::Real>>(mEMTPh1, "SSNTypeI2T",
143 py::multiple_inheritance())
144 .def(py::init<std::string>())
145 .def(py::init<std::string, CPS::Logger::Level>())
146 .def("set_parameters", &CPS::EMT::Ph1::SSNTypeI2T::setParameters, "A"_a,
147 "B"_a, "C"_a, "D"_a)
148 .def("manual_init", &CPS::EMT::Ph1::SSNTypeI2T::manualInit,
149 "initialState"_a, "initialInput"_a, "initialOldInput"_a,
150 "initCurr"_a, "initVol"_a)
151 .def("connect", &CPS::EMT::Ph1::SSNTypeI2T::connect)
152 .def_property("mA", createAttributeGetter<CPS::Matrix>("mA"),
153 createAttributeSetter<CPS::Matrix>("mA"))
154 .def_property("mB", createAttributeGetter<CPS::Matrix>("mB"),
155 createAttributeSetter<CPS::Matrix>("mB"))
156 .def_property("mC", createAttributeGetter<CPS::Matrix>("mC"),
157 createAttributeSetter<CPS::Matrix>("mC"))
158 .def_property("mD", createAttributeGetter<CPS::Matrix>("mD"),
159 createAttributeSetter<CPS::Matrix>("mD"))
160 .def_property("mdA", createAttributeGetter<CPS::Matrix>("mdA"),
161 createAttributeSetter<CPS::Matrix>("mdA"))
162 .def_property("mdB", createAttributeGetter<CPS::Matrix>("mdB"),
163 createAttributeSetter<CPS::Matrix>("mdB"))
164 .def_property("mdC", createAttributeGetter<CPS::Matrix>("mdC"),
165 createAttributeSetter<CPS::Matrix>("mdC"));
166
167 py::class_<CPS::EMT::Ph1::SSNTypeV2T,
168 std::shared_ptr<CPS::EMT::Ph1::SSNTypeV2T>,
169 CPS::SimPowerComp<CPS::Real>>(mEMTPh1, "SSNTypeV2T",
170 py::multiple_inheritance())
171 .def(py::init<std::string>())
172 .def(py::init<std::string, CPS::Logger::Level>())
173 .def("set_parameters", &CPS::EMT::Ph1::SSNTypeV2T::setParameters, "A"_a,
174 "B"_a, "C"_a, "D"_a)
175 .def("manual_init", &CPS::EMT::Ph1::SSNTypeV2T::manualInit,
176 "initialState"_a, "initialInput"_a, "initialOldInput"_a,
177 "initCurr"_a, "initVol"_a)
178 .def("connect", &CPS::EMT::Ph1::SSNTypeV2T::connect)
179 .def_property("mA", createAttributeGetter<CPS::Matrix>("mA"),
180 createAttributeSetter<CPS::Matrix>("mA"))
181 .def_property("mB", createAttributeGetter<CPS::Matrix>("mB"),
182 createAttributeSetter<CPS::Matrix>("mB"))
183 .def_property("mC", createAttributeGetter<CPS::Matrix>("mC"),
184 createAttributeSetter<CPS::Matrix>("mC"))
185 .def_property("mD", createAttributeGetter<CPS::Matrix>("mD"),
186 createAttributeSetter<CPS::Matrix>("mD"))
187 .def_property("mdA", createAttributeGetter<CPS::Matrix>("mdA"),
188 createAttributeSetter<CPS::Matrix>("mdA"))
189 .def_property("mdB", createAttributeGetter<CPS::Matrix>("mdB"),
190 createAttributeSetter<CPS::Matrix>("mdB"))
191 .def_property("mdC", createAttributeGetter<CPS::Matrix>("mdC"),
192 createAttributeSetter<CPS::Matrix>("mdC"));
193}
194
195void addEMTPh3Components(py::module_ mEMTPh3) {
197 std::shared_ptr<CPS::EMT::Ph3::VoltageSource>,
198 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "VoltageSource",
199 py::multiple_inheritance())
200 .def(py::init<std::string>())
201 .def(py::init<std::string, CPS::Logger::Level>())
202 .def("set_parameters",
203 py::overload_cast<CPS::MatrixComp, CPS::Real>(
205 "V_ref"_a, "f_src"_a = 50)
207 .def_property("V_ref", createAttributeGetter<CPS::MatrixComp>("V_ref"),
208 createAttributeSetter<CPS::MatrixComp>("V_ref"))
209 .def_property("f_src", createAttributeGetter<CPS::Real>("f_src"),
210 createAttributeSetter<CPS::Real>("f_src"));
211
213 std::shared_ptr<CPS::EMT::Ph3::ControlledVoltageSource>,
214 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "ControlledVoltageSource",
215 py::multiple_inheritance())
216 .def(py::init<std::string>())
217 .def(py::init<std::string, CPS::Logger::Level>())
218 .def("set_parameters",
219 py::overload_cast<CPS::Matrix>(
221 "V_ref"_a)
223 .def_property("V_ref", createAttributeGetter<CPS::MatrixComp>("V_ref"),
224 createAttributeSetter<CPS::MatrixComp>("V_ref"));
225
227 std::shared_ptr<CPS::EMT::Ph3::CurrentSource>,
228 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "CurrentSource",
229 py::multiple_inheritance())
230 .def(py::init<std::string>())
231 .def(py::init<std::string, CPS::Logger::Level>())
232 .def("set_parameters",
233 py::overload_cast<CPS::MatrixComp, CPS::Real>(
235 "I_ref"_a, "f_src"_a = 50)
237 .def_property("I_ref", createAttributeGetter<CPS::MatrixComp>("I_ref"),
238 createAttributeSetter<CPS::MatrixComp>("V_ref"))
239 .def_property("f_src", createAttributeGetter<CPS::Real>("f_src"),
240 createAttributeSetter<CPS::Real>("f_src"));
241
242 py::class_<CPS::EMT::Ph3::Resistor, std::shared_ptr<CPS::EMT::Ph3::Resistor>,
243 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "Resistor",
244 py::multiple_inheritance())
245 .def(py::init<std::string>())
246 .def(py::init<std::string, CPS::Logger::Level>())
247 .def("set_parameters", &CPS::EMT::Ph3::Resistor::setParameters, "R"_a)
248 .def("connect", &CPS::EMT::Ph3::Resistor::connect);
249
250 py::class_<CPS::EMT::Ph3::Capacitor,
251 std::shared_ptr<CPS::EMT::Ph3::Capacitor>,
252 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "Capacitor",
253 py::multiple_inheritance())
254 .def(py::init<std::string>())
255 .def(py::init<std::string, CPS::Logger::Level>())
256 .def("set_parameters", &CPS::EMT::Ph3::Capacitor::setParameters, "C"_a)
257 .def("connect", &CPS::EMT::Ph3::Capacitor::connect);
258
259 py::class_<CPS::EMT::Ph3::Inductor, std::shared_ptr<CPS::EMT::Ph3::Inductor>,
260 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "Inductor",
261 py::multiple_inheritance())
262 .def(py::init<std::string>())
263 .def(py::init<std::string, CPS::Logger::Level>())
264 .def("set_parameters", &CPS::EMT::Ph3::Inductor::setParameters, "L"_a)
265 .def("connect", &CPS::EMT::Ph3::Inductor::connect);
266
268 std::shared_ptr<CPS::EMT::Ph3::NetworkInjection>,
269 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "NetworkInjection",
270 py::multiple_inheritance())
271 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
272 "loglevel"_a = CPS::Logger::Level::off)
273 .def("set_parameters",
274 py::overload_cast<CPS::MatrixComp, CPS::Real>(
276 "V_ref"_a, "f_src"_a = 50)
278
279 py::class_<CPS::EMT::Ph3::PiLine, std::shared_ptr<CPS::EMT::Ph3::PiLine>,
280 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "PiLine",
281 py::multiple_inheritance())
282 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
283 "loglevel"_a = CPS::Logger::Level::off)
284 .def("set_parameters", &CPS::EMT::Ph3::PiLine::setParameters,
285 "series_resistance"_a, "series_inductance"_a,
286 "parallel_capacitance"_a = zeroMatrix(3),
287 "parallel_conductance"_a = zeroMatrix(3))
288 .def("connect", &CPS::EMT::Ph3::PiLine::connect);
289
290 py::class_<CPS::EMT::Ph3::RXLoad, std::shared_ptr<CPS::EMT::Ph3::RXLoad>,
291 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "RXLoad",
292 py::multiple_inheritance())
293 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
294 "loglevel"_a = CPS::Logger::Level::off)
295 .def("set_parameters", &CPS::EMT::Ph3::RXLoad::setParameters,
296 "active_power"_a, "reactive_power"_a, "volt"_a,
297 // cppcheck-suppress assignBoolToPointer
298 "reactance_in_series"_a = false)
299 .def("connect", &CPS::EMT::Ph3::RXLoad::connect);
300
301 py::class_<CPS::EMT::Ph3::Shunt, std::shared_ptr<CPS::EMT::Ph3::Shunt>,
302 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "Shunt",
303 py::multiple_inheritance())
304 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
305 "loglevel"_a = CPS::Logger::Level::off)
306 .def("set_parameters",
307 static_cast<void (CPS::EMT::Ph3::Shunt::*)(CPS::Real, CPS::Real)>(
309 "G"_a, "B"_a)
310 .def("connect", &CPS::EMT::Ph3::Shunt::connect);
311
312 py::class_<CPS::EMT::Ph3::Switch, std::shared_ptr<CPS::EMT::Ph3::Switch>,
314 mEMTPh3, "Switch", py::multiple_inheritance())
315 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
316 "loglevel"_a = CPS::Logger::Level::off)
317 .def("set_parameters", &CPS::EMT::Ph3::Switch::setParameters,
318 "open_resistance"_a, "closed_resistance"_a,
319 // cppcheck-suppress assignBoolToPointer
320 "closed"_a = false)
321 .def("open", &CPS::EMT::Ph3::Switch::openSwitch)
322 .def("close", &CPS::EMT::Ph3::Switch::closeSwitch)
323 .def("connect", &CPS::EMT::Ph3::Switch::connect);
324
326 std::shared_ptr<CPS::EMT::Ph3::SynchronGeneratorDQTrapez>,
327 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "SynchronGeneratorDQTrapez",
328 py::multiple_inheritance())
329 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
330 "loglevel"_a = CPS::Logger::Level::off)
331 .def("set_parameters_operational_per_unit",
333 setParametersOperationalPerUnit,
334 "nom_power"_a, "nom_volt"_a, "nom_freq"_a, "pole_number"_a,
335 "nom_field_cur"_a, "Rs"_a, "Ld"_a, "Lq"_a, "Ld_t"_a, "Lq_t"_a,
336 "Ld_s"_a, "Lq_s"_a, "Ll"_a, "Td0_t"_a, "Tq0_t"_a, "Td0_s"_a,
337 "Tq0_s"_a, "inertia"_a)
338 .def("set_parameters_fundamental_per_unit",
340 setParametersFundamentalPerUnit,
341 "nom_power"_a, "nom_volt"_a, "nom_freq"_a, "pole_number"_a,
342 "nom_field_cur"_a, "Rs"_a, "Ll"_a, "Lmd"_a, "Lmq"_a, "Rfd"_a,
343 "Llfd"_a, "Rkd"_a, "Llkd"_a, "Rkq1"_a, "Llkq1"_a, "Rkq2"_a,
344 "Llkq2"_a, "inertia"_a, "init_active_power"_a,
345 "init_reactive_power"_a, "init_terminal_volt"_a, "init_volt_angle"_a,
346 "init_mech_power"_a)
347#ifdef WITH_JSON
348 .def("apply_parameters_from_json",
349 [](std::shared_ptr<CPS::EMT::Ph3::SynchronGeneratorDQTrapez> syngen,
350 const CPS::String json) {
351 DPsim::Utils::applySynchronousGeneratorParametersFromJson(
352 json::parse(json), syngen);
353 })
354#endif
355 .def("set_initial_values",
356 &CPS::EMT::Ph3::SynchronGeneratorDQTrapez::setInitialValues,
357 "init_active_power"_a, "init_reactive_power"_a,
358 "init_terminal_volt"_a, "init_volt_angle"_a, "init_mech_power"_a);
359
361 std::shared_ptr<CPS::EMT::Ph3::VSIVoltageControlVCO>,
362 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "VSIVoltageControlVCO",
363 py::multiple_inheritance())
364 .def(py::init<std::string>())
365 .def(py::init<std::string, CPS::Logger::Level>())
366 .def(py::init<std::string, std::string, CPS::Logger::Level, CPS::Bool>(),
367 "uid"_a, "name"_a, "log_level"_a = CPS::Logger::Level::off,
368 py::arg("with_trafo") = false)
369 .def("set_parameters",
371 "vd_ref"_a, "vq_ref"_a)
372 .def("set_controller_parameters",
374 "kp_voltage_ctrl"_a, "ki_voltage_ctrl"_a, "kp_curr_ctrl"_a,
375 "ki_curr_ctrl"_a, "omega_nominal"_a)
376 .def("set_transformer_parameters",
378 "nom_voltage_end1"_a, "nom_voltage_end2"_a, "rated_power"_a,
379 "ratio_abs"_a, "ratio_phase"_a, "resistance"_a, "inductance"_a,
380 "omega"_a)
381 .def("set_filter_parameters",
383 "cf"_a, "rf"_a, "rc"_a)
384 .def("set_initial_state_values",
386 "phi_d_init"_a, "phi_q_init"_a, "gamma_d_init"_a, "gamma_q_init"_a)
387 .def("with_control", &CPS::EMT::Ph3::VSIVoltageControlVCO::withControl,
388 "control_on"_a)
390
392 std::shared_ptr<CPS::EMT::Ph3::ReducedOrderSynchronGeneratorVBR>,
394 mEMTPh3, "ReducedOrderSynchronGeneratorVBR", py::multiple_inheritance());
395
397 std::shared_ptr<CPS::EMT::Ph3::SynchronGenerator3OrderVBR>,
399 mEMTPh3, "SynchronGenerator3OrderVBR", py::multiple_inheritance())
400 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
401 "loglevel"_a = CPS::Logger::Level::off)
402 .def("set_operational_parameters_per_unit",
403 py::overload_cast<CPS::Real, CPS::Real, CPS::Real, CPS::Real,
404 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
405 CPS::Real>(
407 setOperationalParametersPerUnit),
408 "nom_power"_a, "nom_voltage"_a, "nom_frequency"_a, "H"_a, "Ld"_a,
409 "Lq"_a, "L0"_a, "Ld_t"_a, "Td0_t"_a)
411
413 std::shared_ptr<CPS::EMT::Ph3::SynchronGenerator4OrderVBR>,
415 mEMTPh3, "SynchronGenerator4OrderVBR", py::multiple_inheritance())
416 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
417 "loglevel"_a = CPS::Logger::Level::off)
418 .def("set_operational_parameters_per_unit",
419 py::overload_cast<CPS::Real, CPS::Real, CPS::Real, CPS::Real,
420 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
421 CPS::Real, CPS::Real, CPS::Real>(
423 setOperationalParametersPerUnit),
424 "nom_power"_a, "nom_voltage"_a, "nom_frequency"_a, "H"_a, "Ld"_a,
425 "Lq"_a, "L0"_a, "Ld_t"_a, "Lq_t"_a, "Td0_t"_a, "Tq0_t"_a)
427
429 std::shared_ptr<CPS::EMT::Ph3::SynchronGenerator5OrderVBR>,
431 mEMTPh3, "SynchronGenerator5OrderVBR", py::multiple_inheritance())
432 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
433 "loglevel"_a = CPS::Logger::Level::off)
434 .def("set_operational_parameters_per_unit",
435 py::overload_cast<CPS::Real, CPS::Real, CPS::Real, CPS::Real,
436 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
437 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
438 CPS::Real, CPS::Real, CPS::Real, CPS::Real>(
440 setOperationalParametersPerUnit),
441 "nom_power"_a, "nom_voltage"_a, "nom_frequency"_a, "H"_a, "Ld"_a,
442 "Lq"_a, "L0"_a, "Ld_t"_a, "Lq_t"_a, "Td0_t"_a, "Tq0_t"_a, "Ld_s"_a,
443 "Lq_s"_a, "Td0_s"_a, "Tq0_s"_a, "Taa"_a)
445
447 std::shared_ptr<CPS::EMT::Ph3::SynchronGenerator6aOrderVBR>,
449 mEMTPh3, "SynchronGenerator6aOrderVBR", py::multiple_inheritance())
450 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
451 "loglevel"_a = CPS::Logger::Level::off)
452 .def("set_operational_parameters_per_unit",
453 py::overload_cast<CPS::Real, CPS::Real, CPS::Real, CPS::Real,
454 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
455 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
456 CPS::Real, CPS::Real, CPS::Real, CPS::Real>(
458 setOperationalParametersPerUnit),
459 "nom_power"_a, "nom_voltage"_a, "nom_frequency"_a, "H"_a, "Ld"_a,
460 "Lq"_a, "L0"_a, "Ld_t"_a, "Lq_t"_a, "Td0_t"_a, "Tq0_t"_a, "Ld_s"_a,
461 "Lq_s"_a, "Td0_s"_a, "Tq0_s"_a, "Taa"_a)
463
465 std::shared_ptr<CPS::EMT::Ph3::SynchronGenerator6bOrderVBR>,
467 mEMTPh3, "SynchronGenerator6bOrderVBR", py::multiple_inheritance())
468 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
469 "loglevel"_a = CPS::Logger::Level::off)
470 .def("set_operational_parameters_per_unit",
471 py::overload_cast<CPS::Real, CPS::Real, CPS::Real, CPS::Real,
472 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
473 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
474 CPS::Real, CPS::Real, CPS::Real, CPS::Real>(
476 setOperationalParametersPerUnit),
477 "nom_power"_a, "nom_voltage"_a, "nom_frequency"_a, "H"_a, "Ld"_a,
478 "Lq"_a, "L0"_a, "Ld_t"_a, "Lq_t"_a, "Td0_t"_a, "Tq0_t"_a, "Ld_s"_a,
479 "Lq_s"_a, "Td0_s"_a, "Tq0_s"_a, "Taa"_a = 0)
481
482#ifdef WITH_SUNDIALS
483
485 std::shared_ptr<CPS::EMT::Ph3::SynchronGeneratorDQODE>,
486 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "SynchronGeneratorDQODE",
487 py::multiple_inheritance())
488 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
489 "loglevel"_a = CPS::Logger::Level::off)
490 .def("set_parameters_operational_per_unit",
492 setParametersOperationalPerUnit,
493 "nom_power"_a, "nom_volt"_a, "nom_freq"_a, "pole_number"_a,
494 "nom_field_cur"_a, "Rs"_a, "Ld"_a, "Lq"_a, "Ld_t"_a, "Lq_t"_a,
495 "Ld_s"_a, "Lq_s"_a, "Ll"_a, "Td0_t"_a, "Tq0_t"_a, "Td0_s"_a,
496 "Tq0_s"_a, "inertia"_a)
497 .def("set_parameters_fundamental_per_unit",
499 setParametersFundamentalPerUnit,
500 "nom_power"_a, "nom_volt"_a, "nom_freq"_a, "pole_number"_a,
501 "nom_field_cur"_a, "Rs"_a, "Ll"_a, "Lmd"_a, "Lmq"_a, "Rfd"_a,
502 "Llfd"_a, "Rkd"_a, "Llkd"_a, "Rkq1"_a, "Llkq1"_a, "Rkq2"_a,
503 "Llkq2"_a, "inertia"_a, "init_active_power"_a,
504 "init_reactive_power"_a, "init_terminal_volt"_a, "init_volt_angle"_a,
505 "init_mech_power"_a)
506#ifdef WITH_JSON
507 .def("apply_parameters_from_json",
508 [](std::shared_ptr<CPS::EMT::Ph3::SynchronGeneratorDQODE> syngen,
509 const CPS::String json) {
510 DPsim::Utils::applySynchronousGeneratorParametersFromJson(
511 json::parse(json), syngen);
512 })
513#endif
514 .def("set_initial_values",
515 &CPS::EMT::Ph3::SynchronGeneratorDQODE::setInitialValues,
516 "init_active_power"_a, "init_reactive_power"_a,
517 "init_terminal_volt"_a, "init_volt_angle"_a, "init_mech_power"_a);
518
519#endif
520
522 std::shared_ptr<CPS::EMT::Ph3::AvVoltageSourceInverterDQ>,
523 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "AvVoltageSourceInverterDQ",
524 py::multiple_inheritance())
525 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
526 "loglevel"_a = CPS::Logger::Level::off)
527 .def(py::init<std::string, std::string, CPS::Logger::Level, CPS::Bool>(),
528 "uid"_a, "name"_a, "loglevel"_a = CPS::Logger::Level::off,
529 // cppcheck-suppress assignBoolToPointer
530 "with_trafo"_a = false)
531 .def("set_parameters",
533 "sys_omega"_a, "sys_volt_nom"_a, "p_ref"_a, "q_ref"_a)
534 .def("set_filter_parameters",
536 "Lf"_a, "Cf"_a, "Rf"_a, "Rc"_a)
537 .def("set_controller_parameters",
539 "Kp_pll"_a, "Ki_pll"_a, "Kp_power_ctrl"_a, "Ki_power_ctrl"_a,
540 "Kp_curr_ctrl"_a, "Ki_curr_ctrl"_a, "omega_cutoff"_a)
541 .def("set_transformer_parameters",
543 "nom_voltage_end_1"_a, "nom_voltage_end_2"_a, "rated_power"_a,
544 "ratio_abs"_a, "ratio_phase"_a, "resistance"_a, "inductance"_a,
545 "omega"_a)
546 .def("set_initial_state_values",
548 "p_init"_a, "q_init"_a, "phi_d_init"_a, "phi_q_init"_a,
549 "gamma_d_init"_a, "gamma_q_init"_a)
550 .def("with_control",
551 &CPS::EMT::Ph3::AvVoltageSourceInverterDQ::withControl)
553
555 std::shared_ptr<CPS::EMT::Ph3::Transformer>,
556 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "Transformer",
557 py::multiple_inheritance())
558 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
559 "loglevel"_a = CPS::Logger::Level::off)
560 .def(py::init<std::string, std::string, CPS::Logger::Level, CPS::Bool>(),
561 "uid"_a, "name"_a, "loglevel"_a = CPS::Logger::Level::off,
562 // cppcheck-suppress assignBoolToPointer
563 "with_resistive_losses"_a = false)
564 .def("set_parameters", &CPS::EMT::Ph3::Transformer::setParameters,
565 "nom_voltage_end_1"_a, "nom_voltage_end_2"_a, "rated_power"_a,
566 "ratio_abs"_a, "ratio_phase"_a, "resistance"_a, "inductance"_a)
567 .def("connect", &CPS::EMT::Ph3::Transformer::connect);
568
570 std::shared_ptr<CPS::EMT::Ph3::SeriesResistor>,
571 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "SeriesResistor",
572 py::multiple_inheritance())
573 .def(py::init<std::string>())
574 .def(py::init<std::string, CPS::Logger::Level>())
575 .def("set_parameters", &CPS::EMT::Ph3::SeriesResistor::setParameters,
576 "R"_a)
578
580 std::shared_ptr<CPS::EMT::Ph3::SeriesSwitch>,
582 mEMTPh3, "SeriesSwitch", py::multiple_inheritance())
583 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
584 "loglevel"_a = CPS::Logger::Level::off)
585 .def("set_parameters", &CPS::EMT::Ph3::SeriesSwitch::setParameters,
586 "open_resistance"_a, "closed_resistance"_a,
587 // cppcheck-suppress assignBoolToPointer
588 "closed"_a = false)
591 .def("connect", &CPS::EMT::Ph3::SeriesSwitch::connect);
592
594 std::shared_ptr<CPS::EMT::Ph3::SSN::Full_Serial_RLC>,
595 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "Full_Serial_RLC",
596 py::multiple_inheritance())
597 .def(py::init<std::string>())
598 .def(py::init<std::string, CPS::Logger::Level>())
599 .def("set_parameters",
600 &CPS::EMT::Ph3::SSN::Full_Serial_RLC::setParameters, "R"_a, "L"_a,
601 "C"_a)
603 .def_property("R", createAttributeGetter<CPS::Matrix>("R"),
604 createAttributeSetter<CPS::Matrix>("R"))
605 .def_property("L", createAttributeGetter<CPS::Matrix>("L"),
606 createAttributeSetter<CPS::Matrix>("L"))
607 .def_property("C", createAttributeGetter<CPS::Matrix>("C"),
608 createAttributeSetter<CPS::Matrix>("C"));
609
611 std::shared_ptr<CPS::EMT::Ph3::GenericTwoTerminalVTypeSSN>,
613 mEMTPh3, "GenericTwoTerminalVTypeSSN", py::multiple_inheritance())
614 .def(py::init<std::string>())
615 .def(py::init<std::string, CPS::Logger::Level>())
616 .def("set_parameters",
617 &CPS::EMT::Ph3::GenericTwoTerminalVTypeSSN::setParameters, "A"_a,
618 "B"_a, "C"_a, "D"_a)
620 .def_property_readonly("x", createAttributeGetter<CPS::Matrix>("x"));
621
623 std::shared_ptr<CPS::EMT::Ph3::GenericTwoTerminalITypeSSN>,
625 mEMTPh3, "GenericTwoTerminalITypeSSN", py::multiple_inheritance())
626 .def(py::init<std::string>())
627 .def(py::init<std::string, CPS::Logger::Level>())
628 .def("set_parameters",
629 &CPS::EMT::Ph3::GenericTwoTerminalITypeSSN::setParameters, "A"_a,
630 "B"_a, "C"_a, "D"_a)
632 .def_property_readonly("x", createAttributeGetter<CPS::Matrix>("x"));
633
635 std::shared_ptr<CPS::EMT::Ph3::PiecewiseLinearInductor>,
636 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "PiecewiseLinearInductor",
637 py::multiple_inheritance())
638 .def(py::init<std::string>())
639 .def(py::init<std::string, CPS::Logger::Level>())
640 .def("set_parameters",
641 &CPS::EMT::Ph3::PiecewiseLinearInductor::setParameters,
642 "flux_breakpoints"_a, "current_breakpoints"_a)
644 .def_property_readonly("x", createAttributeGetter<CPS::Matrix>("x"));
645
647 std::shared_ptr<CPS::EMT::Ph3::AvVoltSourceInverterStateSpace>,
649 mEMTPh3, "AvVoltSourceInverterStateSpace", py::multiple_inheritance())
650 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
651 "loglevel"_a = CPS::Logger::Level::off)
652 .def(py::init<std::string, std::string, CPS::Logger::Level>(), "uid"_a,
653 "name"_a, "loglevel"_a = CPS::Logger::Level::off)
654 .def("set_parameters",
655 &CPS::EMT::Ph3::AvVoltSourceInverterStateSpace::setParameters,
656 "Lf"_a, "Cf"_a, "Rf"_a, "Rc"_a, "omega_n"_a, "Kp_pll"_a, "Ki_pll"_a,
657 "omega_cutoff"_a, "p_ref"_a, "q_ref"_a, "Kp_power_ctrl"_a,
658 "Ki_power_ctrl"_a, "Kp_curr_ctrl"_a, "Ki_curr_ctrl"_a)
660 .def_property_readonly("x", createAttributeGetter<CPS::Matrix>("x"))
661 .def_property_readonly("vc_d", createAttributeGetter<CPS::Real>("vc_d"))
662 .def_property_readonly("vc_q", createAttributeGetter<CPS::Real>("vc_q"))
663 .def_property_readonly("irc_d", createAttributeGetter<CPS::Real>("irc_d"))
664 .def_property_readonly("irc_q", createAttributeGetter<CPS::Real>("irc_q"))
665 .def_property_readonly("p_inst",
666 createAttributeGetter<CPS::Real>("p_inst"))
667 .def_property_readonly("q_inst",
668 createAttributeGetter<CPS::Real>("q_inst"))
669 .def_property_readonly("omega_pll",
670 createAttributeGetter<CPS::Real>("omega_pll"));
671
672 py::class_<CPS::EMT::Ph3::SSN_GFM, std::shared_ptr<CPS::EMT::Ph3::SSN_GFM>,
673 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "SSN_GFM",
674 py::multiple_inheritance())
675 .def(py::init<std::string, std::string, CPS::Logger::Level>(), "uid"_a,
676 "name"_a, "log_level"_a = CPS::Logger::Level::off)
677 .def("set_parameters", &CPS::EMT::Ph3::SSN_GFM::setParameters, "lf"_a,
678 "cf"_a, "rf"_a, "rc"_a, "nominal_voltage"_a, "omega_nominal"_a,
679 "p_ref"_a, "q_ref"_a, "virtual_inertia"_a, "damping_coefficient"_a,
680 "voltage_droop_gain"_a, "reactive_integral_gain"_a, "kp_voltage"_a,
681 "ki_voltage"_a, "kp_current"_a, "ki_current"_a,
682 "active_damping_gain"_a, "power_filter_cutoff"_a,
683 "delay_bandwidth"_a)
684 .def("set_numerical_linearization_parameters",
686 "relative_step"_a = 1e-6, "absolute_step"_a = 1e-8)
687 .def("connect", &CPS::EMT::Ph3::SSN_GFM::connect)
688 .def("get_state_names", &CPS::EMT::Ph3::SSN_GFM::getLocalStateNames)
689 .def("get_state", &CPS::EMT::Ph3::SSN_GFM::getState)
690 .def("get_state_derivative", &CPS::EMT::Ph3::SSN_GFM::getStateDerivative)
691 .def("get_interface_voltage",
692 &CPS::EMT::Ph3::SSN_GFM::getInterfaceVoltage)
693 .def("get_interface_current",
694 &CPS::EMT::Ph3::SSN_GFM::getInterfaceCurrent)
695 .def_property_readonly("p_inst",
696 createAttributeGetter<CPS::Real>("p_inst"))
697 .def_property_readonly("q_inst",
698 createAttributeGetter<CPS::Real>("q_inst"))
699 .def_property_readonly("omega_gfm",
700 createAttributeGetter<CPS::Real>("omega_gfm"))
701 .def_property_readonly("theta_gfm",
702 createAttributeGetter<CPS::Real>("theta_gfm"))
703 .def_property_readonly(
704 "voltage_magnitude_gfm",
705 createAttributeGetter<CPS::Real>("voltage_magnitude_gfm"))
706 .def_property_readonly("vc_d", createAttributeGetter<CPS::Real>("vc_d"))
707 .def_property_readonly("vc_q", createAttributeGetter<CPS::Real>("vc_q"))
708 .def_property_readonly("i_grid_d",
709 createAttributeGetter<CPS::Real>("i_grid_d"))
710 .def_property_readonly("i_grid_q",
711 createAttributeGetter<CPS::Real>("i_grid_q"))
712 .def_property_readonly("if_d", createAttributeGetter<CPS::Real>("if_d"))
713 .def_property_readonly("if_q", createAttributeGetter<CPS::Real>("if_q"))
714 .def_property_readonly("v_ref_d",
715 createAttributeGetter<CPS::Real>("v_ref_d"))
716 .def_property_readonly("v_ref_q",
717 createAttributeGetter<CPS::Real>("v_ref_q"));
718
720 std::shared_ptr<CPS::EMT::Ph3::SSN::Capacitor>,
721 CPS::SimPowerComp<CPS::Real>>(mEMTPh3, "SSN_Capacitor",
722 py::multiple_inheritance())
723 .def(py::init<std::string>())
724 .def(py::init<std::string, CPS::Logger::Level>())
725 .def("set_parameters", &CPS::EMT::Ph3::SSN::Capacitor::setParameters,
726 "C"_a)
728 .def_property("C", createAttributeGetter<CPS::Matrix>("C"),
729 createAttributeSetter<CPS::Matrix>("C"));
730
732 std::shared_ptr<CPS::EMT::Ph3::GenericFourTerminalVTypeSSN>,
734 mEMTPh3, "GenericFourTerminalVTypeSSN", py::multiple_inheritance())
735 .def(py::init<std::string>())
736 .def(py::init<std::string, CPS::Logger::Level>())
737 .def("set_parameters",
738 &CPS::EMT::Ph3::GenericFourTerminalVTypeSSN::setParameters, "A"_a,
739 "B"_a, "C"_a, "D"_a)
741 .def_property_readonly("x", createAttributeGetter<CPS::Matrix>("x"));
742}
void setParameters(Real capacitance)
Sets model specific parameters.
void setParameters(Real inductance)
Sets model specific parameters.
Dynamic Phasor Three-Phase Switch.
void close()
Close switch.
void open()
Open switch.
void setParameters(Matrix capacitance)
Sets model specific parameters.
void setParameters(Matrix inductance)
Sets model specific parameters.
void setParameters(Matrix resistance)
Sets model specific parameters.
Dynamic Phasor Three-Phase Switch.
Ideal current source model.
SSNTypeI2T Model for a one phase, two terminal I-type SSN component which can be represented using a ...
SSNTypeV2T Model for a one phase, two terminal V-type SSN component which can be represented using a ...
Ideal Voltage source model.
void setControllerParameters(Real Kp_pll, Real Ki_pll, Real Kp_powerCtrl, Real Ki_powerCtrl, Real Kp_currCtrl, Real Ki_currCtrl, Real Omega_cutoff)
Setter for parameters of control loops.
void setTransformerParameters(Real nomVoltageEnd1, Real nomVoltageEnd2, Real ratedPower, Real ratioAbs, Real ratioPhase, Real resistance, Real inductance, Real omega)
Setter for parameters of transformer.
void setInitialStateValues(Real pInit, Real qInit, Real phi_dInit, Real phi_qInit, Real gamma_dInit, Real gamma_qInit)
Setter for initial values applied in controllers.
void setFilterParameters(Real Lf, Real Cf, Real Rf, Real Rc)
Setter for parameters of filter.
void setParameters(Real sysOmega, Real sysVoltNom, Real Pref, Real Qref)
Setter for gengit eral parameters of inverter.
Ideal current source model.
void setParameters(MatrixComp currentRef, Real srcFreq=50.0)
Setter for reference current.
Concrete generic three-phase, two-terminal I-type SSN component.
Concrete generic three-phase, two-terminal V-type SSN component.
void setParameters(MatrixComp voltageRef, Real srcFreq=50.0)
Setter for reference voltage parameters.
Three-phase, two-terminal, piecewise-linear flux-state inductor.
Base class for EMT VBR simplefied synchronous generator models.
void setNumericalLinearizationParameters(Real relativeStep, Real absoluteStep)
Configure finite-difference steps for local linearization.
void setParameters(Real lf, Real cf, Real rf, Real rc, Real nominalVoltage, Real omegaN, Real pRef, Real qRef, Real virtualInertia, Real dampingCoefficient, Real voltageDroopGain, Real reactiveIntegralGain, Real kpVoltage, Real kiVoltage, Real kpCurrent, Real kiCurrent, Real activeDampingGain, Real powerFilterCutoff, Real delayBandwidth)
Configure the GFM model.
std::vector< String > getLocalStateNames() const override final
void setParameters(Real conductance, Real susceptance)
Set shunt specific parameters.
Voltage-Behind-Reactance (VBR) implementation of 3rd order synchronous generator model.
Voltage-Behind-Reactance (VBR) implementation of 4th order synchronous generator model.
Voltage-Behind-Reactance (VBR) implementation of 5th type 2 order synchronous generator model Ref: Mi...
Voltage-Behind-Reactance (VBR) implementation of 6th order synchronous generator model Marconato's mo...
Voltage-Behind-Reactance (VBR) implementation of 6th order synchronous generator model Anderson - Fou...
Transformer that includes an inductance and resistance.
void setParameters(Real nomVoltageEnd1, Real nomVoltageEnd2, Real ratedPower, Real ratioAbs, Real ratioPhase, Matrix resistance, Matrix inductance)
Defines component parameters.
void setParameters(Real sysOmega, Real VdRef, Real VqRef)
Setter for general parameters of the component.
void setFilterParameters(Real Lf, Real Cf, Real Rf, Real Rc)
Setter for parameters of filter.
void setControllerParameters(Real Kp_voltageCtrl, Real Ki_voltageCtrl, Real Kp_currCtrl, Real Ki_currCtrl, Real Omega_nominal)
Setter for parameters of control loops.
void setInitialStateValues(Real phi_dInit, Real phi_qInit, Real gamma_dInit, Real gamma_qInit)
Setter for initial values applied in controllers.
void setTransformerParameters(Real nomVoltageEnd1, Real nomVoltageEnd2, Real ratedPower, Real ratioAbs, Real ratioPhase, Real resistance, Real inductance, Real omega)
Setter for parameters of transformer.
Ideal Voltage source model.
void setParameters(MatrixComp voltageRef, Real srcFreq=50.0)
Setter for reference voltage and frequency with a sine wave generator.
Base class for all components that are transmitting power.
void connect(typename SimNode< Real >::List nodes)