LBL Tutorial
LBL Tutorial
Michael Wetter
Simulation Research Group
1
Overview
of
Modelica Buildings Library
2
Primary use of Buildings library
Main applications
• Model repository for building and district energy simulation, see https://lbl-srg.github.io/
soep/
• Development of 5th generation district heating and cooling
• Controls design and performance evaluation.
• Repository of control sequences in the Control Description Language, https://obc.lbl.gov/.
• Model-based design process.
• Development and testing of FDD algorithms.
License
• All development is open-source under BSD.
3
Model repository: Modelica Buildings Library.
Open-source repository of 1000+ models and functions.
Air-based HVAC Hydronic heating Chiller plants Embedded Python Room air flow
Natural ventilation, Room heat transfer, Solar collectors FLEXLAB Electrical systems
multizone air exchange, incl. window (TARCOG)
contaminant transport
Current developments
District heating Control design & deployment, Make it the core of the Spawn of EnergyPlus.
and cooling systems including ASHRAE G36
3
(4c)
(4d)
p (d, d) = 2/d , (4e)
1 d/x
where p0 (·, ·) and p00 (·, ·) denote the first and second order par- d p(d, x )
tial derivatives with respect to the second argument. The condition
d f(d, x )
p0 (d, 0) 6= 0 has been selected to avoid that the first derivative van- 0
ishes at the origin, because a Newton solver that solves p(d, x ) = 0
for x may compute the sequence xn+1 = xn p(d, xn )/p0 (d, xn ).
1
The function that we selected and that satisfies (4) is d/x
x 2 3 3 1 1 0 1
p(d, x ) , +x 3 x x + 7 x5 . (5) x/d
d2 d d5 d
Figure 1 shows the graph of this function. The term x/d2 is used to Figure 1: Plot of d f(d, x ).
ensure that the first derivative is non-zero around a neighborhood of
x = 0, and therefore by the Implicit Function Theorem, there exists
in a neighborhood of the origin an inverse function p 1 (d, ·) that is
differentiable.41 41
Polak, E. (1997). Optimization, Algo-
Note that in (2), for ṁ(t) 2 ( ṁd , ṁd ) \ {0}, energy is not con- rithms and Consistent Approximations,
Volume 124 of Applied Mathematical
served. Therefore, ṁd should be chosen small. However, ṁd should Sciences. Springer Verlag
not be too small compared to the design mass flow rate, as this will
cause f(ṁd , ṁ) to be large in magnitude near ṁ ⇡ ±ṁd , which may
lead to problems for numerical solvers. The default setting in the
Buildings library is ṁd = 10 7 ṁ0 , where ṁ0 is the design mass flow
rate. At this low mass flow rate, the impact on the energy consump-
tion is negligible.
To assist component model developers in the regularization of
these functions, the package Buildings.Utilities.Math provides
differentiable approximating functions for many formulations.42 42
Note that Modelica simulation en-
vironments can in general properly
handle non-differentiabilities. How-
ever, a numerically sound treatment
requires an event iteration that is com-
putationally costly. When formulating
equations for physical phenomena, we
therefore replaced non-differentiable
equations with approximations that are
continuously differentiable.
Legend:
Library developer
Component developer
5
End user
Main modeling assumptions
6
Documentation and distribution
Documentation
• General user guide (getting started, best practice,
developer instructions, ...).
• 18 user guides for individual packages.
• 2 tutorials with step-by-step instructions.
• All models contain “info” section.
• Small test models for all classes,
large test cases for “smoke tests,”
and various validation cases.
Distribution
• Main site
http://simulationresearch.lbl.gov/modelica
• Development site with version control, wiki and issue tracker:
https://github.com/lbl-srg/modelica-buildings
7
Best practice and modeling
hints
8
Building large system models
9
Use small unit tests, as in
Chiller plant
base classes
Pumps
10
Propagate common parameters
Don't assign values to the same parameters:
Pump pum(m_flow_nominal=0.1) "Pump";
TemperatureSensor sen(m_flow_nominal=0.1) "Sensor";
TemperatureSensor sen(
redeclare final package Medium = Medium,
final m_flow_nominal=m_flow_nominal) "Sensor";
TemperatureSensor sen[2](
each final m_flow_nominal=m_flow_nominal)
"Sensor";
12
All system models must have a reference pressure
13
Modeling of fluid junctions
14
Avoid oscillations of sensor signal
dT |ṁ|
⌧ = (✓ T)
dt ṁ0
15
Avoid events
h = if port_a.m_flow > 0
then inStream(port_a.h_outflow) else port_a.h_outflow;
17
Setting of nominal values is important for scaling of residuals
18
Exercise: Modeling of a simple thermofluid flow system
How do you implement a source and boundary condition with a tank in between to create the
model below:
19
Exercise: Modeling of a simple thermofluid flow system
20
Further resources
Tutorials
• Buildings.Examples.Tutorial
User guides
• User guides for specific packages of models.
• User guide with general information.
21
Developer Guide
22
Overview
Main topics
• Requirements
Further literature
• Style guide
23
Coding style and conventions
Most variables are 3 letter camel case to avoid too long names, for example,
TOut, QHea, yDamMax, …
Additional information at
https://github.com/lbl-srg/modelica-buildings/wiki/Style-Guide and
http://simulationresearch.lbl.gov/modelica/releases/latest/help/Buildings_UsersGuide.html
24
Requirements
Physical requirements
Mathematical requirements
25
Organization of individual packages
Tutorial
UsersGuide
26
Implementing new thermofluid flow devices
Buildings.Fluid.Interface provides base classes.
Buildings.Fluid.HeatExchangers.HeaterCooler_u
For a device that adds heat to a fluid stream.
Buildings.Fluid.MassExchangers.Humidifier_u
For a device that adds humidity to a fluid stream.
Buildings.Fluid.Chillers.Carnot
For a device that exchanges heat between two fluid streams.
Buildings.Fluid.MassExchangers.ConstantEffectiveness
For a device that exchanges heat and humidity between two fluid streams.
27
Adding a heat exchanger
See HeaterCooler_u
within Buildings.Fluid.HeatExchangers;
protected
Buildings.HeatTransfer.Sources.PrescribedHeatFlow preHea
"Prescribed heat flow";
Modelica.Blocks.Math.Gain gai(k=Q_flow_nominal) "Gain";
equation
connect(u, gai.u); ... // other connect statements
annotation (...); // documentation
end HeaterCooler_u; 28
Add examples and validations to unit testing framework
3. Run
modelica-buildings/bin/
runUnitTests.py
29
?
30