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

Merge branch 'debug-msp-example' into 'master'

Debug msp example

See merge request acs/public/simulation/dpsim!119

Former-commit-id: 099b3d9e
parents 471a4beb 38e89ccf
Subproject commit 4b9674ac044aac25e254017780957b22f3a15d33
Subproject commit 6ac46f089d543665920cbb0ef8841f8bba98ca1a
......@@ -19,6 +19,7 @@ set(CIRCUIT_SOURCES
# EMT examples
/** Reference Circuits
* @author Jan Dinkelbach <>
* @copyright 2019, Institute for Automation of Complex Power Systems, EONERC
* DPsim
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <>.
#include <DPsim.h>
using namespace DPsim;
using namespace CPS::EMT;
using namespace CPS::EMT::Ph1;
int main(int argc, char* argv[]) {
// Define simulation scenario
Real timeStep = 1e-4;
Real finalTime = 1e-3;
String simName = "EMT_CS_RL1";
// Nodes
auto n1 = Node::make("n1", PhaseType::Single, std::vector<Complex>{ 2 });
// Components
auto cs = CurrentSource::make("cs", Logger::Level::info);
cs->setParameters(Complex(10, 0), 0);
auto r1 = Resistor::make("r_1");
auto l1 = Inductor::make("l_1", Logger::Level::info);
// Topology
cs->connect(Node::List{ Node::GND, n1 });
r1->connect(Node::List{ n1, Node::GND });
l1->connect(Node::List{ n1, Node::GND });
// Define system topology
auto sys = SystemTopology(50, SystemNodeList{n1}, SystemComponentList{cs, r1, l1});
// Logger
auto logger = DataLogger::make(simName);
logger->addAttribute("v1", n1->attribute("v"));
logger->addAttribute("iR1", r1->attribute("i_intf"));
logger->addAttribute("iL1", l1->attribute("i_intf"));
Simulation sim(simName, sys, timeStep, finalTime, Domain::EMT);
return 0;
This diff is collapsed.
......@@ -53,11 +53,14 @@ namespace Python {
static PyObject* voltage(PyObject *self, PyObject *args);
static PyObject* gnd(PyObject *self, PyObject *args);
static void setInitialVoltage(PyObject *self, PyObject *args, PyObject *kwds);
static const char *name;
static const char *doc;
static const char *docInitialVoltage;
static const char *docVoltage;
static const char *docGND;
static const char *docSetInitialVoltage;
static PyMethodDef methods[];
static PyTypeObject type;
......@@ -158,11 +158,31 @@ PyObject * Python::Node<VarType>::gnd(PyObject *self, PyObject *args) {
return Py_GND;
template<typename VarType>
const char* Python::Node<VarType>::docSetInitialVoltage =
"Set the initial voltage at this node.\n";
template<typename VarType>
void Python::Node<VarType>::setInitialVoltage(PyObject *self, PyObject *args, PyObject *kwds) {
Py_complex initVoltage;
CPS::Int phaseIndex;
static const char *kwlist[] = {"voltage", "index", nullptr};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "Di", (char **) kwlist, &initVoltage, &phaseIndex))
Python::Node<VarType>* pyNode = (Python::Node<VarType>*) self;
pyNode->node->setInitialVoltage(CPS::Complex(initVoltage.real,initVoltage.imag), phaseIndex);
template<typename VarType>
PyMethodDef Python::Node<VarType>::methods[] = {
{"initial_voltage", (PyCFunction) Python::Node<VarType>::initialVoltage, METH_NOARGS, (char*) Python::Node<VarType>::docInitialVoltage},
{"voltage", (PyCFunction) Python::Node<VarType>::voltage, METH_NOARGS, (char*) Python::Node<VarType>::docVoltage},
{"GND", (PyCFunction) Python::Node<VarType>::gnd, METH_NOARGS | METH_STATIC, (char *) Python::Node<VarType>::docGND},
{"set_initial_voltage", (PyCFunction) Python::Node<VarType>::setInitialVoltage, METH_VARARGS | METH_KEYWORDS, (char *) Python::Node<VarType>::docSetInitialVoltage},
{nullptr, nullptr, 0, nullptr}
Supports Markdown
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