Skip to content

Commit 499525c

Browse files
committed
[ModelicaSystem] remove _has_inputs - is defined by _inputs empty or not
1 parent 92651c5 commit 499525c

1 file changed

Lines changed: 14 additions & 20 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 14 additions & 20 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._result_file: Optional[pathlib.Path] = None # for storing result file
394393
self._variable_filter = variableFilter
@@ -967,21 +966,18 @@ def simulate_cmd(
967966

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

970-
if self._has_inputs: # if model has input quantities
971-
# csvfile is based on name used for result file
972-
csvfile = result_file.parent / f"{result_file.stem}.csv"
973-
974-
for i in self._inputs:
975-
val = self._inputs[i]
969+
if self._inputs: # if model has input quantities
970+
for key in self._inputs:
971+
val = self._inputs[key]
976972
if val is None:
977973
val = [(float(self._simulate_options["startTime"]), 0.0),
978974
(float(self._simulate_options["stopTime"]), 0.0)]
979-
self._inputs[i] = [(float(self._simulate_options["startTime"]), 0.0),
980-
(float(self._simulate_options["stopTime"]), 0.0)]
975+
self._inputs[key] = val
981976
if float(self._simulate_options["startTime"]) != val[0][0]:
982-
raise ModelicaSystemError(f"startTime not matched for Input {i}!")
977+
raise ModelicaSystemError(f"startTime not matched for Input {key}!")
983978
if float(self._simulate_options["stopTime"]) != val[-1][0]:
984-
raise ModelicaSystemError(f"stopTime not matched for Input {i}!")
979+
raise ModelicaSystemError(f"stopTime not matched for Input {key}!")
980+
self._csvFile = self._createCSVData() # create csv file
985981

986982
# write csv file and store the name
987983
csvfile = self._createCSVData(csvfile=csvfile)
@@ -1379,8 +1375,6 @@ def setInputs(
13791375
else:
13801376
raise ModelicaSystemError(f"Data cannot be evaluated for {repr(key)}: {repr(val)}")
13811377

1382-
self._has_inputs = True
1383-
13841378
return True
13851379

13861380
def _createCSVData(self) -> pathlib.Path:
@@ -1567,13 +1561,13 @@ def load_module_from_path(module_name, file_path):
15671561

15681562
om_cmd.arg_set(key="overrideFile", val=overrideLinearFile.as_posix())
15691563

1570-
if self._has_inputs:
1571-
nameVal = self.getInputs()
1572-
for n in nameVal:
1573-
tupleList = nameVal.get(n)
1574-
if tupleList is not None:
1575-
for l in tupleList:
1576-
if l[0] < float(self._simulate_options["startTime"]):
1564+
inputs = self.getInputs()
1565+
if inputs:
1566+
for key in inputs:
1567+
data = inputs[key]
1568+
if data is not None:
1569+
for value in data:
1570+
if value[0] < float(self._simulate_options["startTime"]):
15771571
raise ModelicaSystemError('Input time value is less than simulation startTime')
15781572
csvfile = self._createCSVData()
15791573
om_cmd.arg_set(key="csvInput", val=csvfile.as_posix())

0 commit comments

Comments
 (0)