WOLFRAM

Energy Resource Dynamics with the New System Dynamics Library for SystemModeler

Explore the contents of this article with a free Wolfram SystemModeler trial. 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.

Wolfram SystemModeler chalkboard cartoon

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.

In and outflow example

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?”

Oil market model

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.

Needs["WSMLink`"]

oilPriceData from   WolframAlpha

unitlessoilPriceData = {#[[1]], #[[2, 1]]} & /@ oilPriceData

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.

oilPrice =    Table[{DateDifference[{2002, 1, 1}, unitlessoilPriceData[[i, 1]]], unitlessoilPriceData[[i, 2]]}, {i, 1, Length@unitLessoilPriceData}];

Export["oilPriceTable.txt", {"var1", oilPrice}, {"ModelicaCombiTimeTable"}];

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:

The oil power plant production module

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.

Oil reservoir model

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.

simCCGT = WSMSimulate["Energy.Continuous.ControlledElectricityProduction", {90, 3750}];

supplyDemandRatio = Table[simCCGT[{"integratingModule.supplyDemand"}, t], {t, 90, 3750}] // Flatten;

productionLevel =    Table[simCCGT[{"oilPowerPlant.controller.totalControllLevel" }, t]*100/14, {t, 90, 3750}] // Flatten;

For visualizing the analysis, I use the DateListPlot function.

Production Level DataListPlot

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.

oilPriceWA = Table[simCCGT[{"oilMarket.oilPrice"}, t], {t, 90, 3750}] // Flatten;

Spot oil price based on a Wolfram|Alpha query

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.

A set of new parameters

WSMSimulate

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:

Mean table

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.

CCGTfuelConsumption =    Table[{DatePlus[{2002, 1, 1}, i], simCCGT[{"oilPowerPlant.currentFuelConsumption"}, i][[1]]}, {i, 90, 3750}];

OCGTfuelConsumption =    Table[{DatePlus[{2002, 1, 1}, i], simOCGT[{"oilPowerPlant.currentFuelConsumption"}, i][[1]]}, {i, 90, 3750}];

Daily fuel consumption DataListPlot

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.

CCGTcostPerkWh =    Table[{DatePlus[{2002, 1, 1}, i], simCCGT[{"oilPowerPlant.fuelCostPerMWh"}, i][[1]]/10}, {i, 90, 3750}];

OCGTcostPerkWh =    Table[{DatePlus[{2002, 1, 1}, i], simOCGT[{"oilPowerPlant.fuelCostPerMWh"}, i][[1]]/10}, {i, 90, 3750}];

Production costs DataListPlot

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.

Comments

Join the discussion

!Please enter your comment (at least 5 characters).

!Please enter your name.

!Please enter a valid email address.

18 comments

  1. 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

    Reply
  2. 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

    Reply
    • 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

      Reply
  3. Hello Mikael,

    May I request to have the model for energy production to try it at my end.

    Best,
    Vijay

    Reply
  4. Hello Mikael,

    The blog and the technique is very useful for me, because I’am studying by my selft System Modeler. Can you share me the production plant model to explore and see how integrate concepts. Thanks

    Reply
  5. Hi Mikael,

    I am learning how to use SystemModeler as well as System Dynamics by myself and I am having trouble with a few basic tasks.

    If you could answer any of these questions I would greatly appreciate it!

    1. How and where can I make equations for my model variables? I cannot figure out how to write equations in for rates, levels, and most other SD components!

    2. I am creating a system that has many different modules that all work together. This may seem like a silly question but I do not understand how to link these multiple classes together to create one big system.

    3. Could you send any pdfs that you believe could help a beginner to this System Dynamics software?

    Thank you so much again Mikael,

    Max

    Reply
    • Hi Max!

      3. There are some instructions that might be useful to you in the documentation of the SystemDynamics library. Simply select the library in the Class Browser and press F1 to open the documentation; you can also right-click on the library in the Class Browser and select the Class Documentation option in the context menu.

      In the Documentation Centre (Help>Documentation Centre) you can also find ample instructions on how to use Wolfram SystemModeler. Some of the great things you can find here include an e-book on the modelling language and large selection of short training videos ranging from an first introduction to advanced topics (which can be found trough the Documentation Centre or directly at: http://www.wolfram.com/training/courses/system-modeler/).

      A short tip; when you have a class or component on the diagram view you can always press F1 to open the specific documentation for that component.

      1. This is hopefully clearer to you after the introduction part of the library documentation. You can also use math blocks that are compatible with the SystemDyanmics library these classes are found in the Modelica Standard Library that is shipped with SystemModeler (path: Modelica.Blocks.Math in the Class Browser).

      The example: SystemDynamics.PopulationDynamics.LarchBudMoth.LBM could be of interest to you. Here you can see how you can create custom and arbitrary rate governing equations. The author of the example has four such custom classes (Starvation, Defoliation, Grecr, and Logarithm). The connectors are inherited by using the ‘extends’ clause in the model equations (more can be found extends on this example page wsm:///ref/ModelicaByExample/behavior/equations/model_def/index.html , just copy and paste the path the Documentation Centre).

      2. In order to connect sub-modules to each other they first need connectors, these can be created in a few different ways (such as programmatically, by inheritance or by using the GUI). The simplest way is by using the GUI, a good example from the documentation: http://reference.wolfram.com/system-modeler/GettingStarted/CustomComponentChainPendulum.html. This is also in the Documentation Centre in SystemModeler, just search for ‘custom component’.

      Once you have the connectors defined in the sub-modules they will show on the diagram on your system model and you can thereafter connect them just as the ‘ordinary’ components.

      I hope this helps,

      Mikael

      Reply
  6. Hi Maxi,

    Thank you for your well written article. I would also like to request the Energy Production model.

    Kind Regards
    Kevin

    Reply
  7. 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.

    Reply
  8. 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.

    Reply
  9. 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

    Reply
  10. 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.

    Reply