Package: Difference between revisions

From Mechanomy Composer Wiki
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
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
 
  end PartialBox;
   model SmallBox
   model SmallBox
 
   
   end SmallBox;
   end SmallBox;
 
 
 
  model LargeBox
   
  end LargeBox;
  end Container;
  end Container;

Revision as of 20:59, 11 June 2020

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;