# 导入物理类型¶

within ModelicaByExample.BasicEquations.CoolingExample;
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/(K.kg)", 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";
equation
m*c_p*der(T) = h*A*(T_inf-T) "Newton's law of cooling";
end NewtonCoolingWithTypes;


within ModelicaByExample.PackageExamples;
model NewtonCooling
"Cooling example importing physical types from the Modelica Standard Library"
import Modelica.SIunits.Temperature;
import Modelica.SIunits.Mass;
import Modelica.SIunits.Area;
import ConvectionCoefficient = Modelica.SIunits.CoefficientOfHeatTransfer;
import SpecificHeat = Modelica.SIunits.SpecificHeatCapacity;

// Parameters
parameter Temperature T_inf=300.0 "Ambient temperature";
parameter Temperature T0=280.0 "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";
equation
m*c_p*der(T) = h*A*(T_inf-T) "Newton's law of cooling";
end NewtonCooling;


  import Modelica.SIunits.Temperature;


  import ConvectionCoefficient = Modelica.SIunits.CoefficientOfHeatTransfer;


import Modelica.SIunits.Temperature; // Celsius
import ImperialUnits.Temperature;    // Fahrenheit


import DegK = Modelica.SIunits.Temperature; // Kelvin
import DegR = ImperialUnits.Temperature;    // Rankine


import语句最后一个值得讨论的形式是通配符导入语句。一个一个地导入单位可能有些乏味。通配符导入允许我们从给定的包里一次性导入所有类型。回想一下早前的如下例子：

within ModelicaByExample.BasicEquations.RotationalSMD;
model SecondOrderSystem "A second order rotational system"
type Inertia=Real(unit="kg.m2");
parameter Inertia J1=0.4 "Moment of inertia for inertia 1";
parameter Inertia J2=1.0 "Moment of inertia for inertia 2";
parameter Stiffness k1=11 "Spring constant for spring 1";
parameter Stiffness k2=5 "Spring constant for spring 2";
parameter Damping d1=0.2 "Damping for damper 1";
parameter Damping d2=1.0 "Damping for damper 2";
Angle phi1 "Angle for inertia 1";
Angle phi2 "Angle for inertia 2";
AngularVelocity omega1 "Velocity of inertia 1";
AngularVelocity omega2 "Velocity of inertia 2";
initial equation
phi1 = 0;
phi2 = 1;
omega1 = 0;
omega2 = 0;
equation
// Equations for inertia 1
omega1 = der(phi1);
J1*der(omega1) = k1*(phi2-phi1)+d1*der(phi2-phi1);
// Equations for inertia 2
omega2 = der(phi2);
J2*der(omega2) = k1*(phi1-phi2)+d1*der(phi1-phi2)-k2*phi2-d2*der(phi2);
end SecondOrderSystem;


import Modelica.SIunits.Angle;
import Modelica.SIunits.AngularVelocity;
import Modelica.SIunits.Inertia;
import Stiffness = Modelica.SIunits.RotationalSpringConstant;
import Damping = Modelica.SIunits.RotationalDampingConstant;


within ModelicaByExample.PackageExamples;
model SecondOrderSystem
"A second order rotational system importing types from Modelica Standard Library"
import Modelica.SIunits.*;
parameter Angle phi1_init = 0;
parameter Angle phi2_init = 1;
parameter AngularVelocity omega1_init = 0;
parameter AngularVelocity omega2_init = 0;
parameter Inertia J1=0.4;
parameter Inertia J2=1.0;
parameter RotationalSpringConstant k1=11;
parameter RotationalSpringConstant k2=5;
parameter RotationalDampingConstant d1=0.2;
parameter RotationalDampingConstant d2=1.0;
Angle phi1;
Angle phi2;
AngularVelocity omega1;
AngularVelocity omega2;
initial equation
phi1 = phi1_init;
phi2 = phi2_init;
omega1 = omega1_init;
omega2 = omega2_init;
equation
omega1 = der(phi1);
omega2 = der(phi2);
J1*der(omega1) = k1*(phi2-phi1)+d1*der(phi2-phi1);
J2*der(omega2) = k1*(phi1-phi2)+d1*der(phi1-phi2)-k2*phi2-d2*der(phi2);
end SecondOrderSystem;