Commit c7f25683 authored by Georg Martin Reinke's avatar Georg Martin Reinke
Browse files

few tweaks/fixes for PySimulation


Former-commit-id: 1a6e1dba
parent fa5cdb59
#include "PySimulation.h"
#include <cfloat>
#include <iostream>
using namespace DPsim;
......@@ -45,14 +46,17 @@ PyObject* PySimulation::newfunc(PyTypeObject* type, PyObject *args, PyObject *kw
}
int PySimulation::init(PySimulation* self, PyObject *args, PyObject *kwds) {
// TODO: actually parse arguments (frequency, timestep etc.)
static char *kwlist[] = {"frequency", "timestep", "duration", NULL};
double frequency, timestep, duration;
static char *kwlist[] = {"frequency", "timestep", "duration", "log", NULL};
double frequency = 50, timestep = 1e-3, duration = DBL_MAX;
const char *log = nullptr;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ddd", kwlist,
&frequency, &timestep, &duration))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ddds", kwlist,
&frequency, &timestep, &duration, &log))
return -1;
self->log = new Logger("log.txt");
if (log)
self->log = new Logger(log);
else
self->log = new Logger();
self->sim = new Simulation(components, 2*PI*frequency, timestep, duration, *self->log);
return 0;
};
......@@ -67,6 +71,8 @@ void PySimulation::dealloc(PySimulation* self) {
}
if (self->sim)
delete self->sim;
if (self->log)
delete self->log;
delete self->mut;
delete self->cond;
Py_TYPE(self)->tp_free((PyObject*)self);
......
......@@ -53,11 +53,11 @@ namespace DPsim {
};
static PyMethodDef PySimulation_methods[] = {
{"start", PySimulation::start, METH_VARARGS, "Start the simulation, or resume if it is paused."},
{"step", PySimulation::step, METH_VARARGS, "Perform a single simulation step."},
{"stop", PySimulation::stop, METH_VARARGS, "Cancel the running simulation."},
{"pause", PySimulation::pause, METH_VARARGS, "Pause the already running simulation."},
{"wait", PySimulation::wait, METH_VARARGS, "Wait for the simulation to finish."},
{"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."},
{"pause", PySimulation::pause, METH_NOARGS, "Pause the already running simulation."},
{"wait", PySimulation::wait, METH_NOARGS, "Wait for the simulation to finish."},
{NULL, NULL, 0, NULL}
};
......
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