Commit 658b8c6f authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

python: add new option "fail_on_overrun" for dpsim.Simulation

Former-commit-id: 5aa67ba5
parent af5cd6eb
......@@ -76,6 +76,7 @@ namespace Python {
double realTimeStep; /// effective timestep for real-time simulation
bool realTime;
bool startSync;
bool failOnOverrun;
bool singleStepping; /// Debugger like stepping for simulations
Timer::StartTimePoint startTime;
......
......@@ -81,10 +81,12 @@ void Python::Simulation::threadFunction(Python::Simulation *self)
catch (Timer::OverrunException e) {
std::unique_lock<std::mutex> lk(*self->mut);
if (self->failOnOverrun) {
newState(self, Simulation::State::overrun);
self->cond->notify_one();
}
}
}
if (self->sim->timeStepCount() == 1) {
std::unique_lock<std::mutex> lk(*self->mut);
......@@ -151,10 +153,11 @@ PyObject* Python::Simulation::newfunc(PyTypeObject* subtype, PyObject *args, PyO
int Python::Simulation::init(Simulation* self, PyObject *args, PyObject *kwds)
{
static const char *kwlist[] = {"name", "system", "timestep", "duration", "start_time", "start_time_us", "sim_type", "solver_type", "single_stepping", "rt", "rt_factor", "start_sync", "init_steady_state", "log_level", nullptr};
static const char *kwlist[] = {"name", "system", "timestep", "duration", "start_time", "start_time_us", "sim_type", "solver_type", "single_stepping", "rt", "rt_factor", "start_sync", "init_steady_state", "log_level", "fail_on_overrun", nullptr};
double timestep = 1e-3, duration = DBL_MAX, rtFactor = 1;
const char *name = nullptr;
int t = 0, s = 0, rt = 0, ss = 0, st = 0, initSteadyState = 0;
int failOnOverrun = 0;
CPS::Logger::Level logLevel = CPS::Logger::Level::INFO;
......@@ -164,8 +167,8 @@ int Python::Simulation::init(Simulation* self, PyObject *args, PyObject *kwds)
enum Solver::Type solverType;
enum Domain domain;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO|ddkkiippdppi", (char **) kwlist,
&name, &self->pySys, &timestep, &duration, &startTime, &startTimeUs, &s, &t, &ss, &rt, &rtFactor, &st, &initSteadyState, &logLevel)) {
if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO|ddkkiippdppip", (char **) kwlist,
&name, &self->pySys, &timestep, &duration, &startTime, &startTimeUs, &s, &t, &ss, &rt, &rtFactor, &st, &initSteadyState, &logLevel, &failOnOverrun)) {
return -1;
}
......@@ -173,6 +176,7 @@ int Python::Simulation::init(Simulation* self, PyObject *args, PyObject *kwds)
self->realTime = rt;
self->startSync = ss;
self->singleStepping = st;
self->failOnOverrun = failOnOverrun;
self->realTimeStep = timestep / rtFactor;
if (startTime > 0) {
......
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