Professional Documents
Culture Documents
WetterHaugstetter 2006
WetterHaugstetter 2006
WetterHaugstetter 2006
0
1100 1120 1140 1160 1180
hour of the year
200
2
T
150
out
Figure 2: Schematic view of building model in Dy-
q
din,Mod
q
mola’s graphical editor.
100 kit,Mod
q
50 din,TRN
q cal editor. Fig. 2 shows how our multizone building
kit,TRN
0
model was created by graphically connecting heat
−50 and air flow ports of thermal zone models. Each icon
−100 contains a model that can consist of other models,
−150
thus allowing to create complex models in a hierar-
chical way. This hierarchical model building facil-
−200
1100 1120 1140 1160 1180 itates model reuse and testing of submodels before
hour of the year
they are assembled to a large system model that may
(b) Sensible load (heating and cooling). Not shown are the loads be difficult to debug. To reduce the model develop-
for the storage area and bath rooms which are for both zones
smaller than 15 W/m2 in magnitude.
ment time, the object-oriented model construction in
Modelica allows discipline experts, such as an HVAC
engineer and a controls engineer, to model their re-
Figure 1: Comparison of room air temperatures and
spective process, and latter interface the models, ef-
sensible load for a mild day. In the legend, “T ” de-
fectively allowing to concurrently as opposed to se-
notes air temperature, “q” denotes sensible load, the
quentially build a model. By drawing lines between
subscript “out” denotes outside, “din” denotes din-
model ports, mathematical relationships are gener-
ing area, “kit” denotes kitchen, “sto” denotes stor-
ated based on the ports’ physical quantities.
age area, “bat” denotes bathroom, “Mod” denotes
Modelica libraries for multi-domain physics in-
Modelica and “T RN” denotes TRNSYS.
clude models for control systems, for thermal sys-
tems, for electrical systems and for mechanical sys-
cooling by 3%. Sensible cooling, however, is over- tems. Libraries are created using objects that define
predicted in the dining area by 7% and underpre- standard interfaces. For example, in Modelica’s ther-
dicted in the kitchen area by 5%. mal library there is a connector called HeatPort that
defines temperature and heat flow as
COMPARISON OF SIMULATION
1 p a r t i a l connector
ENVIRONMENTS 2 Modelica . Thermal .
Modelica (Fritzson and Engelson 1998) is an 3 HeatTransfer . I n t e r f a c e s . HeatPort
equation-based, non-causal, object oriented model- 4 ” T h e r m a l p o r t f o r 1−D h e a t t r a n s f e r ” ;
ing language that is designed for component oriented 5 SI . Temperature T ”Port t em perat ure” ;
multi-domain modeling of dynamic systems. Mod- 6 f l o w S I . H e a t F l o w R a t e Q flow
els are described by differential equations, algebraic 7 ” Heat f l o w r a t e ( p o s i t i v e i f
equations and discrete equations. Using standardized 8 f l o w i n g i n t o t h e component ) ” ;
9 end H e a t P o r t ;
interfaces, a model’s mathematical relations between
its interface variables is encapsulated, and the model On line 6, the type prefix flow declares that all vari-
can be represented graphically by an icon to facil- ables connected to Q flow need to sum to zero. For
itate model reuse, model exchange and connecting example, if two HeatPorts are connected, the re-
component models to system models using a graphi- lationships T1 = T2 and the conservation equation
Q f low,1 + Q f low,2 = 0 are generated. This connector time integrator can be selected from a library with
can then be used to define the interface for a one- 14 integration algorithms. The library includes im-
dimensional heat transfer element in the form plicit integration algorithms with variable step size,
which are of particular interest for building energy
1 p a r t i a l model Element1D
2 ” P a r ti a l heat t r a n s f e r element with
and controls systems since those systems are often
3 two H e a t P o r t c o n n e c t o r s t h a t d o e s stiff. For controls design, simulating with time steps
4 not s t o r e energy ” of less than a minute is often required to properly
5 S I . H e a t F l o w R a t e Q flow represent state machines and the rejection of distur-
6 ”Heat f l o w r a t e f r o m p o r t a −>p o r t b ” ; bances, and using a variable step size solver allows
7 S I . T e m p e r a t u r e dT ” p o r t a . T−p o r t b . T” ; increasing the time step during times when no mode
8 public switching or no fast transients occur.
9 HeatPort p o rt a ;
10 HeatPort port b ; Because the formulation of the system of equa-
11 equation tions is separated from its numerical solution
12 dT = p o r t a . T − p o r t b . T ; algorithm, restarting the integrator, as required if
13 p o r t a . Q flow = Q flow ; the model is used as a state estimator in a model
14 p o r t b . Q flow = −Q flow ; predictive control algorithm, or linearizing the
15 end Element1D ;
model, as required for many controls design meth-
This one-dimensional heat transfer element can then ods, can easily be performed. Furthermore, the
be used to define a thermal conductor as separation between equations and solution procedure
also allows automatic design of controllers that
1 model T h e r m a l C o n d u c t o r are based on nonlinear inverse plant models (see
2 ”Lumped t h e r m a l e l e m e n t Looye et al. 2005). The steps involved symbolic
3 t ra n s p o r ti n g heat without s to r i n g i t ”
equation manipulations to obtain an inverse model,
4 e x t e n d s I n t e r f a c e s . Element1D ;
5 parameter SI . ThermalConductance G
automatic differentiation and generation of C code
6 ”Constant thermal conductance”; with real-time integration algorithms that has been
7 equation downloaded to control platform and successfully
8 Q flow = G∗dT ; flight tested on an aircraft. Furthermore, models
9 end T h e r m a l C o n d u c t o r ; formulated in Modelica can also be compiled and
run from MATLAB/Simulink which allows using
Note that by replacing the parameter declaration on Simulink for controls design.
line 5 and the mathematical model on line 8, the
semantics can be changed to represent other one-
dimensional heat transfer elements such as a model In comparison, TRNSYS uses a procedural lan-
for long-wave radiation between two surfaces. guage to define its simulation models and discrete
Modelica is a language for model representation time integration algorithm. Models can be encapsu-
and cannot be executed directly. To create executable lated in so-called TYPEs, which are FORTRAN rou-
code, it need to be parsed to a programming lan- tines with standardized arguments. Many TYPEs im-
guage that can be compiled. To do so, we used plement their own mathematical solvers for differen-
the Dymola 5.3e simulation environment. Dymola tial and algebraic equations. For example, the multi-
performs symbolic manipulations to reduce the di- zone building model TYPE56 uses transfer functions
mensionality of the linear and non-linear systems of by Mitalas for the time integration of the opaque con-
equations that is defined by the Modelica model. Dy- struction’s temperature and an iterative solver for the
mola creates two models, one for computing the ini- window pane temperatures. The output of TYPEs
tial values, and one for performing the time integra- can be declared as input of TYPEs in a text editor
tion. For the building and HVAC model described or in a graphical editor such as in the TRNSYS Sim-
in this paper, Tab. 1 shows the dimensionality be- ulation Studio to define a system model. The system
fore and after the symbolic manipulations for those model is then solved using either successive substitu-
two models. Dymola’s implementation of Model- tion with relaxation, or a differential equation solver
ica also performs automatic differentiation. For our that converts the system of differential equations to
problem, it found analytic expressions for all Jaco- non-linear algebraic equations which it solves using
bian matrices, eliminating the need for numerically Powell’s method, a combination between steepest de-
approximating derivatives. This reduces the compu- scent and Newton’s method. There is no symbolic
tation time and increases the robustness of the numer- manipulations to reduce the size of the system of
ical solver. Finally, Dymola generates C/C++ code equations nor is there automatic differentiation per-
and compiles it. Before running the simulation, a formed.
Table 1: Reduction of the number of equations and number of variables to be solved for in Dymola’s implemen-
tation of Modelica.
MODEL DEVELOPMENT TIME they are not implemented in our Modelica model.
To comment on the model development time, we We neither accounted for the size of the commer-
compare the model development time for our Model- cial solver DASPK. We expect that the comparison
ica model with the multizone thermal building model would be similar for adding new models in Modelica
BuildOpt (Wetter 2005) because giving a time esti- vs. TRNSYS, since the overhead in each TRNSYS
mate for the TRNSYS building model is difficult if type is comparable to the overhead in each BuildOpt
not impossible since it evolved over many years with model.
contributions of several developers. BuildOpt, how-
ever, was developed by one of the authors, has a ther- NUMERICAL PERFORMANCE
mal building model with similar complexity than our
Modelica model, and its overhead for data manage-
We will now make an attempt to compare the com-
ment between the model equations and the program
putation time of the TRNSYS and Modelica repre-
kernel is comparable with the overhead in TRNSYS.
sentation of our multizone building model. As dis-
BuildOpt is implemented in C/C++ and took about
cussed by Sahlin et al. (2004), the creation of a prac-
one year to develop. This estimate does not include
tical and politically acceptable framework for fair
the time it took to implement BuildOpt’s optical win-
comparison of the numerical performance of a sim-
dow model, sky temperature model and rather sim-
ulator with a fixed time step and a variable time
ple daylighting model, which are not implemented in
step integration algorithm is delicate since the tem-
our Modelica model.1 This compares to one to two
poral resolutions are very different. In our com-
months of development time for the Modelica build-
parison, because the computation time depends on
ing model by the same author. Thus, using Model-
the solver tolerance and in the case of TRNSYS on
ica led to a 5 to 10 times reduction in development
the integration step size, we compare the computa-
time compared to using C/C++. The reduced de-
tion times for various settings of those precision pa-
velopment time is mainly attributed to the fact that
rameters. To verify the numerical accuracy of the
Modelica is an equation-based object-oriented lan-
obtained solutions, we also compare for each ex-
guage which eliminates the need for writing routines
periment the numerical error of the state variables
for data input and output and for managing the large
with the state variables computed at the highest tol-
amount of data that is involved in a building simu-
erance settings. Specifically, for Modelica, let εm ∈
lation. The shorter development time also manifests
{10−k }9k=1 be the solver tolerance and for TRNSYS,
itself in a four times smaller code size. Specifically,
let εt ∈ {(10−k , 1/n)}, with k ∈ {1, 2, . . ., 9} and n ∈
the Modelica model required us to write 6, 000 lines
{1, 2, . . . , 8} be the vector of solver tolerance and in-
of code (0.25 MB), whereas in BuildOpt, 24, 000
tegration step size in hours. We define ε∗m ! 10−9 and
lines of code (1.0 MB) were required. To make the
εt∗ ! (10−9 , 1/8), which corresponds to the highest
comparison representative, in Modelica we did in
precision settings used in our experiments.
the line count only include the code that we wrote,
and not the commercially available libraries Mod-
For a fixed solver tolerance ε, let u(ε, ·) ∈ R4 de-
elica 2.2 and Modelica Fluid. In BuildOpt, we did
note the numerical approximation to the state trajec-
not count the daylighting model, the optical win-
tory on the time interval [0, 1], which corresponds
dow model and the sky temperature model, which
to one year. The state variable can be for the four
account for 3, 500 lines of code (0.2 MB), because
thermal zones the air temperature which we denote
1 Based on the by T (·, ·), the heating energy which we denote by
code size of BuildOpt’s implementation of those
models, we estimate that implementing those models in Modelica Eh (·, ·) or the sensible and latent cooling energy
would take about one to two weeks of labor. which we denote by Ec (·, ·). We will compare for
different solver settings ε the absolute errors ’−’ : eT(ε), ’− ⋅’ : ec(ε), ’− −’ : eh(ε)
−1
10
1 4
Z 1
eT (ε) ! ∑ |T i (ε∗ , s) − T i (ε, s)| ds, (1) 10
−2
4 i=1 0
compiler and the ode15s solver which is applicable TRNSYS (εt = 1/1)
2
ε2t = 1/2
0.04
2 0
εt = 1/3 10 −9 −7 −5 −3 −1
ε2 = 1/4 10 10 10 10 10
0.03 t 1 1
ε and ε
ε2
eT(εt)
= 1/5 m t
t
0.02 ε2t = 1/6