|
19 | 19 |
|
20 | 20 | import numpy as np |
21 | 21 |
|
| 22 | +import re |
| 23 | + |
22 | 24 | from OMPython.OMCSession import ( |
23 | 25 | OMCSessionException, |
24 | 26 | OMCSessionRunData, |
@@ -1068,13 +1070,32 @@ def simulate_cmd( |
1068 | 1070 | # simulation options are not added to override file anymore |
1069 | 1071 | # pass them to simulation executable directly as individual arguments |
1070 | 1072 | # see https://github.com/OpenModelica/OpenModelica/pull/14813 |
1071 | | - for key, opt_value in self._simulate_options_override.items(): |
1072 | | - om_cmd.arg_set(key=key, val=str(opt_value)) |
1073 | 1073 |
|
1074 | | - override_content = ( |
1075 | | - "\n".join([f"{key}={value}" for key, value in self._override_variables.items()]) |
1076 | | - + "\n" |
1077 | | - ) |
| 1074 | + |
| 1075 | + version = self._session.sendExpression("getVersion()", parsed=True) |
| 1076 | + print(f"OpenModelica version string: {version}") |
| 1077 | + |
| 1078 | + m = re.search(r"v(\d+)\.(\d+)\.(\d+)", s) |
| 1079 | + if not m: |
| 1080 | + raise ValueError("Version not found") |
| 1081 | + |
| 1082 | + major, minor, patch = map(int, m.groups()) |
| 1083 | + |
| 1084 | + if (major, minor, patch) > (1, 25, 0): |
| 1085 | + print("Version > 1.27.0") |
| 1086 | + for key, opt_value in self._simulate_options_override.items(): |
| 1087 | + om_cmd.arg_set(key=key, val=str(opt_value)) |
| 1088 | + override_content = ( |
| 1089 | + "\n".join([f"{key}={value}" for key, value in self._override_variables.items()]) |
| 1090 | + + "\n" |
| 1091 | + ) |
| 1092 | + else: |
| 1093 | + print("Version < 1.27.0") |
| 1094 | + override_content = ( |
| 1095 | + "\n".join([f"{key}={value}" for key, value in self._override_variables.items()]) |
| 1096 | + + "\n".join([f"{key}={value}" for key, value in self._simulate_options_override.items()]) |
| 1097 | + + "\n" |
| 1098 | + ) |
1078 | 1099 |
|
1079 | 1100 | override_file.write_text(override_content) |
1080 | 1101 | om_cmd.arg_set(key="overrideFile", val=override_file.as_posix()) |
|
0 commit comments