Skip to content

Commit 6e154f3

Browse files
committed
[ModelicaSystem] rename model_definition() => model()
1 parent 8cc8f50 commit 6e154f3

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

OMPython/ModelicaSystem.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,9 @@ def __init__(
424424
self._file_name: Optional[os.PathLike]
425425
self._variable_filter: Optional[str] = None
426426

427-
def model_definition(
427+
def model(
428428
self,
429-
model: str,
429+
name: str,
430430
file: Optional[str | os.PathLike | pathlib.Path] = None,
431431
libraries: Optional[list[str | tuple[str, str]]] = None,
432432
variable_filter: Optional[str] = None,
@@ -440,7 +440,7 @@ def model_definition(
440440
Args:
441441
file: Path to the model file. Either absolute or relative to
442442
the current working directory.
443-
model: The name of the model class. If it is contained within
443+
name: The name of the model class. If it is contained within
444444
a package, "PackageName.ModelName" should be used.
445445
libraries: List of libraries to be loaded before the model itself is
446446
loaded. Two formats are supported for the list elements:
@@ -462,8 +462,8 @@ def model_definition(
462462
mod.setup_model(model="modelName", file="ModelicaModel.mo", libraries=[("Modelica","3.2.3"), "PowerSystems"])
463463
"""
464464

465-
if not isinstance(model, str):
466-
raise ModelicaSystemError("A model name must be provided (argument modelName)!")
465+
if not isinstance(name, str):
466+
raise ModelicaSystemError("A model name must be provided (argument name)!")
467467

468468
if libraries is None:
469469
libraries = []
@@ -472,7 +472,7 @@ def model_definition(
472472
raise ModelicaSystemError(f"Invalid input type for lmodel: {type(libraries)} - list expected!")
473473

474474
# set variables
475-
self._model_name = model # Model class name
475+
self._model_name = name # Model class name
476476
self._lmodel = libraries # may be needed if model is derived from other model
477477
self._file_name = pathlib.Path(file).resolve() if file is not None else None # Model file/package name
478478
self._variable_filter = variable_filter

tests/test_FMIExport.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
def test_CauerLowPassAnalog():
77
mod = OMPython.ModelicaSystem()
8-
mod.model_definition(
9-
model="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
8+
mod.model(
9+
name="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
1010
libraries=["Modelica"],
1111
)
1212
tmp = mod.getWorkDirectory()
@@ -19,8 +19,8 @@ def test_CauerLowPassAnalog():
1919

2020
def test_DrumBoiler():
2121
mod = OMPython.ModelicaSystem()
22-
mod.model_definition(
23-
model="Modelica.Fluid.Examples.DrumBoiler.DrumBoiler",
22+
mod.model(
23+
name="Modelica.Fluid.Examples.DrumBoiler.DrumBoiler",
2424
libraries=["Modelica"],
2525
)
2626
tmp = mod.getWorkDirectory()

tests/test_ModelicaSystem.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def test_ModelicaSystem_loop(model_firstorder):
2323
def worker():
2424
filePath = model_firstorder.as_posix()
2525
mod = OMPython.ModelicaSystem()
26-
mod.model_definition(
26+
mod.model(
2727
file=filePath,
28-
model="M",
28+
name="M",
2929
)
3030
mod.simulate()
3131
mod.convertMo2Fmu(fmuType="me")
@@ -37,9 +37,9 @@ def test_setParameters():
3737
omc = OMPython.OMCSessionZMQ()
3838
model_path = omc.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels/"
3939
mod = OMPython.ModelicaSystem()
40-
mod.model_definition(
40+
mod.model(
4141
file=model_path + "BouncingBall.mo",
42-
model="BouncingBall",
42+
name="BouncingBall",
4343
)
4444

4545
# method 1
@@ -70,9 +70,9 @@ def test_setSimulationOptions():
7070
omc = OMPython.OMCSessionZMQ()
7171
model_path = omc.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels/"
7272
mod = OMPython.ModelicaSystem()
73-
mod.model_definition(
73+
mod.model(
7474
file=model_path + "BouncingBall.mo",
75-
model="BouncingBall",
75+
name="BouncingBall",
7676
)
7777

7878
# method 1
@@ -107,9 +107,9 @@ def test_relative_path(model_firstorder):
107107
assert "/" not in model_relative
108108

109109
mod = OMPython.ModelicaSystem()
110-
mod.model_definition(
110+
mod.model(
111111
file=model_relative,
112-
model="M",
112+
name="M",
113113
)
114114
assert float(mod.getParameters("a")[0]) == -1
115115
finally:
@@ -121,9 +121,9 @@ def test_customBuildDirectory(tmp_path, model_firstorder):
121121
tmpdir = tmp_path / "tmpdir1"
122122
tmpdir.mkdir()
123123
mod = OMPython.ModelicaSystem(customBuildDirectory=tmpdir)
124-
mod.model_definition(
124+
mod.model(
125125
file=filePath,
126-
model="M",
126+
name="M",
127127
)
128128
assert mod.getWorkDirectory().resolve() == tmpdir.resolve()
129129
result_file = tmpdir / "a.mat"
@@ -135,9 +135,9 @@ def test_customBuildDirectory(tmp_path, model_firstorder):
135135
def test_getSolutions(model_firstorder):
136136
filePath = model_firstorder.as_posix()
137137
mod = OMPython.ModelicaSystem()
138-
mod.model_definition(
138+
mod.model(
139139
file=filePath,
140-
model="M",
140+
name="M",
141141
)
142142
x0 = 1
143143
a = -1
@@ -176,9 +176,9 @@ def test_getters(tmp_path):
176176
end M_getters;
177177
""")
178178
mod = OMPython.ModelicaSystem()
179-
mod.model_definition(
179+
mod.model(
180180
file=model_file.as_posix(),
181-
model="M_getters",
181+
name="M_getters",
182182
)
183183

184184
q = mod.getQuantities()
@@ -372,9 +372,9 @@ def test_simulate_inputs(tmp_path):
372372
end M_input;
373373
""")
374374
mod = OMPython.ModelicaSystem()
375-
mod.model_definition(
375+
mod.model(
376376
file=model_file.as_posix(),
377-
model="M_input",
377+
name="M_input",
378378
)
379379

380380
mod.setSimulationOptions(simOptions={"stopTime": 1.0})

tests/test_ModelicaSystemCmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def model_firstorder(tmp_path):
1818
@pytest.fixture
1919
def mscmd_firstorder(model_firstorder):
2020
mod = OMPython.ModelicaSystem()
21-
mod.model_definition(
21+
mod.model(
2222
file=model_firstorder.as_posix(),
23-
model="M",
23+
name="M",
2424
)
2525
mscmd = OMPython.ModelicaSystemCmd(runpath=mod.getWorkDirectory(), modelname=mod._model_name)
2626
return mscmd

tests/test_OMSessionCmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def test_isPackage():
99

1010
def test_isPackage2():
1111
mod = OMPython.ModelicaSystem()
12-
mod.model_definition(
13-
model="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
12+
mod.model(
13+
name="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
1414
libraries=["Modelica"],
1515
)
1616
omccmd = OMPython.OMCSessionCmd(session=mod._getconn)

tests/test_linearization.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def model_linearTest(tmp_path):
2525

2626
def test_example(model_linearTest):
2727
mod = OMPython.ModelicaSystem()
28-
mod.model_definition(
28+
mod.model(
2929
file=model_linearTest,
30-
model="linearTest",
30+
name="linearTest",
3131
)
3232
[A, B, C, D] = mod.linearize()
3333
expected_matrixA = [[-3, 2, 0, 0], [-7, 0, -5, 1], [-1, 0, -1, 4], [0, 1, -1, 5]]
@@ -60,9 +60,9 @@ def test_getters(tmp_path):
6060
end Pendulum;
6161
""")
6262
mod = OMPython.ModelicaSystem()
63-
mod.model_definition(
63+
mod.model(
6464
file=model_file.as_posix(),
65-
model="Pendulum",
65+
name="Pendulum",
6666
libraries=["Modelica"],
6767
)
6868

tests/test_optimization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def test_optimization_example(tmp_path):
3434
""")
3535

3636
mod = OMPython.ModelicaSystem()
37-
mod.model_definition(
37+
mod.model(
3838
file=model_file.as_posix(),
39-
model="BangBang2021",
39+
name="BangBang2021",
4040
)
4141

4242
mod.setOptimizationOptions(optimizationOptions={"numberOfIntervals": 16,

0 commit comments

Comments
 (0)