Package: Difference between revisions

From Mechanomy Composer Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 8: Line 8:
   //imports shared across all package models
   //imports shared across all package models
    
    
 
   //type definitions shared with all package models
   //type definitions shared with all package models
   type Weight = Real(final quantity = "Weight", final unit = "N");
   type Weight = Real(final quantity = "Weight", final unit = "N");
Line 28: Line 28:
     v := bd.length * bd.width * bd.height;
     v := bd.length * bd.width * bd.height;
   end calcVolume;
   end calcVolume;
 
 
   //models
   //models
   partial model PartialBox
   partial model PartialBox
    Modelica.SIunits.Mass m "mass of the empty box";
    BoxData bd;
  end PartialBox;
    
    
  end PartialBox;
   model SmallBox
   model SmallBox
      
      

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;