Opened 7 years ago
Last modified 7 years ago
#5344 assigned defect
Duplicate of model causes incomplete code
| Reported by: | 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:
- 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 thatComponents.Component component;
has to be replaced by
Source.Components.Component component;
- The
importofSIis missing in the duplicate. So after addingimport 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
- When creating a duplicate of a model into a package on the same hierarchy level the actual implementation is OK
- When creating a duplicate of a model into a package on a different hierarchy level, but still inside the package where the inherited
importstatements are located, only the class names have to be replaced by the fully qualified class names - When creating a duplicate of a model into a package on a different hierarchy level outside the package where the inherited
importstatements are located, then the "missing"importstatements 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)
Change History (3)
by , 7 years ago
| Attachment: | script.mos added |
|---|
comment:1 by , 7 years ago
| Component: | OMEdit → Interactive Environment |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
comment:2 by , 7 years ago
| Milestone: | Future → 2.0.0 |
|---|

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