Package

From Mechanomy Composer Wiki
Revision as of 20:59, 11 June 2020 by Unknown user (talk)
Jump to navigation Jump to search

Package

Modelica organizes libraries in packages via the package and within keywords.

Single File Packages

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
  
  end PartialBox;
  model SmallBox
    
  end SmallBox;
  
  model LargeBox
    
  end LargeBox;
end Container;