# Energy Resource Dynamics with the New System Dynamics Library for *SystemModeler*

June 11, 2013 — Mikael Forsgren, Wolfram MathCore

Wolfram *SystemModeler* ships with model libraries for a large selection of domains such as electronics, mechanics, and biochemistry. Now I am pleased to present a new library in the family, the SystemDynamics library by François E. Cellier and Stefan Fabricius. System dynamics, a methodology developed by Jay Forrester in the ’60s and ’70s, is well suited for understanding the dynamics of large-scale systems with diverse components. It has been famously applied by the Club of Rome to investigate the limits of human growth; other applications include production management, life sciences, and economics (some showcases of the methodology can be found here).

The dynamics of the many types of global energy resources are another good example of such a large and complex system, and are a recurring topic on politicians’ lips, so I thought that this could be a good starting point to explore the possibilities of this new library. The U.S. Department of Energy has for some time been working on a modeling system toward a better understanding of this problem, in order to let politicians make adequate legislation and policy decisions. Recreating their work (basically all energy demands in the US) is not possible within the scope of this blog post; I will however show an expandable framework for how one can do this, which will only focus on a single electricity producing plant and how it is affected by the global marketplace. But before we dig into more complex modeling, I’d like to start with a short introduction to the library and the methodology.

The system dynamics methodology is used for modeling the continuous flow of mass and information, using in principle two types of objects: levels, which are quantities that can accumulate mass or information (state variables), and rates, which influence the accumulation/depletion of the levels (state derivatives). As an example: money is a typical level for which the inflow rate is the income and the outflow rate is the expense. The rates are in turn controlled by laundry lists (in the system dynamics terminology), which are sets of influencing factors that modify the rates. In this example these laundry lists would include for instance rent, food costs, and internet service. In the picture below this simple example is shown, where the interest is a function of the current money level; of course the rates can also be defined with a nonlinear relationship. The purple clouds are sources and sinks of mass used in the system dynamics methodology.

So let’s explore how you can create models in order to understand energy resource dynamics using the SystemDynamics library, and use Wolfram|Alpha to get real data into the model.

### The model

As previously mentioned, the model contains a single electricity producing plant, and I have based this power plant on the newly finished Shoaiba power and desalination plant in Saudi Arabia. The desalination for salt water is not taken into account here. By connecting this production facility to the international fuel market and the regional electricity demand, we can start to look at questions such as, “How long will the plant be able to meet demand?” and “How is the price of electricity affected by high-efficiency turbines?”

The model consists of three primary modules: demand, market, and production. The overall structure, with an integrating module at its heart, allows for adding arbitrarily many other modules, that is, the integrating module connects all other modules together and routes the flows of mass or information to its designated module. In this case the integrating module is somewhat unnecessary, and adds extra equations, but it’s designed for showing how you can begin creating such a large system with a modular design.

In the market module, which supplies historic spot oil price data from Wolfram|Alpha, the data from Wolfram|Alpha is retrieved, processed, and exported to *SystemModeler* with just few lines of *Mathematica* code, starting with loading the Wolfram *SystemModeler Link*, which is needed for formatting the export, and also later on when I start interacting with the model in *Mathematica*.

Here I just convert the date strings to the number of days from the 1st of January 2002, so that it can be used in the model.

The time series can now be used in *SystemModeler* trough the CombiTimeTable component in the Modelica standard library.

I’ve based the demand module on data from a Wolfram|Alpha query of Saudi Arabia’s electricity usage, where the yearly increase in electricity consumption is used as a base for generating the electricity needed in the demand module (a combination of sine and trapezoid functions is used for adding seasonal changes in between the data points).

The power plant in the production model uses gas turbines that burn oil in a combined cycle, which means that the exhaust gases are used in a secondary steam turbine for increased efficiency; these are known as combined-cycle gas turbines (CCGT), as compared to the older, less efficient open-cycle gas turbines (OCGT). The power plant consists of 14 CCGT units with maximal capacity of 400 MW, yielding a net capacity of 5.6 GW, spread out into 4 blocks with 4 or 3 gas turbines in each block. The production module is a fairly large hierarchical model scaling from a top level with controller and resource ordering logic down to a single gas turbine:

At the turbine model level, the system dynamics rate classes are found, where the rate at which fuel is burned governs the reduction of the level in the oil reservoirs found higher up in the hierarchy. The oil consumption (the laundry list, in system dynamics terminology) calculations are based on the heat of combustion for oil, the thermal efficiency of the turbine, and the turbine load and effect.

The oil reservoir component of the power plant model can be found if we go back up the hierarchy a bit; here the amount of oil in storage is computed by taking into account the fuel burnt by the turbines and the tankers delivering new oil. Refueling the plant is modeled in a simplified fashion where the consumed amount is restored biweekly.

The controller for the plant allows for a lowest turbine load of 40% and goes up with a load step size of 5% to the maximum load, where the turbine has the top efficiency. The startup time for a modern CCGT is about 30 minutes (from standstill to full load, with full efficiency); however, since the startup time is so small compared to the time step of the model (1 day), this effect is negligible and thus disregarded. The all-important thermal efficiency of the gas turbine varies as a function of the load, where the efficiency at a 40% turbine load is 50% and at a 100% turbine load is 60%, assuming a linear increase in efficiency between the two loads.

### Analyzing different scenarios

Let’s simulate the model and then analyze the results for a CCGT scenario for 10 years starting at April 1, 2002.

For visualizing the analysis, I use the `DateListPlot` function.

Here it is apparent that the increase in electric demand reaches beyond the power output of the plant, which starts from about 60% load in 2002 and goes up to 100% in 2012. So there is a need to build even more power plants with this growth in demand; however, there are of course more power plants out there in real life to pick up the slack, but the increase in demand is quite massive.

The price for the electricity is largely due to the fuel costs, which were retrieved from Wolfram|Alpha and used in the model.

Before I move further with the analyses of the system, let’s define another scenario where the simpler open cycle gas turbine technology is used, assuming an efficiency of 35% and 42% for 40% and 100% loads, respectively. The simulation call to *SystemModeler* is similar to the first scenario; I just define a set of new parameters for this scenario.

Since the turbines are not run at their full load at all times, the actual efficiency where the demand and controller schemes are also taken into account is more interesting than the mere theoretical efficiency. For this comparison I will look at the entire 10-year time scale:

So for this scenario and these assumptions, the CCGT is on average 43% more efficient than the OCGT turbine. Visualizing these differences throughout the 10-year period is easily done, and by using the `DatePlus` function to create the date strings, we get a nice *x* axis in the figure.

The cost of producing electricity is largely defined by the fuel costs, and with the market module, the associated fuel costs for the plant’s production can be calculated. Fuel price spikes can strike hard at the economy of, for instance, private households and energy demand industries. Spikes effectively lower their ability to consume other goods and services in a larger complex model where the consumers’ ability to consume affects the industry demand. These feedback loops are at the heart of the system and are important structural aspects in many system dynamics applications.

Due to the rapid increase in the spot oil price during the last 10 years, the fuel part of the production costs of electricity increases quite rapidly, especially for the OCGT type, starting at 5¢ in 2002 and topping off at 25¢ in mid-2008. Note that these costs are affected by the heat of combustion of the fuel oil (in this case it’s assumed to be 139 500 Btu/gallon), and that the fuel price used here is the spot oil price. Moreover, the costs are also dependent on the scenario specifications.

By clicking this link you can download the SystemDynamics library for free and start working on your own system directly or explore the many other example systems included in the library. You can get your hands on Wolfram *SystemModeler* here or download a free, fully functional trial version.

Download this post as a Computable Document Format (CDF) file.

## 11 Comments

I have no Modelica/SystemModeler experience, but I am interested in exploring a range of platforms which might be capable of expressing and simulating System Dynamics models. During my searches, I came across the François Cellier System Dynamics library for Modelica some time ago, and in fact wrote a short blog post on it (http://www.simulistics.com/blog/system-dynamics-modelling-modelica-modelling-language).

My analysis, which might merely reflect my poor understanding of Modelica, is that Modelica is not a suitable tool for conventional System Dynamics modelling, as supported by any of the SD modelling software (such as Stella, Vensim, Powersim, Simile…) Any such software allows you to decide, while you are drawing the stock-and-flow diagram:

1. how many inflows and outflows you have for a particular stock;

2. what variables influence each of the intermediate (“auxiliary”) variables and flows; and

3. the equation for each calculated intermediate variable and flow.

The equation may be, but often is not, some standard equation: it’s often made up (on good scientific grounds, of course) by the modeller then-and-there.

As I understand it, each of these three aspects sits uncomfortably with the idea of (pre-defined) components in a Modelica library, since the nature of the basic model-building elements (how many inputs it has; what these are, and the functional relationship to use) is so fluid, and not something that can be handled by creating more-and more library components.

I would be happy to be proved wrong, but until then I will have to assume that Modelica’s applicability for System Dynamics is limited to a very small number of quite stylised examples.

Robert

Hi Robert,

I am just coming from the 1st Wolfram European Technology Conference, where Jan Brugård had shown the System Modeler using the SD Library in action, and I am using System Dynamics in my professional work (mostly using Vensim). As far as I have understood Mr. Brugård’s explanations there seems to be a way in the System Modeler allowing for the flexibility needed without having to stick to predefined symbols in a rather restricted way. But the question you are raising is spot on regarding the way systems modeling is done in management and economics next to the environmental domains you have mentioned – where System Dynamics very likely is the modeling paradigm most widely in use.

I am not sure that I understand the restricting limitations you have mentioned in your question completely – not having any experience with Modelica at all. Wouldn’t any system or partial system in system dynamics essentially be open to being modeled by just one stock and one flow once you allow vectors as inputs, which the System Modeler probably supports (so that the need to define many different symbols for each possible tuple [#inputs, #outputs] is not a real restriction)? And wouldn’t there also be some kind of general building blocks like f(x) where x is a vector – e.g. what you called a ‘laundry list’ – again reducing the limitations that you have mentioned?

Also once a general symbol like a stock or flow is defined couldn’t its equations be easily modified locally?

I hope the people from Wolfram will not keep this important issue pending for too long and will provide an answer on this blog. While I have not looked upon Simile yet, there is need for object-oriented modeling environments that truely allow for hierarchical model building in System Dynamics.

Hi Robert, Guido

Thanks for your comments. As you point out, Robert, the SystemsDynamics library has not been developed in order to allow for flexibly changing e.g. number of inports. However, using vectorized inputs and outputs this can be achieved for e.g. a level component, just as Guido theorized.

It is also possible to design the library so that you can select between given equations or even allow the end user to define his own.

If you are interested in discussing how to accomplish this you are welcome to contact me directly and I can give you advise.

I’ve always wondered how SystemModeler might be used in finance and your first example hints at it. But you don’t show the code for how this might be implemented. I would like to see the very simple interest minus expenses idea coded up in Mathematica.

Hi Seth

Good question, the equations can be seen in Mathematica through the WSMLink (using the WSMModelData function). The Modelica code for the example you are referring to is really simple, that image is basically all you need in order to recreate the example, with the SystemDynamics library loaded, all you need to do is to drag and drop the components you see in the image and connect them. If you wish I can send you that example as Modelica file, or the extracted equation system in a notebook.

Hi Michael,

thanks for the article and your answers. As I have written I am very intrigued by the System Modeler’s ability of hierarchical model building which I find is a feature most System Dynamics tools ,that I know of, lack. One also misses features like a decent IDE, a profiler and other features once one starts to build models in a team. So I will give the System Modeler an evaluation trial but would like to know about some features that I am interested in.

Roughly speaking when talking about simulation in a social sciences context (including economics) I am aware of three modeling paradigms: Discrete Event Simulation (DES), Continuous Time Simulation (ODE) which imo includes System Dynamics and Agent-based modeling (ABM). The more I work with simulations the more I see the need for hybrid models mixing say ABM – maybe to simulate individuals – and SD to keep track of the environment and the big picture. DES to my understanding has a more operational focus where events trigger actions and we are typically talking about constructs like conveyor belts, queues and batch delays (“ovens”).

This article might make this clearer: http://bit.ly/145MATo

So here are my questions:

1. Does the System Modeler allow all to model and mix all of the three modeling paradigms mentioned above?

2. How does the System Modeler compare to tools like AnyLogic and other SD-tools? (Speed, flexibility and other features – Is there a feature comparison as it is done with Mathematica vs. tools like Maple?)

3. The graphical user interface and the symbolic structure is highly valued in System Dynamics methodology. I noted that the System Dynamics interface uses the ‘dusted’ notation of Jay Forrester’s Industrial Dynamics from the 60s. Can one have more modern symbols for flows and maybe double conncetions to distinguish materal from information flows? (cf. the paper above to see what I mean)

4. How to build a front end for experimentation with a model (not necessarily for re-modeling by the client) and what about licensing, can you build a stand alone model for simulation maybe using the PlayerPro or is there a need for one’s client to have a System Modeler as well?

5. I noted that the System Modeler is not using Mathematica’s NDSolve-Framework. Can you explain the difference here a bit more? Whatare ups and downs here?

Kind regards,

Guido

Hi Guido,

I’m glad to hear about your continued interest in our product. I will have to look into some of your questions a bit further, specifically Q1 and Q2, and get back to you at a later stage. As for the other three questions, I have some answers for you:

A 3: The design of the icons is up to the library developer, as in this case of Francois Cellier’s System Dynamics library, the choice was made to mimic the graphical design of older System Dynamics simulation environments, but it could just as well be of a more modern graphical design. SystemModeler includes an editor to design the graphical representation of any component using either vector based graphics or by importing images.

A 4: You can export a license-free standalone simulation executable that you can write your own user interface for.

A 5: SystemModeler is based on a code generation technology for efficient simulations, connected to optimized numerical solvers implemented in FORTRAN or C. NDSolve is an integrated super function in Mathematica that can deal with both symbolic and numeric techniques for a wide variety of problems.

The benefits of SystemModeler technology:

– Reduces high index problems (now also recently available in NDSolve in Mathematica)

– Makes it possible to easy integrate routines in FORTRAN or C (Modelica external functions)

– Support for the hybrid DAE formalism required by Modelica (NDSolve has partial support for this).

- Efficient code generation with equation tearing, alias elimination and other techniques to reduce the simulation time.

– Suitable for real time simulation for e.g. Hardware in the loop simulations (HIL).

Benefits of NDSolve:

-Can work with arbitrary precision.

– Has a wide set of different solvers (ODE, DAE, high index solvers, projection based solvers, etc.)

– Can work with symbolic expressions and benefit from that.

– Integrated into Mathematica i.e. available in CDF, etc.

Best wishes,

Mikael

Hi again Guido, here are the answers to the first two questions.

A 1: Yes, discrete event simulation can be done with the StateGraph library (http://reference.wolfram.com/system-modeler/libraries/Modelica/Modelica.StateGraph.html) and agents could be constructed with StateGraph and logical blocks (http://reference.wolfram.com/system-modeler/libraries/Modelica/Modelica.Blocks.Examples.html).

A 2: SystemModeler provides a much better way of integrating physical systems into the models. This will be hard or impossible to do with other tools for system dynamics. The components are very flexible and extendible.

There is currently no comparison chart available for the listed tools.

Thank you very much, Mikael, for these answers. I will be standing by for some comparison graph.

Best,

Guido

Hi Mikael,

Nice article. But How do i get you powerplant model to work? I have downloaded the system modeler 2.1 file and installed it. But I can’t find the Energy module. ergo the CDF doesn’t work.

Thank you very much in advance.

Wouter

Hi Wouter,

I’m glad you liked the blog post. The model for the energy production, which I used in this blog post, is not part of the System Dynamics 2.1 library. However, I can send a copy of the model to you.

Regards,

Mikael