|
@@ -24,6 +24,7 @@ class Clock:
|
|
|
def getDeltaT(self):
|
|
|
return self.__delta_t
|
|
|
|
|
|
+
|
|
|
class Simulator:
|
|
|
def __init__(self, model):
|
|
|
self.model = model
|
|
@@ -40,18 +41,20 @@ class Simulator:
|
|
|
# TODO: make this variable, given more solver implementations
|
|
|
self.__solver = GaussianJordanLinearSolver(self.__logger)
|
|
|
|
|
|
- def run(self):
|
|
|
+ def run(self, term_time=None):
|
|
|
"""
|
|
|
Simulate the model!
|
|
|
"""
|
|
|
self.model.setClock(Clock(self.__deltaT))
|
|
|
self.__lasttime = time.time()
|
|
|
+ if term_time is None:
|
|
|
+ term_time = self.__termination_time
|
|
|
depGraph = None
|
|
|
sortedGraph = None
|
|
|
- __duration_log = []
|
|
|
+ self.__duration_log = []
|
|
|
|
|
|
curIteration = 0
|
|
|
- while self.getClock().getTime() < self.__termination_time:
|
|
|
+ while self.getClock().getTime() < term_time:
|
|
|
if self.__termination_condition is not None and \
|
|
|
self.__termination_condition(self.model, curIteration):
|
|
|
break
|
|
@@ -66,7 +69,7 @@ class Simulator:
|
|
|
# Time is computed w.r.t. last time a step was executed to
|
|
|
# account for delays due to processor scheduling
|
|
|
duration = time.time() - self.__lasttime
|
|
|
- __duration_log.append(duration)
|
|
|
+ self.__duration_log.append(duration)
|
|
|
time.sleep(max(0.0, self.__deltaT - duration))
|
|
|
self.__lasttime = time.time()
|
|
|
|
|
@@ -87,6 +90,9 @@ class Simulator:
|
|
|
def setTerminationTime(self, term_time):
|
|
|
self.__termination_time = term_time
|
|
|
|
|
|
+ def getDurationLog(self):
|
|
|
+ return self.__duration_log
|
|
|
+
|
|
|
def __step(self, depGraph, sortedGraph, curIteration):
|
|
|
self.__computeBlocks(sortedGraph, depGraph, curIteration)
|
|
|
self.getClock().setDeltaT(self.__deltaT)
|