modelicaunits-of-measurementopenmodelicasystemmodeler

Can a type be set globally using inner/outer and be replaceable?


Problem Description

I would like to use Non-SI-Units for time in economical modeling (e.g. System Dynamics). While of course I could go for seconds (s) and then use displayUnit there is to my knowledge no nice way to modify displayUnit for time in System Modeler, which I am mainly using.

So, writing a library I would like the user to make a choice of a global type called ModelTime which ideally would be declared as inner and replaceable at some top-level class. Then any component within a model could use the global type to consistently treat any time-related vars.

Minimal Example

The following example shows how I would like to implement this.

Here is the code:

model MinimalExample

  package Units
    type Time_year = Real(final quantity = "Time", final unit = "yr");    
    type Time_month = Real(final quantity = "Time", final unit = "mo");
  end Units;

  package Interfaces
    partial model GenericSimulationModel "Top-level model scope providing global vars"
      inner replaceable type ModelTime = Years "Set to : Months, Years";
    protected
      type Years = Units.Time_year;
      type Months = Units.Time_month;
    end GenericSimulationModel;
  end Interfaces;

  package Components
    block ComponentUsingTime
      outer type ModelTime = MinimalExample.Units.Time_year;
      output ModelTime y;
    equation
      y = time;
    end ComponentUsingTime;
  end Components;

  model Example
    extends Interfaces.GenericSimulationModel(
      redeclare replaceable type ModelTime = Months
    );
    Components.ComponentUsingTime c;
  end Example;
equation

end MinimalExample;

While everything compiles without error in System Modeler and OpenModelica, it unfortunately does not work out: The redeclared type is not used within the component c in the Example model given above.

What can I do to achieve what I want to do?


Solution

  • I have received some feedback on Wolfram Community from someone at Wolfram MathCore (developers of the System Modeler):

    The behavior you see for MinimalExample.example and MinimalLibrary.Example are bugs, and from what I can see they should work, I have forwarded them to a developer working on these things.