Closed modelica-trac-importer closed 6 years ago
Comment by ahaumer on 31 Jul 2013 10:20 UTC [If a connect statement defines the connection of a non-conditional component c1 with a conditional component c2 and c2 is de-activated, then c1 must still be a declared element.] This means: connecting two conditional components is forbidden? Ouch!
However, modifiers can only reference variables/components that are not conditional. How does this match the example? You are modifying the conditional variable r_rel.
Comment by jmattsson on 31 Jul 2013 10:30 UTC Replying to [comment:1 ahaumer]:
This means: connecting two conditional components is forbidden? Ouch!
No, a conditional component is still declared. It just explicitly forbids the model:
model M
parameter Boolean p = false;
input Real x if p;
equation
connect(x, does_not_exist);
end M;
Comment by otter on 31 Jul 2013 10:32 UTC Replying to [comment:1 ahaumer]:
[If a connect statement defines the connection of a non-conditional component c1 with a conditional component c2 and c2 is de-activated, then c1 must still be a declared element.] This means: connecting two conditional components is forbidden? Ouch!
No. This was just an example. Of course, the case where both c1 and c2 are conditional (with the same or with different activation conditions), is also allowed.
However, modifiers can only reference variables/components that are not conditional. How does this match the example? You are modifying the conditional variable r_rel.
A modifier on a conditional variable/component is allowed. However, it is not allowed to use elements that are conditional by themselves. For example:
Resistor R1(R=100) if use_R1;
Resistor R2(R=R1.R) if use_R2; // error
Here the modifier of R1 is o.k., but the modifier of R2 is wrong, because it references an element that is conditional.
Comment by hansolsson on 24 Sep 2013 15:54 UTC Language group: Add example; and clarify if possible.
Comment by hansolsson on 23 Oct 2013 11:09 UTC Resolved in r7098
Reported by otter on 31 Jul 2013 09:59 UTC In #1223 issues have been pointed out regarding conditional components in MSL 3.2.1 Beta. There have been several attempts to fix these issues. A detailed analysis and discussion between Hans, Toni and Martin (O.) finally came to a reasonable solution that is based on the following interpretation of the Modelica Specification 3.2 rev. 2, section 4.4.5, page 37:
If the Boolean expression is false the component is not present in the flattened DAE [its modifier is ignored], and connections to/from the component are removed. A component declared with a condition_attribute can only be modified and/or used in connections. If the condition is false, the component, its modifiers, and any connect-equations involving the component, are removed. [If a connect statement defines the connection of a non-conditional component c1 with a conditional component c2 and c2 is de-activated, then c1 must still be a declared element.]
This defines that modifiers on conditional components are allowed, and are ignored if the component is not present. However, modifiers can only reference variables/components that are not conditional.
A typical use case in MSL 3.2.1 Beta is the following (simplified from Modelica.Mechanics.MultiBody.Joints.FreeMotionScalarInit, but in a similar form also present for conditional component damperCage in the Machines library):
Note, modifiers in the declaration of the conditional component ("
RealOutput r_rel(start=0)
"), as well as modifiers in a higher hierarchy ("Init init1(r_rel(start=1))
)") are allowed, as long as only elements are present in the modifier that are not conditional. If the conditional component is present ("use_r = true
"), the component is present and the modifiers have an effect. If the conditional component is not present ("use_r = false
"), the component is not present and the modifiers (especially in "Init init2(r_rel(start=1))
") are ignored.For the next version of the specification, this should be more clearly explained and the example above should be added to the specification.
Migrated-From: https://trac.modelica.org/Modelica/ticket/1227