A support case with the identification [CASE:4275098] was created.
While I noted some implementation problems regarding inner
and outer
in another context which have been acknowledged, I would like to get very general advice on how to reliably (= correctly?) make use of inner
and outer
declarations in Wolfram System Modeler.
I would like to provide three simple examples for a clarifying discussion.
Outer Declaration inside a subcomponent
The following example works fine: The inner
variables x, y, z[3]
are passed on towards the submodel using corresponding outer declarations and accordingly subX
, subY
, and subZ
show correct values if we simulate MainModel
.
package TestingInnerOuter_1
model MainModel
inner parameter Integer x = 1;
inner parameter Real y = 2;
inner Real z[3];
Submodel submodel;
equation
z = ones(3);
end MainModel;
block Submodel
outer parameter Integer x;
outer parameter Real y;
outer Real[3] z;
output Real subX, subY;
output Real[3] subZ;
equation
subX = x;
subY = y;
subZ = z;
end Submodel;
end TestingInnerOuter_1;
Simultaneous inner outer declaration inside a subcomponent
Now we simply add inner
as a prefix to the outer
declarations making them simultaneous inner outer
declarations.
package TestingInnerOuter_2
model MainModel
inner parameter Integer x = 1;
inner parameter Real y = 2;
inner Real z[3];
Submodel submodel;
equation
z = ones(3);
end MainModel;
block Submodel
inner outer parameter Integer x;
inner outer parameter Real y;
inner outer Real[3] z;
output Real subX, subY;
output Real[3] subZ;
equation
subX = x;
subY = y;
subZ = z;
end Submodel;
end TestingInnerOuter_2;
And now the MainModel
will not run but give errors from compilation:
From this message we already get a "hunch" about what is going amiss. And indeed the following modified version of Submodel will work in the second example:
block Submodel
inner outer parameter Integer x;
inner outer parameter Real y;
output Real subX, subY;
equation
subX = x;
subY = y;
end Submodel;
While the MainModel
will now simulate, we note that the values for x
and y
are not passed on, instead we see that each has been given the default value of zero.
Simultaneous inner outer declaration inside a subcomponent with modifications
So, given the error message for z we finally look at a version where the submodel will modify the values for x
and y
.
package TestingInnerOuter_3
model MainModel
inner parameter Integer x = 1;
inner parameter Real y = 2;
inner Real z[3];
Submodel submodel;
equation
z = ones(3);
end MainModel;
block Submodel
inner outer parameter Integer x = -1;
inner outer parameter Real y = -2;
output Real subX, subY;
equation
subX = x;
subY = y;
end Submodel;
end TestingInnerOuter_3;
Interestingly, this works out for the parameters and subX
and subY
show the correct values (e.g. 1 and 2). But, what surprises me, is that 'submodl.x' and 'submodel.y' are reported to be -1 and -2 in the ModelCenter.
So to wrap it up, the following questions arise for me:
- Why will an
inner outer
declaration not work out for continuous variables? What can be done?
- Why are
submodel.x
and submodel.y
not reported with the values according to the lookup to the inner
values in a higher scope (e.g. the MainModel
values)?
Update 1 (Warnings upon validation for inner outer
)
I am a bit confused about the compiler messages I get for the following simple declaration of a parameter as inner outer
:
model InnerOuter "Test of inner outer model"
inner outer parameter Real myParameter = 1;
end InnerOuter;
Validating this model gives:
Those warnings do not really make sense, do they?
- There is an
inner
declaration since the outer
declaration is simultaneously an inner
one.
- The
parameter myParameter
has explicitly been given a start value of 1 which is not recognized somehow.
So another question is: What about those warnings - they do not seem correct. What is going on?
Update 2 (Internal error upon using inner outer
in a subcomponent)
I am getting an internal error message validating a component that has a subcomponent with a parameter that is declared as inner outer
. A minimal example for this is the following code:
package InnerOuterTest
block HasInnerOuterParameter
inner outer parameter Real k = 1;
end HasInnerOuterParameter;
block UsesComponentWithInnerOuterParameter
HasInnerOuterParameter c;
end UsesComponentWithInnerOuterParameter;
end InnerOuterTest;
Validation of the block UsesComponentWithInnerOuterParameter will give the following error message:
What is the reason for this message? How then should we have a parameter in a subcomponent that is simultaneously inner outer
?
(Note: I tested the code given here (package InnerOuterTest
) in OpenModelica and there it will validate without any errors)