Commit 099b3d9e authored by Markus Mirz's avatar Markus Mirz

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

Debug msp example

See merge request !119
parents 5e27f51d 0a39b92b
Subproject commit 4b9674ac044aac25e254017780957b22f3a15d33
Subproject commit 6ac46f089d543665920cbb0ef8841f8bba98ca1a
......@@ -19,6 +19,7 @@ set(CIRCUIT_SOURCES
#Circuits/DP_ResVS_RL_Switch.cpp
# EMT examples
Circuits/EMT_CS_RL1.cpp
Circuits/EMT_VS_RL1.cpp
Circuits/EMT_Circuits.cpp
Circuits/DP_Basics_EMT_Sims.cpp
......
/** Reference Circuits
*
* @author Jan Dinkelbach <jdinkelbach@eonerc.rwth-aachen.de>
* @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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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 <http://www.gnu.org/licenses/>.
*********************************************************************************/
#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";
Logger::setLogDir("logs/"+simName);
// 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");
r1->setParameters(0.2);
auto l1 = Inductor::make("l_1", Logger::Level::info);
l1->setParameters(0.001);
// 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);
sim.addLogger(logger);
sim.run();
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_initial_voltage\n"
"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))
return;
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}
};
......
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