Skip to content

Commit

Permalink
Fix getTime and doStep (#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel authored Feb 10, 2021
1 parent b4463d5 commit ea8c7d5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/OMSimulatorLib/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ oms_status_enu_t oms::Model::setStopTime(double value)

double oms::Model::getTime() const
{
if (system)
if (system && validState(oms_modelState_simulation))
return system->getTime();
return getStartTime();
}
Expand Down
8 changes: 4 additions & 4 deletions src/OMSimulatorLib/SystemSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,8 @@ oms_status_enu_t oms::SystemSC::doStep()
hcur = tnext - tlast;
}

// logInfo("SystemSC::doStep [" + std::to_string(tlast) + "; " + std::to_string(tnext) + "]");

// integrate using specified solver
if (oms_solver_sc_explicit_euler == solverMethod)
{
Expand Down Expand Up @@ -626,9 +628,7 @@ oms_status_enu_t oms::SystemSC::doStep()
oms_status_enu_t oms::SystemSC::stepUntil(double stopTime, void (*cb)(const char* ident, double time, oms_status_enu_t status))
{
CallClock callClock(clock);

ComRef modelName = this->getModel()->getCref();
double startTime=time;
const double startTime=time;

if (Flags::ProgressBar())
logInfo("stepUntil [" + std::to_string(startTime) + "; " + std::to_string(stopTime) + "]");
Expand All @@ -642,7 +642,7 @@ oms_status_enu_t oms::SystemSC::stepUntil(double stopTime, void (*cb)(const char
if (isTopLevelSystem())
{
if (cb)
cb(modelName.c_str(), time, status);
cb(this->getModel()->getCref().c_str(), time, status);

if (Flags::ProgressBar())
Log::ProgressBar(startTime, stopTime, time);
Expand Down
2 changes: 2 additions & 0 deletions src/OMSimulatorPython/OMSimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def initialize(self, cref):
return Scope._capi.initialize(cref)
def simulate(self, cref):
return Scope._capi.simulate(cref)
def doStep(self, cref):
return Scope._capi.doStep(cref)
def stepUntil(self, cref, stopTime):
return Scope._capi.stepUntil(cref, stopTime)
def terminate(self, cref):
Expand Down
14 changes: 12 additions & 2 deletions src/OMSimulatorPython/capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ def __init__(self):
self.obj.oms_deleteConnectorFromBus.restype = ctypes.c_int
self.obj.oms_deleteConnectorFromTLMBus.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
self.obj.oms_deleteConnectorFromTLMBus.restype = ctypes.c_int
self.obj.oms_doStep.argtypes = [ctypes.c_char_p]
self.obj.oms_doStep.restype = ctypes.c_int
self.obj.oms_export.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
self.obj.oms_export.restype = ctypes.c_int
self.obj.oms_exportDependencyGraphs.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]
self.obj.oms_exportDependencyGraphs.restype = ctypes.c_int
self.obj.oms_exportSnapshot.argtypes = [ctypes.c_char_p]
self.obj.oms_exportSnapshot.restype = ctypes.c_int
self.obj.oms_exportSSVTemplate.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
self.obj.oms_exportSSVTemplate.restype = ctypes.c_int
self.obj.oms_exportSSMTemplate.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
self.obj.oms_exportSSMTemplate.restype = ctypes.c_int
self.obj.oms_exportSSVTemplate.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
self.obj.oms_exportSSVTemplate.restype = ctypes.c_int
self.obj.oms_faultInjection.argtypes = [ctypes.c_char_p, ctypes.c_int, ctypes.c_double]
self.obj.oms_faultInjection.restype = ctypes.c_int
self.obj.oms_getBoolean.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_bool)]
Expand All @@ -74,6 +76,8 @@ def __init__(self):
self.obj.oms_getStopTime.restype = ctypes.c_int
self.obj.oms_getSystemType.argtypes = [ctypes.c_char_p]
self.obj.oms_getSystemType.restype = ctypes.c_int
self.obj.oms_getTime.argtypes = [ctypes.c_char_p]
self.obj.oms_getTime.restype = ctypes.c_int
self.obj.oms_getVariableStepSize.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double)]
self.obj.oms_getVariableStepSize.restype = ctypes.c_int
self.obj.oms_getVersion.argtypes = None
Expand Down Expand Up @@ -186,6 +190,8 @@ def deleteConnectorFromBus(self, busCref, connectorCref):
return self.obj.oms_deleteConnectorFromBus(busCref.encode(), connectorCref.encode())
def deleteConnectorFromTLMBus(self, busCref, connectorCref):
return self.obj.oms_deleteConnectorFromTLMBus(busCref.encode(), connectorCref.encode())
def doStep(self, cref):
return self.obj.oms_doStep(cref.encode())
def export(self, cref, filename):
return self.obj.oms_export(cref.encode(), filename.encode())
def exportDependencyGraphs(self, cref, initialization, event, simulation):
Expand Down Expand Up @@ -232,6 +238,10 @@ def getSystemType(self, cref):
type_ = ctypes.c_int()
status = self.obj.oms_getSystemType(cref.encode(), ctypes.byref(type_))
return [type_.value, status]
def getTime(self, cref):
time = ctypes.c_double()
status = self.obj.oms_getTime(cref.encode(), ctypes.byref(time))
return [time.value, status]
def getVariableStepSize(self, cref):
initialStepSize = ctypes.c_double()
minimumStepSize = ctypes.c_double()
Expand Down

0 comments on commit ea8c7d5

Please sign in to comment.