-
Notifications
You must be signed in to change notification settings - Fork 119
/
coupled_clutches.py
51 lines (40 loc) · 1.74 KB
/
coupled_clutches.py
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
43
44
45
46
47
48
49
50
51
from __future__ import print_function
from fmpy import simulate_fmu
from fmpy.util import download_test_file
import numpy as np
def simulate_coupled_clutches(fmi_version='2.0',
fmi_type='ModelExchange',
output=['outputs[1]', 'outputs[2]', 'outputs[3]', 'outputs[4]'],
solver='CVode',
events=True,
fmi_logging=False,
show_plot=True):
# download the FMU and input file
for filename in ['CoupledClutches.fmu', 'CoupledClutches_in.csv']:
download_test_file(fmi_version, fmi_type, 'MapleSim', '2016.2', 'CoupledClutches', filename)
print("Loading input...")
input = np.genfromtxt('CoupledClutches_in.csv', delimiter=',', names=True)
print("Simulating CoupledClutches.fmu (FMI %s, %s, %s)..." % (fmi_version, fmi_type, solver))
result = simulate_fmu(
filename='CoupledClutches.fmu',
validate=False,
start_time=0,
stop_time=1.5,
solver=solver,
step_size=1e-2,
output_interval=2e-2,
record_events=events,
start_values={'CoupledClutches1_freqHz': 0.4},
input=input,
output=output,
fmi_call_logger=lambda s: print('[FMI] ' + s) if fmi_logging else None)
if show_plot:
print("Plotting results...")
from fmpy.util import plot_result
plot_result(result=result,
window_title="CoupledClutches.fmu (FMI %s, %s, %s)" % (fmi_version, fmi_type, solver),
events=events)
print("Done.")
return result
if __name__ == '__main__':
simulate_coupled_clutches()