modelicaopenmodelicasystemmodeler

How to have a causal connector with a replaceable type?


While the Advanced Modelica Tutorial: Developing Modelica Libraries is from 2003, I would still believe that the code from page 29 would give a causal connector (RealPort) with a replaceable type:

connector RealPort
  replaceable type SignalType = Real;
  extends SignalType;
end RealPort;

While this code works in the current release for Wolfram SystemModeler, Open Modelica v1.16.0-dev.03 (64-bit) complains, giving the following error:

Class 'SignalType' in 'extends SignalType' is replaceable, the base class name must be transitively non-replaceable.

So, who is right about transitive non-replaceability here and how to do this correctly?

References:


Solution

  • The class above is not transitively non-replaceable and thus translation should fail.

    The problem that the non-replaceable rule intends to avoid is a set of model such as:

    connector RealPort
      replaceable type SignalType = Real;
      extends SignalType;
    end RealPort;
    
    type MySignal
      type SignalType=Integer;
      extends Real(...);
    end MySignal;
    
    connector MyPort=RealPort(redeclare type SignalType=MySignal);
    

    The problem with those classes is to that SignalType in MyPort seems to be two things at once, and it is not clear where the problem was introduced, as the redeclare seems consistent with the constraining class and the original class looked ok.

    (Transitively just mean that you can have intermediate non-replaceable classes to confuse things.)

    And the work-around by Adrian Pop is a good solution.