Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,824 changes: 999 additions & 825 deletions OMPython/ModelicaSystem.py

Large diffs are not rendered by default.

651 changes: 316 additions & 335 deletions OMPython/OMCSession.py

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions OMPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,29 @@
from OMPython.ModelicaSystem import (
LinearizationResult,
ModelicaSystem,
ModelicaSystemCmd,
ModelicaSystemOMC,
ModelExecutionCmd,
ModelicaSystemDoE,
ModelicaDoEOMC,
ModelicaSystemError,

doe_get_solutions,
)
from OMPython.OMCSession import (
OMPathABC,
OMCPath,

OMCSession,

ModelExecutionData,
ModelExecutionException,

OMCSessionCmd,
OMCSessionDocker,
OMCSessionDockerContainer,
OMCSessionException,
OMCSessionLocal,
OMCSessionPort,
OMCSessionRunData,
OMCSessionWSL,
OMCSessionZMQ,
)
Expand All @@ -36,21 +45,29 @@
__all__ = [
'LinearizationResult',

'ModelExecutionData',
'ModelExecutionException',

'ModelicaSystem',
'ModelicaSystemCmd',
'ModelicaSystemOMC',
'ModelExecutionCmd',
'ModelicaSystemDoE',
'ModelicaDoEOMC',
'ModelicaSystemError',

'OMPathABC',
'OMCPath',

'OMCSession',

'doe_get_solutions',

'OMCSessionCmd',
'OMCSessionDocker',
'OMCSessionDockerContainer',
'OMCSessionException',
'OMCSessionPort',
'OMCSessionLocal',
'OMCSessionRunData',
'OMCSessionWSL',
'OMCSessionZMQ',
]
4 changes: 2 additions & 2 deletions tests/test_FMIExport.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_CauerLowPassAnalog():
mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_name="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
libraries=["Modelica"],
Expand All @@ -20,7 +20,7 @@ def test_CauerLowPassAnalog():


def test_DrumBoiler():
mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_name="Modelica.Fluid.Examples.DrumBoiler.DrumBoiler",
libraries=["Modelica"],
Expand Down
4 changes: 2 additions & 2 deletions tests/test_FMIImport.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def model_firstorder(tmp_path):

def test_FMIImport(model_firstorder):
# create model & simulate it
mod1 = OMPython.ModelicaSystem()
mod1 = OMPython.ModelicaSystemOMC()
mod1.model(
model_file=model_firstorder,
model_name="M",
Expand All @@ -35,7 +35,7 @@ def test_FMIImport(model_firstorder):

# import FMU & check & simulate
# TODO: why is '--allowNonStandardModelica=reinitInAlgorithms' needed? any example without this possible?
mod2 = OMPython.ModelicaSystem(command_line_options=['--allowNonStandardModelica=reinitInAlgorithms'])
mod2 = OMPython.ModelicaSystemOMC(command_line_options=['--allowNonStandardModelica=reinitInAlgorithms'])
mo = mod2.convertFmu2Mo(fmu=fmu)
assert os.path.exists(mo)

Expand Down
26 changes: 13 additions & 13 deletions tests/test_ModelicaSystemDoE.py → tests/test_ModelicaDoEOMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,75 +51,75 @@ def param_doe() -> dict[str, list]:
return param


def test_ModelicaSystemDoE_local(tmp_path, model_doe, param_doe):
def test_ModelicaDoEOMC_local(tmp_path, model_doe, param_doe):
tmpdir = tmp_path / 'DoE'
tmpdir.mkdir(exist_ok=True)

mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_file=model_doe,
model_name="M",
)

doe_mod = OMPython.ModelicaSystemDoE(
doe_mod = OMPython.ModelicaDoEOMC(
mod=mod,
parameters=param_doe,
resultpath=tmpdir,
simargs={"override": {'stopTime': '1.0'}},
)

_run_ModelicaSystemDoe(doe_mod=doe_mod)
_run_ModelicaDoEOMC(doe_mod=doe_mod)


@skip_on_windows
@skip_python_older_312
def test_ModelicaSystemDoE_docker(tmp_path, model_doe, param_doe):
def test_ModelicaDoEOMC_docker(tmp_path, model_doe, param_doe):
omcs = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
omversion = omcs.sendExpression("getVersion()")
assert isinstance(omversion, str) and omversion.startswith("OpenModelica")

mod = OMPython.ModelicaSystem(
mod = OMPython.ModelicaSystemOMC(
session=omcs,
)
mod.model(
model_file=model_doe,
model_name="M",
)

doe_mod = OMPython.ModelicaSystemDoE(
doe_mod = OMPython.ModelicaDoEOMC(
mod=mod,
parameters=param_doe,
simargs={"override": {'stopTime': '1.0'}},
)

_run_ModelicaSystemDoe(doe_mod=doe_mod)
_run_ModelicaDoEOMC(doe_mod=doe_mod)


@pytest.mark.skip(reason="Not able to run WSL on github")
@skip_python_older_312
def test_ModelicaSystemDoE_WSL(tmp_path, model_doe, param_doe):
def test_ModelicaDoEOMC_WSL(tmp_path, model_doe, param_doe):
omcs = OMPython.OMCSessionWSL()
omversion = omcs.sendExpression("getVersion()")
assert isinstance(omversion, str) and omversion.startswith("OpenModelica")

mod = OMPython.ModelicaSystem(
mod = OMPython.ModelicaSystemOMC(
session=omcs,
)
mod.model(
model_file=model_doe,
model_name="M",
)

doe_mod = OMPython.ModelicaSystemDoE(
doe_mod = OMPython.ModelicaDoEOMC(
mod=mod,
parameters=param_doe,
simargs={"override": {'stopTime': '1.0'}},
)

_run_ModelicaSystemDoe(doe_mod=doe_mod)
_run_ModelicaDoEOMC(doe_mod=doe_mod)


def _run_ModelicaSystemDoe(doe_mod):
def _run_ModelicaDoEOMC(doe_mod):
doe_count = doe_mod.prepare()
assert doe_count == 16

Expand Down
12 changes: 8 additions & 4 deletions tests/test_ModelicaSystemCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ def model_firstorder(tmp_path):

@pytest.fixture
def mscmd_firstorder(model_firstorder):
mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_file=model_firstorder,
model_name="M",
)
mscmd = OMPython.ModelicaSystemCmd(
session=mod.get_session(),

mscmd = OMPython.ModelExecutionCmd(
runpath=mod.getWorkDirectory(),
modelname=mod._model_name,
cmd_local=mod.get_session().model_execution_local,
cmd_windows=mod.get_session().model_execution_windows,
cmd_prefix=mod.get_session().model_execution_prefix(cwd=mod.getWorkDirectory()),
model_name=mod._model_name,
)

return mscmd


Expand Down
22 changes: 13 additions & 9 deletions tests/test_ModelicaSystem.py → tests/test_ModelicaSystemOMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def model_firstorder(tmp_path, model_firstorder_content):

def test_ModelicaSystem_loop(model_firstorder):
def worker():
mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_file=model_firstorder,
model_name="M",
Expand All @@ -56,7 +56,9 @@ def test_setParameters():
omcs = OMPython.OMCSessionLocal()
model_path_str = omcs.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels"
model_path = omcs.omcpath(model_path_str)
mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC(
session=omcs,
)
mod.model(
model_file=model_path / "BouncingBall.mo",
model_name="BouncingBall",
Expand Down Expand Up @@ -91,7 +93,9 @@ def test_setSimulationOptions():
omcs = OMPython.OMCSessionLocal()
model_path_str = omcs.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels"
model_path = omcs.omcpath(model_path_str)
mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC(
session=omcs,
)
mod.model(
model_file=model_path / "BouncingBall.mo",
model_name="BouncingBall",
Expand Down Expand Up @@ -128,7 +132,7 @@ def test_relative_path(model_firstorder):
model_relative = str(model_file)
assert "/" not in model_relative

mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_file=model_relative,
model_name="M",
Expand All @@ -141,7 +145,7 @@ def test_relative_path(model_firstorder):
def test_customBuildDirectory(tmp_path, model_firstorder):
tmpdir = tmp_path / "tmpdir1"
tmpdir.mkdir()
mod = OMPython.ModelicaSystem(work_directory=tmpdir)
mod = OMPython.ModelicaSystemOMC(work_directory=tmpdir)
mod.model(
model_file=model_firstorder,
model_name="M",
Expand All @@ -157,7 +161,7 @@ def test_customBuildDirectory(tmp_path, model_firstorder):
@skip_python_older_312
def test_getSolutions_docker(model_firstorder):
omcs = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
mod = OMPython.ModelicaSystem(
mod = OMPython.ModelicaSystemOMC(
session=omcs,
)
mod.model(
Expand All @@ -169,7 +173,7 @@ def test_getSolutions_docker(model_firstorder):


def test_getSolutions(model_firstorder):
mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_file=model_firstorder,
model_name="M",
Expand Down Expand Up @@ -217,7 +221,7 @@ def test_getters(tmp_path):
y = der(x);
end M_getters;
""")
mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_file=model_file,
model_name="M_getters",
Expand Down Expand Up @@ -426,7 +430,7 @@ def test_simulate_inputs(tmp_path):
y = x;
end M_input;
""")
mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_file=model_file,
model_name="M_input",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_OMSessionCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_isPackage():


def test_isPackage2():
mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_name="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
libraries=["Modelica"],
Expand Down
4 changes: 2 additions & 2 deletions tests/test_linearization.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def model_linearTest(tmp_path):


def test_example(model_linearTest):
mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_file=model_linearTest,
model_name="linearTest",
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_getters(tmp_path):
y2 = phi + u1;
end Pendulum;
""")
mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_file=model_file,
model_name="Pendulum",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_optimization_example(tmp_path):
end BangBang2021;
""")

mod = OMPython.ModelicaSystem()
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_file=model_file,
model_name="BangBang2021",
Expand Down
Loading