DPsim
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
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 <iomanip>
10
11#include <pybind11/complex.h>
12#include <pybind11/eigen.h>
13#include <pybind11/functional.h>
14#include <pybind11/iostream.h>
15#include <pybind11/pybind11.h>
16#include <pybind11/stl.h>
17
18#include <DPsim.h>
19
20#include <DPsimPy.h>
21
23
24namespace py = pybind11;
25using namespace pybind11::literals;
26
30 const py::handle &item) {
31 if (py::isinstance<CPS::TopologicalNode>(item))
32 sys.addNode(item.cast<CPS::TopologicalNode::Ptr>());
33 else if (py::isinstance<CPS::IdentifiedObject>(item))
35 else
36 throw py::type_error("SystemTopology.add expects a node, a component, "
37 "or a list of nodes and components");
38}
39
40PYBIND11_MODULE(dpsimpy, m) {
41 m.doc() = R"pbdoc(
42 DPsim Python bindings
43 -----------------------
44 The Python bindings provide access to most of the DPsim features implemented in C++.
45 It is possible to run powerflow, quasi-static, dynamic phasor and electromagnetic transient simulations
46 and to parameterize all components of the network from Python.
47 )pbdoc";
48
49 //Enums
50 py::enum_<CPS::Logger::Level>(m, "LogLevel")
51 .value("trace", CPS::Logger::Level::trace)
52 .value("debug", CPS::Logger::Level::debug)
53 .value("info", CPS::Logger::Level::info)
54 .value("warn", CPS::Logger::Level::warn)
55 .value("err", CPS::Logger::Level::err)
56 .value("critical", CPS::Logger::Level::critical)
57 .value("off", CPS::Logger::Level::off);
58
59 py::class_<CPS::Math>(m, "Math")
60 .def_static("single_phase_variable_to_three_phase",
62 .def_static("single_phase_parameter_to_three_phase",
64 .def_static("single_phase_power_to_three_phase",
66
67 py::enum_<DPsim::Solver::Behaviour>(m, "SolverBehaviour")
68 .value("Initialization", DPsim::Solver::Behaviour::Initialization)
69 .value("Simulation", DPsim::Solver::Behaviour::Simulation);
70
71 py::enum_<DPsim::Solver::SystemMatrixRecomputationMode>(
72 m, "SystemMatrixRecomputationMode")
75 .value("Disabled",
77
78 py::enum_<CPS::Domain>(m, "Domain")
79 .value("SP", CPS::Domain::SP)
80 .value("DP", CPS::Domain::DP)
81 .value("EMT", CPS::Domain::EMT);
82
83 py::enum_<CPS::PhaseType>(m, "PhaseType")
84 .value("A", CPS::PhaseType::A)
85 .value("B", CPS::PhaseType::B)
86 .value("C", CPS::PhaseType::C)
87 .value("ABC", CPS::PhaseType::ABC)
88 .value("Single", CPS::PhaseType::Single)
89 .value("DC", CPS::PhaseType::DC);
90
91 py::enum_<CPS::PowerflowBusType>(m, "PowerflowBusType")
92 .value("PV", CPS::PowerflowBusType::PV)
93 .value("PQ", CPS::PowerflowBusType::PQ)
94 .value("VD", CPS::PowerflowBusType::VD)
95 .value("None", CPS::PowerflowBusType::None);
96
97 py::enum_<CPS::GeneratorType>(m, "GeneratorType")
98 .value("PVNode", CPS::GeneratorType::PVNode)
99 .value("TransientStability", CPS::GeneratorType::TransientStability)
100 .value("IdealVoltageSource", CPS::GeneratorType::IdealVoltageSource)
101 .value("SG3OrderVBR", CPS::GeneratorType::SG3OrderVBR)
102 .value("SG4OrderVBR", CPS::GeneratorType::SG4OrderVBR)
103 .value("SG5OrderVBR", CPS::GeneratorType::SG5OrderVBR)
104 .value("SG6aOrderVBR", CPS::GeneratorType::SG6aOrderVBR)
105 .value("SG6bOrderVBR", CPS::GeneratorType::SG6bOrderVBR)
106 .value("FullOrderVBR", CPS::GeneratorType::FullOrderVBR)
107 .value("FullOrder", CPS::GeneratorType::FullOrder)
108 .value("NONE", CPS::GeneratorType::None);
109
110 py::enum_<CPS::CouplingMethod>(m, "CouplingMethod")
111 .value("DELAY", CPS::CouplingMethod::DELAY)
112 .value("EXTRAPOLATION_ZOH", CPS::CouplingMethod::EXTRAPOLATION_ZOH)
113 .value("EXTRAPOLATION_LINEAR", CPS::CouplingMethod::EXTRAPOLATION_LINEAR);
114
115 py::enum_<DPsim::Solver::Type>(m, "Solver")
116 .value("MNA", DPsim::Solver::Type::MNA)
117 .value("DAE", DPsim::Solver::Type::DAE)
118 .value("NRP", DPsim::Solver::Type::NRP);
119
120 py::enum_<DPsim::DirectLinearSolverImpl>(m, "DirectLinearSolverImpl")
127 .value("CUDAMagma", DPsim::DirectLinearSolverImpl::CUDAMagma);
128
129 py::enum_<DPsim::SCALING_METHOD>(m, "scaling_method")
130 .value("no_scaling", DPsim::SCALING_METHOD::NO_SCALING)
131 .value("sum_scaling", DPsim::SCALING_METHOD::SUM_SCALING)
132 .value("max_scaling", DPsim::SCALING_METHOD::MAX_SCALING);
133
134 py::enum_<DPsim::FILL_IN_REDUCTION_METHOD>(m, "fill_in_reduction_method")
139
140 py::enum_<DPsim::PARTIAL_REFACTORIZATION_METHOD>(
141 m, "partial_refactorization_method")
142 .value("no_partial_refactorization",
144 .value("factorization_path",
146 .value("refactorization_restart",
148
149 py::enum_<DPsim::USE_BTF>(m, "use_btf")
150 .value("no_btf", DPsim::USE_BTF::NO_BTF)
151 .value("do_btf", DPsim::USE_BTF::DO_BTF);
152
153 py::enum_<CPS::CSVReader::Mode>(m, "CSVReaderMode")
154 .value("AUTO", CPS::CSVReader::Mode::AUTO)
155 .value("MANUAL", CPS::CSVReader::Mode::MANUAL);
156
157 py::enum_<CPS::CSVReader::DataFormat>(m, "CSVReaderFormat")
158 .value("HHMMSS", CPS::CSVReader::DataFormat::HHMMSS)
159 .value("SECONDS", CPS::CSVReader::DataFormat::SECONDS)
160 .value("HOURS", CPS::CSVReader::DataFormat::HOURS)
161 .value("MINUTES", CPS::CSVReader::DataFormat::MINUTES);
162
163 py::enum_<DPsim::StateSpaceAnalysisFrame>(m, "StateSpaceAnalysisFrame")
166
167 py::enum_<DPsim::StateSpacePoleMapping>(m, "StateSpacePoleMapping")
169 .value("Logarithmic", DPsim::StateSpacePoleMapping::Logarithmic);
170
171 py::enum_<CPS::WindingReference>(m, "WindingReference")
172 .value("Auto", CPS::WindingReference::Auto)
173 .value("Primary", CPS::WindingReference::Primary)
174 .value("Secondary", CPS::WindingReference::Secondary)
175 .value("Tertiary", CPS::WindingReference::Tertiary);
176
177 m.attr("RMS3PH_TO_PEAK1PH") = RMS3PH_TO_PEAK1PH;
178 m.attr("PEAK1PH_TO_RMS3PH") = PEAK1PH_TO_RMS3PH;
179 m.attr("DOUBLE_EPSILON") = DOUBLE_EPSILON;
180
181 addAttributes(m);
182
183 py::class_<DPsim::DirectLinearSolverConfiguration>(
184 m, "DirectLinearSolverConfiguration")
185 .def(py::init<>())
186 .def("set_fill_in_reduction_method",
188 .def("set_scaling_method",
190 .def("set_partial_refactorization_method",
192 setPartialRefactorizationMethod)
194 .def("get_scaling_method",
196 .def("get_fill_in_reduction_method",
198 .def("get_partial_refactorization_method",
200 getPartialRefactorizationMethod)
202
203 py::class_<DPsim::MNAStateSpaceExtractor>(m, "MNAStateSpaceExtractor")
204 .def("is_initialized", &DPsim::MNAStateSpaceExtractor::isInitialized)
205 .def("get_state_count", &DPsim::MNAStateSpaceExtractor::getStateCount)
206 .def("get_time_step", &DPsim::MNAStateSpaceExtractor::getTimeStep)
207 .def("get_discrete_state_matrix",
209 py::return_value_policy::reference_internal);
210
211 py::class_<DPsim::StateSpaceModalAnalysis>(m, "StateSpaceModalAnalysis")
212 .def(py::init<const DPsim::MNAStateSpaceExtractor &>(),
213 py::keep_alive<1, 2>())
214 .def("set_analysis_frame",
216 .def("set_global_dq0_frame",
218 "theta0"_a = 0.0)
219 .def("set_pole_mapping", &DPsim::StateSpaceModalAnalysis::setPoleMapping)
221 .def("get_discrete_eigenvalues",
223 py::return_value_policy::reference_internal)
224 .def("get_continuous_eigenvalues",
226 py::return_value_policy::reference_internal)
227 .def("get_right_eigenvectors",
229 py::return_value_policy::reference_internal)
230 .def("get_left_eigenvectors",
232 py::return_value_policy::reference_internal)
233 .def("get_participation_factors",
235 py::return_value_policy::reference_internal)
236 .def("get_state_names", &DPsim::StateSpaceModalAnalysis::getStateNames,
237 py::return_value_policy::reference_internal);
238
239 py::class_<DPsim::Simulation>(m, "Simulation")
240 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
241 "loglevel"_a = CPS::Logger::Level::off)
242 .def("name", &DPsim::Simulation::name)
243 .def("set_time_step", &DPsim::Simulation::setTimeStep)
244 .def("set_final_time", &DPsim::Simulation::setFinalTime)
245 .def("add_logger", &DPsim::Simulation::addLogger)
246 .def("set_system", &DPsim::Simulation::setSystem)
247 .def("run", &DPsim::Simulation::run)
248 .def("set_solver", &DPsim::Simulation::setSolverType)
249 .def("set_pf_keep_last_solution",
251 .def("get_pf_keep_last_solution",
253 .def("set_pf_base_apparent_power_fallback",
255 .def("get_pf_base_apparent_power_fallback",
257 .def("set_pf_max_iterations", &DPsim::Simulation::setPFMaxIterations)
258 .def("get_pf_max_iterations", &DPsim::Simulation::getPFMaxIterations)
259 .def("set_pf_solver_use_sparse", &DPsim::Simulation::setPFSolverUseSparse)
260 .def("get_pf_solver_use_sparse", &DPsim::Simulation::getPFSolverUseSparse)
261 .def("set_pf_solver_enforce_q_limits",
263 .def("get_pf_solver_enforce_q_limits",
265 .def("set_pf_solver_base_voltage_loose_tolerance",
267 .def("get_pf_solver_base_voltage_loose_tolerance",
269 .def("set_pf_solver_base_voltage_strict_tolerance",
271 .def("get_pf_solver_base_voltage_strict_tolerance",
273 .def("set_domain", &DPsim::Simulation::setDomain)
274 .def("start", &DPsim::Simulation::start)
275 .def("next", &DPsim::Simulation::next)
276 .def("stop", &DPsim::Simulation::stop)
277 .def("get_idobj_attr", &DPsim::Simulation::getIdObjAttribute, "comp"_a,
278 "attr"_a)
279 .def("add_interface", &DPsim::Simulation::addInterface, "interface"_a)
280 .def("log_idobj_attribute", &DPsim::Simulation::logIdObjAttribute,
281 "comp"_a, "attr"_a)
282 .def("log_attribute", &DPsim::Simulation::logAttribute, "name"_a,
283 "attr"_a)
284 .def("do_init_from_nodes_and_terminals",
286 .def("set_system_matrix_recomputation_mode",
288 .def("do_system_matrix_recomputation",
290 .def("do_state_space_extraction",
292 py::arg_v("value", true, "True"))
293 .def("get_state_space_extractor",
294 &DPsim::Simulation::getStateSpaceExtractor, "solver_index"_a = 0,
295 py::return_value_policy::reference_internal)
296 .def("do_steady_state_init", &DPsim::Simulation::doSteadyStateInit)
297 .def("set_steady_state_init_acc_limit",
299 .def("set_steady_state_init_time_limit",
301 .def("do_frequency_parallelization",
303 .def("do_split_subnets", &DPsim::Simulation::doSplitSubnets)
304 .def("set_tearing_components", &DPsim::Simulation::setTearingComponents)
305 .def("add_event", &DPsim::Simulation::addEvent)
306 .def("set_solver_component_behaviour",
308 .def("set_direct_solver_implementation",
310 .def("set_direct_linear_solver_configuration",
312 .def("log_lu_times", &DPsim::Simulation::logLUTimes);
313
314#ifdef WITH_RT
315 py::class_<DPsim::RealTimeSimulation, DPsim::Simulation>(m,
316 "RealTimeSimulation")
317 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
318 "loglevel"_a = CPS::Logger::Level::info)
320 .def("set_time_step", &DPsim::RealTimeSimulation::setTimeStep)
321 .def("set_final_time", &DPsim::RealTimeSimulation::setFinalTime)
322 .def("add_logger", &DPsim::RealTimeSimulation::addLogger)
323 .def("set_system", &DPsim::RealTimeSimulation::setSystem)
324 .def("run",
325 static_cast<void (DPsim::RealTimeSimulation::*)(CPS::Int startIn)>(
328 .def("set_domain", &DPsim::RealTimeSimulation::setDomain);
329#endif
330
331 py::class_<CPS::SystemTopology, std::shared_ptr<CPS::SystemTopology>>(
332 m, "SystemTopology")
337 .def(py::init<CPS::Real>())
338 .def("add_component", &DPsim::SystemTopology::addComponent)
339 .def("add_component", &DPsim::SystemTopology::addComponents)
340 .def("add_node", &DPsim::SystemTopology::addNode)
341 // Deprecated alias for add_component/add_node, kept so that scripts
342 // written before the rename keep working
343 .def(
344 "add",
345 [](DPsim::SystemTopology &sys, const py::object &obj) {
346 if (PyErr_WarnEx(PyExc_DeprecationWarning,
347 "SystemTopology.add is deprecated; use "
348 "add_component for components and add_node "
349 "for nodes instead.",
350 1) == -1)
351 throw py::error_already_set();
352
353 if (py::isinstance<py::list>(obj) ||
354 py::isinstance<py::tuple>(obj)) {
355 for (const py::handle &item : obj)
356 systemTopologyAddSingle(sys, item);
357 } else {
358 systemTopologyAddSingle(sys, obj);
359 }
360 },
361 "Deprecated alias for add_component and add_node.")
362 .def("node", py::overload_cast<std::string_view>(
364 .def("node", py::overload_cast<CPS::UInt>(
366 .def("connect_component",
367 py::overload_cast<CPS::SimPowerComp<CPS::Real>::Ptr,
370 .def("connect_component",
371 py::overload_cast<CPS::SimPowerComp<CPS::Complex>::Ptr,
374 .def("component",
376 .def("add_tear_component", &DPsim::SystemTopology::addTearComponent)
377#ifdef WITH_GRAPHVIZ
378 .def("_repr_svg_", &DPsim::SystemTopology::render)
379 .def("render_to_file", &DPsim::SystemTopology::renderToFile)
380#endif
381 .def_readwrite("nodes", &DPsim::SystemTopology::mNodes)
382 .def_readwrite("components", &DPsim::SystemTopology::mComponents)
383 .def_property_readonly("components_at_node",
384 [](DPsim::SystemTopology &sys) {
385 // Derived view: rebuild before every read (see #635)
387 return sys.mComponentsAtNode;
388 })
389 .def_readonly("tear_components", &DPsim::SystemTopology::mTearComponents)
390 .def("list_idobjects", &DPsim::SystemTopology::listIdObjects)
391 .def("init_with_powerflow", &DPsim::SystemTopology::initWithPowerflow,
392 "systemPF"_a, "domain"_a)
393 .def("add_components", &DPsim::SystemTopology::addComponents)
394 .def("remove_component", &DPsim::SystemTopology::removeComponent)
395 .def("remove_node", &DPsim::SystemTopology::removeNode);
396
397 py::class_<DPsim::Interface, std::shared_ptr<DPsim::Interface>>(m,
398 "Interface");
399
401 std::shared_ptr<DPsim::DataLoggerInterface>>(m,
402 "DataLoggerInterface")
403 .def("log_attribute",
404 py::overload_cast<const CPS::String &, CPS::AttributeBase::Ptr,
407 "name"_a, "attr"_a, "max_cols"_a = 0, "max_rows"_a = 0)
409 .def("log_attribute",
410 py::overload_cast<const std::vector<CPS::String> &,
413 "names"_a, "attr"_a)
415 .def("log_attribute",
417 const std::vector<CPS::String> &names, const CPS::String &attr,
418 const CPS::IdentifiedObject &comp) {
419 logger.logAttribute(names, comp.attribute(attr));
420 });
421
423 std::shared_ptr<DPsim::DataLogger>>(m, "Logger")
424 .def(py::init<std::string>())
425 .def_static("set_log_dir", &CPS::Logger::setLogDir)
426 .def_static("get_log_dir", &CPS::Logger::logDir)
427 .def("log_attribute",
428 py::overload_cast<const CPS::String &, CPS::AttributeBase::Ptr,
431 "name"_a, "attr"_a, "max_cols"_a = 0, "max_rows"_a = 0)
433 .def("log_attribute",
434 py::overload_cast<const std::vector<CPS::String> &,
437 "names"_a, "attr"_a)
439 .def(
440 "log_attribute",
441 [](DPsim::DataLogger &logger, const CPS::String &name,
442 const CPS::String &attr, const CPS::IdentifiedObject &comp,
443 CPS::UInt rowsMax, CPS::UInt colsMax) {
444 logger.logAttribute(name, comp.attribute(attr), rowsMax, colsMax);
445 },
446 "name"_a, "attr"_a, "comp"_a, "rows_max"_a = 0, "cols_max"_a = 0)
448 .def("log_attribute",
449 [](DPsim::DataLogger &logger, const std::vector<CPS::String> &names,
450 const CPS::String &attr, const CPS::IdentifiedObject &comp) {
451 logger.logAttribute(names, comp.attribute(attr));
452 });
453#ifdef WITH_RT
455 std::shared_ptr<DPsim::RealTimeDataLogger>>(m,
456 "RealTimeDataLogger")
457
458 .def(py::init([](py::object filename, DPsim::Real final_time,
459 DPsim::Real time_step) {
460 py::object fspath =
461 py::module_::import("os").attr("fspath")(filename);
462 std::string s = py::cast<std::string>(fspath);
463 std::filesystem::path p(s);
464 return std::make_shared<DPsim::RealTimeDataLogger>(p, final_time,
465 time_step);
466 }),
467 "filename"_a, "final_time"_a, "time_step"_a)
468
469 .def(py::init([](py::object filename, std::size_t row_number) {
470 py::object fspath =
471 py::module_::import("os").attr("fspath")(filename);
472 std::string s = py::cast<std::string>(fspath);
473 std::filesystem::path p(s);
474 return std::make_shared<DPsim::RealTimeDataLogger>(p, row_number);
475 }),
476 "filename"_a, "row_number"_a)
477
478 .def("log_attribute",
479 py::overload_cast<const CPS::String &, CPS::AttributeBase::Ptr,
482 "name"_a, "attr"_a, "max_cols"_a = 0, "max_rows"_a = 0)
483
484 .def("log_attribute",
485 py::overload_cast<const std::vector<CPS::String> &,
488 "names"_a, "attr"_a)
489
490 .def(
491 "log_attribute",
492 [](DPsim::RealTimeDataLogger &logger, const CPS::String &name,
493 const CPS::String &attr, const CPS::IdentifiedObject &comp,
494 CPS::UInt rowsMax, CPS::UInt colsMax) {
495 logger.logAttribute(name, comp.attribute(attr), rowsMax, colsMax);
496 },
497 "name"_a, "attr"_a, "comp"_a, "rows_max"_a = 0, "cols_max"_a = 0)
498
499 .def(
500 "log_attribute",
501 [](DPsim::RealTimeDataLogger &logger,
502 const std::vector<CPS::String> &names, const CPS::String &attr,
503 const CPS::IdentifiedObject &comp) {
504 logger.logAttribute(names, comp.attribute(attr));
505 },
506 "names"_a, "attr"_a, "comp"_a);
507#endif
508
509 py::class_<CPS::IdentifiedObject, std::shared_ptr<CPS::IdentifiedObject>>(
510 m, "IdentifiedObject")
511 .def("name", &CPS::IdentifiedObject::name)
515 .def("attr", &CPS::IdentifiedObject::attribute, "name"_a)
516 .def("print_attribute_list", &printAttributes)
517 .def("print_attribute", &printAttribute, "attribute_name"_a)
518 .def("__str__", &getAttributeList);
519
520#ifdef WITH_CIM
521 py::enum_<CPS::CIM::Reader::VoltageTargetUnit>(m,
522 "CIMReaderVoltageTargetUnit")
526
527 py::class_<CPS::CIM::Reader>(m, "CIMReader")
528 .def(py::init<std::string, CPS::Logger::Level, CPS::Logger::Level>(),
529 "name"_a, "loglevel"_a = CPS::Logger::Level::info,
530 "comploglevel"_a = CPS::Logger::Level::off)
531 .def("loadCIM", (CPS::SystemTopology(CPS::CIM::Reader::*)(
532 CPS::Real, const std::list<CPS::String> &,
535 .def("set_extnet_voltage_target_unit",
537#endif
538
539 py::class_<CPS::CSVReader>(m, "CSVReader")
540 .def(py::init<std::string, const std::string &,
541 std::map<std::string, std::string> &, CPS::Logger::Level>())
542 .def("assignLoadProfile", &CPS::CSVReader::assignLoadProfile);
543
544 //Base Classes
545
546 py::class_<CPS::TopologicalPowerComp,
547 std::shared_ptr<CPS::TopologicalPowerComp>, CPS::IdentifiedObject>(
548 m, "TopologicalPowerComp");
549 py::class_<CPS::SimPowerComp<CPS::Complex>,
550 std::shared_ptr<CPS::SimPowerComp<CPS::Complex>>,
551 CPS::TopologicalPowerComp>(m, "SimPowerCompComplex")
553 .def("set_intf_current", &CPS::SimPowerComp<CPS::Complex>::setIntfCurrent)
554 .def("set_intf_voltage", &CPS::SimPowerComp<CPS::Complex>::setIntfVoltage)
555 .def("get_terminal", &CPS::SimPowerComp<CPS::Complex>::terminal,
556 "index"_a);
557 py::class_<CPS::SimPowerComp<CPS::Real>,
558 std::shared_ptr<CPS::SimPowerComp<CPS::Real>>,
559 CPS::TopologicalPowerComp>(m, "SimPowerCompReal")
561 .def("set_intf_current", &CPS::SimPowerComp<CPS::Real>::setIntfCurrent)
562 .def("set_intf_voltage", &CPS::SimPowerComp<CPS::Real>::setIntfVoltage)
563 .def("get_terminal", &CPS::SimPowerComp<CPS::Real>::terminal, "index"_a);
564 py::class_<CPS::TopologicalNode, std::shared_ptr<CPS::TopologicalNode>,
565 CPS::IdentifiedObject>(m, "TopologicalNode")
566 .def("initial_single_voltage",
568 "phase_type"_a = CPS::PhaseType::Single);
569
570 py::class_<CPS::TopologicalTerminal,
571 std::shared_ptr<CPS::TopologicalTerminal>, CPS::IdentifiedObject>(
572 m, "TopologicalTerminal")
573 .def("set_power",
574 py::overload_cast<CPS::Complex>(&CPS::TopologicalTerminal::setPower))
575 .def("set_power", py::overload_cast<CPS::MatrixComp>(
577
578 py::class_<CPS::SimTerminal<CPS::Complex>,
579 std::shared_ptr<CPS::SimTerminal<CPS::Complex>>,
580 CPS::TopologicalTerminal>(m, "SimTerminalComplex");
581 py::class_<CPS::SimTerminal<CPS::Real>,
582 std::shared_ptr<CPS::SimTerminal<CPS::Real>>,
583 CPS::TopologicalTerminal>(m, "SimTerminalReal");
584
585 //Events
586 py::module mEvent = m.def_submodule("event", "events");
587 py::class_<DPsim::Event, std::shared_ptr<DPsim::Event>>(mEvent, "Event");
588 py::class_<DPsim::SwitchEvent, std::shared_ptr<DPsim::SwitchEvent>,
589 DPsim::Event>(mEvent, "SwitchEvent", py::multiple_inheritance())
590 .def(py::init<CPS::Real, const std::shared_ptr<CPS::Base::Ph1::Switch>,
591 CPS::Bool>());
592 py::class_<DPsim::SwitchEvent3Ph, std::shared_ptr<DPsim::SwitchEvent3Ph>,
593 DPsim::Event>(mEvent, "SwitchEvent3Ph", py::multiple_inheritance())
594 .def(py::init<CPS::Real, const std::shared_ptr<CPS::Base::Ph3::Switch>,
595 CPS::Bool>());
596
597 //Components
598 py::module mBase = m.def_submodule("base", "base models");
599 addBaseComponents(mBase);
600
601 py::module mDP = m.def_submodule("dp", "dynamic phasor models");
602 addDPComponents(mDP);
603
604 py::module mEMT = m.def_submodule("emt", "electromagnetic-transient models");
605 addEMTComponents(mEMT);
606
607 py::module mSP = m.def_submodule("sp", "static phasor models");
608 mSP.attr("SimNode") = mDP.attr("SimNode");
609 addSPComponents(mSP);
610
611 py::module mSignal = m.def_submodule("signal", "signal models");
612 addSignalComponents(mSignal);
613
614#ifdef VERSION_INFO
615 m.attr("__version__") = VERSION_INFO;
616#else
617 m.attr("__version__") = "dev";
618#endif
619}
void addAttributes(py::module_ m)
void addBaseComponents(py::module_ mBase)
void addDPComponents(py::module_ mDP)
void addEMTComponents(py::module_ mEMT)
void addSPComponents(py::module_ mSP)
void addSignalComponents(py::module_ mSignal)
AttributePointer< AttributeBase > Ptr
Definition Attribute.h:122
void setExtnetVoltageTargetUnit(VoltageTargetUnit unit)
Definition Reader.cpp:62
SystemTopology loadCIM(Real systemFrequency, const fs::path &filename, Domain domain=Domain::DP, PhaseType phase=PhaseType::Single, GeneratorType genType=GeneratorType::None)
Parses data from CIM files into the CPS data structure.
Definition Reader.cpp:249
void assignLoadProfile(SystemTopology &sys, Real start_time=-1, Real time_step=1, Real end_time=-1, CSVReader::Mode mode=CSVReader::Mode::AUTO, CSVReader::DataFormat format=CSVReader::DataFormat::SECONDS)
assign load profile to corresponding load object
std::shared_ptr< IdentifiedObject > Ptr
std::vector< Ptr > List
AttributeBase::Ptr attribute(const String &name) const
Return pointer to an attribute.
spdlog::level::level_enum Level
Definition Logger.h:33
static void setLogDir(String path)
Set env variable CPS_LOG_DIR and overwrite.
Definition Logger.cpp:88
static String logDir()
Definition Logger.cpp:81
static Matrix singlePhasePowerToThreePhase(Real power)
To convert single phase power to symmetrical three phase.
static Matrix singlePhaseParameterToThreePhase(Real parameter)
To convert single phase parameters to symmetrical three phase ones.
static MatrixComp singlePhaseVariableToThreePhase(Complex var_1ph)
To convert single phase complex variables (voltages, currents) to symmetrical three phase ones.
std::vector< Ptr > List
Definition SimNode.h:33
SimTerminal< VarType >::Ptr terminal(UInt index)
Get pointer to Terminal.
void connect(typename SimNode< VarType >::List nodes)
Sets all nodes and checks for nominal number of Nodes for this Component.
void setIntfVoltage(MatrixVar< VarType > voltage)
void setIntfCurrent(MatrixVar< VarType > current)
std::shared_ptr< SimPowerComp< VarType > > Ptr
void removeNode(const String &name)
Remove node and all components connected to it.
IdentifiedObject::List mComponents
List of network components.
std::shared_ptr< Type > node(UInt index)
Returns TopologicalNode by index in node list.
void initWithPowerflow(const SystemTopology &systemPF, CPS::Domain domain)
Initialize nodes and SG power from PowerFlow.
void removeComponent(const String &name)
Remove system component.
void addNode(TopologicalNode::Ptr topNode)
Adds node and initializes frequencies.
std::map< String, String, std::less<> > listIdObjects() const
void addTearComponent(IdentifiedObject::Ptr component)
Adds component and initializes frequencies.
std::shared_ptr< Type > component(const String &name)
Returns Component by name.
TopologicalNode::List mNodes
List of network nodes.
void addComponents(const IdentifiedObject::List &components)
Add multiple components.
void connectComponentToNodes(typename SimPowerComp< VarType >::Ptr component, typename SimNode< VarType >::List simNodes)
Connect component to simNodes.
void addComponent(IdentifiedObject::Ptr component)
Adds component and initializes frequencies.
IdentifiedObject::List mTearComponents
std::map< TopologicalNode::Ptr, TopologicalPowerComp::List > mComponentsAtNode
Map of network components connected to network nodes.
std::vector< Ptr > List
std::shared_ptr< TopologicalNode > Ptr
Complex initialSingleVoltage(PhaseType phaseType=PhaseType::Single)
virtual void logAttribute(const String &name, CPS::AttributeBase::Ptr attr, UInt rowsMax=0, UInt colsMax=0)
void setFillInReductionMethod(FILL_IN_REDUCTION_METHOD fillInReductionMethod)
FILL_IN_REDUCTION_METHOD getFillInReductionMethod() const
const Matrix & getDiscreteStateMatrix() const
Extending Simulation class by real-time functionality.
void run(const Timer::StartClock::duration &startIn=std::chrono::seconds(1))
void setDirectLinearSolverImplementation(DirectLinearSolverImpl directImpl)
Definition Simulation.h:208
void doFrequencyParallelization(Bool value)
Compute phasors of different frequencies in parallel.
Definition Simulation.h:238
void logIdObjAttribute(const String &comp, const String &attr)
void setSteadStIniAccLimit(Real v)
set steady state initialization accuracy limit
Definition Simulation.h:265
CPS::UInt getPFMaxIterations() const
void logLUTimes()
Write LU decomposition times measurements to log file.
void setSolverType(Solver::Type solverType=Solver::Type::MNA)
Definition Simulation.h:200
void setSystem(const CPS::SystemTopology &system)
Definition Simulation.h:192
String name() const
Definition Simulation.h:339
void setFinalTime(Real finalTime)
Definition Simulation.h:196
void setPFSolverBaseVoltageLooseTolerance(Real tolerance)
void setSystemMatrixRecomputationMode(Solver::SystemMatrixRecomputationMode mode)
Set the system-matrix recomputation mode.
Definition Simulation.h:241
void setSteadStIniTimeLimit(Real v)
set steady state initialization time limit
Definition Simulation.h:263
void setTimeStep(Real timeStep)
Definition Simulation.h:194
void setTearingComponents(CPS::IdentifiedObject::List tearComponents=CPS::IdentifiedObject::List())
Definition Simulation.h:229
void setPFKeepLastSolution(Bool value)
Real next()
Run until next time step.
void setDirectLinearSolverConfiguration(const DirectLinearSolverConfiguration &configuration)
Definition Simulation.h:212
Bool getPFSolverEnforceReactiveLimits() const
void addLogger(DataLoggerInterface::Ptr logger)
Add a new data logger.
Definition Simulation.h:316
void doInitFromNodesAndTerminals(Bool f=true)
Definition Simulation.h:221
void setPFMaxIterations(CPS::UInt value)
void setPFBaseApparentPowerFallback(Real value)
Bool getPFSolverUseSparse() const
void doSplitSubnets(Bool splitSubnets=true)
Definition Simulation.h:225
void setSolverAndComponentBehaviour(Solver::Behaviour behaviour)
set solver and component to initialization or simulation behaviour
Definition Simulation.h:204
void setDomain(CPS::Domain domain=CPS::Domain::DP)
Definition Simulation.h:198
Real getPFBaseApparentPowerFallback() const
Bool getPFKeepLastSolution() const
void setPFSolverUseSparse(Bool value)
void setPFSolverEnforceReactiveLimits(Bool value)
Real getPFSolverBaseVoltageLooseTolerance() const
CPS::AttributeBase::Ptr getIdObjAttribute(const String &comp, const String &attr)
CHECK: Can these be deleted? getIdObjAttribute + "**attr =" should suffice.
void addInterface(Interface::Ptr eint)
Definition Simulation.h:328
void start()
Start simulation without advancing in time.
void doSteadyStateInit(Bool f)
activate steady state initialization
Definition Simulation.h:261
void addEvent(Event::Ptr e)
Schedule an event in the simulation.
Definition Simulation.h:314
void doStateSpaceExtraction(Bool value=true)
Enable extraction of the MNA-coupled discrete-time state matrix.
Definition Simulation.h:252
void run()
Run simulation until total time is elapsed.
void setPFSolverBaseVoltageStrictTolerance(Real tolerance)
void logAttribute(String name, CPS::AttributeBase::Ptr attr)
CHECK: Can we store the attribute name / UID intrinsically inside the attribute?
const MNAStateSpaceExtractor & getStateSpaceExtractor(UInt solverIndex=0) const
Real getPFSolverBaseVoltageStrictTolerance() const
void stop()
Stop simulation including scheduler and interfaces.
void doSystemMatrixRecomputation(Bool value)
Definition Simulation.h:246
@ Initialization
Definition Solver.h:40
@ Enabled
Always enable system-matrix recomputation.
Definition Solver.h:47
@ Auto
Select the mode automatically based on the system topology.
Definition Solver.h:45
@ Disabled
Always disable system-matrix recomputation.
Definition Solver.h:49
void setAnalysisFrame(StateSpaceAnalysisFrame frame)
const std::vector< String > & getStateNames() const
const CPS::VectorComp & getContinuousEigenvalues() const
const CPS::VectorComp & getDiscreteEigenvalues() const
Eigenvalues of the extracted discrete-time state matrix in the selected analysis frame.
void setPoleMapping(StateSpacePoleMapping mapping)
void update()
Update modal quantities from the current extracted state matrix.
void setGlobalDq0Frame(Real omega, Real theta0=0.0)
const CPS::MatrixComp & getLeftEigenvectors() const
const CPS::MatrixComp & getRightEigenvectors() const
const CPS::MatrixComp & getParticipationFactors() const
#define RMS3PH_TO_PEAK1PH
Definition Definitions.h:50
#define PEAK1PH_TO_RMS3PH
Definition Definitions.h:51
#define DOUBLE_EPSILON
Definition Definitions.h:14
PYBIND11_DECLARE_HOLDER_TYPE(T, CPS::AttributePointer< T >)
static void systemTopologyAddSingle(DPsim::SystemTopology &sys, const py::handle &item)
Definition main.cpp:29
PYBIND11_MODULE(dpsimpy, m)
Definition main.cpp:40
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:79
std::string String
Definition Definitions.h:63
double Real
Definition Definitions.h:60
int Int
Definition Definitions.h:59
bool Bool
Definition Definitions.h:62
GeneratorType
unsigned int UInt
Definition Definitions.h:58
CPS::Real Real
Definition Definitions.h:18
CPS::SystemTopology SystemTopology
Definition DPsim.h:34
void printAttribute(CPS::IdentifiedObject &obj, std::string attrName)
Definition Utils.cpp:74
std::string getAttributeList(CPS::IdentifiedObject &obj)
Definition Utils.cpp:13
void printAttributes(CPS::IdentifiedObject &obj)
Definition Utils.cpp:70