Commit 8e767e65 authored by Georg Martin Reinke's avatar Georg Martin Reinke
Browse files

add lvector method to PySimulation

parent 1a6e1dba
......@@ -78,6 +78,19 @@ void PySimulation::dealloc(PySimulation* self) {
PyObject* PySimulation::lvector(PyObject *self, PyObject *args) {
PySimulation *pySim = (PySimulation*) self;
if (pySim->state == StateRunning) {
PyErr_SetString(PyExc_SystemError, "Simulation currently running");
return nullptr;
Matrix& lvector = pySim->sim->getLeftSideVector();
PyObject* list = PyList_New(lvector.rows());
for (int i = 0; i < lvector.rows(); i++)
PyList_SetItem(list, i, PyFloat_FromDouble(lvector(i, 0)));
return list;
PyObject* PySimulation::start(PyObject *self, PyObject *args) {
PySimulation *pySim = (PySimulation*) self;
std::unique_lock<std::mutex> lk(*pySim->mut);
......@@ -45,6 +45,7 @@ namespace DPsim {
static void dealloc(PySimulation*);
// Methods that are actually available from Python
static PyObject* lvector(PyObject *self, PyObject *args);
static PyObject* start(PyObject *self, PyObject *args);
static PyObject* step(PyObject *self, PyObject *args);
static PyObject* stop(PyObject *self, PyObject *args);
......@@ -53,6 +54,7 @@ namespace DPsim {
static PyMethodDef PySimulation_methods[] = {
{"lvector", PySimulation::lvector, METH_NOARGS, "Returns the left-side vector from the last step."},
{"start", PySimulation::start, METH_NOARGS, "Start the simulation, or resume if it is paused."},
{"step", PySimulation::step, METH_NOARGS, "Perform a single simulation step."},
{"stop", PySimulation::stop, METH_NOARGS, "Cancel the running simulation."},
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