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