Skip to content

Commit 84f97ac

Browse files
committed
Change the flag --exposeLocalIOs to integer specifying the level
--exposeLocalIOs=0 is the top-level (default). --exposeLocalIOs=1 are input/output connectors of top-level components ... This enables the use of Modelica.Media that internally defines local input connectors and leaves them unconnected at deeper levels, see also #10599. Also strip subscripts so that arrays in connection sets are identified. See e.g. Modelica.Electrical.Machines.Examples.InductionMachines.IMC_DOL. Besides using arrays, it is also a good expample for local outputs at different levels.
1 parent 5ab1c79 commit 84f97ac

File tree

6 files changed

+67
-32
lines changed

6 files changed

+67
-32
lines changed

OMCompiler/Compiler/BackEnd/BackendDAECreate.mo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,8 +1518,8 @@ algorithm
15181518
else
15191519
algorithm
15201520
/* Consider toplevel inputs as known unless they are protected. Ticket #5591 */
1521-
/* Consider all inputs known with flag exposeLocalIOs unless they are protected */
1522-
if not Flags.getConfigBool(Flags.EXPOSE_LOCAL_IOS) then
1521+
/* Consider all inputs known with flag exposeLocalIOs > 0 unless they are protected */
1522+
if Flags.getConfigInt(Flags.EXPOSE_LOCAL_IOS) == 0 then
15231523
false := DAEUtil.topLevelInput(inComponentRef, inVarDirection, inConnectorType, protection);
15241524
else
15251525
false := DAEUtil.varDirectionEqual(inVarDirection, DAE.INPUT()) and not DAEUtil.boolVarVisibility(protection);
@@ -1551,7 +1551,7 @@ algorithm
15511551
case DAE.CONST() then BackendDAE.CONST();
15521552
case DAE.VARIABLE()
15531553
equation
1554-
if not Flags.getConfigBool(Flags.EXPOSE_LOCAL_IOS) then
1554+
if Flags.getConfigInt(Flags.EXPOSE_LOCAL_IOS) == 0 then
15551555
true = DAEUtil.topLevelInput(componentRef, varDirection, connectorType, visibility);
15561556
else
15571557
true = DAEUtil.varDirectionEqual(varDirection, DAE.INPUT()) and not DAEUtil.boolVarVisibility(visibility);

OMCompiler/Compiler/NFFrontEnd/NFConnectEquations.mo

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,12 @@ algorithm
212212
if Connector.variability(c1) > Variability.PARAMETER then
213213
equations := list(makeEqualityEquation(c1.name, c1.source, c2.name, c2.source)
214214
for c2 in listRest(elements));
215-
// collect inputs and outputs that are inside in connections if --exposeLocalIOs
216-
if Flags.getConfigBool(Flags.EXPOSE_LOCAL_IOS) then
215+
// collect inputs and outputs that are inside in connections if exposeLocalIOs > 0
216+
// strip array indices so that the variables will be found later
217+
if Flags.getConfigInt(Flags.EXPOSE_LOCAL_IOS) > 0 then
217218
for c in elements loop
218219
if (Connector.isInside(c) and (ComponentRef.isInput(c.name) or ComponentRef.isOutput(c.name))) then
219-
UnorderedSet.add(c.name, connectedLocalIOs);
220+
UnorderedSet.add(ComponentRef.stripSubscripts(c.name), connectedLocalIOs);
220221
end if;
221222
end for;
222223
end if;

OMCompiler/Compiler/NFFrontEnd/NFConvertDAE.mo

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ protected
104104
uniontype VariableConversionSettings
105105
record VARIABLE_CONVERSION_SETTINGS
106106
Boolean useLocalDirection;
107-
Boolean exposeLocalIOs;
107+
Integer exposeLocalIOs;
108108
Boolean isFunctionParameter;
109109
Boolean addTypeToSource;
110110
end VARIABLE_CONVERSION_SETTINGS;
111111
end VariableConversionSettings;
112112

113113
constant VariableConversionSettings FUNCTION_VARIABLE_CONVERSION_SETTINGS =
114-
VARIABLE_CONVERSION_SETTINGS(false, false, true, false);
114+
VARIABLE_CONVERSION_SETTINGS(false, 0, true, false);
115115

116116
function convertVariables
117117
input list<Variable> variables;
@@ -121,7 +121,7 @@ protected
121121
algorithm
122122
settings := VariableConversionSettings.VARIABLE_CONVERSION_SETTINGS(
123123
useLocalDirection = Flags.getConfigBool(Flags.USE_LOCAL_DIRECTION),
124-
exposeLocalIOs = Flags.getConfigBool(Flags.EXPOSE_LOCAL_IOS),
124+
exposeLocalIOs = Flags.getConfigInt(Flags.EXPOSE_LOCAL_IOS),
125125
isFunctionParameter = false,
126126
addTypeToSource = Flags.isSet(Flags.INFO_XML_OPERATIONS) or Flags.isSet(Flags.VISUAL_XML)
127127
);
@@ -178,7 +178,8 @@ algorithm
178178
// Alternatively strip input/output only from non connectors and from protected connectors if
179179
// --exposeLocalIOs has been set.
180180
if (attr.direction == Direction.NONE or settings.useLocalDirection) or
181-
(settings.exposeLocalIOs and attr.connectorType <> ConnectorType.NON_CONNECTOR and vis == Visibility.PUBLIC) then
181+
(settings.exposeLocalIOs > 0 and attr.connectorType <> ConnectorType.NON_CONNECTOR and
182+
ComponentRef.depth(cref) <= settings.exposeLocalIOs + 1 and vis == Visibility.PUBLIC) then
182183
dir := attr.direction;
183184
else
184185
dir := getComponentDirection(attr.direction, cref);

OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,7 @@ algorithm
20662066
flatModel.variables := list(v for v guard Variable.isPresent(v) in flatModel.variables);
20672067

20682068
// remove input and output prefixes from local IOs that are determined through connect equations
2069-
if Flags.getConfigBool(Flags.EXPOSE_LOCAL_IOS) then
2069+
if Flags.getConfigInt(Flags.EXPOSE_LOCAL_IOS) > 0 then
20702070
flatModel.variables := list(stripInputOutputForConnected(v, connectedLocalIOs) for v in flatModel.variables);
20712071
end if;
20722072

OMCompiler/Compiler/Util/Flags.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,8 +1454,8 @@ constant ConfigFlag FRONTEND_INLINE = CONFIG_FLAG(154, "frontendInline",
14541454
Gettext.gettext("Enables inlining of functions in the frontend."));
14551455

14561456
constant ConfigFlag EXPOSE_LOCAL_IOS = CONFIG_FLAG(155, "exposeLocalIOs",
1457-
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
1458-
Gettext.gettext("Keeps the input/output prefix for unconnected inputs and outputs at all levels, besides top-level ones."));
1457+
NONE(), EXTERNAL(), INT_FLAG(0), NONE(),
1458+
Gettext.gettext("Keeps the input/output prefix for unconnected inputs and outputs at requested levels, 0 meaning top-level."));
14591459

14601460
function getFlags
14611461
"Loads the flags with getGlobalRoot. Assumes flags have been loaded."

testsuite/openmodelica/cppruntime/fmu/modelExchange/2.0/exposeLocalIOs.mos

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// teardown_command: rm -f *LocalIOs.System* modelDescription.tmp.xml
55

66
setCommandLineOptions("--simCodeTarget=Cpp");
7-
setCommandLineOptions("--exposeLocalIOs=true"); getErrorString();
7+
setCommandLineOptions("--exposeLocalIOs=10"); getErrorString();
88

99
loadString("
1010
package LocalIOs
@@ -23,6 +23,7 @@ model Source
2323
RealInput u_in(start = u_par) if use_u_in;
2424
RealOutput yp;
2525
RealOutput yf;
26+
RealOutput[2] y;
2627
PhysicalConnector c;
2728
protected
2829
RealInput u_in_internal;
@@ -34,6 +35,7 @@ equation
3435
c.p = u_in_internal;
3536
connect(u_in_internal, yp);
3637
yf = c.f;
38+
y = {c.p, c.f};
3739
end Source;
3840

3941
model Component
@@ -44,16 +46,18 @@ protected
4446
Signaling signaling(u1 = 1);
4547
equation
4648
signaling.u2 = 2;
49+
signaling.u = 3:4;
4750
c.f = 0.5*c.p + modifiedInput + signaling.y;
4851
connect(signaling.y, measurement);
4952
end Component;
5053

5154
block Signaling
5255
RealInput u1;
5356
RealInput u2;
57+
RealInput[2] u;
5458
RealOutput y;
5559
equation
56-
y = u1 + u2;
60+
y = u1 + u2 + sum(u);
5761
end Signaling;
5862

5963
model System
@@ -63,6 +67,7 @@ model System
6367
equation
6468
connect(source.c, component.c);
6569
connect(source.yf, signaling.u1);
70+
connect(source.y, signaling.u);
6671
end System;
6772

6873
end LocalIOs;
@@ -128,38 +133,38 @@ readFile("modelDescription.tmp.xml");
128133
// <!-- Index of variable = \"3\" -->
129134
// <ScalarVariable
130135
// name=\"signaling.u2\"
131-
// valueReference=\"4\"
136+
// valueReference=\"6\"
132137
// causality=\"input\"
133138
// >
134139
// <Real start=\"0.0\"/>
135140
// </ScalarVariable>
136141
// <!-- Index of variable = \"4\" -->
137142
// <ScalarVariable
138143
// name=\"signaling.y\"
139-
// valueReference=\"5\"
144+
// valueReference=\"7\"
140145
// causality=\"output\"
141146
// >
142147
// <Real/>
143148
// </ScalarVariable>
144149
// <!-- Index of variable = \"5\" -->
145150
// <ScalarVariable
146151
// name=\"source.u_in\"
147-
// valueReference=\"6\"
152+
// valueReference=\"8\"
148153
// causality=\"input\"
149154
// >
150155
// <Real start=\"2.0\"/>
151156
// </ScalarVariable>
152157
// <!-- Index of variable = \"6\" -->
153158
// <ScalarVariable
154-
// name=\"source.yf\"
155-
// valueReference=\"7\"
159+
// name=\"source.y[2]\"
160+
// valueReference=\"9\"
156161
// >
157162
// <Real/>
158163
// </ScalarVariable>
159164
// <!-- Index of variable = \"7\" -->
160165
// <ScalarVariable
161166
// name=\"source.u_par\"
162-
// valueReference=\"8\"
167+
// valueReference=\"10\"
163168
// variability=\"fixed\"
164169
// causality=\"parameter\"
165170
// >
@@ -168,47 +173,75 @@ readFile("modelDescription.tmp.xml");
168173
// <!-- Index of variable = \"8\" -->
169174
// <ScalarVariable
170175
// name=\"component.c.f\"
171-
// valueReference=\"9\"
176+
// valueReference=\"11\"
172177
// >
173178
// <Real/>
174179
// </ScalarVariable>
175180
// <!-- Index of variable = \"9\" -->
176181
// <ScalarVariable
177182
// name=\"component.c.p\"
178-
// valueReference=\"6\"
183+
// valueReference=\"8\"
179184
// >
180185
// <Real/>
181186
// </ScalarVariable>
182187
// <!-- Index of variable = \"10\" -->
183188
// <ScalarVariable
184-
// name=\"signaling.u1\"
185-
// valueReference=\"7\"
189+
// name=\"signaling.u[1]\"
190+
// valueReference=\"8\"
186191
// >
187192
// <Real/>
188193
// </ScalarVariable>
189194
// <!-- Index of variable = \"11\" -->
190195
// <ScalarVariable
191-
// name=\"source.c.f\"
192-
// valueReference=\"7\"
196+
// name=\"signaling.u[2]\"
197+
// valueReference=\"9\"
193198
// >
194199
// <Real/>
195200
// </ScalarVariable>
196201
// <!-- Index of variable = \"12\" -->
197202
// <ScalarVariable
198-
// name=\"source.c.p\"
199-
// valueReference=\"6\"
203+
// name=\"signaling.u1\"
204+
// valueReference=\"9\"
200205
// >
201206
// <Real/>
202207
// </ScalarVariable>
203208
// <!-- Index of variable = \"13\" -->
204209
// <ScalarVariable
210+
// name=\"source.c.f\"
211+
// valueReference=\"9\"
212+
// >
213+
// <Real/>
214+
// </ScalarVariable>
215+
// <!-- Index of variable = \"14\" -->
216+
// <ScalarVariable
217+
// name=\"source.c.p\"
218+
// valueReference=\"8\"
219+
// >
220+
// <Real/>
221+
// </ScalarVariable>
222+
// <!-- Index of variable = \"15\" -->
223+
// <ScalarVariable
224+
// name=\"source.y[1]\"
225+
// valueReference=\"8\"
226+
// >
227+
// <Real/>
228+
// </ScalarVariable>
229+
// <!-- Index of variable = \"16\" -->
230+
// <ScalarVariable
231+
// name=\"source.yf\"
232+
// valueReference=\"9\"
233+
// >
234+
// <Real/>
235+
// </ScalarVariable>
236+
// <!-- Index of variable = \"17\" -->
237+
// <ScalarVariable
205238
// name=\"source.yp\"
206-
// valueReference=\"6\"
239+
// valueReference=\"8\"
207240
// causality=\"output\"
208241
// >
209242
// <Real/>
210243
// </ScalarVariable>
211-
// <!-- Index of variable = \"14\" -->
244+
// <!-- Index of variable = \"18\" -->
212245
// <ScalarVariable
213246
// name=\"source.use_u_in\"
214247
// valueReference=\"0\"
@@ -221,7 +254,7 @@ readFile("modelDescription.tmp.xml");
221254
// <ModelStructure>
222255
// <InitialUnknowns>
223256
// <Unknown index=\"4\" dependencies=\"3 5\" dependenciesKind=\"dependent dependent\" />
224-
// <Unknown index=\"14\" dependencies=\"\" dependenciesKind=\"\" />
257+
// <Unknown index=\"18\" dependencies=\"\" dependenciesKind=\"\" />
225258
// </InitialUnknowns>
226259
// </ModelStructure>
227260
// </fmiModelDescription>

0 commit comments

Comments
 (0)