Aufgrund einer Störung des s3 Storage, könnten in nächster Zeit folgende GitLab Funktionen nicht zur Verfügung stehen: LFS, Container Registry, Job Artifacs, Uploads (Wiki, Bilder, Projekt-Exporte). Wir bitten um Verständnis. Es wird mit Hochdruck an der Behebung des Problems gearbeitet. Weitere Informationen zur Störung des Object Storage finden Sie hier: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/59-object-storage-pilot

Commit a7287d82 authored by Markus Mirz's avatar Markus Mirz
Browse files

pybind: extend attribute get, set methods


Signed-off-by: Markus Mirz's avatarMarkus Mirz <mmirz@eonerc.rwth-aachen.de>
parent 04926cde
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# CIGRE MV Powerflow Solver Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Run simulation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import urllib.request\n",
"import glob\n",
"\n",
"import dpsimpy"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"name = 'CIGRE_MV'\n",
"files = glob.glob('../../../build/_deps/cim-data-src/CIGRE_MV/NEPLAN/CIGRE_MV_no_tapchanger_With_LoadFlow_Results/*.xml')\n",
"print(files)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"reader = dpsimpy.CIMReader(name)\n",
"system = reader.loadCIM(50, files, dpsimpy.Domain.SP, dpsimpy.PhaseType.Single)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#system.render_to_file('CIGRE_MV.svg')\n",
"system"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sim = dpsimpy.Simulation(name)\n",
"sim.set_system(system)\n",
"sim.set_domain(dpsimpy.Domain.SP)\n",
"sim.set_solver(dpsimpy.Solver.NRP)\n",
"sim.set_time_step(1)\n",
"sim.set_final_time(10)\n",
"\n",
"logger = dpsimpy.Logger(name)\n",
"for node in system.nodes:\n",
" logger.log_attribute(node.name()+'.V', 'v', node);\n",
"sim.add_logger(logger)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sim.start()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sim.next()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sim.get_real_idobj_attr('LOAD-I-10', 'P_pu')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sim.get_comp_idobj_attr('N10', 'v')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sim.set_idobj_attr('LOAD-I-10', 'P_pu', 0.00128)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"system.list_idobjects()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.7"
},
"tests": {
"skip": true
}
},
"nbformat": 4,
"nbformat_minor": 4
}
......@@ -255,8 +255,8 @@ namespace DPsim {
void setIdObjAttr(const String &comp, const String &attr, Complex value);
// #### Get component attributes during simulation ####
Real getRealIdObjAttr(const String &comp, const String &attr);
Complex getComplexIdObjAttr(const String &comp, const String &attr);
Real getRealIdObjAttr(const String &comp, const String &attr, UInt row = 0, UInt col = 0);
Complex getComplexIdObjAttr(const String &comp, const String &attr, UInt row = 0, UInt col = 0);
void exportIdObjAttr(const String &comp, const String &attr, UInt idx, CPS::AttributeBase::Modifier mod = CPS::AttributeBase::Modifier::real, UInt row = 0, UInt col = 0);
void logIdObjAttr(const String &comp, const String &attr);
......
......@@ -505,31 +505,47 @@ void Simulation::setIdObjAttr(const String &comp, const String &attr, Complex va
mLog->error("Component not found");
}
Real Simulation::getRealIdObjAttr(const String &comp, const String &attr) {
Real Simulation::getRealIdObjAttr(const String &comp, const String &attr, UInt row, UInt col) {
IdentifiedObject::Ptr compObj = mSystem.component<IdentifiedObject>(comp);
if (!compObj) compObj = mSystem.node<IdentifiedObject>(comp);
if (compObj) {
try {
return compObj->attribute<Real>(attr)->getByValue();
} catch (InvalidAttributeException &e) {
mLog->error("Attribute not found");
}
} catch (InvalidAttributeException &e) { }
try {
return compObj->attributeMatrixReal(attr)->coeff(row, col)->getByValue();
} catch (InvalidAttributeException &e) { }
mLog->error("Attribute not found");
}
else {
mLog->error("Component not found");
}
mLog->error("Component not found");
return 0;
}
Complex Simulation::getComplexIdObjAttr(const String &comp, const String &attr) {
Complex Simulation::getComplexIdObjAttr(const String &comp, const String &attr, UInt row, UInt col) {
IdentifiedObject::Ptr compObj = mSystem.component<IdentifiedObject>(comp);
if (!compObj) compObj = mSystem.node<IdentifiedObject>(comp);
if (compObj) {
try {
return compObj->attributeComplex(attr)->getByValue();
} catch (InvalidAttributeException &e) {
mLog->error("Attribute not found");
}
} catch (InvalidAttributeException &e) { }
try {
return compObj->attributeMatrixComp(attr)->coeff(row, col)->getByValue();
} catch (InvalidAttributeException &e) { }
mLog->error("Attribute not found");
}
else {
mLog->error("Component not found");
}
mLog->error("Component not found");
return 0;
}
......
......@@ -45,8 +45,8 @@ PYBIND11_MODULE(dpsimpy, m) {
.def("next", &DPsim::Simulation::next)
.def("set_idobj_attr", static_cast<void (DPsim::Simulation::*)(const std::string&, const std::string&, CPS::Real)>(&DPsim::Simulation::setIdObjAttr))
.def("set_idobj_attr", static_cast<void (DPsim::Simulation::*)(const std::string&, const std::string&, CPS::Complex)>(&DPsim::Simulation::setIdObjAttr))
.def("get_real_idobj_attr", &DPsim::Simulation::getRealIdObjAttr)
.def("get_comp_idobj_attr", &DPsim::Simulation::getComplexIdObjAttr)
.def("get_real_idobj_attr", &DPsim::Simulation::getRealIdObjAttr, py::arg("obj"), py::arg("attr"), py::arg("row") = 0, py::arg("col") = 0)
.def("get_comp_idobj_attr", &DPsim::Simulation::getComplexIdObjAttr, py::arg("obj"), py::arg("attr"), py::arg("row") = 0, py::arg("col") = 0)
.def("add_interface", &DPsim::Simulation::addInterface, py::arg("interface"), py::arg("syncStart") = false)
.def("export_attr", &DPsim::Simulation::exportIdObjAttr, py::arg("obj"), py::arg("attr"), py::arg("idx"), py::arg("modifier"), py::arg("row") = 0, py::arg("col") = 0)
.def("log_attr", &DPsim::Simulation::logIdObjAttr);
......@@ -63,8 +63,8 @@ PYBIND11_MODULE(dpsimpy, m) {
.def("set_domain", &DPsim::RealTimeSimulation::setDomain)
.def("set_idobj_attr", static_cast<void (DPsim::RealTimeSimulation::*)(const std::string&, const std::string&, CPS::Real)>(&DPsim::Simulation::setIdObjAttr))
.def("set_idobj_attr", static_cast<void (DPsim::RealTimeSimulation::*)(const std::string&, const std::string&, CPS::Complex)>(&DPsim::Simulation::setIdObjAttr))
.def("get_real_idobj_attr", &DPsim::RealTimeSimulation::getRealIdObjAttr)
.def("get_comp_idobj_attr", &DPsim::RealTimeSimulation::getComplexIdObjAttr)
.def("get_real_idobj_attr", &DPsim::RealTimeSimulation::getRealIdObjAttr, py::arg("obj"), py::arg("attr"), py::arg("row") = 0, py::arg("col") = 0)
.def("get_comp_idobj_attr", &DPsim::RealTimeSimulation::getComplexIdObjAttr, py::arg("obj"), py::arg("attr"), py::arg("row") = 0, py::arg("col") = 0)
.def("add_interface", &DPsim::RealTimeSimulation::addInterface, py::arg("interface"), py::arg("syncStart") = false)
.def("export_attr", &DPsim::RealTimeSimulation::exportIdObjAttr, py::arg("obj"), py::arg("attr"), py::arg("idx"), py::arg("modifier"), py::arg("row") = 0, py::arg("col") = 0)
.def("log_attr", &DPsim::RealTimeSimulation::logIdObjAttr);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment