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 9654eb92 authored by Markus Mirz's avatar Markus Mirz
Browse files

python: add rt-sim, csvreader and extend sim with step control


Signed-off-by: Markus Mirz's avatarMarkus Mirz <mmirz@eonerc.rwth-aachen.de>
parent 1c7e2d34
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# CIGRE MV Powerflow with Profiles 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",
"from villas.dataprocessing.readtools import *\n",
"from villas.dataprocessing.timeseries import *\n",
"import villas.dataprocessing.validationtools as validationtools\n",
"import dpsimpy"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"name = 'CIGRE-MV-Profiles'\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": [
"csv_files = glob.glob('../../../build/_deps/profile-data-src/CIGRE_MV_NoTap/load_profiles/')[0]\n",
"print(csv_files)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"assignList = { }\n",
"assignList['LOAD-H-1'] = 'Load_H_1'\n",
"assignList['LOAD-H-3'] = 'Load_H_3'\n",
"assignList['LOAD-H-4'] = 'Load_H_4'\n",
"assignList['LOAD-H-5'] = 'Load_H_5'\n",
"assignList['LOAD-H-6'] = 'Load_H_6'\n",
"assignList['LOAD-H-8'] = 'Load_H_8'\n",
"assignList['LOAD-H-10'] = 'Load_H_10'\n",
"assignList['LOAD-H-11'] = 'Load_H_11'\n",
"assignList['LOAD-H-12'] = 'Load_H_12'\n",
"assignList['LOAD-H-14'] = 'Load_H_14'\n",
"assignList['LOAD-I-1'] = 'Load_I_1'\n",
"assignList['LOAD-I-3'] = 'Load_I_3'\n",
"assignList['LOAD-I-7'] = 'Load_I_7'\n",
"assignList['LOAD-I-9'] = 'Load_I_9'\n",
"assignList['LOAD-I-10'] = 'Load_I_10'\n",
"assignList['LOAD-I-12'] = 'Load_I_12'\n",
"assignList['LOAD-I-13'] = 'Load_I_13'\n",
"assignList['LOAD-I-14'] = 'Load_I_14'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"csvreader = dpsimpy.CSVReader(name, csv_files, assignList, dpsimpy.LogLevel.info)\n",
"csvreader.assignLoadProfile(system, 0, 1, 300, dpsimpy.CSVReaderMode.MANUAL, dpsimpy.CSVReaderFormat.SECONDS)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"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(300)\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.run()"
]
}
],
"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
}
......@@ -11,10 +11,13 @@
#include <pybind11/stl.h>
#include <dpsim/Simulation.h>
#include <dpsim/RealTimeSimulation.h>
#include <cps/IdentifiedObject.h>
#include <cps/CIM/Reader.h>
#include <DPsim.h>
#include <cps/CSVReader.h>
namespace py = pybind11;
PYBIND11_MODULE(dpsimpy, m) {
......@@ -27,6 +30,23 @@ PYBIND11_MODULE(dpsimpy, m) {
)pbdoc";
py::class_<DPsim::Simulation>(m, "Simulation")
.def(py::init<std::string>())
.def("name", &DPsim::Simulation::name)
.def("set_time_step", &DPsim::Simulation::setTimeStep)
.def("set_final_time", &DPsim::Simulation::setFinalTime)
.def("add_logger", &DPsim::Simulation::addLogger)
.def("set_system", &DPsim::Simulation::setSystem)
.def("run", &DPsim::Simulation::run)
.def("set_solver", &DPsim::Simulation::setSolverType)
.def("set_domain", &DPsim::Simulation::setDomain)
.def("start", &DPsim::Simulation::start)
.def("next", &DPsim::Simulation::next)
.def("set_attribute", static_cast<void (DPsim::Simulation::*)(const std::string&, const std::string&, CPS::Real)>(&DPsim::Simulation::setAttribute))
.def("set_attribute", static_cast<void (DPsim::Simulation::*)(const std::string&, const std::string&, CPS::Complex)>(&DPsim::Simulation::setAttribute))
.def("get_real_attribute", &DPsim::Simulation::getRealAttribute)
.def("get_complex_attribute", &DPsim::Simulation::getComplexAttribute);
py::class_<DPsim::RealTimeSimulation>(m, "RealTimeSimulation")
.def(py::init<std::string>())
.def("name", &DPsim::Simulation::name)
.def("set_time_step", &DPsim::Simulation::setTimeStep)
......@@ -69,10 +89,33 @@ PYBIND11_MODULE(dpsimpy, m) {
.value("DAE", DPsim::Solver::Type::DAE)
.value("NRP", DPsim::Solver::Type::NRP);
py::enum_<CPS::Logger::Level>(m, "LogLevel")
.value("trace", CPS::Logger::Level::trace)
.value("debug", CPS::Logger::Level::debug)
.value("info", CPS::Logger::Level::info)
.value("warn", CPS::Logger::Level::warn)
.value("err", CPS::Logger::Level::err)
.value("critical", CPS::Logger::Level::critical)
.value("off", CPS::Logger::Level::off);
py::enum_<CPS::CSVReader::Mode>(m, "CSVReaderMode")
.value("AUTO", CPS::CSVReader::Mode::AUTO)
.value("MANUAL", CPS::CSVReader::Mode::MANUAL);
py::enum_<CPS::CSVReader::DataFormat>(m, "CSVReaderFormat")
.value("HHMMSS", CPS::CSVReader::DataFormat::HHMMSS)
.value("SECONDS", CPS::CSVReader::DataFormat::SECONDS)
.value("HOURS", CPS::CSVReader::DataFormat::HOURS)
.value("MINUTES", CPS::CSVReader::DataFormat::MINUTES);
py::class_<CPS::CIM::Reader>(m, "CIMReader")
.def(py::init<std::string>())
.def("loadCIM", (CPS::SystemTopology (CPS::CIM::Reader::*)(CPS::Real, const std::list<CPS::String> &, CPS::Domain, CPS::PhaseType)) &CPS::CIM::Reader::loadCIM);
py::class_<CPS::CSVReader>(m, "CSVReader")
.def(py::init<std::string, const std::string &, std::map<std::string, std::string> &, CPS::Logger::Level>())
.def("assignLoadProfile", &CPS::CSVReader::assignLoadProfile);
py::class_<CPS::TopologicalPowerComp, std::shared_ptr<CPS::TopologicalPowerComp>, CPS::IdentifiedObject>(m, "TopologicalPowerComp");
py::class_<CPS::SimPowerComp<CPS::Complex>, std::shared_ptr<CPS::SimPowerComp<CPS::Complex>>, CPS::TopologicalPowerComp>(m, "SimPowerCompComplex");
......
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