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/SPComponents.h>
15 #include <dpsim/pybind/Utils.h>
17 namespace py = pybind11;
18 using namespace pybind11::literals;
20 void addSPComponents(py::module_ mSP) {
22 mSP.def_submodule(
"ph1",
"single phase static phasor models");
23 addSPPh1Components(mSPPh1);
25 mSP.def_submodule(
"ph3",
"three phase static phasor models");
26 addSPPh3Components(mSPPh3);
29 void addSPPh1Components(py::module_ mSPPh1) {
32 std::shared_ptr<CPS::SP::Ph1::VoltageSource>,
34 py::multiple_inheritance())
35 .def(py::init<std::string>())
36 .def(py::init<std::string, CPS::Logger::Level>())
37 .def(
"set_parameters",
38 py::overload_cast<CPS::Complex, CPS::Real>(
40 "V_ref"_a,
"f_src"_a = 0)
42 .def_property(
"V_ref", createAttributeGetter<CPS::Complex>(
"V_ref"),
43 createAttributeSetter<CPS::Complex>(
"V_ref"))
44 .def_property(
"f_src", createAttributeGetter<CPS::Real>(
"f_src"),
45 createAttributeSetter<CPS::Real>(
"f_src"));
47 py::class_<CPS::SP::Ph1::Resistor, std::shared_ptr<CPS::SP::Ph1::Resistor>,
49 py::multiple_inheritance())
50 .def(py::init<std::string>())
51 .def(py::init<std::string, CPS::Logger::Level>())
52 .def(
"set_parameters", &CPS::SP::Ph1::Resistor::setParameters,
"R"_a)
54 .def_property(
"R", createAttributeGetter<CPS::Real>(
"R"),
55 createAttributeSetter<CPS::Complex>(
"R"));
57 py::class_<CPS::SP::Ph1::Capacitor, std::shared_ptr<CPS::SP::Ph1::Capacitor>,
59 py::multiple_inheritance())
60 .def(py::init<std::string>())
61 .def(py::init<std::string, CPS::Logger::Level>())
64 .def_property(
"C", createAttributeGetter<CPS::Real>(
"C"),
65 createAttributeSetter<CPS::Real>(
"C"));
67 py::class_<CPS::SP::Ph1::Inductor, std::shared_ptr<CPS::SP::Ph1::Inductor>,
69 py::multiple_inheritance())
70 .def(py::init<std::string>())
71 .def(py::init<std::string, CPS::Logger::Level>())
74 .def_property(
"L", createAttributeGetter<CPS::Real>(
"L"),
75 createAttributeSetter<CPS::Real>(
"L"));
78 std::shared_ptr<CPS::SP::Ph1::NetworkInjection>,
80 py::multiple_inheritance())
81 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
82 "loglevel"_a = CPS::Logger::Level::off)
83 .def(
"set_parameters",
84 py::overload_cast<CPS::Real>(
86 "voltage_set_point"_a)
87 .def(
"set_parameters",
88 py::overload_cast<CPS::Complex, CPS::Real>(
90 "V_ref"_a,
"f_src"_a = 0)
94 .def(
"modify_power_flow_bus_type",
98 py::class_<CPS::SP::Ph1::PiLine, std::shared_ptr<CPS::SP::Ph1::PiLine>,
100 py::multiple_inheritance())
101 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
102 "loglevel"_a = CPS::Logger::Level::off)
103 .def(
"set_parameters", &CPS::SP::Ph1::PiLine::setParameters,
"R"_a,
"L"_a,
104 "C"_a = -1,
"G"_a = -1)
109 py::class_<CPS::SP::Ph1::Shunt, std::shared_ptr<CPS::SP::Ph1::Shunt>,
111 py::multiple_inheritance())
112 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
113 "loglevel"_a = CPS::Logger::Level::off)
119 py::class_<CPS::SP::Ph1::Load, std::shared_ptr<CPS::SP::Ph1::Load>,
121 py::multiple_inheritance())
122 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
123 "loglevel"_a = CPS::Logger::Level::off)
124 .def(
"set_parameters", &CPS::SP::Ph1::Load::setParameters,
125 "active_power"_a,
"reactive_power"_a,
"nominal_voltage"_a)
126 .def(
"modify_power_flow_bus_type",
130 py::class_<CPS::SP::Ph1::Switch, std::shared_ptr<CPS::SP::Ph1::Switch>,
132 mSPPh1,
"Switch", py::multiple_inheritance())
133 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
134 "loglevel"_a = CPS::Logger::Level::off)
135 .def(
"set_parameters", &CPS::SP::Ph1::Switch::setParameters,
136 "open_resistance"_a,
"closed_resistance"_a,
144 std::shared_ptr<CPS::SP::Ph1::SynchronGenerator>,
146 py::multiple_inheritance())
147 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
148 "loglevel"_a = CPS::Logger::Level::off)
150 "rated_apparent_power"_a,
"rated_voltage"_a,
151 "set_point_active_power"_a,
"set_point_voltage"_a,
152 "powerflow_bus_type"_a,
"set_point_reactive_power"_a = 0)
156 .def(
"modify_power_flow_bus_type",
159 .def(
"get_apparent_power",
163 std::shared_ptr<CPS::SP::Ph1::varResSwitch>,
165 mSPPh1,
"varResSwitch", py::multiple_inheritance())
166 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
167 "loglevel"_a = CPS::Logger::Level::off)
168 .def(
"set_parameters", &CPS::SP::Ph1::varResSwitch::setParameters,
169 "open_resistance"_a,
"closed_resistance"_a,
174 .def(
"set_init_parameters",
175 &CPS::SP::Ph1::varResSwitch::setInitParameters,
"time_step"_a)
179 std::shared_ptr<CPS::SP::Ph1::SynchronGeneratorTrStab>,
181 py::multiple_inheritance())
182 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
183 "loglevel"_a = CPS::Logger::Level::off)
184 .def(
"set_standard_parameters_PU",
186 "nom_power"_a,
"nom_volt"_a,
"nom_freq"_a,
"Xpd"_a,
"inertia"_a,
187 "Rs"_a = 0,
"D"_a = 0)
188 .def(
"set_initial_values",
189 &CPS::SP::Ph1::SynchronGeneratorTrStab::setInitialValues,
190 "elec_power"_a,
"mech_power"_a)
192 .def(
"set_model_flags",
194 "convert_with_omega_mech"_a)
196 "set_reference_omega",
198 std::string refOmegaName, CPS::IdentifiedObject::Ptr refOmegaComp,
199 std::string refDeltaName,
200 CPS::IdentifiedObject::Ptr refDeltaComp) {
201 gen.setReferenceOmega(
202 refOmegaComp->attributeTyped<CPS::Real>(refOmegaName),
203 refDeltaComp->attributeTyped<CPS::Real>(refDeltaName));
205 "ref_omega_name"_a =
"w_r",
"ref_omage_comp"_a,
206 "ref_delta_name"_a =
"delta_r",
"ref_delta_comp"_a);
209 std::shared_ptr<CPS::SP::Ph1::ReducedOrderSynchronGeneratorVBR>,
211 mSPPh1,
"ReducedOrderSynchronGeneratorVBR", py::multiple_inheritance());
214 std::shared_ptr<CPS::SP::Ph1::SynchronGenerator3OrderVBR>,
216 mSPPh1,
"SynchronGenerator3OrderVBR", py::multiple_inheritance())
217 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
218 "loglevel"_a = CPS::Logger::Level::off)
219 .def(
"set_operational_parameters_per_unit",
220 py::overload_cast<CPS::Real, CPS::Real, CPS::Real, CPS::Real,
221 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
224 setOperationalParametersPerUnit),
225 "nom_power"_a,
"nom_voltage"_a,
"nom_frequency"_a,
"H"_a,
"Ld"_a,
226 "Lq"_a,
"L0"_a,
"Ld_t"_a,
"Td0_t"_a)
230 std::shared_ptr<CPS::SP::Ph1::SynchronGenerator4OrderVBR>,
232 mSPPh1,
"SynchronGenerator4OrderVBR", py::multiple_inheritance())
233 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
234 "loglevel"_a = CPS::Logger::Level::off)
235 .def(
"set_operational_parameters_per_unit",
236 py::overload_cast<CPS::Real, CPS::Real, CPS::Real, CPS::Real,
237 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
238 CPS::Real, CPS::Real, CPS::Real>(
240 setOperationalParametersPerUnit),
241 "nom_power"_a,
"nom_voltage"_a,
"nom_frequency"_a,
"H"_a,
"Ld"_a,
242 "Lq"_a,
"L0"_a,
"Ld_t"_a,
"Lq_t"_a,
"Td0_t"_a,
"Tq0_t"_a)
246 std::shared_ptr<CPS::SP::Ph1::SynchronGenerator5OrderVBR>,
248 mSPPh1,
"SynchronGenerator5OrderVBR", py::multiple_inheritance())
249 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
250 "loglevel"_a = CPS::Logger::Level::off)
251 .def(
"set_operational_parameters_per_unit",
252 py::overload_cast<CPS::Real, CPS::Real, CPS::Real, CPS::Real,
253 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
254 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
255 CPS::Real, CPS::Real, CPS::Real, CPS::Real>(
257 setOperationalParametersPerUnit),
258 "nom_power"_a,
"nom_voltage"_a,
"nom_frequency"_a,
"H"_a,
"Ld"_a,
259 "Lq"_a,
"L0"_a,
"Ld_t"_a,
"Lq_t"_a,
"Td0_t"_a,
"Tq0_t"_a,
"Ld_s"_a,
260 "Lq_s"_a,
"Td0_s"_a,
"Tq0_s"_a,
"Taa"_a)
264 std::shared_ptr<CPS::SP::Ph1::SynchronGenerator6aOrderVBR>,
266 mSPPh1,
"SynchronGenerator6aOrderVBR", py::multiple_inheritance())
267 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
268 "loglevel"_a = CPS::Logger::Level::off)
269 .def(
"set_operational_parameters_per_unit",
270 py::overload_cast<CPS::Real, CPS::Real, CPS::Real, CPS::Real,
271 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
272 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
273 CPS::Real, CPS::Real, CPS::Real, CPS::Real>(
275 setOperationalParametersPerUnit),
276 "nom_power"_a,
"nom_voltage"_a,
"nom_frequency"_a,
"H"_a,
"Ld"_a,
277 "Lq"_a,
"L0"_a,
"Ld_t"_a,
"Lq_t"_a,
"Td0_t"_a,
"Tq0_t"_a,
"Ld_s"_a,
278 "Lq_s"_a,
"Td0_s"_a,
"Tq0_s"_a,
"Taa"_a)
282 std::shared_ptr<CPS::SP::Ph1::SynchronGenerator6bOrderVBR>,
284 mSPPh1,
"SynchronGenerator6bOrderVBR", py::multiple_inheritance())
285 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
286 "loglevel"_a = CPS::Logger::Level::off)
287 .def(
"set_operational_parameters_per_unit",
288 py::overload_cast<CPS::Real, CPS::Real, CPS::Real, CPS::Real,
289 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
290 CPS::Real, CPS::Real, CPS::Real, CPS::Real,
291 CPS::Real, CPS::Real, CPS::Real, CPS::Real>(
293 setOperationalParametersPerUnit),
294 "nom_power"_a,
"nom_voltage"_a,
"nom_frequency"_a,
"H"_a,
"Ld"_a,
295 "Lq"_a,
"L0"_a,
"Ld_t"_a,
"Lq_t"_a,
"Td0_t"_a,
"Tq0_t"_a,
"Ld_s"_a,
296 "Lq_s"_a,
"Td0_s"_a,
"Tq0_s"_a,
"Taa"_a = 0)
300 std::shared_ptr<CPS::SP::Ph1::AvVoltageSourceInverterDQ>,
302 mSPPh1,
"AvVoltageSourceInverterDQ", py::multiple_inheritance())
303 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
304 "loglevel"_a = CPS::Logger::Level::off)
305 .def(py::init<std::string, std::string, CPS::Logger::Level, CPS::Bool>(),
306 "uid"_a,
"name"_a,
"loglevel"_a = CPS::Logger::Level::off,
308 "with_trafo"_a =
false)
309 .def(
"set_parameters",
311 "sys_omega"_a,
"sys_volt_nom"_a,
"p_ref"_a,
"q_ref"_a)
312 .def(
"set_filter_parameters",
314 "Lf"_a,
"Cf"_a,
"Rf"_a,
"Rc"_a)
315 .def(
"set_controller_parameters",
317 "Kp_pll"_a,
"Ki_pll"_a,
"Kp_power_ctrl"_a,
"Ki_power_ctrl"_a,
318 "Kp_curr_ctrl"_a,
"Ki_curr_ctrl"_a,
"omega_cutoff"_a)
319 .def(
"set_transformer_parameters",
321 "nom_voltage_end_1"_a,
"nom_voltage_end_2"_a,
"rated_power"_a,
322 "ratio_abs"_a,
"ratio_phase"_a,
"resistance"_a,
"inductance"_a)
323 .def(
"set_initial_state_values",
325 "p_init"_a,
"q_init"_a,
"phi_d_init"_a,
"phi_q_init"_a,
326 "gamma_d_init"_a,
"gamma_q_init"_a)
328 &CPS::SP::Ph1::AvVoltageSourceInverterDQ::withControl)
332 std::shared_ptr<CPS::SP::Ph1::Transformer>,
334 py::multiple_inheritance())
335 .def(py::init<std::string, CPS::Logger::Level>(),
"name"_a,
336 "loglevel"_a = CPS::Logger::Level::off)
337 .def(py::init<std::string, std::string, CPS::Logger::Level, CPS::Bool>(),
338 "uid"_a,
"name"_a,
"loglevel"_a = CPS::Logger::Level::off,
340 "with_resistive_losses"_a =
false)
341 .def(
"set_parameters",
342 py::overload_cast<CPS::Real, CPS::Real, CPS::Real, CPS::Real,
343 CPS::Real, CPS::Real>(
345 "nom_voltage_end_1"_a,
"nom_voltage_end_2"_a,
"ratio_abs"_a,
346 "ratio_phase"_a,
"resistance"_a,
"inductance"_a)
347 .def(
"set_parameters",
348 py::overload_cast<CPS::Real, CPS::Real, CPS::Real, CPS::Real,
349 CPS::Real, CPS::Real, CPS::Real>(
351 "nom_voltage_end_1"_a,
"nom_voltage_end_2"_a,
"rated_power"_a,
352 "ratio_abs"_a,
"ratio_phase"_a,
"resistance"_a,
"inductance"_a)
358 void addSPPh3Components(py::module_ mSPPh3) {
360 std::shared_ptr<CPS::SP::Ph3::VoltageSource>,
362 py::multiple_inheritance())
363 .def(py::init<std::string>())
364 .def(py::init<std::string, CPS::Logger::Level>())
365 .def(
"set_parameters", &CPS::SP::Ph3::VoltageSource::setParameters,
368 .def_property(
"V_ref", createAttributeGetter<CPS::MatrixComp>(
"V_ref"),
369 createAttributeSetter<CPS::MatrixComp>(
"V_ref"))
370 .def_property(
"f_src", createAttributeGetter<CPS::Real>(
"f_src"),
371 createAttributeSetter<CPS::Real>(
"f_src"));
373 py::class_<CPS::SP::Ph3::Resistor, std::shared_ptr<CPS::SP::Ph3::Resistor>,
375 py::multiple_inheritance())
376 .def(py::init<std::string>())
377 .def(py::init<std::string, CPS::Logger::Level>())
381 py::class_<CPS::SP::Ph3::Capacitor, std::shared_ptr<CPS::SP::Ph3::Capacitor>,
383 py::multiple_inheritance())
384 .def(py::init<std::string>())
385 .def(py::init<std::string, CPS::Logger::Level>())
389 py::class_<CPS::SP::Ph3::Inductor, std::shared_ptr<CPS::SP::Ph3::Inductor>,
391 py::multiple_inheritance())
392 .def(py::init<std::string>())
393 .def(py::init<std::string, CPS::Logger::Level>())
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 setParameters(Matrix capacitance)
Sets model specific parameters.
void setParameters(Matrix inductance)
Sets model specific parameters.
void setParameters(Matrix resistance)
Sets model specific parameters.
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 setParameters(Real sysOmega, Real sysVoltNom, Real Pref, Real Qref)
Setter for general parameters of inverter.
void setFilterParameters(Real Lf, Real Cf, Real Rf, Real Rc)
Setter for parameters of filter.
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)
Setter for parameters of transformer.
void modifyPowerFlowBusType(PowerflowBusType powerflowBusType) override
Modify powerflow bus type.
void setParameters(Real vSetPointPerUnit)
Set parameters relevant for PF solver.
void setBaseVoltage(Real baseVoltage)
Set base voltage.
void modifyPowerFlowBusType(PowerflowBusType powerflowBusType) override
Modify powerflow bus type.
void setBaseVoltage(Real baseVoltage)
Set base voltage.
Base class for SP VBR synchronous generator model single phase.
void setBaseVoltage(Real baseVoltage)
Set base voltage.
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-Fouad...
void modifyPowerFlowBusType(PowerflowBusType powerflowBusType) override
Modify powerflow bus type.
Complex getApparentPower() const
Get Apparent power of Powerflow solution.
void setBaseVoltage(Real baseVoltage)
Set base voltage.
void setParameters(Real ratedApparentPower, Real ratedVoltage, Real setPointActivePower, Real setPointVoltage, PowerflowBusType powerflowBusType, Real setPointReactivepower=0)
Setter for synchronous generator parameters.
Synchronous generator model for transient stability analysis.
void setModelFlags(Bool convertWithOmegaMech)
Flags to modify model behavior.
void setStandardParametersPU(Real nomPower, Real nomVolt, Real nomFreq, Real Xpd, Real inertia, Real Rs=0, Real D=0)
Initializes the machine parameters.
Ideal Voltage source model.
void setParameters(Complex voltageRef, Real srcFreq=0.0)
Switch with variable resistance to avoid numerical oscillations, when an inductive current is suddenl...
Ideal Voltage source model.
Base class for all components that are transmitting power.
void connect(typename SimNode< Complex >::List nodes)
Sets all nodes and checks for nominal number of Nodes for this Component.