Skip to content

Commit d89cd29

Browse files
committed
Rename _modelName to _model_name
1 parent 2574485 commit d89cd29

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class ModelicaSystemCmd:
117117

118118
def __init__(self, runpath: pathlib.Path, modelname: str, timeout: Optional[float] = None) -> None:
119119
self._runpath = pathlib.Path(runpath).resolve().absolute()
120-
self._modelname = modelname
120+
self._model_name = modelname
121121
self._timeout = timeout
122122
self._args: dict[str, str | None] = {}
123123
self._arg_override: dict[str, str] = {}
@@ -179,9 +179,9 @@ def args_set(self, args: dict[str, Optional[str | dict[str, str]]]) -> None:
179179
def get_exe(self) -> pathlib.Path:
180180
"""Get the path to the compiled model executable."""
181181
if platform.system() == "Windows":
182-
path_exe = self._runpath / f"{self._modelname}.exe"
182+
path_exe = self._runpath / f"{self._model_name}.exe"
183183
else:
184-
path_exe = self._runpath / self._modelname
184+
path_exe = self._runpath / self._model_name
185185

186186
if not path_exe.exists():
187187
raise ModelicaSystemError(f"Application file path not found: {path_exe}")
@@ -221,7 +221,7 @@ def run(self) -> int:
221221
path_dll = ""
222222

223223
# set the process environment from the generated .bat file in windows which should have all the dependencies
224-
path_bat = self._runpath / f"{self._modelname}.bat"
224+
path_bat = self._runpath / f"{self._model_name}.bat"
225225
if not path_bat.exists():
226226
raise ModelicaSystemError("Batch file (*.bat) does not exist " + str(path_bat))
227227

@@ -385,7 +385,7 @@ def __init__(
385385

386386
self._xml_file = None
387387
self._lmodel = lmodel # may be needed if model is derived from other model
388-
self._modelName = modelName # Model class name
388+
self._model_name = modelName # Model class name
389389
self._fileName = pathlib.Path(fileName).resolve() if fileName is not None else None # Model file/package name
390390
self._inputFlag = False # for model with input quantity
391391
self._simulationFlag = False # if the model is simulated?
@@ -479,7 +479,7 @@ def buildModel(self, variableFilter: Optional[str] = None):
479479
else:
480480
varFilter = 'variableFilter=".*"'
481481

482-
buildModelResult = self._requestApi("buildModel", self._modelName, properties=varFilter)
482+
buildModelResult = self._requestApi("buildModel", self._model_name, properties=varFilter)
483483
logger.debug("OM model build result: %s", buildModelResult)
484484

485485
self._xml_file = pathlib.Path(buildModelResult[0]).parent / buildModelResult[1]
@@ -938,11 +938,11 @@ def simulate(self,
938938
mod.simulate(simargs={"noEventEmit": None, "noRestart": None, "override": "override": {"e": 0.3, "g": 10}}) # using simargs
939939
"""
940940

941-
om_cmd = ModelicaSystemCmd(runpath=self._tempdir, modelname=self._modelName, timeout=timeout)
941+
om_cmd = ModelicaSystemCmd(runpath=self._tempdir, modelname=self._model_name, timeout=timeout)
942942

943943
if resultfile is None:
944944
# default result file generated by OM
945-
self._resultfile = self._tempdir / f"{self._modelName}_res.mat"
945+
self._resultfile = self._tempdir / f"{self._model_name}_res.mat"
946946
elif os.path.exists(resultfile):
947947
self._resultfile = pathlib.Path(resultfile)
948948
else:
@@ -957,7 +957,7 @@ def simulate(self,
957957
if simargs:
958958
om_cmd.args_set(args=simargs)
959959

960-
overrideFile = self._tempdir / f"{self._modelName}_override.txt"
960+
overrideFile = self._tempdir / f"{self._model_name}_override.txt"
961961
if self._override_variables or self._simulate_options_override:
962962
tmpdict = self._override_variables.copy()
963963
tmpdict.update(self._simulate_options_override)
@@ -1145,7 +1145,7 @@ def isParameterChangeable(self, name, value):
11451145
if q[0]["changeable"] == "false":
11461146
logger.debug(f"setParameters() failed : It is not possible to set the following signal {repr(name)}. "
11471147
"It seems to be structural, final, protected or evaluated or has a non-constant binding, "
1148-
f"use sendExpression(\"setParameterValue({self._modelName}, {name}, {value})\") "
1148+
f"use sendExpression(\"setParameterValue({self._model_name}, {name}, {value})\") "
11491149
"and rebuild the model using buildModel() API")
11501150
return False
11511151
return True
@@ -1272,7 +1272,7 @@ def _createCSVData(self) -> pathlib.Path:
12721272
]
12731273
csv_rows.append(row)
12741274

1275-
csvFile = self._tempdir / f'{self._modelName}.csv'
1275+
csvFile = self._tempdir / f'{self._model_name}.csv'
12761276

12771277
with open(file=csvFile, mode="w", encoding="utf-8", newline="") as fh:
12781278
writer = csv.writer(fh)
@@ -1299,13 +1299,13 @@ def convertMo2Fmu(self, version: str = "2.0", fmuType: str = "me_cs",
12991299
"""
13001300

13011301
if fileNamePrefix == "<default>":
1302-
fileNamePrefix = self._modelName
1302+
fileNamePrefix = self._model_name
13031303
if includeResources:
13041304
includeResourcesStr = "true"
13051305
else:
13061306
includeResourcesStr = "false"
13071307
properties = f'version="{version}", fmuType="{fmuType}", fileNamePrefix="{fileNamePrefix}", includeResources={includeResourcesStr}'
1308-
fmu = self._requestApi('buildModelFMU', self._modelName, properties)
1308+
fmu = self._requestApi('buildModelFMU', self._model_name, properties)
13091309

13101310
# report proper error message
13111311
if not os.path.exists(fmu):
@@ -1357,7 +1357,7 @@ def optimize(self) -> dict[str, Any]:
13571357
'timeTemplates': 0.002007785,
13581358
'timeTotal': 1.079097854}
13591359
"""
1360-
cName = self._modelName
1360+
cName = self._model_name
13611361
properties = ','.join(f"{key}={val}" for key, val in self._optimization_options.items())
13621362
self.setCommandLineOptions("-g=Optimica")
13631363
optimizeResult = self._requestApi('optimize', cName, properties)
@@ -1402,9 +1402,9 @@ def load_module_from_path(module_name, file_path):
14021402
"use ModelicaSystem() to build the model first"
14031403
)
14041404

1405-
om_cmd = ModelicaSystemCmd(runpath=self._tempdir, modelname=self._modelName, timeout=timeout)
1405+
om_cmd = ModelicaSystemCmd(runpath=self._tempdir, modelname=self._model_name, timeout=timeout)
14061406

1407-
overrideLinearFile = self._tempdir / f'{self._modelName}_override_linear.txt'
1407+
overrideLinearFile = self._tempdir / f'{self._model_name}_override_linear.txt'
14081408

14091409
with open(file=overrideLinearFile, mode="w", encoding="utf-8") as fh:
14101410
for key, value in self._override_variables.items():
@@ -1443,9 +1443,9 @@ def load_module_from_path(module_name, file_path):
14431443
# code to get the matrix and linear inputs, outputs and states
14441444
linearFile = self._tempdir / "linearized_model.py"
14451445

1446-
# support older openmodelica versions before OpenModelica v1.16.2 where linearize() generates "linear_modelname.mo" file
1446+
# support older openmodelica versions before OpenModelica v1.16.2 where linearize() generates "linear_model_name.mo" file
14471447
if not linearFile.exists():
1448-
linearFile = pathlib.Path(f'linear_{self._modelName}.py')
1448+
linearFile = pathlib.Path(f'linear_{self._model_name}.py')
14491449

14501450
if not linearFile.exists():
14511451
raise ModelicaSystemError(f"Linearization failed: {linearFile} not found!")

tests/test_ModelicaSystemCmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def model_firstorder(tmp_path):
1818
@pytest.fixture
1919
def mscmd_firstorder(model_firstorder):
2020
mod = OMPython.ModelicaSystem(fileName=model_firstorder.as_posix(), modelName="M")
21-
mscmd = OMPython.ModelicaSystemCmd(runpath=mod.getWorkDirectory(), modelname=mod._modelName)
21+
mscmd = OMPython.ModelicaSystemCmd(runpath=mod.getWorkDirectory(), modelname=mod._model_name)
2222
return mscmd
2323

2424

0 commit comments

Comments
 (0)