|
| 1 | +import sys |
| 2 | + |
1 | 3 | import numpy as np |
2 | 4 | import pytest |
3 | 5 |
|
4 | 6 | import OMPython |
5 | 7 |
|
6 | 8 |
|
| 9 | +skip_on_windows = pytest.mark.skipif( |
| 10 | + sys.platform.startswith("win"), |
| 11 | + reason="OpenModelica Docker image is Linux-only; skipping on Windows.", |
| 12 | +) |
| 13 | + |
| 14 | + |
7 | 15 | @pytest.fixture |
8 | 16 | def model_firstorder_content(): |
9 | 17 | return """ |
@@ -71,6 +79,50 @@ def test_ModelicaSystemRunner(model_firstorder, param): |
71 | 79 | _check_result(mod=mod, resultfile=resultfile_modr, param=param) |
72 | 80 |
|
73 | 81 |
|
| 82 | +@skip_on_windows |
| 83 | +def test_ModelicaSystemRunner_bash_docker(model_firstorder, param): |
| 84 | + omcp = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal") |
| 85 | + om = OMPython.OMCSessionZMQ(omc_process=omcp) |
| 86 | + assert om.sendExpression("getVersion()") == "OpenModelica 1.25.0" |
| 87 | + |
| 88 | + # create a model using ModelicaSystem |
| 89 | + mod = OMPython.ModelicaSystemOMC( |
| 90 | + session=omcp, |
| 91 | + ) |
| 92 | + mod.model( |
| 93 | + model_file=model_firstorder, |
| 94 | + model_name="M", |
| 95 | + ) |
| 96 | + |
| 97 | + resultfile_mod = mod.getWorkDirectory() / f"{mod.get_model_name()}_res_mod.mat" |
| 98 | + _run_simulation(mod=mod, resultfile=resultfile_mod, param=param) |
| 99 | + |
| 100 | + # run the model using only the runner class |
| 101 | + omcs = OMPython.OMSessionRunner( |
| 102 | + version=mod.get_session().get_version(), |
| 103 | + cmd_prefix=omcp.model_execution_prefix(cwd=mod.getWorkDirectory()), |
| 104 | + ompath_runner=OMPython.OMPathRunnerBash, |
| 105 | + model_execution_local=False, |
| 106 | + ) |
| 107 | + modr = OMPython.ModelicaSystemRunner( |
| 108 | + session=omcs, |
| 109 | + work_directory=mod.getWorkDirectory(), |
| 110 | + ) |
| 111 | + modr.setup( |
| 112 | + model_name="M", |
| 113 | + ) |
| 114 | + |
| 115 | + resultfile_modr = mod.getWorkDirectory() / f"{mod.get_model_name()}_res_modr.mat" |
| 116 | + _run_simulation(mod=modr, resultfile=resultfile_modr, param=param) |
| 117 | + |
| 118 | + # cannot check the content as runner does not have the capability to open a result file |
| 119 | + assert resultfile_mod.size() == resultfile_modr.size() |
| 120 | + |
| 121 | + # check results |
| 122 | + _check_result(mod=mod, resultfile=resultfile_mod, param=param) |
| 123 | + _check_result(mod=mod, resultfile=resultfile_modr, param=param) |
| 124 | + |
| 125 | + |
74 | 126 | def _run_simulation(mod, resultfile, param): |
75 | 127 | simOptions = {"stopTime": param['stopTime'], "stepSize": 0.1, "tolerance": 1e-8} |
76 | 128 | mod.setSimulationOptions(**simOptions) |
|
0 commit comments