... continued from above
Inner/Outer with a simple constant
I am even more perplexed by the following. Let's simplify the above example, instead of using complicated type
constructs, we might simply define a constant String UnitOfTime
that will be set to provide the string-expression needed to define unit = "some unit"
for a var in a sub-component. Again, that constant expression will be given the prefix inner
(note, that we should not be needing replaceable
here, as we may use simple modification instead).
Minimal Library
The "library" now only consists of a partial model GenericSimulationModel
where the unit-string is defined and a very simple component SimpleClock
that is to return the simulation time in the Non-SI-Unit chosen. Within that component we use the unit-string given as a global constant directly to configure the output y:
output Real y( final quantity = "Time", unit = UnitOfTime );
Here is the complete MinimalLibrary - code for this:
package MinimalLibrary "Example for setting a global unitString constant"
package Interfaces "Partial models and connectors"
partial model GenericSimulationModel "Top-level class defining global parameters for simulation model"
inner constant String UnitOfTime = "yr";
end GenericSimulationModel;
end Interfaces;
package Components
block SimpleClock "Return the simulation time in Non-SI-Unit of time"
outer constant String UnitOfTime;
output Real y(final quantity = "Time", unit = UnitOfTime);
equation
y = time;
end SimpleClock;
end Components;
model Example "Show a simple clock functionality"
extends Interfaces.GenericSimulationModel( UnitOfTime = "mo");
Components.SimpleClock clock;
end Example;
end MinimalLibrary;
Errors and Warnings
Warning issued for missing start value for outer declaration
While the whole library code above validates sucessfully, there is a warning given when validating the SimpleClock
in the Components
package which honestly I do not understand:

System Modeler seems to issue a warning, because within the outer
declaration there is no start value given? But that in my opinion is how you are supposed to write outer
declarations. I will cite Peter Fritzon:
Outer class declarations should be defined using the short class definition. Modifiers to such outer class declarations are only allowed if the inner keyword is also present, i.e., a simultaneous inner outer class declaration.
The last point is illustrated by the following erroneous model:
class A
outer parameter Real p = 2; // Error, since declaration equation needs inner
end A;
Fritzson, Peter. Principles of Object-Oriented Modeling and Simulation with Modelica 3.3: A Cyber-Physical Approach (Kindle-Positionen8875-8881). Wiley. Kindle-Version.
Error given when running the Example model in Simulation Center
Trying to run the model Example
will not finish since the model compiles with an error:

Note: The error will arise also, when the modification (UnitOfTime = "mo"
) is removed.
After having learned, that we must use constants
to set the unit
attribute (here), I am rather perplexed to now find, that this will not work out when we use inner/outer
declarations.
Is there something wrong with the way inner
and outer
are implemented?