DPsim
Loading...
Searching...
No Matches
main.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 <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
22PYBIND11_DECLARE_HOLDER_TYPE(T, CPS::AttributePointer<T>);
23
24namespace py = pybind11;
25using namespace pybind11::literals;
26
27PYBIND11_MODULE(dpsimpy, m) {
28 m.doc() = R"pbdoc(
29 DPsim Python bindings
30 -----------------------
31 The Python bindings provide access to most of the DPsim features implemented in C++.
32 It is possible to run powerflow, quasi-static, dynamic phasor and electromagnetic transient simulations
33 and to parameterize all components of the network from Python.
34 )pbdoc";
35
36 //Enums
37 py::enum_<CPS::Logger::Level>(m, "LogLevel")
38 .value("trace", CPS::Logger::Level::trace)
39 .value("debug", CPS::Logger::Level::debug)
40 .value("info", CPS::Logger::Level::info)
41 .value("warn", CPS::Logger::Level::warn)
42 .value("err", CPS::Logger::Level::err)
43 .value("critical", CPS::Logger::Level::critical)
44 .value("off", CPS::Logger::Level::off);
45
46 py::class_<CPS::Math>(m, "Math")
47 .def_static("single_phase_variable_to_three_phase",
49 .def_static("single_phase_parameter_to_three_phase",
51 .def_static("single_phase_power_to_three_phase",
53
54 py::enum_<DPsim::Solver::Behaviour>(m, "SolverBehaviour")
55 .value("Initialization", DPsim::Solver::Behaviour::Initialization)
56 .value("Simulation", DPsim::Solver::Behaviour::Simulation);
57
58 py::enum_<CPS::Domain>(m, "Domain")
59 .value("SP", CPS::Domain::SP)
60 .value("DP", CPS::Domain::DP)
61 .value("EMT", CPS::Domain::EMT);
62
63 py::enum_<CPS::PhaseType>(m, "PhaseType")
64 .value("A", CPS::PhaseType::A)
65 .value("B", CPS::PhaseType::B)
66 .value("C", CPS::PhaseType::C)
67 .value("ABC", CPS::PhaseType::ABC)
68 .value("Single", CPS::PhaseType::Single);
69
70 py::enum_<CPS::PowerflowBusType>(m, "PowerflowBusType")
71 .value("PV", CPS::PowerflowBusType::PV)
72 .value("PQ", CPS::PowerflowBusType::PQ)
73 .value("VD", CPS::PowerflowBusType::VD)
74 .value("None", CPS::PowerflowBusType::None);
75
76 py::enum_<CPS::GeneratorType>(m, "GeneratorType")
77 .value("PVNode", CPS::GeneratorType::PVNode)
78 .value("TransientStability", CPS::GeneratorType::TransientStability)
79 .value("IdealVoltageSource", CPS::GeneratorType::IdealVoltageSource)
80 .value("SG3OrderVBR", CPS::GeneratorType::SG3OrderVBR)
81 .value("SG4OrderVBR", CPS::GeneratorType::SG4OrderVBR)
82 .value("SG5OrderVBR", CPS::GeneratorType::SG5OrderVBR)
83 .value("SG6aOrderVBR", CPS::GeneratorType::SG6aOrderVBR)
84 .value("SG6bOrderVBR", CPS::GeneratorType::SG6bOrderVBR)
85 .value("FullOrderVBR", CPS::GeneratorType::FullOrderVBR)
86 .value("FullOrder", CPS::GeneratorType::FullOrder)
87 .value("NONE", CPS::GeneratorType::None);
88
89 py::enum_<DPsim::Solver::Type>(m, "Solver")
90 .value("MNA", DPsim::Solver::Type::MNA)
91 .value("DAE", DPsim::Solver::Type::DAE)
92 .value("NRP", DPsim::Solver::Type::NRP);
93
94 py::enum_<DPsim::DirectLinearSolverImpl>(m, "DirectLinearSolverImpl")
95 .value("Undef", DPsim::DirectLinearSolverImpl::Undef)
96 .value("DenseLU", DPsim::DirectLinearSolverImpl::DenseLU)
97 .value("SparseLU", DPsim::DirectLinearSolverImpl::SparseLU)
98 .value("KLU", DPsim::DirectLinearSolverImpl::KLU)
99 .value("CUDADense", DPsim::DirectLinearSolverImpl::CUDADense)
100 .value("CUDASparse", DPsim::DirectLinearSolverImpl::CUDASparse)
101 .value("CUDAMagma", DPsim::DirectLinearSolverImpl::CUDAMagma);
102
103 py::enum_<DPsim::SCALING_METHOD>(m, "scaling_method")
104 .value("no_scaling", DPsim::SCALING_METHOD::NO_SCALING)
105 .value("sum_scaling", DPsim::SCALING_METHOD::SUM_SCALING)
106 .value("max_scaling", DPsim::SCALING_METHOD::MAX_SCALING);
107
108 py::enum_<DPsim::FILL_IN_REDUCTION_METHOD>(m, "fill_in_reduction_method")
109 .value("amd", DPsim::FILL_IN_REDUCTION_METHOD::AMD)
110 .value("amd_nv", DPsim::FILL_IN_REDUCTION_METHOD::AMD_NV)
111 .value("amd_ra", DPsim::FILL_IN_REDUCTION_METHOD::AMD_RA)
112 .value("colamd", DPsim::FILL_IN_REDUCTION_METHOD::COLAMD);
113
114 py::enum_<DPsim::PARTIAL_REFACTORIZATION_METHOD>(
115 m, "partial_refactorization_method")
116 .value("no_partial_refactorization",
117 DPsim::PARTIAL_REFACTORIZATION_METHOD::NO_PARTIAL_REFACTORIZATION)
118 .value("factorization_path",
119 DPsim::PARTIAL_REFACTORIZATION_METHOD::FACTORIZATION_PATH)
120 .value("refactorization_restart",
121 DPsim::PARTIAL_REFACTORIZATION_METHOD::REFACTORIZATION_RESTART);
122
123 py::enum_<DPsim::USE_BTF>(m, "use_btf")
124 .value("no_btf", DPsim::USE_BTF::NO_BTF)
125 .value("do_btf", DPsim::USE_BTF::DO_BTF);
126
127 py::enum_<CPS::CSVReader::Mode>(m, "CSVReaderMode")
128 .value("AUTO", CPS::CSVReader::Mode::AUTO)
129 .value("MANUAL", CPS::CSVReader::Mode::MANUAL);
130
131 py::enum_<CPS::CSVReader::DataFormat>(m, "CSVReaderFormat")
132 .value("HHMMSS", CPS::CSVReader::DataFormat::HHMMSS)
133 .value("SECONDS", CPS::CSVReader::DataFormat::SECONDS)
134 .value("HOURS", CPS::CSVReader::DataFormat::HOURS)
135 .value("MINUTES", CPS::CSVReader::DataFormat::MINUTES);
136
137 py::enum_<DPsim::StateSpaceAnalysisFrame>(m, "StateSpaceAnalysisFrame")
138 .value("Native", DPsim::StateSpaceAnalysisFrame::Native)
139 .value("GlobalDQ0", DPsim::StateSpaceAnalysisFrame::GlobalDQ0);
140
141 m.attr("RMS3PH_TO_PEAK1PH") = RMS3PH_TO_PEAK1PH;
142 m.attr("PEAK1PH_TO_RMS3PH") = PEAK1PH_TO_RMS3PH;
143 m.attr("P_SNUB_TRANSFORMER") = P_SNUB_TRANSFORMER;
144 m.attr("Q_SNUB_TRANSFORMER") = Q_SNUB_TRANSFORMER;
145
146 addAttributes(m);
147
148 py::class_<DPsim::DirectLinearSolverConfiguration>(
149 m, "DirectLinearSolverConfiguration")
150 .def(py::init<>())
151 .def("set_fill_in_reduction_method",
152 &DPsim::DirectLinearSolverConfiguration::setFillInReductionMethod)
153 .def("set_scaling_method",
154 &DPsim::DirectLinearSolverConfiguration::setScalingMethod)
155 .def("set_partial_refactorization_method",
157 setPartialRefactorizationMethod)
158 .def("set_btf", &DPsim::DirectLinearSolverConfiguration::setBTF)
159 .def("get_scaling_method",
160 &DPsim::DirectLinearSolverConfiguration::getScalingMethod)
161 .def("get_fill_in_reduction_method",
162 &DPsim::DirectLinearSolverConfiguration::getFillInReductionMethod)
163 .def("get_partial_refactorization_method",
165 getPartialRefactorizationMethod)
166 .def("get_btf", &DPsim::DirectLinearSolverConfiguration::getBTF);
167
168 py::class_<DPsim::MNAStateSpaceExtractor>(m, "MNAStateSpaceExtractor")
169 .def("is_initialized", &DPsim::MNAStateSpaceExtractor::isInitialized)
170 .def("get_state_count", &DPsim::MNAStateSpaceExtractor::getStateCount)
171 .def("get_time_step", &DPsim::MNAStateSpaceExtractor::getTimeStep)
172 .def("get_discrete_state_matrix",
173 &DPsim::MNAStateSpaceExtractor::getDiscreteStateMatrix,
174 py::return_value_policy::reference_internal);
175
176 py::class_<DPsim::StateSpaceModalAnalysis>(m, "StateSpaceModalAnalysis")
177 .def(py::init<const DPsim::MNAStateSpaceExtractor &>(),
178 py::keep_alive<1, 2>())
179 .def("set_analysis_frame",
181 .def("set_global_dq0_frame",
183 "theta0"_a = 0.0)
185 .def("get_discrete_eigenvalues",
187 py::return_value_policy::reference_internal)
188 .def("get_continuous_eigenvalues",
190 py::return_value_policy::reference_internal);
191
192 py::class_<DPsim::Simulation>(m, "Simulation")
193 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
194 "loglevel"_a = CPS::Logger::Level::off)
195 .def("name", &DPsim::Simulation::name)
196 .def("set_time_step", &DPsim::Simulation::setTimeStep)
197 .def("set_final_time", &DPsim::Simulation::setFinalTime)
198 .def("add_logger", &DPsim::Simulation::addLogger)
199 .def("set_system", &DPsim::Simulation::setSystem)
200 .def("run", &DPsim::Simulation::run)
201 .def("set_solver", &DPsim::Simulation::setSolverType)
202 .def("set_pf_keep_last_solution",
203 &DPsim::Simulation::setPFKeepLastSolution)
204 .def("get_pf_keep_last_solution",
205 &DPsim::Simulation::getPFKeepLastSolution)
206 .def("set_pf_solver_use_sparse", &DPsim::Simulation::setPFSolverUseSparse)
207 .def("get_pf_solver_use_sparse", &DPsim::Simulation::getPFSolverUseSparse)
208 .def("set_domain", &DPsim::Simulation::setDomain)
209 .def("start", &DPsim::Simulation::start)
210 .def("next", &DPsim::Simulation::next)
211 .def("stop", &DPsim::Simulation::stop)
212 .def("get_idobj_attr", &DPsim::Simulation::getIdObjAttribute, "comp"_a,
213 "attr"_a)
214 .def("add_interface", &DPsim::Simulation::addInterface, "interface"_a)
215 .def("log_idobj_attribute", &DPsim::Simulation::logIdObjAttribute,
216 "comp"_a, "attr"_a)
217 .def("log_attribute", &DPsim::Simulation::logAttribute, "name"_a,
218 "attr"_a)
219 .def("do_init_from_nodes_and_terminals",
220 &DPsim::Simulation::doInitFromNodesAndTerminals)
221 .def("do_system_matrix_recomputation",
222 &DPsim::Simulation::doSystemMatrixRecomputation)
223 .def("do_state_space_extraction",
225 py::arg_v("value", true, "True"))
226 .def("get_state_space_extractor",
227 &DPsim::Simulation::getStateSpaceExtractor, "solver_index"_a = 0,
228 py::return_value_policy::reference_internal)
229 .def("do_steady_state_init", &DPsim::Simulation::doSteadyStateInit)
230 .def("do_frequency_parallelization",
232 .def("do_split_subnets", &DPsim::Simulation::doSplitSubnets)
233 .def("set_tearing_components", &DPsim::Simulation::setTearingComponents)
234 .def("add_event", &DPsim::Simulation::addEvent)
235 .def("set_solver_component_behaviour",
237 .def("set_direct_solver_implementation",
238 &DPsim::Simulation::setDirectLinearSolverImplementation)
239 .def("set_direct_linear_solver_configuration",
240 &DPsim::Simulation::setDirectLinearSolverConfiguration)
241 .def("log_lu_times", &DPsim::Simulation::logLUTimes);
242
243#ifdef WITH_RT
244 py::class_<DPsim::RealTimeSimulation, DPsim::Simulation>(m,
245 "RealTimeSimulation")
246 .def(py::init<std::string, CPS::Logger::Level>(), "name"_a,
247 "loglevel"_a = CPS::Logger::Level::info)
248 .def("name", &DPsim::RealTimeSimulation::name)
249 .def("set_time_step", &DPsim::RealTimeSimulation::setTimeStep)
250 .def("set_final_time", &DPsim::RealTimeSimulation::setFinalTime)
251 .def("add_logger", &DPsim::RealTimeSimulation::addLogger)
252 .def("set_system", &DPsim::RealTimeSimulation::setSystem)
253 .def("run",
254 static_cast<void (DPsim::RealTimeSimulation::*)(CPS::Int startIn)>(
256 .def("set_solver", &DPsim::RealTimeSimulation::setSolverType)
257 .def("set_domain", &DPsim::RealTimeSimulation::setDomain);
258#endif
259
260 py::class_<CPS::SystemTopology, std::shared_ptr<CPS::SystemTopology>>(
261 m, "SystemTopology")
262 .def(py::init<CPS::Real, CPS::TopologicalNode::List,
263 CPS::IdentifiedObject::List>())
264 .def(py::init<CPS::Real, CPS::Matrix, CPS::TopologicalNode::List,
265 CPS::IdentifiedObject::List>())
266 .def(py::init<CPS::Real>())
269 .def("node", py::overload_cast<std::string_view>(
271 .def("node", py::overload_cast<CPS::UInt>(
273 .def("connect_component",
274 py::overload_cast<CPS::SimPowerComp<CPS::Real>::Ptr,
275 CPS::SimNode<CPS::Real>::List>(
277 .def("connect_component",
278 py::overload_cast<CPS::SimPowerComp<CPS::Complex>::Ptr,
279 CPS::SimNode<CPS::Complex>::List>(
281 .def("component",
283 .def("add_tear_component", &DPsim::SystemTopology::addTearComponent)
284#ifdef WITH_GRAPHVIZ
285 .def("_repr_svg_", &DPsim::SystemTopology::render)
286 .def("render_to_file", &DPsim::SystemTopology::renderToFile)
287#endif
288 .def_readwrite("nodes", &DPsim::SystemTopology::mNodes)
289 .def_readwrite("components", &DPsim::SystemTopology::mComponents)
290 .def_readwrite("components_at_node",
292 .def_readonly("tear_components", &DPsim::SystemTopology::mTearComponents)
293 .def("list_idobjects", &DPsim::SystemTopology::listIdObjects)
294 .def("init_with_powerflow", &DPsim::SystemTopology::initWithPowerflow,
295 "systemPF"_a, "domain"_a)
296 .def("add_component", &DPsim::SystemTopology::addComponent)
297 .def("add_components", &DPsim::SystemTopology::addComponents)
298 .def("remove_component", &DPsim::SystemTopology::removeComponent);
299
300 py::class_<DPsim::Interface, std::shared_ptr<DPsim::Interface>>(m,
301 "Interface");
302
304 std::shared_ptr<DPsim::DataLoggerInterface>>(m,
305 "DataLoggerInterface")
306 .def("log_attribute",
307 py::overload_cast<const CPS::String &, CPS::AttributeBase::Ptr,
308 CPS::UInt, CPS::UInt>(
309 &DPsim::DataLoggerInterface::logAttribute),
310 "name"_a, "attr"_a, "max_cols"_a = 0, "max_rows"_a = 0)
312 .def("log_attribute",
313 py::overload_cast<const std::vector<CPS::String> &,
314 CPS::AttributeBase::Ptr>(
315 &DPsim::DataLoggerInterface::logAttribute),
316 "names"_a, "attr"_a)
318 .def("log_attribute",
320 const std::vector<CPS::String> &names, const CPS::String &attr,
321 const CPS::IdentifiedObject &comp) {
322 logger.logAttribute(names, comp.attribute(attr));
323 });
324
326 std::shared_ptr<DPsim::DataLogger>>(m, "Logger")
327 .def(py::init<std::string>())
328 .def_static("set_log_dir", &CPS::Logger::setLogDir)
329 .def_static("get_log_dir", &CPS::Logger::logDir)
330 .def("log_attribute",
331 py::overload_cast<const CPS::String &, CPS::AttributeBase::Ptr,
332 CPS::UInt, CPS::UInt>(
333 &DPsim::DataLogger::logAttribute),
334 "name"_a, "attr"_a, "max_cols"_a = 0, "max_rows"_a = 0)
336 .def("log_attribute",
337 py::overload_cast<const std::vector<CPS::String> &,
338 CPS::AttributeBase::Ptr>(
339 &DPsim::DataLogger::logAttribute),
340 "names"_a, "attr"_a)
342 .def(
343 "log_attribute",
344 [](DPsim::DataLogger &logger, const CPS::String &name,
345 const CPS::String &attr, const CPS::IdentifiedObject &comp,
346 CPS::UInt rowsMax, CPS::UInt colsMax) {
347 logger.logAttribute(name, comp.attribute(attr), rowsMax, colsMax);
348 },
349 "name"_a, "attr"_a, "comp"_a, "rows_max"_a = 0, "cols_max"_a = 0)
351 .def("log_attribute",
352 [](DPsim::DataLogger &logger, const std::vector<CPS::String> &names,
353 const CPS::String &attr, const CPS::IdentifiedObject &comp) {
354 logger.logAttribute(names, comp.attribute(attr));
355 });
356#ifdef WITH_RT
358 std::shared_ptr<DPsim::RealTimeDataLogger>>(m,
359 "RealTimeDataLogger")
360
361 .def(py::init([](py::object filename, DPsim::Real final_time,
362 DPsim::Real time_step) {
363 py::object fspath =
364 py::module_::import("os").attr("fspath")(filename);
365 std::string s = py::cast<std::string>(fspath);
366 std::filesystem::path p(s);
367 return std::make_shared<DPsim::RealTimeDataLogger>(p, final_time,
368 time_step);
369 }),
370 "filename"_a, "final_time"_a, "time_step"_a)
371
372 .def(py::init([](py::object filename, std::size_t row_number) {
373 py::object fspath =
374 py::module_::import("os").attr("fspath")(filename);
375 std::string s = py::cast<std::string>(fspath);
376 std::filesystem::path p(s);
377 return std::make_shared<DPsim::RealTimeDataLogger>(p, row_number);
378 }),
379 "filename"_a, "row_number"_a)
380
381 .def("log_attribute",
382 py::overload_cast<const CPS::String &, CPS::AttributeBase::Ptr,
383 CPS::UInt, CPS::UInt>(
384 &DPsim::DataLoggerInterface::logAttribute),
385 "name"_a, "attr"_a, "max_cols"_a = 0, "max_rows"_a = 0)
386
387 .def("log_attribute",
388 py::overload_cast<const std::vector<CPS::String> &,
389 CPS::AttributeBase::Ptr>(
390 &DPsim::DataLoggerInterface::logAttribute),
391 "names"_a, "attr"_a)
392
393 .def(
394 "log_attribute",
395 [](DPsim::RealTimeDataLogger &logger, const CPS::String &name,
396 const CPS::String &attr, const CPS::IdentifiedObject &comp,
397 CPS::UInt rowsMax, CPS::UInt colsMax) {
398 logger.logAttribute(name, comp.attribute(attr), rowsMax, colsMax);
399 },
400 "name"_a, "attr"_a, "comp"_a, "rows_max"_a = 0, "cols_max"_a = 0)
401
402 .def(
403 "log_attribute",
404 [](DPsim::RealTimeDataLogger &logger,
405 const std::vector<CPS::String> &names, const CPS::String &attr,
406 const CPS::IdentifiedObject &comp) {
407 logger.logAttribute(names, comp.attribute(attr));
408 },
409 "names"_a, "attr"_a, "comp"_a);
410#endif
411
412 py::class_<CPS::IdentifiedObject, std::shared_ptr<CPS::IdentifiedObject>>(
413 m, "IdentifiedObject")
414 .def("name", &CPS::IdentifiedObject::name)
418 .def("attr", &CPS::IdentifiedObject::attribute, "name"_a)
419 .def("print_attribute_list", &printAttributes)
420 .def("print_attribute", &printAttribute, "attribute_name"_a)
421 .def("__str__", &getAttributeList);
422
423#ifdef WITH_CIM
424 py::class_<CPS::CIM::Reader>(m, "CIMReader")
425 .def(py::init<std::string, CPS::Logger::Level, CPS::Logger::Level>(),
426 "name"_a, "loglevel"_a = CPS::Logger::Level::info,
427 "comploglevel"_a = CPS::Logger::Level::off)
428 .def("loadCIM", (CPS::SystemTopology(CPS::CIM::Reader::*)(
429 CPS::Real, const std::list<CPS::String> &,
430 CPS::Domain, CPS::PhaseType, CPS::GeneratorType)) &
432#endif
433
434 py::class_<CPS::CSVReader>(m, "CSVReader")
435 .def(py::init<std::string, const std::string &,
436 std::map<std::string, std::string> &, CPS::Logger::Level>())
437 .def("assignLoadProfile", &CPS::CSVReader::assignLoadProfile);
438
439 //Base Classes
440
441 py::class_<CPS::TopologicalPowerComp,
442 std::shared_ptr<CPS::TopologicalPowerComp>, CPS::IdentifiedObject>(
443 m, "TopologicalPowerComp");
444 py::class_<CPS::SimPowerComp<CPS::Complex>,
445 std::shared_ptr<CPS::SimPowerComp<CPS::Complex>>,
446 CPS::TopologicalPowerComp>(m, "SimPowerCompComplex")
448 .def("set_intf_current", &CPS::SimPowerComp<CPS::Complex>::setIntfCurrent)
449 .def("set_intf_voltage", &CPS::SimPowerComp<CPS::Complex>::setIntfVoltage)
450 .def("get_terminal", &CPS::SimPowerComp<CPS::Complex>::terminal,
451 "index"_a);
452 py::class_<CPS::SimPowerComp<CPS::Real>,
453 std::shared_ptr<CPS::SimPowerComp<CPS::Real>>,
454 CPS::TopologicalPowerComp>(m, "SimPowerCompReal")
456 .def("set_intf_current", &CPS::SimPowerComp<CPS::Real>::setIntfCurrent)
457 .def("set_intf_voltage", &CPS::SimPowerComp<CPS::Real>::setIntfVoltage)
458 .def("get_terminal", &CPS::SimPowerComp<CPS::Real>::terminal, "index"_a);
459 py::class_<CPS::TopologicalNode, std::shared_ptr<CPS::TopologicalNode>,
460 CPS::IdentifiedObject>(m, "TopologicalNode")
461 .def("initial_single_voltage",
462 &CPS::TopologicalNode::initialSingleVoltage,
463 "phase_type"_a = CPS::PhaseType::Single);
464
465 py::class_<CPS::TopologicalTerminal,
466 std::shared_ptr<CPS::TopologicalTerminal>, CPS::IdentifiedObject>(
467 m, "TopologicalTerminal")
468 .def("set_power",
469 py::overload_cast<CPS::Complex>(&CPS::TopologicalTerminal::setPower))
470 .def("set_power", py::overload_cast<CPS::MatrixComp>(
471 &CPS::TopologicalTerminal::setPower));
472
473 py::class_<CPS::SimTerminal<CPS::Complex>,
474 std::shared_ptr<CPS::SimTerminal<CPS::Complex>>,
475 CPS::TopologicalTerminal>(m, "SimTerminalComplex");
476 py::class_<CPS::SimTerminal<CPS::Real>,
477 std::shared_ptr<CPS::SimTerminal<CPS::Real>>,
478 CPS::TopologicalTerminal>(m, "SimTerminalReal");
479
480 //Events
481 py::module mEvent = m.def_submodule("event", "events");
482 py::class_<DPsim::Event, std::shared_ptr<DPsim::Event>>(mEvent, "Event");
483 py::class_<DPsim::SwitchEvent, std::shared_ptr<DPsim::SwitchEvent>,
484 DPsim::Event>(mEvent, "SwitchEvent", py::multiple_inheritance())
485 .def(py::init<CPS::Real, const std::shared_ptr<CPS::Base::Ph1::Switch>,
486 CPS::Bool>());
487 py::class_<DPsim::SwitchEvent3Ph, std::shared_ptr<DPsim::SwitchEvent3Ph>,
488 DPsim::Event>(mEvent, "SwitchEvent3Ph", py::multiple_inheritance())
489 .def(py::init<CPS::Real, const std::shared_ptr<CPS::Base::Ph3::Switch>,
490 CPS::Bool>());
491
492 //Components
493 py::module mBase = m.def_submodule("base", "base models");
494 addBaseComponents(mBase);
495
496 py::module mDP = m.def_submodule("dp", "dynamic phasor models");
497 addDPComponents(mDP);
498
499 py::module mEMT = m.def_submodule("emt", "electromagnetic-transient models");
500 addEMTComponents(mEMT);
501
502 py::module mSP = m.def_submodule("sp", "static phasor models");
503 mSP.attr("SimNode") = mDP.attr("SimNode");
504 addSPComponents(mSP);
505
506 py::module mSignal = m.def_submodule("signal", "signal models");
507 addSignalComponents(mSignal);
508
509#ifdef VERSION_INFO
510 m.attr("__version__") = VERSION_INFO;
511#else
512 m.attr("__version__") = "dev";
513#endif
514}
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:211
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
AttributeBase::Ptr attribute(const String &name) const
Return pointer to an attribute.
static void setLogDir(String path)
Set env variable CPS_LOG_DIR and overwrite.
Definition Logger.cpp:88
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.
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.
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 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.
Extending Simulation class by real-time functionality.
void run(const Timer::StartClock::duration &startIn=std::chrono::seconds(1))
void doFrequencyParallelization(Bool value)
Compute phasors of different frequencies in parallel.
Definition Simulation.h:220
void logLUTimes()
Write LU decomposition times measurements to log file.
Real next()
Run until next time step.
void addLogger(DataLoggerInterface::Ptr logger)
Add a new data logger.
Definition Simulation.h:270
void setSolverAndComponentBehaviour(Solver::Behaviour behaviour)
set solver and component to initialization or simulation behaviour
Definition Simulation.h:186
CPS::AttributeBase::Ptr getIdObjAttribute(const String &comp, const String &attr)
CHECK: Can these be deleted? getIdObjAttribute + "**attr =" should suffice.
void start()
Start simulation without advancing in time.
void doSteadyStateInit(Bool f)
activate steady state initialization
Definition Simulation.h:235
void addEvent(Event::Ptr e)
Schedule an event in the simulation.
Definition Simulation.h:268
void doStateSpaceExtraction(Bool value=true)
Enable extraction of the MNA-coupled discrete-time state matrix.
Definition Simulation.h:226
void run()
Run simulation until total time is elapsed.
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
void stop()
Stop simulation including scheduler and interfaces.
void setAnalysisFrame(StateSpaceAnalysisFrame frame)
const CPS::VectorComp & getContinuousEigenvalues() const
Continuous-time EMT eigenvalues reconstructed from discrete eigenvalues.
const CPS::VectorComp & getDiscreteEigenvalues() const
Eigenvalues of the extracted discrete-time state matrix in the selected analysis frame.
void update()
Update modal quantities from the current extracted state matrix.
void setGlobalDq0Frame(Real omega, Real theta0=0.0)