Professional Documents
Culture Documents
Modelica
Michael Wetter
Simulation Research Group
The vision is to
create a flexible computing infrastructure for research, product
development and operation of engineered systems,
based on open standards
for expressing models and interfacing computing modules,
which allows
analysis and reasoning based on models,
and model-transformation for different use cases.
data
dynamics
x = f (x)
Case study:
Building in which the fixed schematic of the simulator required
a model to be used that is different from the actual system
Actual system and implementation in BIM
Granularity & connectivity defined by product
offerings and physical connections.
Procedural Modeling
Acausal Modeling
Acausal connectors
Domain
Potential
Flow
Heat flow
Q_flow
input/output determined
at compilation time
Fluid flow
h_outflow
X_outflow
C_outflow
Electrical
Translational
Requirement of locally
balanced models
# of equations = # of
variables,
at each level of model
hierarchy.
Stream
m_flow
Automatically summed
up at connections to
satisfy conservation
equation.
connector Pin "Pin of an electrical component"
SIunits.Voltage v "Potential at the pin";
flow SIunits.Current i "Current flowing into the pin";
end Pin;
model Ground "Ground node"
Modelica.Electrical.Analog.Interfaces.Pin p;
equation
p.v = 0;
end Ground;
Encapsulation - Modelica
...
equation
dT = solid.T - fluid.T;
solid.Q_flow = Q_flow;
fluid.Q_flow = -Q_flow;
Q_flow = A*qCon_flow();
end Convection;
10
Numerics
11
t 2 [0, 1]
If your model does not satisfy these properties, what can you do if a solver does not
converge, or gives unexpected results? Is it a problem of the model or the solver?
12
V = sign( p) k
| p|
Suppose this expression is part of an algebraic loop that is solved for the pressure p using a
Newton algorithm.
Let g(p) = 0 be the residual function.
g(pk )
@g(pk )/@p
-5
-4
-3
-2
-1
13
Stream of fluids
For electrical systems, we have a potential (voltage) that drives a flow (current).
For fluids, we have a potential (pressure) that drives a flow (mass flow rate) which carries
properties (temperatures, mass concentration).
Conservation of mass
n
X
0=
m
i
houtf low,a
houtf low,b
i=1
Conservation of energy
(
n
X
hmix ,
if m
i>0
0=
m
i
houtf low,i , otherwise.
i=1
hmix
If mass flow rates are computed based on (nonlinear) pressure drops, this cannot be solved
reliably as the residual equation depends on a boolean variable.
14
inStream(h
)=
j =1...n , j i
j =1...n , j i
0
m& 1
m& 2
m& 3
houtflow, j
(n 1)
j =1...n , j i
houtflow, j
n 1
(
(
3(
3ba
)
2 ba )
m
,
)
+
h
max
(
m
inStream(houtflow
2 ,i ) = 3 a
3 , )
system
is basically described by the following set of
inStream(h1a ) =
max(m& 2 ,houtflow
) +, j max
( m& 3 , )m&equations:
positiveMax(
j , i )
mix
3 ab
j =1...n , j i
j =1...n , j i
2 ab
(13)
15
Incidence matrix
1: Q = T1 T2
2 : 0 = T1
3 : f (t) = T1 + T2
T1
T2
T1
T2
Application to an
electric circuit model
16
(ii) Tearing
0 = f ( x ), x , n > 1,
that can be written in the form
1
2
(1) L x = f ( x ),
1
(2)
2
1
2
0 = f ( x , x ),
18
Non-careful constructed
models can lead to numerical
problems for which it can take
days to find the root cause
19
Symptom:
Mass flow rate started to oscillate when fan control
(54)
signal was off
by nu-
airflow
damper
fan
pump
south
east
north
west
zone
zone
zone
zone
zone
cooling
coil
-
control valve
m (t)/m 0
w resistance
pre-heat
coil
core
1
0.5
0
0.5
1
1,000
1,600
time in seconds
20
m (t)/m 0
Problem size
1
0.5
0
0.5
1
600
1,000
1,600
time in seconds
21
volume
Fi
of
ca
(a)
Solid lines indicate flow paths with zero volume flow rate;
dashed lines indicate flow paths in which volume flow rates oscillate.
Fi
22
r (e, t) c2
(54)
6.2Problem
Implementation
in Buildings Library
0.12V (e, t) required dividing numerical noise by nuThus, computing
abstraction
merical noise.
Fan curve
V (e, t)
Figure
of con
caused
m (t)/m 0
fan, consisting
of a volume
(circle)
WeNonlinear
will nowresidual
explain
how the first two problems
were
avoided
in
the
function:
and a pressure source (triangle)
flow resistance
Buildings library version 0.12. We will then explain why the new
f (x) = 0
implementation was also not robust. Finally, in Section 6.3 we will
Numerical approximation:
volume
heating coil, consisting
explain how we reimplemented
the
fan
model
to
circumvent
all three
of volumes in series
kf (x) f (x ())k K
DRAFT working paper. Do not distribute.
problems.
(a)
for
K > 0.
In some
the Buildings
library version 0.12,Solidthe
first two problems are
lines indicate flow paths with zero volume flow rate;
For small values of r (t) and Dp(r (t), V (t)), the governing equation
dashed lines indicate flow paths in which volume flow rates oscillate.
became
avoided by reformulating
(51) as
r (e, t)2 c1
fans (52a)
were connected
as
= c r (t) + c r (t)Moreover,
V (t), since in the system model, theDRAFT
working
paper.
Figure
shown
in
Figure
10,
the
fluid
volumes
of
two
fan
models
were
cou
.
(54)
r (e, t)2c
2parameterization, multiple volumes were
m (t)/
= c 1 r (t) + c2 r (tpled.
) V Due
(t)to+thecmodel
V
(
t
)
,
(52b)
3
2
flow r
Thus, computing
V (e, t) required dividing
numerical
noise
by nuA model is always
an idealization,
but the
above
idealization,
whileingood
text abooks,
connected
without
a flow resistance
between,for
forming
sequence is
n
ure 10
merical noise.
of connected volumes. Within this sequence, the mass flow rate benot suited for simulation:
n i i 1
Dp
(
r
(
t
)
,
V
(
t
))
=
c
r
(
t
)
VVcame
(oscillatory
t, )the
, governing
for
n Ifaspressure
4.
(52c)
and
unstable,
shown in Figure
11, because at
fan,
consisting
of
a
volume
(circle)
For small values of r (and
t)a and
Dp
(
r
(
t
)
,
(
t
))
equation
i
raise
and fan speed
pressure source (triangle)
Figure
10:
Schematic
diagram
r = 0 (and Dp
= 0), any value of V (t) satisfied the governing equaflow resistance
i
=
1
thepath.
approximate
became
ofare
configuration
of
fanscaused
that thesolution
tion (52a)
for the fan in the lower
flow
This
solver to of
Numerical approximation of the volume flow
rate
caused
unstable
simulation.then numerical
stall.
iterative
solvers,
This implementation
has
shown
to
be
numerically
problematic
in a
Dp
(
e,
r
(
e,
t
)
,
V
(
e,
t
))
r
(
e,
t
)
c
1
noise is divided by numerical
(e, t) =
volume
V
heating coil, consisting
large system model in which ofrthe
curve
was modeled
as a linear
( e,fan
New Implementation
in Buildings
volumes
intseries
) c6.3
noise! Library
2
12
(t) as 1an iteration
function.12 The reason
was
that
Dymola
selected
V
This prob
600
23
1,000
1,600
Thus,
computing
V
(
e,
t
)
required
dividing
numerical
noise
by
nuflow r
time
in
seconds
m (t)/m 0
(a)
Solid lines indicate flow paths with zero volume flow rate;
dashed lines indicate flow paths in which volume flow rates oscillate.
network
putes the pressure raise p r(t), V (t) . Fan curves
Solution:
a model
satisfies
physics
where of
that
relateConstruct
volume flow
rate tothat
pressure
raise
are not
Implem
interest,decreasing
is differentiable
a unique
strictly
if a fanand
has has
a stall
region. solution
However,
The Mo
pressure
state
pressure
source
flow
resistance
pressure
state
below we will show that strict decrease is required to
for a fan
prove existence of a solution. A numerical solver then
computes
r(t),V (t))
pa (t) and ppr (bV(t)
pa (t) for some p(r(t),
(t)) a numerical
pb (t)
approximation
to
the
flow
rate
V
(t)
that
satisfies
1: Schematic
diagram
for
pressure
boundary
condition,
pressure
source of fan, and flow resistance.
p(r
Find functional form p(, ) so that
nV
0
=
p(r(t),
(t))
p
(
V
(2)for a robust simulatio
a (t) pbis(t).
proximation. Let x 2 R , for some n 2 r
N. (t))+p
suited formulation
required
ite x () 2 Rn to denote the numerical apwhere r
n tohas
x obtained
with
solver
precision
conNote
that even
if the fan is controlled to be either on
a
unique
solution
(and
physics
is
satisfied
in
region
of
interest).
We
are
interested
in
how
to
formulate
the
fan
curve
N
(t)/N
eter 2 R+ . For example, for f (x) = 0,
off, the speed r(t) may attain any value between 0 a
Hence,
we
want
p(,to)
such
that
(2)
has always
unique
solution.
thespeed
volu
p(,If)
a solution
the
equation.
obtaining
this
1.a For
example,
a user may compute the
as
quires an iterative solver, then one computes
output of a second order filter for two cients
reasons: th
Fi
Now,
continuous
time
system
simulation
programs
to be continuously
mate1)solution
x () 2 Rndifferentiable,
that satisfies,and
for
this provides a continuous change in flow rate, wh
ing
poin
compute
for
any
time
instant
t
2
R
and
speed
0, can
can
be
faster
and
more
robust
to
simulate
compa
fa
an approximate solution V (,fan.
t) For
to this
(2).reason,
In thecases
fan models inby
thethe
Model
Mwhere
DEFINITION
/ user
Buildings library
have a parameter
allows
r.24
no solution exists, the iterative
solution
will that V
<
(8)
p(V )
n
Otherwise,
the
following
may
occur:
ite x@ ()p(r,
2 RV )to<
denote.the numerical ap(10)
n to x obtained
with solver precision conNote that even if the fan is controlled to be either on
@ V
Wespeed
will r(t)
nowmay
create
fan
model
that0 sa
eter 2 R+ . For example, for f (x) = 0,
off, the
attain aany
value
between
pr (V )
tion
(10) and
themay
fancompute
affinitythelaws
willtobetheused
below
to construct
a(10)
solution
equation.
If obtaining
this a 1. For
example,
a user
speedinas
)
p(r
,
V
1
quires an iterative solver, then one computes
output
of aof
second
order filter
forsimplify
two reasons:
Fi
gion
operation.
To
notat
n.
pb (t) pa (t)
mate solution x () 2 Rn that satisfies, for
this
provides
change
in flow rate, whp
{(
V i , pa icontinuous
)}ni=1 , with
Vp(r
i 2 , V )0 and
0,
can be faster and more robust to simulate compa
i 2 {1, . . . , n}, denote
first show that a solution may not exist
p(r3the
, V )user-supplie
to a step change.
Second, the second order filter m
0
datatofor
the
between
the of
fa
0) is kx
not xsatisfied.
Figure
()k K Consider
.
(1) 6 be used
0 pressure
approximate
the rise
transient
response
speed
1. Let
= 0
V =models
a fan with a stall region that works fan. let
Foratthisfull
reason,
the rfan
in the Model
M DEFINITION
as have
aand
small
number
that
bel
Buildings
afan
parameter
allows
tive
pressure.
For
6:selected
Flow library
resistance
curve
thatthat
shows
theis user
For
deviation, see
Wetterp(r
2013
1 , V ), thereFigure
25
))
4 order
situation
where
two
solutions
exist
(with
p(r
,
V
enable
or
disable
such
a
second
filter.
er
the
system
shown
in
Figure
1
at
some
1
normalized fan speed.
ons. This situation can happen in a
@ V
26
Optimal control
Parameter estimation
Simulation
Source: http://www.jmodelica.org
27
Support
for Optimization
The Optimica extension
is discussed in detail -[1].JModelica
In this paper, a brief overview of Optimica is given and the
extension is illustrated by means of an example. We consider the following dynamic optimization problem:
min
u(t)
Z tf
0
1 dt
(1)
(2)
model VDP
Real x1(start=0);
Real x2(start=1);
input Real u;
equation
der(x1) = (1-x2^2)*x1 - x2 + u;
der(x2) = x1;
end VDP;
x1 (t f ) = 0
x2 (t f ) = 0
1 u(t) 1
(3)
28
Modelica Matlab
FMI
FMI
FMI
FMI
FMI
simulation master algorithm
FMI:
FunctionalMockup
Interface, a
standard for
interfacing
computer
code.
design
FMI
communication layer,
e.g, Volttron
hardware
Set
controller
PI
PI
DESIGN
set=0
Experts and
designers
Q_flow
Library of models
Simulation model
Q=3000
inletTemp
boiler
Design phase
F(x',x,y,p)=0
outletTemp
Construction
con2
PI
PI
U
FM
sin
Fix faults
Notify faults
Q_flow
Estimation of fault
parameters in real-time
Fault detection
and diagnosis
Maintenance and
operators
Q=3000
heaDyn
senTem2
OPERATION
30
R&D Needs
modular modeling
infrastructure
en
ab
lin
te
c
hn
ol
og
ie
pr
oc
es
domain-specific
model libraries
31
Further literature
Although the Modelica Language Tutorial is for an older version (Modelica 1.4), it is still
instructive and relevant to understand the concepts of the language.
32
References
J. Akesson, M. Gaefvert, and H. Tummescheit. Jmodelica an open source platform for optimization of modelica
models. In Proceedings of MATHMOD 2009 - 6th Vienna International Conference on Mathematical Modelling, Vienna,
Austria, feb 2009. TU Wien.
M. Bonvini, M. D. Sohn, J. Granderson, M. Wetter, and M. A. Piette. Robust on-line fault detection diagnosis for HVAC
components based on nonlinear state estimation techniques. Applied Energy, 124(0):156 166, 2014.
P. Bunus and P. Fritzson. Automated static analysis of equation-based components. Simulation, 80(7 8):321345,
2004.
R. Franke, F. Casella, M. Otter, M. Sielemann, H. Elmqvist, S. E. Mattsson, and H. Olsson. Stream connectors an
extension of modelica for device-oriented modeling of convective transport phenomena. In F. Casella, editor, Proc. of the
7-th International Modelica Conference, Como, Italy, Sept. 2009.
P. Fritzson. Principles of Object-Oriented Modeling and Simulation with Modelica 2.1. John Wiley & Sons, 2004.
P. Fritzson. Introduction to Modeling and Simulation of Technical and Physical Systems with Modelica. Wiley-IEEE Press,
Sept. 2011.
M. M. Tiller. Introduction to Physical Modeling with Modelica. Kluwer Academic Publisher, 2001.
M. Wetter. Fan and pump model that has a unique solution for any pressure boundary condition and control signal. In J.
J. Roux and M. Woloszyn, editors, Proc. of the 13-th IBPSA Conference, pages 35053512, 2013.
33