-
Notifications
You must be signed in to change notification settings - Fork 298
/
test03.mos
192 lines (179 loc) · 7.24 KB
/
test03.mos
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// name: test03.mos
// status: correct
// teardown_command: rm -rf test03/ test_res.mat
setCommandLineOptions("-g=MetaModelica");
loadModel(Modelica);
getErrorString();
buildModelFMU(Modelica.Blocks.Sources.Constant, version="2.0", fmuType="me_cs", fileNamePrefix="Modelica.Blocks.Sources.Constant", platforms={"static"});
getErrorString();
buildModelFMU(Modelica.Blocks.Sources.Sine, version="2.0", fmuType="me_cs", fileNamePrefix="Modelica.Blocks.Sources.Sine", platforms={"static"});
getErrorString();
echo(false);
loadString("
function printStatus
input Integer status;
input Integer expected;
protected
String outstatus;
String cmp=\" \";
algorithm
if (status==expected) then
cmp := \"correct\";
else
cmp := \"wrong\";
end if;
if 0 == status then
outstatus := \" ok\";
elseif 1 == status then
outstatus := \" warning\";
elseif 3 == status then
outstatus := \" error\";
end if;
print(\"status: [\" + cmp + \"]\" + outstatus);
print(\"\n\");
end printStatus;
function printType
input Integer t;
algorithm
if (Integer(OpenModelica.Scripting.oms_system.oms_system_tlm)-1 == t) then
print(\"type: oms_system_tlm\");
elseif (Integer(OpenModelica.Scripting.oms_system.oms_system_wc)-1 == t) then
print(\"type: oms_system_wc\");
elseif (Integer(OpenModelica.Scripting.oms_system.oms_system_sc)-1 == t) then
print(\"type: oms_system_sc\");
else
print(\"Unknown type\");
end if;
print(\"\n\");
end printType;
");
loadOMSimulator();
oms_setCommandLineOption("--suppressPath=true");
oms_setTempDirectory("./test03/");
oms_newModel("test");
oms_addSystem("test.eoo", OpenModelica.Scripting.oms_system.oms_system_wc);
oms_addSubModel("test.eoo.source", "Modelica.Blocks.Sources.Sine.fmu");
// save snapshot
(src,status) := oms_list("test");
print(src);
// change model
oms_addSystem("test.eoo.goo", OpenModelica.Scripting.oms_system.oms_system_sc);
oms_delete("test.eoo.source");
oms_addSubModel("test.eoo.source", "Modelica.Blocks.Sources.Constant.fmu");
// restore model from snapshot
status := oms_loadSnapshot("test", src);
printStatus(status, 0);
(src,status) := oms_list("test");
print(src);
oms_instantiate("test");
oms_initialize("test");
oms_simulate("test");
oms_terminate("test");
oms_delete("test");
unloadOMSimulator();
// Result:
// true
// true
// ""
// "Modelica.Blocks.Sources.Constant.fmu"
// "[Modelica 3.2.3+maint.om/Blocks/Sources.mo:216:5-217:102:writable] Warning: Parameter k has no value, and is fixed during initialization (fixed=true), using available start value (start=1.0) as default value.
// "
// "Modelica.Blocks.Sources.Sine.fmu"
// "[Modelica 3.2.3+maint.om/Blocks/Sources.mo:517:5-517:73:writable] Warning: Parameter freqHz has no value, and is fixed during initialization (fixed=true), using available start value (start=1.0) as default value.
// "
// <?xml version="1.0"?>
// <ssd:SystemStructureDescription xmlns:ssc="http://ssp-standard.org/SSP1/SystemStructureCommon" xmlns:ssd="http://ssp-standard.org/SSP1/SystemStructureDescription" xmlns:ssv="http://ssp-standard.org/SSP1/SystemStructureParameterValues" xmlns:ssm="http://ssp-standard.org/SSP1/SystemStructureParameterMapping" xmlns:ssb="http://ssp-standard.org/SSP1/SystemStructureSignalDictionary" xmlns:oms="https://raw.githubusercontent.com/OpenModelica/OMSimulator/master/schema/oms.xsd" name="test" version="1.0">
// <ssd:System name="eoo">
// <ssd:Annotations>
// <ssc:Annotation type="org.openmodelica">
// <oms:SimulationInformation>
// <oms:FixedStepMaster description="oms-ma" stepSize="0.100000" absoluteTolerance="0.000100" relativeTolerance="0.000100" />
// </oms:SimulationInformation>
// </ssc:Annotation>
// </ssd:Annotations>
// <ssd:Connectors />
// <ssd:Elements>
// <ssd:Component name="source" type="application/x-fmu-sharedlibrary" source="resources/0001_source.fmu">
// <ssd:Connectors>
// <ssd:Connector name="y" kind="output">
// <ssc:Real />
// <ssd:ConnectorGeometry x="1.000000" y="0.500000" />
// </ssd:Connector>
// <ssd:Connector name="amplitude" kind="parameter">
// <ssc:Real />
// </ssd:Connector>
// <ssd:Connector name="freqHz" kind="parameter">
// <ssc:Real />
// </ssd:Connector>
// <ssd:Connector name="offset" kind="parameter">
// <ssc:Real />
// </ssd:Connector>
// <ssd:Connector name="phase" kind="parameter">
// <ssc:Real />
// </ssd:Connector>
// <ssd:Connector name="startTime" kind="parameter">
// <ssc:Real />
// </ssd:Connector>
// </ssd:Connectors>
// </ssd:Component>
// </ssd:Elements>
// <ssd:Connections />
// </ssd:System>
// <ssd:DefaultExperiment startTime="0.000000" stopTime="1.000000">
// <ssd:Annotations>
// <ssc:Annotation type="org.openmodelica">
// <oms:SimulationInformation resultFile="test_res.mat" loggingInterval="0.000000" bufferSize="10" signalFilter="" />
// </ssc:Annotation>
// </ssd:Annotations>
// </ssd:DefaultExperiment>
// </ssd:SystemStructureDescription>
// info: Delete source
// status: [correct] ok
// <?xml version="1.0"?>
// <ssd:SystemStructureDescription xmlns:ssc="http://ssp-standard.org/SSP1/SystemStructureCommon" xmlns:ssd="http://ssp-standard.org/SSP1/SystemStructureDescription" xmlns:ssv="http://ssp-standard.org/SSP1/SystemStructureParameterValues" xmlns:ssm="http://ssp-standard.org/SSP1/SystemStructureParameterMapping" xmlns:ssb="http://ssp-standard.org/SSP1/SystemStructureSignalDictionary" xmlns:oms="https://raw.githubusercontent.com/OpenModelica/OMSimulator/master/schema/oms.xsd" name="test" version="1.0">
// <ssd:System name="eoo">
// <ssd:Annotations>
// <ssc:Annotation type="org.openmodelica">
// <oms:SimulationInformation>
// <oms:FixedStepMaster description="oms-ma" stepSize="0.100000" absoluteTolerance="0.000100" relativeTolerance="0.000100" />
// </oms:SimulationInformation>
// </ssc:Annotation>
// </ssd:Annotations>
// <ssd:Connectors />
// <ssd:Elements>
// <ssd:Component name="source" type="application/x-fmu-sharedlibrary" source="resources/0001_source.fmu">
// <ssd:Connectors>
// <ssd:Connector name="y" kind="output">
// <ssc:Real />
// <ssd:ConnectorGeometry x="1.000000" y="0.500000" />
// </ssd:Connector>
// <ssd:Connector name="amplitude" kind="parameter">
// <ssc:Real />
// </ssd:Connector>
// <ssd:Connector name="freqHz" kind="parameter">
// <ssc:Real />
// </ssd:Connector>
// <ssd:Connector name="offset" kind="parameter">
// <ssc:Real />
// </ssd:Connector>
// <ssd:Connector name="phase" kind="parameter">
// <ssc:Real />
// </ssd:Connector>
// <ssd:Connector name="startTime" kind="parameter">
// <ssc:Real />
// </ssd:Connector>
// </ssd:Connectors>
// </ssd:Component>
// </ssd:Elements>
// <ssd:Connections />
// </ssd:System>
// <ssd:DefaultExperiment startTime="0.000000" stopTime="1.000000">
// <ssd:Annotations>
// <ssc:Annotation type="org.openmodelica">
// <oms:SimulationInformation resultFile="test_res.mat" loggingInterval="0.000000" bufferSize="10" signalFilter="" />
// </ssc:Annotation>
// </ssd:Annotations>
// </ssd:DefaultExperiment>
// </ssd:SystemStructureDescription>
// info: Result file: test_res.mat (bufferSize=10)
// endResult