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
2,136 changes: 1,296 additions & 840 deletions OMPython/ModelicaSystem.py

Large diffs are not rendered by default.

1,390 changes: 946 additions & 444 deletions OMPython/OMCSession.py

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions OMPython/OMTypedParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,6 @@ def om_parser_typed(string) -> Any:
if len(res) == 0:
return None
return res[0]


parseString = om_parser_typed
82 changes: 67 additions & 15 deletions OMPython/__init__.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,103 @@
# -*- coding: utf-8 -*-
"""
OMPython is a Python interface to OpenModelica.
To get started, create an OMCSessionZMQ object:
from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
To get started on a local OMC server, create an OMCSessionLocal object:

```
import OMPython
omc = OMPython.OMCSessionLocal()
omc.sendExpression("command")
```

"""

from OMPython.ModelicaSystem import (
LinearizationResult,
ModelicaSystem,
ModelicaSystemCmd,
ModelicaSystemOMC,
ModelExecutionCmd,
ModelicaSystemDoE,
ModelicaDoEOMC,
ModelicaSystemError,
ModelicaSystemRunner,
ModelicaDoERunner,

doe_get_solutions,

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

OMSessionRunner,

OMCSessionABC,

ModelExecutionData,
ModelExecutionException,

OMCSessionCmd,
OMCSessionException,
OMCSessionRunData,
OMCSessionZMQ,
OMCSessionPort,
OMCSessionLocal,
OMCSessionDocker,
OMCSessionDockerContainer,
OMCSessionException,
OMCSessionLocal,
OMCSessionPort,

OMPathRunnerBash,
OMPathRunnerLocal,

OMCSessionWSL,
OMCSessionZMQ,

OMCProcessLocal,
OMCProcessPort,
OMCProcessDocker,
OMCProcessDockerContainer,
)

# global names imported if import 'from OMPython import *' is used
__all__ = [
'LinearizationResult',

'ModelExecutionData',
'ModelExecutionException',

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

'ModelicaSystemRunner',
'ModelicaDoERunner',

'OMPathABC',
'OMCPath',

'OMCSession',
'OMSessionRunner',

'OMCSessionABC',

'doe_get_solutions',

'OMCSessionCmd',
'OMCSessionDocker',
'OMCSessionDockerContainer',
'OMCSessionException',
'OMCSessionRunData',
'OMCSessionZMQ',
'OMCSessionPort',
'OMCSessionLocal',
'OMCSessionDocker',
'OMCSessionDockerContainer',

'OMPathRunnerBash',
'OMPathRunnerLocal',

'OMCSessionWSL',
'OMCSessionZMQ',

'OMCProcessLocal',
'OMCProcessPort',
'OMCProcessDocker',
'OMCProcessDockerContainer',
]
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
51 changes: 34 additions & 17 deletions tests/test_ModelicaSystemDoE.py → tests/test_ModelicaDoEOMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,56 +51,73 @@ 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)

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

doe_mod = OMPython.ModelicaDoEOMC(
mod=mod,
parameters=param_doe,
resultpath=tmpdir,
simargs={"override": {'stopTime': 1.0}},
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")
assert omcs.sendExpression("getVersion()") == "OpenModelica 1.25.0"

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

doe_mod = OMPython.ModelicaDoEOMC(
mod=mod,
parameters=param_doe,
session=omcs,
simargs={"override": {'stopTime': 1.0}},
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):
tmpdir = tmp_path / 'DoE'
tmpdir.mkdir(exist_ok=True)
def test_ModelicaDoEOMC_WSL(tmp_path, model_doe, param_doe):
omcs = OMPython.OMCSessionWSL()
assert omcs.sendExpression("getVersion()") == "OpenModelica 1.25.0"

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

doe_mod = OMPython.ModelicaDoEOMC(
mod=mod,
parameters=param_doe,
resultpath=tmpdir,
simargs={"override": {'stopTime': 1.0}},
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
Loading
Loading