Introduction to Computer Simulation Continuous Simulation Basics Jonathan Thaler Department of Computer Science 1 / 25
Continuous Simulation Figure: In a continuous model the state Figure: In a discrete model the state changes at changes continuously . discrete points. A discrete model does not arise out of artifical discretisation of time but by the nature of things : the process observed in reality is actually discrete. Therefore time can be discretised without loss of precision. 2 / 25
Continuous Simulation Figure: Simulation goal : When assuming a varying inflow, determine the times required, to control both ventiles so that no overflow happens and even flow as much as possible. 3 / 25
Continuous Simulation Particularly suited to investigating strategic issues . Takes an endogenous point of view. Model the system as a causally closed structure that itself defines its behavior. Discover the feedback loops in the system. Identify stocks (accumulations) and the flows that affect them. Stocks are the memory of the system, and sources of disequilibrium. Take a continuous view where events and decisions are blurred. Unlike discrete event and agent-based models, system dynamics models are deterministic . Output are dynamics of the stocks (change of aggregates) and flows (change of rates). Mathematically: A system of coupled, nonlinear, firstorder differential equations . Solved (simulated) with numerical methods such as Euler and Runge-Kutta. They partition simulated time into discrete intervals of length ∆ t and step the system through time one ∆ t at a time. 4 / 25
Continuous Simulation For continuous simulation exist specific modelling techniques and diagrams: Causal Loop Diagram (Wirkungsdiagramm) Stock & Flows Diagram (Flussdiagramm) They have their origin in System Dynamics developed by J. Forrester at MIT in the 1950s. The main reference is John Sterman, Business Dynamics - Thinking and Modeling for a Complex World. McGraw-Hill 2000 . 5 / 25
Continuous Simulation Causal Loop Diagram 6 / 25
Causal Loop Diagram Elements Variables Causal connections between variables. Causal loops. Purpose Quick notes of hypotheses about the origin of the system dynamic. Discuss/document mental models of a system individually or within a group. A first explanation for a problem to solve. Preparation for a simulation model. 7 / 25
Causal Loop Diagram Reinforcement If x increases (decreases), y increases (decreases). Balancing / Dampening If x increases (decreases), y decreases (increases). 8 / 25
Causal Loop Diagram Cause vs. Correlation Wrong : although there is a correlation between ice cream sales and homicide rate, there is no causal connection. Figure: Correlation Correct : the average temperature causes the ice cream sales and the homicide rate to increase. Figure: Cause 9 / 25
Causal Loop Diagram Figure: Midnight Oil Example (Sterman, p 149). R reinforcement cycle: variable values increasing. B balancing cycle: variable values decreasing. 10 / 25
Continuous Simulation Stocks & Flows Diagram 11 / 25
Stocks & Flows Elements Containers: Stocks Flows with flow rates between Stocks: Flows Variables (similar to Stocks but without flows) Causal relations between variables/Stocks and variables/Flows. Purpose Define a precise simulation model . The influence on variables are of qualitative nature in a causal loop diagram, but for simulation we need a quantiative model. A network of Stocks and Flows defined the system dynamic : stocks are increasing and decreasing due to precise flow rates . 12 / 25
Stocks & Flows Figure: Dynamics of a consumer population: potential consumers are becoming adopters, which can influence other customers. 13 / 25
Stocks & Flows Figure: Flow Figure: Stock Figure: Rate Figure: Relation (determines) Figure: Variable Figure: Source / Sink Difference between Stock and Variable: Stock: change is described by rates . Variable: change is modeled through scenarios or functions of other variables or stocks. 14 / 25
Stocks & Flows Figure: Diagram of Stock & Flows Figure: Hydraulic Metaphor for Stock & Flows Mathematically it is a differential equation (more on that later). d Stock = net change in stock per infinitely small time unit at time t. This is the d t same as inflow(t) - outflow(t) . Important: inflow(t) and outflow(t) are rates : stock per time unit. 15 / 25
Stocks & Flows Change rates can be absolute or relative : 1. Absolute : change of a stock per time unit. 2. Relative : change of a stock per time unit and additional unit... a. ... of the stock itself (feedback). b. ... of another variable. 16 / 25
Stocks & Flows Modeling with change rates: Feedback Model relative change rates with feedback : birth rate = relative birth rate · population population death rate = relative death rate · population = average life span 17 / 25
Stocks & Flows Modeling with change rates: Duration The reciprocal of a relative rate can be interpreted as a duration 1 d = decreasing rate is the (average) duration of a unit in a stock. 1 Example: a decreasing rate of 0 . 1 means: 10 th of a stock unit leaves the stock per time unit (if rate stays constant in this time unit). This means 1 that in d = 10(= 0 . 1 ) time units exactly 1 (= 10 · 0 . 1) units are leaving the stock, therefore their (average) duration in this stock. 1 d = increasing rate is (average) time between two ”births” of a new unit of the given stock. 18 / 25
Continuous Simulation Defining Continuous Simulations with Differential Equations 19 / 25
Defining Continuous Simulations Defining Continuous Simulation Systemvariables with continuous ranges (float, double) Variables are changing continuously , depending on the flow of time . Changes over time are described using differential equations : they model continuous increase/decrease of systemvariables through a mathematical function. Continuous Simulation is a numerical approach to find solutions of a dif- ferential equation system. 20 / 25
Defining Continuous Simulations Differential Equations Differential equations describe the rate of change d y ( t ) of a time-dependent d t function y ( t ) . Given this rate, we need to determine the change over time of y ( t ) . The solution of a differential equation is a function which explicitly depends on t . A differential equation describes a time-dependent function only indirectly in the form of an equation. To make the time-dependent behaviour of the function explicit , the differential equation needs to be solved, similar to a ”normal” equation. Ordinary differential equations (ODE) contain only derivations after time t (otherwise we speak of partial differential equations such as time and distance). 21 / 25
Defining Continuous Simulations Quadratic function: y 2 + y = 6 has solutions: y = 2 , − 3 Differential equation: d y d t = 0 . 2 y has solution: y ( t ) = e 0 . 2 t A solution y = y ( t ) of a differential equation d y d t = f ( t, y ) satisfies the equation d y d t ( t ) = f ( t, y ( t )) for each t . 22 / 25
Defining Continuous Simulations Differential equation example: free fall with friction Differential equation : d v d t ( t ) = − g − γ m v ( t ) Solution (velocity at time t ) : v ( t ) = − m · g + const · e − γ m · t γ There are infinitely many solutions ( γ � = 0 ) because const can be chosen arbi- trary . 23 / 25
Defining Continuous Simulations Initial value problem: differential eqution and value for initial point guarantee a unique solution. 1. Define initival value for differential equation: d v d t ( t ) = − g − γ m v ( t ) with v (0) = 0 2. Define a function for const in the solution: m t = m · g m t − 1) v ( t ) = − m · g + m · g γ e − γ γ ( e − γ γ sec 2 , m = 10 kg , γ = 2 kg 3. Define parameters : g = 9 . 8 m sec 4. Substituting parameters into DE : d v d t ( t ) = − 9 . 8 − 0 . 2 · v ( t ) 5. Substituting parameters into solution : v ( t ) = 49 · ( e − 0 . 2 t − 1) 6. For stable state solution: v ( t ) = 49 · ( e − 0 . 2 t − 1) t →∞ v final = − 49 m − − − → sec = − 176 . 4 km/h 24 / 25
Defining Continuous Simulations v ( t ) = − m · g + m · g γ e − γ d v d t ( t ) = − g − γ m t m v ( t ) with v (0) = 0 γ Explicit solution of the differential Differential equation as problem equation of Free fall with friction . model of Free fall with friction . We are modeling dynamical systems in form of differential equations and not in form of an explicit solution of a differential equation. A differential equation is the right form for a dynamical model where we model change over time . However, many problems expressed as differential equations do not have an explicit solution . In these cases we therefore have to simulate ! 25 / 25
Recommend
More recommend