Skip to content

Commit a34a8ea

Browse files
committed
[ModelicaSystem] remove _has_inputs - is defined by _inputs empty or not
1 parent c0a7f73 commit a34a8ea

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ def __init__(
388388
self._lmodel = lmodel # may be needed if model is derived from other model
389389
self._model_name = modelName # Model class name
390390
self._file_name = pathlib.Path(fileName).resolve() if fileName is not None else None # Model file/package name
391-
self._has_inputs = False # for model with input quantity
392391
self._simulated = False # True if the model has already been simulated
393392
self._csvFile: Optional[pathlib.Path] = None # for storing inputs condition
394393
self._result_file: Optional[pathlib.Path] = None # for storing result file
@@ -969,18 +968,17 @@ def simulate(self,
969968

970969
om_cmd.arg_set(key="overrideFile", val=overrideFile.as_posix())
971970

972-
if self._has_inputs: # if model has input quantities
973-
for i in self._inputs:
974-
val = self._inputs[i]
971+
if self._inputs: # if model has input quantities
972+
for key in self._inputs:
973+
val = self._inputs[key]
975974
if val is None:
976975
val = [(float(self._simulate_options["startTime"]), 0.0),
977976
(float(self._simulate_options["stopTime"]), 0.0)]
978-
self._inputs[i] = [(float(self._simulate_options["startTime"]), 0.0),
979-
(float(self._simulate_options["stopTime"]), 0.0)]
977+
self._inputs[key] = val
980978
if float(self._simulate_options["startTime"]) != val[0][0]:
981-
raise ModelicaSystemError(f"startTime not matched for Input {i}!")
979+
raise ModelicaSystemError(f"startTime not matched for Input {key}!")
982980
if float(self._simulate_options["stopTime"]) != val[-1][0]:
983-
raise ModelicaSystemError(f"stopTime not matched for Input {i}!")
981+
raise ModelicaSystemError(f"stopTime not matched for Input {key}!")
984982
self._csvFile = self._createCSVData() # create csv file
985983

986984
om_cmd.arg_set(key="csvInput", val=self._csvFile.as_posix())
@@ -1334,8 +1332,6 @@ def setInputs(
13341332
else:
13351333
raise ModelicaSystemError(f"Data cannot be evaluated for {repr(key)}: {repr(val)}")
13361334

1337-
self._has_inputs = True
1338-
13391335
return True
13401336

13411337
def _createCSVData(self) -> pathlib.Path:
@@ -1521,13 +1517,13 @@ def load_module_from_path(module_name, file_path):
15211517

15221518
om_cmd.arg_set(key="overrideFile", val=overrideLinearFile.as_posix())
15231519

1524-
if self._has_inputs:
1525-
nameVal = self.getInputs()
1526-
for n in nameVal:
1527-
tupleList = nameVal.get(n)
1528-
if tupleList is not None:
1529-
for l in tupleList:
1530-
if l[0] < float(self._simulate_options["startTime"]):
1520+
inputs = self.getInputs()
1521+
if inputs:
1522+
for key in inputs:
1523+
data = inputs[key]
1524+
if data is not None:
1525+
for value in data:
1526+
if value[0] < float(self._simulate_options["startTime"]):
15311527
raise ModelicaSystemError('Input time value is less than simulation startTime')
15321528
self._csvFile = self._createCSVData()
15331529
om_cmd.arg_set(key="csvInput", val=self._csvFile.as_posix())

0 commit comments

Comments
 (0)