﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5344	Duplicate of model causes incomplete code	Christian Kral <dr.christian.kral@…>	Per Östlund	"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;
}}}

2. 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.

"	defect	assigned	high	2.0.0	Interactive Environment	v1.14.0-dev-nightly			
