-
Notifications
You must be signed in to change notification settings - Fork 2
/
RunOMSim.m
49 lines (40 loc) · 1.78 KB
/
RunOMSim.m
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
function [time, outs, t_elapsed] = RunOMSim(filename, outputs, stopTime, stepSize)
% Runs a simulation of exe simulator from openmodelica
% command = [ ...
% 'C:/Users/User/AppData/Local/Temp/OpenModelica/OMEdit/Cardiovascular.Model.Smith2004.HemodynamicsSmith_shallow/Cardiovascular.Model.Smith2004.HemodynamicsSmith_shallow.exe ', ...
% '-port=55507 -logFormat=xmltcp ', ...
% '-override=startTime=0,stopTime=300,stepSize=0.06,tolerance=1e-06,', ...
% 'solver=dassl,outputFormat=mat,variableFilter=.* ', ...
% '-r=C:/Users/User/AppData/Local/Temp/OpenModelica/OMEdit/Cardiovascular.Model.Smith2004.HemodynamicsSmith_shallow/Cardiovascular.Model.Smith2004.HemodynamicsSmith_shallow_res.mat ', ...
% '-w -lv=LOG_STATS ', ...
% '-inputPath=C:/Users/User/AppData/Local/Temp/OpenModelica/OMEdit/Cardiovascular.Model.Smith2004.HemodynamicsSmith_shallow ', ...
% '-outputPath=C:/Users/User/AppData/Local/Temp/OpenModelica/OMEdit/Cardiovascular.Model.Smith2004.HemodynamicsSmith_shallow ' ...
% ]
%
%% SIMULATE
% params = ',HR.k=1';
params = '';
command = [ ...
filename, ' ', ...
'-override startTime=0,stopTime=', num2str(stopTime), ',stepSize=', num2str(stepSize), ',tolerance=1e-07,', ...
'solver=dassl,outputFormat=mat,variableFilter=.*',params, ...
];
tic
[s, a] = system(command);
disp('OpenModelica exe simulation time:')
toc
%% LOAD RESULTS
m = load('FMITest.Smith_patSpec_res.mat');
% unpack the modelica mat structure
names = cellstr(m.name');
% names(find(contains(names, 'pressure')))
plot_var_i = find(contains(names, outputs));
% get the position in data_2
data2_i = m.dataInfo(2, plot_var_i);
% get the time
time = m.data_2(1, :);
% get the var
outs = m.data_2(data2_i, :)';
disp('OpenMOdelica loading results:')
toc
t_elapsed = toc;