-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (39 loc) · 1.19 KB
/
main.py
File metadata and controls
42 lines (39 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from OMPython import ModelicaSystem
from pathlib import Path
def main(file=None):
"""Run a simple parameters validation model."""
model = ModelicaSystem(
str(Path(__file__).parent/'model.mo'), # Path to file where modelica code is.
'ParametersValidation', # Name of model from that file.
)
# Run the model with different parameters values and print the results:
for positive_number in [-1,1,.1]:
for negative_number in [-1,1,-.1]:
model.setParameters(
[
f'positive_number={positive_number}',
f'negative_number={negative_number}',
],
)
print('--------------------------------------', file=file)
print(f'model parameters: {model.getParameters()}', file=file)
try:
model.simulate() # Parameters values are validated here.
print('No errors')
continue
except Exception as e:
print(e, file=file)
def test_passing()->bool:
"""Function to use for automatic testing. If returns `True` it means this example is working."""
class PrintSilencer:
def write(self, s:str):
pass
test_passing = False
try:
main(file=PrintSilencer())
test_passing = True
except Exception as e:
test_passing = False
return test_passing
if __name__ == '__main__':
main()