Tags and keywords
The Modelica By Example target code (using 'initial equation') is:
model NewtonCoolingDynamic
"Cooling example with fluctuating ambient conditions"
// 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 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_inf "Ambient temperature";
Temperature T "Temperature";
initial equation
T = T0 "Specify initial value for T";
equation
if time<=0.5 then
T_inf = 298.15 "Constant temperature when time<=0.5";
else
T_inf = 298.15-20*(time-0.5) "Otherwise, decreasing";
end if;
m*c_p*der(T) = h*A*(T_inf-T) "Newton's law of cooling";
end NewtonCoolingDynamic;
This case is similar to the previous Newtown cooling example but with an if/then/else for the ambient temperature t_inf
, which is treated as a PhSVariable not a PhSConstant (a Modelica parameter).
The exported Modelica code is:
model NewtonCoolingDynamic
NewtonCoolingDynamic _NewtonCoolingDynamic;
model NewtonCoolingDynamic
parameter Temperature t0(start=363.15,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_inf;
Temperature t(start=363.15,fixed=true);
equation
m*c_p*der(t)=h*a*(t_inf-t);
if time<=0.5 then
t_inf=298.15;
else
t_inf=298.15-20*(time-0.5);
end if;
end NewtonCoolingDynamic;
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/(K.kg)");
end NewtonCoolingDynamic;
The formatting is not ideal, but it exports the if/then/else part (with comments removed) fine.
Note that because SysPhS-1.1 does not support Modelica's 'initial equation' the t0
is ignored in this trail version and the same 'start' value is set directly on t
:
Temperature t(start=363.15,fixed=true);