Getting Physical - NewtonCoolingWithTypes

Click on the image to view it full size

Firstly, before introducing NewtownCoolingWithTypes, Modelica By Example introduces a version NewtownCoolingWithUnits with inline units declarations:

model NewtonCoolingWithUnits "Cooling example with physical units"
  parameter Real T_inf(unit="K")=298.15 "Ambient temperature";
  parameter Real T0(unit="K")=363.15 "Initial temperature";
  parameter Real h(unit="W/(m2.K)")=0.7 "Convective cooling coefficient";
  parameter Real A(unit="m2")=1.0 "Surface area";
  parameter Real m(unit="kg")=0.1 "Mass of thermal capacitance";
  parameter Real c_p(unit="J/(")=1.2 "Specific heat";

  Real T(unit="K") "Temperature";
initial equation
  T = T0 "Specify initial value for T";
  m*c_p*der(T) = h*A*(T_inf-T) "Newton's law of cooling";
end NewtonCoolingWithUnits;

This form can't be directly reproduced via SysPhS.

The Modelica By Example target code with 'initial equation' and explicit type declarations is:

model NewtonCoolingWithTypes "Cooling example with physical types"
  // Types
  type Temperature=Real(unit="K", min=0);
  type ConvectionCoefficient=Real(unit="W/(m2.K)", min=0);
  type Area=Real(unit="m2", min=0);
  type Mass=Real(unit="kg", min=0);
  type SpecificHeat=Real(unit="J/(", min=0);

  // Parameters
  parameter Temperature T_inf=298.15 "Ambient temperature";
  parameter Temperature T0=363.15 "Initial temperature";
  parameter ConvectionCoefficient h=0.7 "Convective cooling coefficient";
  parameter Area A=1.0 "Surface area";
  parameter Mass m=0.1 "Mass of thermal capacitance";
  parameter SpecificHeat c_p=1.2 "Specific heat";

  // Variables
  Temperature T "Temperature";
initial equation
  T = T0 "Specify initial value for T";
  m*c_p*der(T) = h*A*(T_inf-T) "Newton's law of cooling";
end NewtonCoolingWithTypes;

To introduce units via SysPhS you have to use explicit SysML ValueTypes with SysML Units as shown for block NewtownCoolingWithTypes. Unfortunately, most of the ISO-80000 ModelLibrary Units don't have Modelica-friendly unit symbols, and some the ValueType names export badly, but it's easy to create custom ones. Just remember:

The exported Modelica code is (using lower case value property names):

model NewtonCoolingWithTypes
  NewtonCoolingWithTypes _NewtonCoolingWithTypes;
  model NewtonCoolingWithTypes
    parameter Temperature t_inf(start=25.0,fixed=true);
    parameter Temperature t0(start=90.0,fixed=true);
    parameter ConvectionCoefficient h(start=0.7,fixed=true);
    parameter Area a(start=1.0,fixed=true);
    parameter Mass m(start=0.1,fixed=true);
    parameter SpecificHeat c_p(start=1.2,fixed=true);
    Temperature t(start=90.0,fixed=true);
  end NewtonCoolingWithTypes;
  type Temperature=Real(unit="K");
  type ConvectionCoefficient=Real(unit="W/(m2.K)");
  type Area=Real(unit="m2");
  type Mass=Real(unit="kg");
  type SpecificHeat=Real(unit="J/(");
end NewtonCoolingWithTypes;
The SysPhS version as formulated here is quite different from the Modelica University version because:

The initial temperature t0 is «UNUSED» and a default is set directly on t, which becomes a 'start' on export to Modelica.

The SysPhS version also has a limitation:

One could argue that the explicit types approach is clearer than inline units and more self-documenting.

Up next
Snippets (quotes/extracts)
Visit also
Visit also (backlinks)
Related slides (includes other tutorials)
Related slides (backlinks, includes other tutorials)
External links