Package: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== Package == Modelica organizes libraries in packages via the package and within keywords. === Single File Packages === Single file packages allow multiple models/functions/...") |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 6: | Line 6: | ||
package Container "OptionalDisplayName" | package Container "OptionalDisplayName" | ||
//imports shared across all package models | |||
//type definitions shared with all package models | //type definitions shared with all package models | ||
type | type Weight = Real(final quantity = "Weight", final unit = "N"); | ||
//record definitions shared with all package models | //record definitions shared with all package models | ||
record BoxData | |||
Weight grossWeight "the box's maximum weight limit"; | |||
Weight emptyWeight "the empty box's weight limit"; | |||
Modelica.SIunits.Length length "the box's length"; | |||
Modelica.SIunits.Length width "the box's width"; | |||
Modelica.SIunits.Length height "the box's height"; | |||
end BoxData; | |||
//function definitions shared with all package models | //function definitions shared with all package models | ||
function calcVolume | |||
input BoxData bd; | |||
output Modelica.SIunits.Volume v; | |||
algorithm | |||
v := bd.length * bd.width * bd.height; | |||
end calcVolume; | |||
//models | //models | ||
partial model PartialBox | |||
Modelica.SIunits.Mass m "mass of the empty box"; | |||
BoxData bd; | |||
end PartialBox; | |||
model SmallBox | model SmallBox | ||
end SmallBox; | end SmallBox; | ||
model LargeBox | |||
end LargeBox; | |||
end Container; | end Container; |
Latest revision as of 21:01, 11 June 2020
Package[edit]
Modelica organizes libraries in packages via the package and within keywords.
Single File Packages[edit]
Single file packages allow multiple models/functions/records/types to be written and run a single Modelica file. The format is
package Container "OptionalDisplayName" //imports shared across all package models //type definitions shared with all package models type Weight = Real(final quantity = "Weight", final unit = "N"); //record definitions shared with all package models record BoxData Weight grossWeight "the box's maximum weight limit"; Weight emptyWeight "the empty box's weight limit"; Modelica.SIunits.Length length "the box's length"; Modelica.SIunits.Length width "the box's width"; Modelica.SIunits.Length height "the box's height"; end BoxData; //function definitions shared with all package models function calcVolume input BoxData bd; output Modelica.SIunits.Volume v; algorithm v := bd.length * bd.width * bd.height; end calcVolume; //models partial model PartialBox Modelica.SIunits.Mass m "mass of the empty box"; BoxData bd; end PartialBox; model SmallBox end SmallBox; model LargeBox end LargeBox; end Container;