Skip to content

Commit 24a4bee

Browse files
authored
Updated User's Guide about conditional connectors, with new MLS 3.7 rules (#14647)
1 parent 7672c99 commit 24a4bee

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

doc/UsersGuide/source/porting.rst

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,19 @@ appropriate.
8383
Access to conditional components
8484
--------------------------------
8585

86-
According to `Section 4.4.5 <https://specification.modelica.org/maint/3.5/class-predefined-types-and-declarations.html#conditional-component-declaration>`_
86+
Up to Modelica 3.6, according to `Section 4.4.5 <https://specification.modelica.org/maint/3.6/class-predefined-types-and-declarations.html#conditional-component-declaration>`_
8787
of the language specification, "A component declared with a condition-attribute
88-
can only be modified and/or used in connections". When dealing, e.g., with
89-
conditional input connectors, one can use the following patterns:
88+
can only be modified and/or used in connections". This required to use the following, slightly
89+
convoluted patterns when dealing, e.g., with conditional input connectors, making use of internal
90+
auxiliary variables or connectors:
9091

9192
.. code-block:: modelica
9293
9394
model M
9495
parameter Boolean activateIn1 = true;
9596
parameter Boolean activateIn2 = true;
9697
Modelica.Blocks.Interfaces.RealInput u1_in if activateIn1;
97-
Modelica.Blocks.Interfaces.RealInput u2_in = u2 if activateIn2;
98+
Modelica.Blocks.Interfaces.RealInput u2_in = u2 if activateIn2 "binding equation only holds if activateIn2 = true";
9899
Real u2 "internal variable corresponding to u2_in";
99100
Real y;
100101
protected
@@ -110,8 +111,9 @@ conditional input connectors, one can use the following patterns:
110111
end if;
111112
end M;
112113
113-
where conditional components are only used in connect equations. The following
114-
patterns instead are not legal:
114+
where conditional components 'u1_in' and 'u2_in' were only used in connect equations. Other Modelica
115+
tools accepted code that was more straightforward and easier to understand, but actually not compliant
116+
with this restriction, causing compatibility issues, e.g.:
115117

116118
.. code-block:: modelica
117119
@@ -120,23 +122,30 @@ patterns instead are not legal:
120122
parameter Boolean activateIn2 = true;
121123
Modelica.Blocks.Interfaces.RealInput u1_in if activateIn1;
122124
Modelica.Blocks.Interfaces.RealInput u2_in if activateIn2;
123-
Real u1 "internal variable corresponding to u1_in";
124-
Real u2 "internal variable corresponding to u2_in";
125+
Real u1;
126+
Real u2;
125127
Real y;
126128
equation
129+
y = u1 + u2;
127130
if activateIn1 then
128-
u1 = u1_in "invalid: uses conditional u1_in outside connect equations";
131+
u1 = u1_in;
132+
else
133+
u1 = 0 "default value for protected connector value when u1_in is disabled";
129134
end if;
130135
if activateIn2 then
131-
u2 = u2_in "invalid: uses conditional u1_in outside connect equations";
136+
u2 = u2_in;
137+
else
138+
u2 = 0 "default value for protected connector value when u2_in is disabled";
132139
end if;
133-
y = u1 + u2;
134140
end M;
135141
136-
because those components are also used in other
137-
equations. The fact that those equations are conditional and are not activated
138-
when the corresponding conditional components are also not activated is
139-
irrelevant, according to the language specification.
142+
Although this restriction makes identifying structurally inconsistent models easier, it requires to
143+
write code that can be pretty obscure when handling use cases that would be very straightforward to handle othewise.
144+
Hence, this restriction will be removed in Modelica 3.7. In particular, the current
145+
`draft of Modelica 3.7 <https://specification.modelica.org/master/class-predefined-types-and-declarations.html#conditional-component-declaration>`_
146+
explicitly states that if the Boolean expression activating the component is true, there are no
147+
restrictions on the use of such component. Since version 1.26.0, OpenModelica complies with
148+
these new relaxed rules.
140149

141150
Access to classes defined in partial packages
142151
---------------------------------------------

0 commit comments

Comments
 (0)