Package

From Mechanomy Composer Wiki
Jump to navigation Jump to search

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;