Opened 6 years ago

Last modified 6 years ago

#5344 assigned defect

Duplicate of model causes incomplete code

Reported by: Christian Kral <dr.christian.kral@…> Owned by: Per Östlund
Priority: high Milestone: 2.0.0
Component: Interactive Environment Version: v1.14.0-dev-nightly
Keywords: Cc:

Description

Consider the following package:

package Source
  import Modelica.Constants.pi;
  import SI = Modelica.SIunits;

  package Components
    model Component
      parameter SI.Radius r = 1 "Radius";
      parameter SI.Area area = r^2*pi;
    end Component;
  end Components;

  model Example
    Components.Component component;
    parameter SI.Length l = 1;
    annotation(experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.002));
  end Example;
end Source;

If I make a right click on the model Example and select duplicate with the following settings,

Name: Example
Path: (blank)

the duplicated example

model Example
  Components.Component component;
  parameter SI.Length l = 1;
  annotation(experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.002));
end Example;

cannot be simulated for the following reasons:

  1. In the duplicate model the class name is just copied and pasted, but not replaced by the fully qualified class name which is required when copying the model the outside of the package Source. This means that
    Components.Component component;
    

has to be replaced by

  Source.Components.Component component;
  1. The import of SI is missing in the duplicate. So after adding
      import SI = Modelica.SIunits;  
    

the model is finally complete:

model Example
  import SI = Modelica.SIunits;  
  Source.Components.Component component;
  parameter SI.Length l = 1;
  annotation(experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.002));
end Example;

Conclusions and proposal

  1. When creating a duplicate of a model into a package on the same hierarchy level the actual implementation is OK
  2. When creating a duplicate of a model into a package on a different hierarchy level, but still inside the package where the inherited import statements are located, only the class names have to be replaced by the fully qualified class names
  3. When creating a duplicate of a model into a package on a different hierarchy level outside the package where the inherited import statements are located, then the "missing" import statements have to be inserted, in addition to replacing the class names by the fully qualified class names

For a productive development of models it were extremely helpful to improve the duplicate in the proposed way. Otherwise, it is particularly for beginners extremely difficult to implement the required manual changes. But even experienced user usually suffer from a long list of adaptations to be made when duplicating a model.

Attachments (1)

script.mos (630 bytes ) - added by Adeel Asghar 6 years ago.

Download all attachments as: .zip

Change History (3)

by Adeel Asghar, 6 years ago

Attachment: script.mos added

comment:1 by Adeel Asghar, 6 years ago

Component: OMEditInteractive Environment
Owner: changed from Adeel Asghar to Per Östlund
Status: newassigned

Per can you fix the copyClass to handle such cases. See the attached script.

comment:2 by Francesco Casella, 6 years ago

Milestone: Future2.0.0
Note: See TracTickets for help on using tickets.