Skip to content

Commit 60daa84

Browse files
committed
[ModelicaSystem] remove _has_inputs - is defined by _inputs empty or not
1 parent 6ea552d commit 60daa84

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
@@ -968,18 +967,17 @@ def simulate_cmd(
968967

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

971-
if self._has_inputs: # if model has input quantities
972-
for i in self._inputs:
973-
val = self._inputs[i]
970+
if self._inputs: # if model has input quantities
971+
for key in self._inputs:
972+
val = self._inputs[key]
974973
if val is None:
975974
val = [(float(self._simulate_options["startTime"]), 0.0),
976975
(float(self._simulate_options["stopTime"]), 0.0)]
977-
self._inputs[i] = [(float(self._simulate_options["startTime"]), 0.0),
978-
(float(self._simulate_options["stopTime"]), 0.0)]
976+
self._inputs[key] = val
979977
if float(self._simulate_options["startTime"]) != val[0][0]:
980-
raise ModelicaSystemError(f"startTime not matched for Input {i}!")
978+
raise ModelicaSystemError(f"startTime not matched for Input {key}!")
981979
if float(self._simulate_options["stopTime"]) != val[-1][0]:
982-
raise ModelicaSystemError(f"stopTime not matched for Input {i}!")
980+
raise ModelicaSystemError(f"stopTime not matched for Input {key}!")
983981
self._csvFile = self._createCSVData() # create csv file
984982

985983
om_cmd.arg_set(key="csvInput", val=self._csvFile.as_posix())
@@ -1375,8 +1373,6 @@ def setInputs(
13751373
else:
13761374
raise ModelicaSystemError(f"Data cannot be evaluated for {repr(key)}: {repr(val)}")
13771375

1378-
self._has_inputs = True
1379-
13801376
return True
13811377

13821378
def _createCSVData(self) -> pathlib.Path:
@@ -1562,13 +1558,13 @@ def load_module_from_path(module_name, file_path):
15621558

15631559
om_cmd.arg_set(key="overrideFile", val=overrideLinearFile.as_posix())
15641560

1565-
if self._has_inputs:
1566-
nameVal = self.getInputs()
1567-
for n in nameVal:
1568-
tupleList = nameVal.get(n)
1569-
if tupleList is not None:
1570-
for l in tupleList:
1571-
if l[0] < float(self._simulate_options["startTime"]):
1561+
inputs = self.getInputs()
1562+
if inputs:
1563+
for key in inputs:
1564+
data = inputs[key]
1565+
if data is not None:
1566+
for value in data:
1567+
if value[0] < float(self._simulate_options["startTime"]):
15721568
raise ModelicaSystemError('Input time value is less than simulation startTime')
15731569
self._csvFile = self._createCSVData()
15741570
om_cmd.arg_set(key="csvInput", val=self._csvFile.as_posix())

0 commit comments

Comments
 (0)