Skip to content

Commit ea8c7d5

Browse files
authored
Fix getTime and doStep (#937)
1 parent b4463d5 commit ea8c7d5

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

src/OMSimulatorLib/Model.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ oms_status_enu_t oms::Model::setStopTime(double value)
900900

901901
double oms::Model::getTime() const
902902
{
903-
if (system)
903+
if (system && validState(oms_modelState_simulation))
904904
return system->getTime();
905905
return getStartTime();
906906
}

src/OMSimulatorLib/SystemSC.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ oms_status_enu_t oms::SystemSC::doStep()
557557
hcur = tnext - tlast;
558558
}
559559

560+
// logInfo("SystemSC::doStep [" + std::to_string(tlast) + "; " + std::to_string(tnext) + "]");
561+
560562
// integrate using specified solver
561563
if (oms_solver_sc_explicit_euler == solverMethod)
562564
{
@@ -626,9 +628,7 @@ oms_status_enu_t oms::SystemSC::doStep()
626628
oms_status_enu_t oms::SystemSC::stepUntil(double stopTime, void (*cb)(const char* ident, double time, oms_status_enu_t status))
627629
{
628630
CallClock callClock(clock);
629-
630-
ComRef modelName = this->getModel()->getCref();
631-
double startTime=time;
631+
const double startTime=time;
632632

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

647647
if (Flags::ProgressBar())
648648
Log::ProgressBar(startTime, stopTime, time);

src/OMSimulatorPython/OMSimulator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ def initialize(self, cref):
173173
return Scope._capi.initialize(cref)
174174
def simulate(self, cref):
175175
return Scope._capi.simulate(cref)
176+
def doStep(self, cref):
177+
return Scope._capi.doStep(cref)
176178
def stepUntil(self, cref, stopTime):
177179
return Scope._capi.stepUntil(cref, stopTime)
178180
def terminate(self, cref):

src/OMSimulatorPython/capi.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ def __init__(self):
4646
self.obj.oms_deleteConnectorFromBus.restype = ctypes.c_int
4747
self.obj.oms_deleteConnectorFromTLMBus.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
4848
self.obj.oms_deleteConnectorFromTLMBus.restype = ctypes.c_int
49+
self.obj.oms_doStep.argtypes = [ctypes.c_char_p]
50+
self.obj.oms_doStep.restype = ctypes.c_int
4951
self.obj.oms_export.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
5052
self.obj.oms_export.restype = ctypes.c_int
5153
self.obj.oms_exportDependencyGraphs.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]
5254
self.obj.oms_exportDependencyGraphs.restype = ctypes.c_int
5355
self.obj.oms_exportSnapshot.argtypes = [ctypes.c_char_p]
5456
self.obj.oms_exportSnapshot.restype = ctypes.c_int
55-
self.obj.oms_exportSSVTemplate.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
56-
self.obj.oms_exportSSVTemplate.restype = ctypes.c_int
5757
self.obj.oms_exportSSMTemplate.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
5858
self.obj.oms_exportSSMTemplate.restype = ctypes.c_int
59+
self.obj.oms_exportSSVTemplate.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
60+
self.obj.oms_exportSSVTemplate.restype = ctypes.c_int
5961
self.obj.oms_faultInjection.argtypes = [ctypes.c_char_p, ctypes.c_int, ctypes.c_double]
6062
self.obj.oms_faultInjection.restype = ctypes.c_int
6163
self.obj.oms_getBoolean.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_bool)]
@@ -74,6 +76,8 @@ def __init__(self):
7476
self.obj.oms_getStopTime.restype = ctypes.c_int
7577
self.obj.oms_getSystemType.argtypes = [ctypes.c_char_p]
7678
self.obj.oms_getSystemType.restype = ctypes.c_int
79+
self.obj.oms_getTime.argtypes = [ctypes.c_char_p]
80+
self.obj.oms_getTime.restype = ctypes.c_int
7781
self.obj.oms_getVariableStepSize.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double)]
7882
self.obj.oms_getVariableStepSize.restype = ctypes.c_int
7983
self.obj.oms_getVersion.argtypes = None
@@ -186,6 +190,8 @@ def deleteConnectorFromBus(self, busCref, connectorCref):
186190
return self.obj.oms_deleteConnectorFromBus(busCref.encode(), connectorCref.encode())
187191
def deleteConnectorFromTLMBus(self, busCref, connectorCref):
188192
return self.obj.oms_deleteConnectorFromTLMBus(busCref.encode(), connectorCref.encode())
193+
def doStep(self, cref):
194+
return self.obj.oms_doStep(cref.encode())
189195
def export(self, cref, filename):
190196
return self.obj.oms_export(cref.encode(), filename.encode())
191197
def exportDependencyGraphs(self, cref, initialization, event, simulation):
@@ -232,6 +238,10 @@ def getSystemType(self, cref):
232238
type_ = ctypes.c_int()
233239
status = self.obj.oms_getSystemType(cref.encode(), ctypes.byref(type_))
234240
return [type_.value, status]
241+
def getTime(self, cref):
242+
time = ctypes.c_double()
243+
status = self.obj.oms_getTime(cref.encode(), ctypes.byref(time))
244+
return [time.value, status]
235245
def getVariableStepSize(self, cref):
236246
initialStepSize = ctypes.c_double()
237247
minimumStepSize = ctypes.c_double()

0 commit comments

Comments
 (0)