Commit 5194c15e authored by Markus Mirz's avatar Markus Mirz
Browse files

Merge branch 'development' of git.rwth-aachen.de:acs/core/simulation/dpsim into development

parents 5fa4aac1 add42b0f
......@@ -41,6 +41,8 @@ namespace Python {
struct Logger {
PyObject_HEAD
std::vector<PyObject *> refs;
DPsim::DataLogger::Ptr logger;
const char *filename;
......
......@@ -36,8 +36,10 @@ PyObject* Python::Logger::newfunc(PyTypeObject *type, PyObject *args, PyObject *
self = (Python::Logger*) type->tp_alloc(type, 0);
if (self) {
using PyObjectVector = std::vector<PyObject *>;
using SharedLoggerPtr = std::shared_ptr<DPsim::DataLogger>;
new (&self->refs) PyObjectVector();
new (&self->logger) SharedLoggerPtr();
}
......@@ -46,9 +48,14 @@ PyObject* Python::Logger::newfunc(PyTypeObject *type, PyObject *args, PyObject *
void Python::Logger::dealloc(Python::Logger* self)
{
using PyObjectVector = std::vector<PyObject *>;
using SharedLoggerPtr = std::shared_ptr<DPsim::DataLogger>;
for (PyObject *pyRef : self->refs)
Py_DECREF(pyRef);
self->logger.~SharedLoggerPtr();
self->refs.~PyObjectVector();
Py_TYPE(self)->tp_free((PyObject*) self);
}
......@@ -103,6 +110,9 @@ PyObject* Python::Logger::logAttribute(Logger* self, PyObject* args, PyObject *k
return nullptr;
}
self->refs.push_back(pyObj);
Py_INCREF(pyObj);
Py_RETURN_NONE;
}
......
......@@ -133,6 +133,11 @@ void Python::Simulation::threadFunction(Python::Simulation *self)
for (auto ifm : self->sim->interfaces())
ifm.interface->close();
#endif
for (auto lg : self->sim->loggers()) {
if (self->sim->timeStepCount() % lg.downsampling == 0)
lg.logger->log(self->sim->time());
}
}
PyObject* Python::Simulation::newfunc(PyTypeObject* subtype, PyObject *args, PyObject *kwds)
......
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