Building system modeling in : A next-generation open-source framework for modeling, simulation, optimization and operation

Michael Wetter Simulation Research Group Building Technologies Department Energy and Environmental Technologies Division Lawrence Berkeley National Laboratory

August, 2010

1 Overview

What is Modelica

Toolkit needs & how they are addressed by Modelica

Example applications

2 What is Modelica?

Object-oriented equation-based modeling language Open standard Developed since 1996 because conventional approach for modeling was inadequate for integrated engineered systems Well positioned to become de-facto open standard for modeling multi-engineering systems − ITEA2: 370 person years investment over current three years.

Graphical modeling - input/output free - block-diagram - state machines - bond-graphs C code a:=2; Algorithmic code b:=2*a; executable

C*der(T) = Q_flow; Acausal equations solver 0 = T - TBoundary; 3 Toolkit Needs

Low barrier to entry for new users & developers

− modularization

− transparent (open) models

− free tools & commercial support Exchange of technologies

− standardized interface (models, solvers)

− encapsulation Critical mass

− ecosystem of diverse developers and users Support for modeling, simulation, optimization, operation 4 Modularization & Transparency

connector HeatPort_a "Thermal port for 1-dim. heat transfer" Modelica.SIunits.Temperature T "Port temperature"; flow Modelica.SIunits.HeatFlowRate Q_flow "Heat flow rate (positive if flowing from outside into the component)"; end HeatPort_a;

model HeatCapacitor "Lumped thermal element storing heat"

parameter Modelica.SIunits.HeatCapacity C "Heat capacity"; Modelica.SIunits.Temperature T "Temperature of element"; Interfaces.HeatPort_a port;

equation T = port.T; C*der(T) = port.Q_flow; end HeatCapacitor; a b

connect(a.port, b.port); a.port.T = b.port.T 0 = a.port.Q_flow + b.port.Q_flow 5 Tools

Commercial Free JModelica SimulationX OpenModelica LMS Imagine.Lab SCICOS AMESim MapleSim MathModelica (links to Mathematica)

6 Modelica Standard Library. 1300 models & functions.

Analog Digital Machines Translational

Rotational MultiBody Media HeatTransfer

Blocks StateGraph Math Fluid

7 LBNL Buildings Library. 150+ models and functions.

Provides 150+ HVAC specific models based on “Modelica.Fluids” library. http://simulationresearch.lbl.gov/modelica

8 Standardization for model exchange

Acausal connectors Domain Potential Flow Stream − input/output determined Heat flow T Q_flow at compilation time h_outflow Fluid flow p X_outflow m_flow − can connect none or C_outflow multiple components Electrical V I to a port Translational x F

Automatically summed up at connections to satisfy conservation Requirement of locally balanced models equation. − # of equations = # of variables, at each level of model hierarchy.

9 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 Encapsulation - Functional Mockup Interface

! "#$%&'($)*!+(%,-#.!/$&012)%0!2(1!+(30*!45%6)$70! !"#$%&'()*!8/94:!;!-!<=<<>?! ITEA project, 30 partners, > 175 person! years, > 28 Mill. € budget, July 2008@)$#)1A!;>B!;!(2!E>! Goal Generate C code of hybrid DAE  + systems that can be utilized by t00,,initalpxxyvm values (a subset of {,0 ,0 ,0 ,0 }) other modeling and simulation 4$%*(F'$7!+(30*! environment, including embedded t &'K0! >! 3'F%10&0!F&)&0F!8%($F&)$&!J0&I00$!0N0$&F?! systems. 6! .)1)K0&01F!(2!&A.0!P0)*B!/$&0701B!M((*0)$B!R&1'$7! / /! '$.#&F!(2!&A.0!P0)*B!/$&0701B!M((*0)$B!R&1'$7! =! +! )**!05.(F03!N)1')J*0F! Functional Mockup Interface ?! %($&'$#(#F!F&)&0F!8%($&'$#(#F!J0&I00$!0N0$&F?! =! (#&.#&F!(2!&A.0!P0)*B!/$&0701B!M((*0)$B!R&1'$7! C-interface. @! 0N0$&!'$3'%)&(1F! xml model representation. ! 45&01$)*!+(30*!8"+O!'$F&)$%0?!

Functional Mockup Unit t ? xmz,, Executable, either self-integrating R(*N01! ! (co-simulation) or can be linked to ! ,-./01!2G!H)&)!2*(I!J0&I00$!&60!%(K.($0$&FB!2(1!30&)'*F!F00!F0%&'($!;LCL!! integrator. M*#0!)11(IFG!/$2(1K)&'($!.1(N'303!JA!&60!"+OL! 11 P03!)11(IFG!'$2(1K)&'($!.1(N'303!&(!&60!"+OL!

2323! 4056107-18!9:;!

ExpressivityG!960!"+/!.1(N'30F!&60!$0%0FF)1A!20) F!&6)&!+(30*'%)QB!R'K#*'$,Q!)$3!R/+D:ST!K(30*F;! %)$!J0!&1)$F2(1K03!&(!)$!"+OL! ImplementationG!"+OF!%)$!J0!I1'&&0$!K)$#)**A!(1!%)$!J0!70$01)&03!)#&(K)&'%)**A!21(K!)!K(30**'$7! 0$N'1($K0$&L!45'F&'$7!K)$#)**A!%(303!K(30*F!%)$!J0!&1)$F2(1K03!K)$#)**A!&(!)!K(30*! )%%(13'$7!&(!&60!"+/!F&)$3)13L! Processor independenceG!/&!'F!.(FF'J*0!&(!3'F&1'J#&0!)$!"+O!I'&6(#&!,$(I'$7!&60!&)170&!.1(%0FF(1L!96'F! )**(IF!&(!1#$!)$!"+O!($!)!DSB!)!U)13I)10-'$-&60-V((.!R'K#*)&'($!.*)&2(1K!(1!)F!.)1&!(2!&60! %($&1(**01!F(2&I)10!(2!)$!4SOB!0L!7L!)F!.)1&!(2!)$!:O9WR:P!RX-SL!T00.'$7!&60!"+O! '$30.0$30$&!(2!&60!&)170&!.1(%0FF(1!'$%10)F0F!&60!#F)J'*'&A!(2!&60!"+O!)$3!'F!0N0$!10Y#'103!JA! &60!:O9WR:P!F(2&I)10!%(K.($0$&!K(30*L!/K.*0K0$&)&'($G!#F'$7!)!&05&#)*!"+O!83'F&1'J#&0!&60!S! F(#1%0!(2!&60!"+O?L! Simulator independenceG!/&!'F!.(FF'J*0!&(!%(K.'*0B!*'$,!)$3!3'F&1'J#&0!)$!"+O!I'&6(#&!,$(I'$7!&60!&)170&! F'K#*)&(1L!P0)F($G!960!F&)$3)13!I(#*3!J0!K#%6!*0FF!)&&1)%&'N0!(&601I'F0B!#$$0%0FF)1'*A! 10F&1'%&'$7!&60!*)&01!#F0!(2!)$!"+O!)&!%(K.'*0!&'K0!)$3!2(1%'$7!#F01F!&(!K)'$&)'$!F'K#*)&(1! F.0%'2'%!N)1')$&F!(2!)$!"+OL!/K.*0K0$&)&'($G!#F'$7!)!J'$)1A!"+OL!X60$!70$01)&'$7!)!J'$)1A!

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

;!+(30*'%)!'F!)!107'F&0103!&1)30K)1,!(2!&60!+(30*'%)!:FF(%')&'($B!R'K#*'$,!'F!)!107'F&0103!&1)30K)1,!(2!&60!+)&6X(1,F!/$%LB! R/+D:ST!'F!)!107'F&0103!&1)30K)1,!(2!R/+D:ST!:ZL! Link to other tools through BCVTB

Open-source, free middle-ware that links during run-time - Modelica - EnergyPlus - BACnet - MATLAB/ - Radiance - Ptolemy II - www/xml

http://simulationresearch.lbl.gov/bcvtb 12 Support for Modeling of Heterogenous Systems

Link graphically various - physical domains and control logic. - different models for time evolution (continuous time, discrete time, state graph)

differential equation

algorithmic code for controls algebraic equation

acausal equations for physics

// Water content and pressure port_a.p * (VGas) = p0 * VGas0; port_a.p = medium.p;

state graph

13 Support for Optimization - JModelica

Extensible Modelica-based open source platform for optimization, simulation and analysis of complex dynamic systems.

Main objective: •Create an industrially viable open source platform for optimization of Modelica models. •Offer a flexible platform serving as a virtual lab for algorithm development and research.

Main features Optimal control Parameter estimation Simulation

Source: http://www.jmodelica.org

14 Support for Operation

Language supports model deployment to different hardware (embedded system or computer).

Continuous time and hybrid (switching) systems are modeled correctly.

Can have actual feedback control loops that regulate states (temperatures, duct pressure, etc.) instead of “loads”.

Elmqvist et al., 2009

15 Example Applications

1) Rapid prototyping (13,000 equations) Reproduced trends published by manufacturer for novel hydronic heating system with radiator pumps and hierarchical system controls. Developed boiler model, radiator model, simple room model and both system models in one week.

2) Supervisory controls (4,400 equations) Stabilized control for variable air volume flow “trim and response” sequence and reduced energy by solving optimization problem with state constraints.

3) Local loop controls (2,600 equations) Reused high-order non-linear model for controls design in frequency domain to stabilize closed loop control. 16 Modelica Implementation of VAV System with ASHRAE Standard Sequence of Controls, linked to EnergyPlus DOE Benchmark Bldg.

Variable Air Volume Flow (VAV) System Terminal reheat. Finite state machine for supervisory mode transition. Local loop control with P and PI controllers.

Original system model 1200 components 4,300 equations 150 state variables 17 Modelica Implementation of VAV System with ASHRAE Standard Sequence of Controls, linked to EnergyPlus DOE Benchmark Bldg.

Can execute realistic supervisory and R&D Needs: local loop control in Modelica linked to Robustness of DAE solver. EnergyPlus through the Building Controls Virtual Test Bed. Support for rapid virtual prototyping.

Computing time.

“Packaging” to make technology easier accessible to non-experts.

Scope of validated model library (HVAC & control components and systems).

Code generation to link design to operation.

18 Summary

Remarks Modern simulation of engineered systems moves towards equation-based tools

− Modelica (open-source, with commercial support from Dynasim, Maplesoft and Wolfram)

− SimScape (Mathworks) R&D that does not integrate into such “ecosystems” don’t scale to industrial problems.

Next steps Increase scope & validation of Modelica “Buildings” library. Improve numerical robustness of solver. Test open-source implementations of modeling, simulation & optimization environments.

19