Sim Course

download Sim Course

of 49

Transcript of Sim Course

  • 7/31/2019 Sim Course

    1/49

    Modeling and Simulation

    Course

    byVincent E. Asor, PhD

    Auxiliary materials

  • 7/31/2019 Sim Course

    2/49

    About this document

    Comments to the course on Modeling and Simulation (M&S)

    This is a complementary document with comments on the slides included in the presentation"simcourse.ppt". Before using the slides and the below material in your simulation course,

    take into account the following.

    Obviously, it is supposed that you have certain experience in modeling andsimulation, and perhaps you already are delivering similar courses. The presentcourse slides and comments may help you in the task. If you are registered user of theslides, feel free to modify them, add new material or withdraw some topics.Remember that neither the slides nor the below text is the text-book for the course.Those are merely figures, general ideas and corresponding comments. I suggest thatyou do not pass the below text (except the course program) to your students. Thisis an auxiliary material for the teacher use, not for the students.

    The course is designed as the basic course on M&S. You perfectly know how wide

    is the topic, and how rapidly the methodology and software of M&S growths. It ishardly possible to treat all what should be said about M&S in one basic course. Thisslide set is used at the School of Engineering, Universidad Panamericana, MexicoCity. The course duration is one semester (17 weeks), three hour per week. You mustadapt the material to the specifications of your course. It is common that the teachers,in particular in the M&S field design their course to what they know and do best, andsometimes limit the course to a particular software or a specific topics (like discretesimulation, Monte-Carlo or even time series processing). The present course is anattempt to include as many basic ideas as possible. Some topics are omitted,sometimes intentionally, but mainly because of the physical limitation of the course(like variance reduction, finite element method, applications of some standard

    software and virtual reality). Software. This is NOT a course on the use of M&S software packages. Most of the

    known software packages that claim to be "easy and friendly" are equipped withmanuals of several hundred of pages each, and would need a whole course withhundreds of exercises to dominate the package. Other important question is thelicensing. What a student, who passed the course can do in M&S if he has nosoftware he can legally use in her/his research or professional work? So, the use ofexpensive fully functional packages in such a course is of little usefulness for thestudents. Some software packages have free student versions (like GPSS or Stella,Arena) that you can use. Of course you must check the availability of such copies,their limitations and possibilities of upgrades. In this course we use such version to

    teach the ideas of GPSS and Stella. Other exercises and general simulation ideas arebased on the use of the PSM++ Simulation System. PSM++ is a general purpose, wellintegrated system that includes continuous (ODE, Signal-flow, Bond-graphs), discrete(queuing, discrete events) and combined simulation. You can use PSM++ slides inyour classes, or ignore the related slides as you wish. PSM++ is a low cost software,that can be acquired with discount for the users of this material. The PSM++summary and demo can be found on http://www.raczynski.com/pn/pn.htm

    http://www.raczynski.com/pn/pn.htmhttp://www.raczynski.com/pn/pn.htm
  • 7/31/2019 Sim Course

    3/49

    Other package you can use for discrete simulation is QMS (Queuing ModelSimulator),http://www.raczynski.com/pn/qms.htm . The demo version is free, and itpermits to run small models. Note that this demo includes the complete QMS manual,which can be useful as an auxiliary text.

    Text books. In my opinion, we have no good text books for M&S basic course at all.

    Combining some available publications you can perhaps complete the necessarycourse text. Try to avoid books which are focused on one software tool only, or oneparticular M&S topic. I suggest you use my Simulation Encyclopedia availablefrom http://www.raczynski.com/pn/encyk.htm . As the price of the download is aslow as US$10, you may ask your students do acquire it. At the end of the slide set youwill find a lot of other references (books, articles), which may help you also.

    The slides should be treated as a working material. They are not edited in an"attractive" format, some of them show scanned figures. Few slides have abackground color or design. Note that in some slides animation is used. It is supposedthat you are quite familiar with the use of MS PowerPoint presentations and with theuse of animation.

    You should clearly explain to your students that this set of slides is NOT anycomplete text of the course. Those are main ideas and figures only. In the learningprocess, the student must use text books and other references according to yourindications. The present auxiliary text is for your use rather than for the students.

    The section 7 (Advanced topics) is optional in a basic simulation course. You mayinclude it to the course, depending on the level of student preparation and to thecourse duration. Note that the last section (7.4.1. Differntial Inclusions - a case study)is described here in the form of a complete article, with figures.

    http://www.raczynski.com/pn/qms.htm%20http://www.raczynski.com/pn/qms.htm%20http://www.raczynski.com/pn/encyk.htmhttp://www.raczynski.com/pn/qms.htm%20http://www.raczynski.com/pn/encyk.htm
  • 7/31/2019 Sim Course

    4/49

    Modeling and SimulationCourse program

    1. Introduction1.1. Definition of computer simulation

    1.2. Importance of modeling and simulation in business and manufacturing systemmanagement

    1.3. Modeling and simulation as complementary tasks1.4. Computer simulation as an interdisciplinary tool1.5. Examples of application in various fields of science, technology and life

    2. General concepts of modeling2.1. Continuous and discrete models and simulation2.2. The model: components, descriptive variables and interaction rules2.3. The concept of model state

    2.4. Descriptive variables: input, state, output, model parameters, state transition andoutput functions

    2.5. Experimental frames and simplified models2.6. Model validation, verification and credibility2.7. Classification of dynamic systems

    3. Chronology of M&S methods and software development4. Discrete simulation

    4.1. Probability, distributions and random numbers generation4.2. Simulation "Monte Carlo"4.3. Object- and agent-oriented simulation. Model time, event messages and event queue4.4. CSL

    4.5. GPSS4.6. PSM++4.7. The "Three phases" strategy in event simulation4.8. Object-oriented simulation - ideas of Simula67

    5. Continuous simulation5.1. Analog machines5.2. Possible continuous model representations: ODE, Signal Flow, Bond Graphs5.3. Examples of continuous ODE models

    5.3.1. Mass in movement5.3.2. Car suspension5.3.3. Stirred tank

    5.4. Numerical methods for ODEs5.5. Direct coding of a continuous simulation program5.6. Exercise for ODE simulation : car suspension

    5.7. Signal Flow Graphs (SGF)

    5.7.1. Nodes and links, SFG and block diagrams5.7.2. Examples: an automatic control system, an electric circuit5.7.3. Eliminating equations and coding from the simulation task

  • 7/31/2019 Sim Course

    5/49

    5.7.4. Signal flow module of PSM++ - link types5.7.5. Signal flow module of PSM++ - an exercise

    5.8. Bond graphs5.8.1. The bond and the related variables

    5.8.2. Node and bond types, causality5.8.3. Examples: application to mechanical systems5.8.4. Exercises

    6. System Dynamics (SD)

    6.1. System thinking. Definition of SD by Jay Forrester6.2. Basic concepts6.3. SD software tools6.4. Examples: business dynamics, ecology

    7. Advanced topics7.1. Distributed simulation7.2. High Level Architecture7.3. Discrete Event Specification Formalism (DEVS)7.4. Other possible tools: Differential Inclusions (DIs) in modeling and simulation

    7.4.1. Advanced case study: Stock market simulation using DIs7. References

  • 7/31/2019 Sim Course

    6/49

    The slidesComments and auxiliary text

    Identify the slides by the slide ID on the upper right corner of each slide,

    and not by the slide number (bottom right). In the following there aresome comments and explanations for the slides, each section starting with

    the slide ID.

    1. This is a copy of a transparency stolen from Dr. Ralph Huntsinger, past President of TheSociety for Modeling and Simulation in San Diego. Ralph always starts his presentation withthis transparency. Obviously he is right: SIMULATION is FUN!! As a simulationist youmust learn how the rice grows, how shoes are fabricated, how a plane flies, how galaxies areformed, how molecules interact, how social structures grow, how an epidemic propagates andmany other things. This interdisciplinary aspect makes modeling and simulation so

    fascinating.

    1A. Those are merely a few suggested references. A bigger list of references is given at theend of the presentation.

    1.1. Definitions computer simulation. There are many definitions of computer simulation.For example, A. Alan B. Pritsker defines it as the representation of the dynamic behavior ofthe by moving it from state to state in accordance with well-defined operating rules (Pritsker,Introduction to Simulation and SLAMII, John Wiley and Sons, 1984). Many authors definesimulation in the similar way, with emphasis to the changes of the modeled system state intime.

    Bernard P. Zeigler in Theory of Modeling and Simulation, John Wiley and Sons, 1976 writes:We can therefore define simulation as the technique of solving problems by the observationof the performance, over the time, of a dynamic model of the system. In somewhat moregeneral way, we can define the modelingas the relation between real systems and models,andsimulation as the relation between models and computers.In the article of A.A.B. Pritsker, Compilation of definitions of simulation, SIMULATION,August 1979, pp.61-63, you can find about 30 different definitions of computer simulation.Most of the authors tend to define simulation in terms of the software they develop or use.However, the common approach is that relating simulation with the changes of the modelstate in time.

    1.2. Importance of modeling and simulation in business and manufacturing systemmanagement. The figure is shown due to Inyong Ham, The Pennsylvania State University,The creator of the Group Technology. It is worth to note that the creator of the GroupTechnology, who gave fundaments to manufacturing information systems, considersmodeling and simulation one of the central elements of the information system in anymanufacturing organization.

  • 7/31/2019 Sim Course

    7/49

    1.3. As stated on the slide,we can define the modeling as the relation between real systemsand models, and simulation as the relation between models and computers. The generalconcepts of modeling are treated in Section 2

    1.4. Both modeling and simulation are interdisciplinary tasks. The following series of slides

    illustrates this. Those are merely some selected applications, ranging from manufacturing toecology and literature.

    1.5.A. A fragment of a manufacturing model. QMG module of the PMS++ simulationsystem. This application is carried out to detect bottlenecks and to see the statistics of thebuffers, machines and operations in a manufacturing system. The user creates the modelgraphically on the screen, gives the block parameters and the rest is being done automaticallyby the software. The red boxes are buffers, blue rectangles are machines, green verticalrectangles are assembly operations.

    1.5.B. This is an animations of a simulated production cell, PSM++ simulation system. Theproducts enter the system, then travel over a transportation facility (closed conveyor) andoccupy (if possible) one of the three service facilities. After receiving the service, the itemsenter a buffer and then the quality check. Some of them are rejected and must go back to theconveyor, others go out. The items move on the screen, so that the target user can see howthe system works.

    1.5.C. A System Dynamics model of a factory. This is a screenshot of the Stella program.System dynamics is other approach to the simulation of factories and other systems. This is aglobal approach, rather than discrete event simulation as in the previous examples. Se theSystem Dynamics section for more detail.

    1.5.D. A system dynamics model, similar to the model of the slide 1.5.C. The demand has arandom component. Done with the SimBall program.

    1.5.E, 1.5.F. An application of System Dynamics approach in the classes of literature. Thismodel was created not to write new theater works, but to explain to the students the dynamicsof Hamlet story. The model was widely discussed on one of the System Dynamicsconferences several years ago, as a highly interdisciplinary application of system thinking.The slide 1.5.F is the screenshot of the corresponding Stella model. It can be see how thecharacters interact with each other and what feedback interactions are introduced.

    1.5.G, 1.5.H, 1.5.I. A model of a stock market with bandwagon effect, with one stocktype. P is the action price, n is the demand, ne is the uncertain component of the demand(uncertain or false information). The "bandwagon" feedback represents the market panic oreuphoria, caused by the rate of the price change. This is asignal flow graph representation ofthe model (see the Signal Flow Graphs section). 1.5.H shows the same model introduced tothe Simulink module of MatLab. On the slide 1.5.I we can see the market response to achange in the price. It reveals strong rapid oscillations, that means that the market is close toloose its stability.

  • 7/31/2019 Sim Course

    8/49

    1.5.K, 1.5.L, 1.5.M. Those are some screenshots of a project carried out at the UniversidadPanamericana, by the School of Engineering and the Faculty of Laws. This is the simulationof legal processes, that result from the sell-buy operation of actions between two companies.The trade union of the selling company may not accept the operation, and announce thestrike. The legality of the strike is negotiated, and if there is no agreement, the strike begins.

    The financial state of the selling company becomes bad, and the buying company maydemand the change of the conditions or the cancellation of the whole operation. This invokesa series of legal events, that normally is quite complicated. The model is used as an didacticaid in the classes on laws.

    1.5.N. This PSM++ program is an "ecological game". It simulates a population of entitieswhich grow in a limited environment. First, the screen is filled with food (green area).Several initial entities appear and begin to multiply. To survive, the entity must eat. In somerandom time instants each entity pollutes the environment (red areas). The pollution ispermanent, while the food is renewable. However, no food can reappear on a polluted spot. Ifsome food is available in the neighborhood of the entity, it replicates, producing up toeight new entities. The entity population grows, and those which remain inside the populatedareas do not have enough food to reproduce and survive.

    1.5.O. Fluid dynamics simulation. This is one of the most difficult tasks in simulation. Thefluid dynamics equations are quite complicated and so are the numerical methods andsimulation programs. The screenshot shows a gas flow in a duct. This is a section of the duct;the simulation is three-dimensional. Fluids5 program.

    2.1.The division of modeling and simulation field into discrete and continuous parts is wellknown and practical. This division is perhaps somewhat doubtful: in the real world nothing isexactly "discrete in time" or "continuous". From the conceptual point of view, in my opinion,this division is too simplified and artificial. However, in the simulation practice, it is useful,in particular to classify and select simulation software. The simulation tools for discrete andcontinuous models are very different. (See chapter 5).As stated on the slide, in continuous simulation we deal with a continuous model, where boththe model time and the system state change continuously. In the discrete simulation, the timejumps from one event to another, and each event can change the model state and generateother events at the same time instant or in the future.In discrete simulation the model time jumps from one event to another, and the events changethe model state. The duration of the event execution (in the model time) is equal to zero.Observe, however that both of the above simulation modes are only approximations of thereality and, in fact, their ideal implementations can only provide an illusion. Continuoussimulation on digital computers does not exist, simply because in a digital computernothing is continuous. The discrete event models do not describe the real world, because areal event cannot occur within null time interval.

    General concepts of modeling.First of all, recall that asystem can be defined as a set of components that are interrelated andinteract with each other. These interrelations and interactions differentiate the system from itsenvironment. The system is supposed to be organized in order to perform one or morefunctions or to realize one or more specific goals.

  • 7/31/2019 Sim Course

    9/49

    The commonly mentioned properties of systems include:Aggregation that means that systems can be grouped into categories that can be nested intolager aggregates.Non-linearity - System needs not to be linear that is it not necessarily satisfies the principleof superposition. In other words, the behavior of a system cannot be derived from the sum of

    behaviors of its components.Consult: Holland, J., 1995, Hidden order, Addison-EsleyNow, we can talk about system modeling. P. Bratley, L.F. Bennet and L.E.Schrage in theirbookA guide to Simulation, Springer-Verlag, 1987, say:A model is a description of somesystem intended to predict what happens if certain actions are taken. This is perhaps one ofthe most essential definitions of what a model of a real system is, although it needs someadditional explications. Many years ago A.Rosenblueth and N.Wiener pointed out thatmodeling is one of the central needs of scientific reasoning. Dealing with models we musttake into account many factors, like the level of simplification, experimental frame, modelvalidity, tractability, credibility andthe aim of modeling among others. Bernard P. Zeigler(Theory of Modeling and Simulation, John Wiley and Sons, 1976) gives some basic conceptson modeling. First of all, we must define the model components as elemental parts of themodel, like clients in a bank, ships entering a harbur, cars on a street etc. Each component isdescribed by the descriptive variables that include input, state and output variables. The setof all descriptive variables in a model is the experimantal frame of the model. The same realsystem may have several different experimental frames. For example, a possible experimentalframe for a model of an electronic circuit may include currents and voltages in all circuitelements. Other experimental frame may include the temperatures of all elements (ICs,resistors etc.) and the temperature distribution in the printed circuit. Obviously, the twoexperimental frames lead to different models and satisfy different modeling purposes. Eachexperimental frame results in the corresponding simplified model, as shown on slide 2.5.The basic model is that which reflects exactly the bahvior of the real system. Such modelnormally does not exist.Note that the aim of the modeling task, as well as the technical limitations (the computer onwhich we want to run the resulting simulation program) reduce the number of possiblesimplified models. This helps us to select the appropriate simplification. If there is more thanone simplification that satisfies these criteria, we must apply other selection rules (e.g.modeling cost). If no model exists that satisfies our aim and technical limitation, then nomodeling is possible. Remember that looking for something that does not exist is simply awaste of time.The concepts of model validity, verification, and credibility are treated in other sections. It is well known in the operations research that some problems that have a nicemathematical description cannot be solved using the hardware we actually have. The sameoccurs with models prepared to be run on a computer as a simulation task. Some models arecomputationally intractable, which means that they are too time-consuming or expensive tobe realized.A modeling and simulation task is intractable if its computational complexity increasesexponentially with the number of its descriptive variables. The computational complexitycan roughly be define as the minimal cost of guaranteeing that the computed answer to ourquestion (simulation task) is within a required error threshold.A mostly cited example of an intractable problem is the salesman problem, namely thesimulation of all possible routes of a salesman that must visit various cities. The aim of such

  • 7/31/2019 Sim Course

    10/49

    simulation is to find the route with shortest distance possible. Other examples in continuoussystem simulation can be found in fluids dynamics applied to problems like reentry of spaceshuttle to the atmosphere of the earth (modeling the airflow around the craft).For more discussion on intractability consult Joseph F. Traub and Henryk Wozniakowski,Braking intractability, Scientific American, January 1994, or Arthur G. Werschulz, The

    computational complexity of differential and integral equations: An information-basedapproach, Oxford University Press, 1991.

    2.2. While constructing a model, we must not forget to clearly identify its components,descriptive variables and interaction rules. The model descriptive variables are input, state,output variables and the model parameters. Input means all what affects the model fromoutside, the cause of model movement. The state of the model is the most important group ofvariables, that must be carefully specified (see the next slide). Output variables are defined bythe user. These are simulation results which will be printed, stored or plotted.

    2.3.A, 2.3.B, 2.3.C. Model state.Let U { s , t } be the input to the system over the interval[ s , t ], where s and tare two timeinstants, s < t.We define X(t) as the state of the system at the moment t if and only if a function Fexists, such that

    X( t ) = F( t ,U { s , t } , s , X( s ))

    In other words, it is necessary that the system state at a moment t can be calculated usingsome past state in time instant s and the input function over the interval between the twomoments of time. Here we assume that the system is causal in the sense that its state at amoment does not depend on any variable values in the future time instants.For example, the state of a system that has one spring, one mass and one damper linkedtogether is given by the mass position and velocity. All other descriptive variables of thissystem are parameters, inputs (e.g. external forces), or some output functions defined by themodeler.In the case of an electric red composed by any number of resistors and one capacitor, the sateis a (scalar) value of the capacitor voltage. In this case all the currents in the resistors can becalculated provided we know the capacitor voltage and the external excitations (inputsignals).System state may be a scalar, a vector or an element of certain more abstract space. Forexample, the state of the model describing the changes of the temperature distribution insidea piece of metal belongs to the space of all differentiable functions of three variables definedin the region occupied by the modeled body.

    2.4. Descriptive variables.This slide shows graphically how the descriptive variables change. The set of input and statevariables defines the future state, through the function . Function transforms the state intothe set of output variables. A more detailed interpretation and more advanced issues on thistransformations is explained in the DEVS section (slide 7.3).

    2.5.A, 2.5.B, 2.5.C. Experimental frames and simplified models.

  • 7/31/2019 Sim Course

    11/49

    The set of all descriptive variables in a model is the experimental frame of the model. Thesame real system may have several different experimental frames. For example, a possibleexperimental frame for a model of an electronic circuit may include currents and voltages inall circuit elements. Other experimental frame may include the temperatures of all elements(ICs, resistors etc.) and the temperature distribution in the printed circuit. Obviously, the two

    experimental frames lead to different models and satisfy different modeling purposes.On the slide 2.5.B two possible experimental frames are shown. The frame of simplifiedmodel 1 includes the clients in a barber shop as separate objects in the computer memory.The waiting line is a set of waiting clients. The barber is a server that can be free or busy atthe moment. The frame 2 (simplified model 2) is more simplified: now the queue is merelyan integer number that tells how many clients are waiting. Simplified model 2 can besimulated using Monte Carlo simulation, provided we know the rate of client arrivals and theservice time distribution. Observe however, that using model 2 we loose the possibility ofsimulating the clients as (possibly different) objects. This means, that in the simplification 1we can observe each client, equip him/her with different service requirements, and even makehim/her to report on the simulation screen each time something occurs.Each experimental frame results in the corresponding simplified model, as shown on slide2.5.C. Here, the basic model is that which reflects exactly the behavior of the real system.Such model normally does not exist.Note that the aim of the modeling task, as well as the technical limitations (the computer onwhich we want to run the resulting simulation program) reduce the number of possiblesimplified models. This helps us to select the appropriate simplification. If there is more thanone simplification that satisfies these criteria, we must apply other selection rules (e.g.modeling cost). If no model exists that satisfies our aim and technical limitation, then nomodeling is possible. Remember that looking for something that does not exist is simply awaste of time.

    2.6.A, 2.6.B, 2.6.C. Model validation, verification and credibilityModel validity is one of the central problems in modeling and simulation. Consider a realdynamic system and its model. Let S be the operation of modeling (passing from realsystem to its model). By x(t) we will denote the system state in the time instant t , by y(t)the system output, by the state transition function that maps the state x(t) and input over[t, t+h] into the new state x(t+h). The same letters with suffix s denote the correspondingitems for the model. Our model is said to be valid if and only if the following diagram ofslide 2.6 commutes.In other words, starting with x(t) we must obtain the same model output ys(t+h)independently of the way we go. This must be satisfied for any possible initial state andinput.The above definition of model validity is somewhat difficult for practical applications. Amore practical concept is the "input-output" validity that can be illustrated by the followingscheme of slide 2.6.B.The model is supposed to be I/O valid, if the outputs from model and from the real system are"sufficiently" near. What "sufficiently" means is the individual judgement of the modeller.Obviously, the above property must be satisfied for a long time interval, and perhaps forfuture model inputs. As we do not know what inputs signals will affect our model, the onlyway to check the I/O validity is to compare the model behavior and the real system outputusing some historic data.

  • 7/31/2019 Sim Course

    12/49

    Observe that according to the first definition any approximation of a real continuoussystem by a model with discrete time is invalid. Indeed, in a real system a disturbance maycome within the time period of dircretization, being not detected by the discrete model. If theinput signals have high frequencies, the aliasing phenomenon may result in completely wrong

    results. Other source of error is the time-discretization itself that implies its own errors. Themost direct way to make the discrete model more exact is to decrease the sampling time forthe discrete model. However, there are limitation for such approach, mainly caused by thecomputer resolution and limitations of a numerical method applied for trajectory integration.Anyway the modeler must look for a reasonable compromise.

    Invalid models are often results of wrong assumptions. Creating a simplified model weidealize the real system that may result in physically wrong models. Consider a simpleexample of the electric circuit shown on slide 2.6.D.

    Let the initial voltage for the capacitorC1 be equal to V, and initial voltage forC2 equal tozero, C1=C2=C. After closing the switch, the two voltages become obviously equal to eachother and equal to V/2. Now, consider a simplified model of the circuit. We assume that allelements are "ideal", which means that the capacitors have no internal resistance orinductance, the same assumption taken for the conductors (R=0). Now calculate the initialenergy of the circuit. It is equal to (CVV)/2 (C square V divided by two). After closing thecircuit, the total energy is 2(C(V/2)(V/2))/2 = (CVV)/4. Where the half of the initial energywent? Our model cannot explain this. In other words, the model is invalid. The very simplereason is that it is too simplified. Now, consider other model, where the connecting wireshave resistance R. It is easy to show that the half of the energy is dissipated in the wireresistance during the transient process. Moreover, that this energy does not depend on thevalue of the resistance. This means that the previous simplified model is not the limit case ofthe second model, with Rapproaching zero.Note also that the model validity depends on the actual experimental frame. The first modelof our circuit is valid if the experimental frame only includes the (static) voltages. However,if we add the system energy to the experimental frame, this model becomes invalid and wemust look for another one.

    Program verification must be done to check that the simulation program operates in the waythat the author of the model thinks it does; the program must be free of bugs and consistentwith the model. Such checking is never absolutely complete. The program testing problem isa complex one and widely treated in data processing systems, but the problems are similar.Good verification makes the simulation model and program more believable to the user.

    2.7.A, 2.7.B. Classification of dynamic systemsIn the classification given on the slide 2.7.B we relate the each class to the power of the set ofall possible system states. This is somewhat simplified approach. From the mathematicalpoint of view, we should use the term power of the set of classes of equivalence of inputsignals instead of number of possible states. Roughly speaking, a class of equivalence ofinputs is the set of all input functions that provide the same system response over a giventime interval. For example, if the system is an integrator, it will give the same response equalto zero, if the input is equal to zero everywhere, or almost everywhere, that is, except of a set

  • 7/31/2019 Sim Course

    13/49

    of points of total measure zero. But there is an infinite number of different functions with thisproperty. So, all these input functions belong to the same class of equivalence. However, thisis not a course on mathematics, so it is better to use the term number of possible states,understanding by this thepower of the set of all possible states.The slide 2.7.B contains short characteristics of the following system classes.

    Finite automata finite number of possible states. For example a light switch, a computer.Modeling tool: discrete events.Infinite automata infinite but enumerable set of possible states. For example a waiting linewithout limit, infinitely growing population. Modeling and simulation tool: discrete events.Concentrated parameter systems for this class, the power of the set of all possible states isequal to the power of the set of all real numbers. For example RC circuit, a mass moved by aspring and a dumper. Main modeling tool: ODE (Ordinary Differential Equations).Distributed parameter systems the power of the set of all possible states is greater than thepower of the set of all real numbers. For example: diffusion process, 3D heat distribution in apiece of metal, waves on the water surface. Main modeling tool: PDE (Partial DifferentialEquations).

    3.A - 3.G. These are some important dates and events in the development of Modeling andSimulation. The details are on the slides, no additional comments needed.

    4, 4.A. Discrete simulation.Imagine a small barbershop with one client queue and one barber.Let the aim of our simulation is to observe how the client queue changes during a day ofwork. What really influence the queue length are the client arrival rate and the averageservice time. To satisfy our simulation aim we do not need to simulate how a client movesinside the shop or how much he/she weights. What we must simulate are events like arrival,seizing the server (start service) and releasing the server (be served, go out). These events canbe supposed to happen in a discrete time instants, in other words we will not simulate theprocess of opening the door and passing from the door to the waiting place. We suppose thatall this occurs instantly. So, the events occur in certain time instants, and nothing happensbetween consecutive events. This means that the model time can jump from one event toanother. The model time is a real variable, but takes a discrete, may be random, values. Thisis what happens in discrete event simulation: only the events are simulated, and the time doesnot advance continuously, but rather in finite intervals. In this way we achieve a goodspeedup of the simulation. The problem is, however, how to manage the event queue (not theclient queue of our example) inside the simulation system. The model time must jump to thenext event, so we must every time select the nearest event or to maintain the event queuesorted by the execution time. Anyway, this is always the problem of sorting. A simple linearsearch or sorting where we examine the whole set of events can work with few possibleevents, but becomes very slow when the number of events grows. As it is a sorting problem,it will not be discussed here in detail. Note only that a discrete event simulation package is sogood as good is its event queue management.The first discrete simulation languages like CSL had simple but already goodimplementations of the event queue management. Then, different strategies of the eventscheduling and process interaction appeared.

  • 7/31/2019 Sim Course

    14/49

    As stated earlier, in the discrete simulation the model time jumps from one event to another,and the events change the model state. The duration of the event execution (in the modeltime) is equal to zero.Observe that the discrete event models do not describe the real world, because a real eventcannot occur within null time interval. However, in many cases, in particular in queuing

    models (mass service, manufacturing) discrete event models are widely used and provide agood approximation of the reality. Other advantage of discrete simulation is the simulationcost. The discrete simulation is very fast, compared to the continuous or combinedsimulation, where the model time cannot advance so rapidly.

    The most important problem in discrete simulation is the handling of the event queueinside the simulation tool (software and hardware implementations). It can be said that adiscrete simulation package is so good as good is its internal clock mechanism, that managesthe event queue. See the next slides for more detail. In this chapter we discuss the problemsof Monte-Carlo simulation, object-oriented simulation, agent-oriented simulation,theoretical base:DEVS Discrete Event Specification Formalism, and distributed simulation(this is NOT the same as the simulation of distributed parameter systems). The problem ishow to distribute simulation tasks between multiple processors.

    4.1.A - 4.1.T. Probability and distributions.Any course that includes the discrete simulation, must also provide some comments onprobability, distributions and random number generators. However, this is not a course onprobability and statistics. It is assumed that the students already have certain knowledgeabout these topics. Anyway, it would be an error to dedicate more than, say, 20 % of thecourse to these issues. Here we only suggest some comments on basic issues, to recall what isabsolutely necessary. It seems that the distributions mentioned below are the most importantin queuing models, but of course those are only few of the huge set of known probabilitydistributions.Start this part with the definition of the probability. It can be seen that frequently studentswho are familiar with the use of density and cumulative functions fail to define what exactlythe probability is. It is also very important to recall what the Poisson process is and explainwhy in Monte Carlo-type simulation we frequently use the Poisson distribution, while in suchsoftware as GPSS, Arena and object-oriented languages the same process is described by theexponential distribution. If the student remembers that the Poisson distributed (integer)variable describes the number of occurrences of an event (for example client arrivals) withina time interval, and the exponentially distributed (real) variable defines the times between theconsecutive occurrences (inter-arrival times), he/she will not commit elemental mistakes. It isalso important to be aware of possible errors while using the normal distribution. A commonerror is to use it as the between-arrival time distribution or service time, withoutimplementing an additional procedure that truncates it to positive-only values.4.1.U, 4.1.V These slides explain the chi square test. It is supposed that the students alreadyhave basic knowledge on probability theory and statistics. The items which refer to thesetopics should only be treated as remainders. The slides contain the following:

    Chi-square test

    A frequent question is what probability distribution should be used to generate randomnumbers for a simulation experiment. This data is difficult to obtain from the end user of thesimulation program, who usually has no idea what is the distribution of the time interval of a

  • 7/31/2019 Sim Course

    15/49

    simulated operation. If the variable is the between-arrival interval of a Poisson arrivalprocess, you should use the exponential distribution. If it is not the case, you must supposesomething and then test your hypothesis. The mostly used test is the chi-square test. .NOTE: Chi-square test does NOT determine if the hypothesis is true. It just tells us if aspecific statistical hypothesis should be rejected or not. The procedure is as follows.

    0. Select a null hypothesis about the probability distribution for a randomvariable being examined.(an expectation of some sort).1. Get at least 30 random values for the variable (perform an experiment to get

    the data)2. Calculate the mean and the variance over the data set3. Create a histogram of m = square root of n intervals, where n is the number of

    data points, calculate the number of data points Ni (i=1,..,m) that fall in eachinterval. Note that you must have at least 5 points in each interval. If not, getmore data

    4. For each interval calculate the expected valueEi using the null hypothesis. Todo this, calculate the (theoretical) probability Pi of falling in each interval i,and calculateEi=nPi, i=1,..,m

    5. Calculate the weighet deviation6. Define the level of significance a for the test. Usually it is 10 or 5 percent, that

    is a=0.1 or 0.057. Get the critical value for square chi with parameters a,b where b=m-k-1. The

    value ofkdepends on the number of degree of freedom of the null hypothesisdistribution. For example, for the normal distribution we have k=2, for theexponential distribution k=1.

    8. Compare the value of c with the critical value for square chi distribution, taken

    from the tables of chi test critical values. If the value of c is less that thecritical value, you cannot reject the null hypothesis (this does not mean thatthe hypothesis is true, it just tells that it cannot be rejected). For example, thevalue ofa=0.05 means that there is only a 5% chance that the deviation c isdue to chance alone.

    4.2.A. Simulation Monte-Carlo.In the field of numerical methods, Monte Carlo method is applied mainly to evaluateintegrals. For example, given a function f(x) with values in [0,1] and defined over theinterval [0,1] the Monte Carlo method consists in randomly generating a set of points (x,y) in

    the square area 1x1 and in counting the points for whichy

  • 7/31/2019 Sim Course

    16/49

    evaluation of the result. Monte Carlo simulation has been widely used to simulate problemslike stock management and simple queuing models.

    4.2.B. Simulation Monte-Carlo - example.This flow diagram can be used to implement the simulation for the problem stated on slide

    4.2.A. The resulting program is fast and easy to implement. However, remember that this is arough approximation of the reality. In particular, this program does not take into account thetimes the clients arrive during each day and the moments when the products come to theinventory place. If a client comes at 10 a.m. and the stock is empty, it may go withoutwaiting, while the product he is looking for is available at 2 p.m..4.3.A, 4.3.B. Object-oriented simulation.Recall that in the object-oriented (OO) programming the program is composed by objects.An object is a structure that has its attributes (visible from outside of the object or hidden)and methods. Everything the object knows is in its attributes and everything it can do is in itsmethods. For example, a particle, which is a component of an N-body system, has a set ofattributes that include its position and velocity vectors, its mass, shape, dimensions etc. Themethods of the particle should describe the way it interacts with other particles (calculate theexternal forces) and the particle movement. The difference between OO programminglanguages and OO simulation tools is that an OO simulation language or package mustprovide the clock mechanism, transparent for the user. For example, is an object-orientedprogramming language. Its simulation mechanisms are not in the language definition, butrather in a pre-defined PROCESS class, written in Simula that can be used to create otherobjects. The PROCESS class handles the model time and the event queue. Other examples ofOO simulation are and .The advantage of OO simulation consists in more realistic model building. For example, theclassical prey-predator models were formulated in the form of Lotka-Volterra differentialequations. Now, the common believe is that Lotka-Volterra equations does not describe whatreally happens in the real prey-predator systems. Simulating such systems with object-oriented tools we describe the behavior or each of its members, taking into account itsposition in a geographical region, individual attributes etc. This results in more realisticsimulations.The slide contains also a comment on agent-oriented simulation.

    4.4. Simulation concepts introduced in CSL.The Control and Simulation Language was one of the first simulation languages, developedin the 50s. In fact, the name is somewhat confusing; the language has no capabilities forautomatic control or similar tasks. It is a discrete simulation language that implements theActivity Scanning (AS) simulation strategy.CSL is obsolete and not used recently. However, for historical reasons some CSL conceptsare described here in more detail.CSL is based on Fortran. Compared to Fortran, it has three new elements: the clockmechanism, entity class definition and sets of entities.The clock mechanism manages a set of variables named time variables. These variablesstore various time instants. They are subject to the clock algorithm, and may be used in user-defined logical expressions. The time named CLOCK starts with value equal to zero. Then,all possible model activities are scanned, according to the slide 4.4.A.

  • 7/31/2019 Sim Course

    17/49

    The events are defined by the user and normally have the structure indicated on 4.4.A..In the conditional part of the event the user should use one or more time variables. Moreover,the main condition should be TX EQ 0, where TX is a time variable. So, only the events withcorresponding time variables equal to zero will be executed. After terminating activityscanning, the CLOCK is set equal to the value of the nearest time variable greater than the

    CLOCK, this means to the time instant of next possible event (slide 4.4.B). After this, all thetime variables are being decreased by the same time interval. This way, in the next time, thenext event(s) will be executed. The time variables can be declared by the user as globalvariables, or can be attached to model entities (each entity having its own time variable).The following line is an example of a CSL class definition.

    CLASS TIME CLIENT SET OUTSIDE, QUEUE, SERVICE

    This defines a class named client (e.g. clients in a bank). The word TIME tells that eachclient has its own time variable. A client may belong to the sets OUTSIDE, QUEUE (waitingto be served) or SERVICE (being served). The reference T.CLIENT.K can be used to refer tothe time variable of the client number K.

    The program code includes only the initial part (initial conditions and the wordACTIVITIES), and then the event codes. The order the user puts the events in the program isnot relevant (except possible simultaneous events). The clock part is hidden and runsautomatically. The code of an event should contain a conditional part and some operations.The operations are NOT executed if the conditions fail. For example, the arrivals of a clientcan be described as the following event code.

    BEGINT.ARRIVAL EQ 0T.ARRIVAL = NEGEXP(20)FIND K OUTSIDE FIRST

    CLIENT K FROM OUTSIDECLIENT K TAIL QUEUE

    Note that this event reschedules itself to be executed after a random time interval(exponential distribution with mean equal to 20 time units). The main condition isT.ARRIVAL = 0, where T.ARRIVAL is a time variable. FIND finds a client being outsidethe bank. The client is taken from outside and put as the last one waiting in the queue. Theinstruction FIND returns also a logical value. If it fails (there are no clients outside), thefollowing "operational" part of the event is not executed.

    As mentioned above, this description of CSL is given here only for historical reasons. CSL is

    now obsolete and completely forgotten. However, some important simulation concepts wereintroduced in this language perhaps for the first time in the history of computer simulation.

    4.5.A, 4.5.B, 4.5.C. GPSSNote that this is not a course of the use of any simulation package. In fact, any of thelanguages and packages mentioned here would need a whole separate course to give anecessary information to a future professional user. What we show here are only a main idesand some examples of application.

  • 7/31/2019 Sim Course

    18/49

    The slides contain a comments on GPSS. As for the software, the examples are based onGPSS/H of Wolverine (free student version). The other source can be Minuteman Software,the GPSS for Windows, also available in demo verion for didactic use.Although GPSS is not an object-oriented language in the sense recently used, it, in fact,handles objets (transactions). So, from the simulation point of view, it is object-oriented

    simulation. GPSS is an old tool, but it is still in use and offers all what is necessary tosimulate quite big and complex discrete event models.

    4.6.A - 4.6.D. PSM++If you prefer other simulation tools, simply skip this section. We use PSM++ because it is awell integrated system that supports continuous, discrete and combined models.It is a low-cost tool. To run PSM++ you will need the Borlad's Delphi(TM) installed on your machine. Itcan be Delphi 6,7 or 2005.PSM++ (Pascal Modeling and Simulation) is a new version of the PASION SimulationSystem. PASION stands for PAScal simulatION. PSM++ is an object-oriented, Pascal-related simulation language. The language has a clear process/event structure and is equippedwith appropriate environment. The PSM++ translator generates Pascal source code that canbe run using a Pascal compiler (actual DOS version generates code compatible with theBorland's Turbo-Pascal 6, the Windows version is compatible with the Borland's Delphi 3, 4or 5). The following features make PSM++ the most complete and versatile simulation tool.

    Efficient scheduling and event queue management

    Inheritance mechanism that permits to add new properties to old processes withoutintervening the source code of processes declared earlier.

    State events. Discrete and continuous objects can run concurrently. The state events can beactivated by continuous objects as well as by logical conditions changed by discrete objects.

    The library of PSM++ predefined processes contains various frequently used processes, e.g.a rigid body dynamics and several helpful processes that handle graphics, data, presentationof results and interactive simulation. Program generator for queuing models (QMGW). This module includes graphical editorfor queuing schemes, program and report generators. See also an example of amanufacturing model simulation.

    Program generator for continuous processes (FLOWD) described by signal flowdiagrams. Bond Graph editor and analyzer (BONDW). This module includes a Bond graph editorand a program generator that creates source Pascal and PSM++ code for a given Bond graphmodel. Ordinary Differential Equations (ODE) PSM++ module accepts user-defined sets ofdifferential equations (linear or non-linear). Note that the equations can also be generatedautomatically by the FLOWD and BONDW modules. These three modules (ODE, FLOWDand BONDW) support several simulation modes: simple simulation (transient process),interactive mode, frequency response and post-mortem dynamic analysis for stochasticsystems.

  • 7/31/2019 Sim Course

    19/49

    PSM++ Animator includes a Scenario Editor that permits to create 2D scenarios foranimated simulation. The user can prepare hs/her scenario using any image editor like the MSPaint, or even a photo taken from the real system. A simple calls to animation proceduresfrom the source program make the user-defined icons move according to the simulatedcomponent activities. The Queuing Model Generator of PSM++ generates automatically the

    necessary data to run the animations. Post Mortem analyzer for stochastic (discrete and continuous) models. Shows variance,confidence intervals etc. as functions of time, particularly useful for the statistical analysis oftransient processes.

    Frequency response. All modules for continuous simulation (Signal-flow, bond graphsand ODE models) provide also the frequency response analysis. The result of this option areBode and Nyquist plots.

    CSS - Complex System Simulator. This PSM++ module can be used to create a modelthat is a combination of submodels of any PSM++ model type (bond graph, ODE, Signal-flow, queuing or any other coded directly in PSM++). This results in one simulation programthat containes all these submodels interacting with each other and running concurrently.

    The general concept of PSM++ simulation is to eliminate the coding (programming) andmathematics (deriving of differential model equations) from the simulation task. Of course, ifthe user likes programming he/she can code his program, and if he/she likes mathematicsthen he/she can use the ODE module and type the equations directly.Note that a similar package has been developed for C++ users. It is the C++ version of PSM++, named Blues Simulation System (BLUESSS).Consult: http://www.raczynski.com/pn/pn.htmhttp://www.raczynski.com/pn/bluesss.htm

  • 7/31/2019 Sim Course

    20/49

    4.7. STRATEGIES OF EVENT AND PROCESS SIMULATION

    There are three basic strategies in discrete simulation: Activity scanning (AS), Eventscheduling(ES), and Process interaction (PI). In this section we treat activity and eventassynonyms. More advanced strategies are being developed and can be found in publicationson the DEVS (Discrete Event Specification Formalism).

    Activity Scanning (AS) was the first discrete simulation strategy, developed in the 50s. Oneof the first implementations was the language CSL - Control and Simulation Language.According to this strategy, the model time is set equal to the time instant of the nearest event.Then, all model activities (events) are scanned and those, which can be executed, areexecuted, the others remaining inactive. Next, the time jumps to the next possible event, andthe whole process is repeated. This clock loop stops if no possible events remain in themodel. Obviously an event, while being executed, can schedule itself or other events to beexecuted in the future, so the event sequence can be long and complicated, even if the sourceprogram is relatively short.

    The Event Scheduling(ES) strategy is somewhat more effective. In the computer memorythe event queue is created. Every component orevent message of this queue stores the timethe event will be executed, and the event identifier. So, the only problem is to maintain theevent queue sorted according to execution time. If we do this, then we simply take the firstevent and execute it, without scanning all possible events. This event queue management istransparent (invisible for the user) and works automatically. The user can schedule events,but cannot redefine the model time or manipulate directly the event queue. The most effectiveevent management algorithms are those that use binary tree techniques to sort the eventqueue.

    The Process Interaction(PI) strategy is more advanced. The model is defined in terms ofprocesses that can run concurrently. The rules of interactions between processes are defined,while the specification of a process includes the necessary event scheduling. PI can beimplemented in any object-oriented programming language, and became the main feature ofSimula, Modsim, PSM++ and other languages.

    The Three phase strategy in discrete simulation is a combination of these three strategies.The three phases are as follows.1. Model time jumps to the next event.2. The event(s) scheduled to be executed at this time instant are executed.3. All state- and conditional events are revised. Those that can be executed, are.

    ConsultO'Keefe R.M., The three-phase approach: A comment on strategy-related characteristics ofdiscrete event languages and models, SIMULATION, 47(5), November 1986, pp. 208-210.Lin J.T., Lee Chia-Chu, A three-phase discrete event simulation with EPNSim graphs,SIMULATION, 60(6), June 1993, pp. 382-392.

    4.8.A - 4.8.D. Ideas of Simula67

  • 7/31/2019 Sim Course

    21/49

    This is an object-oriented high level algorithmic language. Developed by Ole-Johan Dahl,Bjorn Myhrhang and Kristen Nygaard in the Norwegian Computer Center in 1967 (see DahlO., Nygaard B., Simula - an Algol-based simulation language, Communications of the ACM,no.9, pp.671-678).Simula 67 is an extension of Algol 60. The basic concept of Simula is an object. It is a

    structure composed by attributes and instructions. Schematically, the object has the followingstructure.

    a1,a2,a3,.........,an

    v1,v2,v3,.........,vn

    where a1,a2,...,an are object attributes, v1,v2,v3,...,vn are the corresponding attribute valuesandIis the instruction list. An attribute may represent a single variable, a data structure or aprocedure. The value of a data attribute is a value of corresponding type, while the value of aprocedure attribute is the procedure body. The instruction list is a list of Algol instructionsthat is being executed when the object is created.

    When created, the object executes the instruction from the list and then detaches itself,remaining inactive. For example, the following object may represent a point on a plane thatcan calculate its norm (a distance from the origin of the coordinate system).

    x,y,real procedure norm

    < --------------------------,0>

    begin

    norm:=abs(x)+abs(y)

    end;

    The object position is not defined by the object itself. The procedure norm is fixed as a "taxi"distance from the origin, and the instruction list is empty. While created, the object does

    nothing. It may be given the values ofx and y. Once defined the object position, theprocedure norm can be call from outside the object to calculate its norm.The basic instructions that manage objects are detach and resume. The detach instructioninterrupts the object activities (the object waits) and resume activates the object (it continuesto execute its instructions).Consider the following example.

    Producer

    ....x....

    while true do begin

    ........

    x:=.......;stock:=x;

    resume(Consumer);

    detach;

    end; end Productor;

    Consumer

    ....y....

    detach;

  • 7/31/2019 Sim Course

    22/49

    while true do begin

    ......

    y:=stock;

    stock:=0;

    ......

    resume(Producer);

    detach;

    end; end Consumer;

    In this example stack is a global variable. After creating these two objects, the Consumerdetaches itself and the Producer starts to execute his instructions. The dotted part of thissketch is other instructions. In the case of the Producer, it should "produce" something(variable x) and put it into the stock. Then, it activates the consumer and detaches itself. TheConsumer takes the produced goods (variable y) from the stock and "consumes" them. Then,it activates the Producer and remains waiting.This is a very primitive example, only to show how detach and resume can be used. Simula67has a class Process where the clock mechanism and event queue management are defined. Itpermits to locate (schedule) the events in model time. In the Process class we should use the

    instructions passivate and activate instead ofdetach and resume, respectively. The hold(v)instruction makes the object wait v model time units, so the object activities can be executedin proper model time instants.The inheritance in Simula67 is realized by simple prefixed declarations. For exampleProcessclass Producer can be the heading of the producer class. If so, the Producer inherits allproperties of a Simula process. This means that it can use the time-related instructions likehold and other mechanisms needed for dynamic modeling.The objects of Simula are instances of the corresponding class definitions.Simula67 was perhaps the first (and excellent) object-oriented language with simulationcapabilities. After more than 20 years from its creation it remains one of the most elegant andsophisticated object-oriented languages. The only disadvantage of Simula is its relation to

    Algol, which is not the most used and practical programming language.Slide 4.8.D depicts the dynamic creation of objects in the computer RAM. This is not onlySimula feature, but rather the mechanism implemented in any object-oriented programminglanguage.

    5.A, 5.B. Continuous simulationContinuous simulation is the name given to the use of a computer to solve models withcontinuously changing states. However, in the digital computer nothing is continuous. Thismeans that the continuous simulation is an illusion that can provide good or not so goodapproximation of the reality (see the next slide 5.B).Continuous models are generally composed of a number of differential equations. In the case

    of digital computer, this equations are solved numerically (P.Bratley, B.L. Fox andL.E.Schrage,A guide to simulation, Springer-Verlag, 1987).Most of continuous simulation models are ODE (ordinary differential equations) model.Recall that the ODEs work only if the real systemcan be simplified to a concentratedparameter one. In other words, if we model, for example, an electric circuit, all capacitancesmust be concentrated in ideal capacitor; all resistances must not have internal capacitance orinductance etc. If there is at least one element like a "large line" where the signal propagateswith finite velocity, the ODEs can not be used. Other limitation for ODE models applicability

  • 7/31/2019 Sim Course

    23/49

    is that the modeled system cannot have other memory than its state. This is the reason whythe ODEs fail while applied to complex tasks, like biomedical or ecological systemsimulation.The widely known field of System Dynamics is nearly completely devoted to ODE modeling.Note that this approach has some risks. Indiscriminate use of ODE models to everything can

    lead to invalid models and wrong simulation results. First of all, few simulationists take careof the problem of the existence of the ODE model for a particular task at all. Second, even ifwe find a corresponding differential equation, we must be sure that it has a solution (this isnot always the case!). If the solution does not exist, the numerical method we apply can work,but the results are completely wrong. Consult Raczynski S., When System Dynamics ODEmodels fail, SIMULATION, vol. 67, no.5, 1996.Other kind of continuous dynamic systems are those of distributed parameters. The mosttypical examples are the temperature distribution problem, diffusion process, the stringmovement or fluid dynamics. Such models are described in terms ofpartial differentialequations (PDE). Simulation of the distributed parameter systems is much more difficult thatof the ODE models. There are many numerical methods that solve the PDEs, but all of themare rather time-consuming. Other approach is to divide the space where the process takesplace into small finite elements and then describe the behavior of each element. This isimplemented in many widely used methods offinite elementthat proved to be more effectivethan the numerical methods for the PEs.

    5.1. Analog computers and simulation.A typical example of analog simulation is a wind-tunnel test on a scaled-down airplanephysical model. Other way to do analog simulation is to look for an analogy between onephysical model and another, for example a mechanical and electrical circuit. A simpleelectronic circuit with one operational amplifier, one resistance and one capacitor can realizethe operation of mathematical integration. As a consequence, it is possible to solvedifferential equations using combinations of such circuits. The advanced devices with manysuch circuits and variable interconnections between them are called analog computers.In early 40s and 50s analog computers were commonly used to simulate continuous dynamicsystems, mainly automatic control systems, mechanical systems and others. During theultimate decades analog computers have been loosing importance, because the differentialequations they solve can be efficiently solved on digital computers.

    5.2.A. Possible continuous model representations.This course does NOT include simulation of distributed parameter systems. To teach thistopic we would need a whole course, including partial differential equations, correspondingnumerical methods, finite element method and related software. So, we restrict thecontinuous simulation part of the course to the models with concentrated parameters.

    Possible model representations:1. ODE Ordinary Differential Equations Mostly systems of ordinary differential

    equations (linear or non-linear) of the first order.2. Transfer functions (the system must be linear). It is recommended to recall the

    definition of system linearity and give examples of systems that have transferfunctions and those which do not.

    3. Block diagrams (Example: control systems)

  • 7/31/2019 Sim Course

    24/49

    4. Signal flow graphs (Control systems, causal diagrams)3. Bond graphs physical systems, like mechanisms, circuits.4. System Dynamics methodology of Jay Forrester, for global models of the dynamics

    of organizations, urban development, economy, ecology.

    5.2.B. Converting an ordinary differential equation of order N into N equations of the firstorder.This operation is almost always necessary in ODE model simulation. The majority of thesimulation languages and packages require this model representation. The advantage of thiscanonical representation is that we are forced to define the model state, and what results arethe model state equations. A simple trick consists in introducing the state vector andassigning a model variable to each state vector component. Not that this in not alwayspossible. If the original equation is f( y (n) , y (n-1), ., y 1 , y(t) , t )=0, (y (p) being thederivative of orderp), we must be able to calculate y (n) from this equation, in terms of thetime and other derivatives. Sometimes it is not possible. If we can do this, the state vectorshould be as follows: ( x 1 , x 2 ,...., x n) = ( y(t) , y

    1 ,...., y (n-1)). An example is given on theslide.

    5.3.1. A mechanical example.The equations are:

    ( )( )w

    K

    pxKtF

    dt

    dx

    wdt

    dp

    tFdt

    dwM

    a

    r ++

    =

    =

    =

    )(

    )(

    In fact, this is a system of equations of the first order. To express it in terms of the statevector, simply denote the state vector as ( x1, x2, x3) = ( w, p, x ). The state equations are asfollows.

    ( )( )1

    233

    32

    1

    )(

    )(

    x

    K

    xxKtF

    dt

    dx

    xdt

    dx

    M

    tF

    dt

    dx

    a

    r ++

    =

    =

    =

    5.3.2. Car suspension.This is a simplified model, where the movement only one wheel is being simulated, verticalmovement only. To simulate a complete vehicle, we should treat it as a rigid body, movingdue to the four (or more) forces produced by the wheels, in 3D.The slide contains the equations. The state vector is ( x1, x2, x3, x4).

  • 7/31/2019 Sim Course

    25/49

    5.3.3.A, 5.3.3.B. Stirred tank.Both problem statement and the solution are explained on the two slides. It is important tonote that in this case the model simplification consists in the word stirred. This means thatthe concentration of the solution is supposed to be uniform inside the tank. As a consequence,the concentration in not described by the diffusion equation, and the whole problem can be

    described by the ordinary differential equations (ODE model). Otherwise, we would need apartial differential equation and a quite difficult simulation tool.This is a good example of a physical system model. Note that to start constructing any modelof such kind, we must look for an adequate physical balance. This may be balance of volume,balance of flow, balance of thermal energy (NOT temperature) etc., or a combination of anyof them. For example, our stirred tank, as specified on the slides, satisfies the balance ofliquid volume. But this balance does not provide any relevant equations, because the volumeis constant. Here we must use the balance of mass of sugar, because the unknown variable isthe concentration (in mass units per volume).

    5.4.A - 5.4.E. Numerical methods for the ODEs.This is not a course on numerical methods. So, only some mostly used algorithms will bementioned in a very abbreviated form.

    A big part of the continuous models are of type ODE (Ordinary Differential Equations.Recall that the ODE models in most cases can be expressed in the form of a set of ODEs ofthe first order, as follows.

    ),,....,,(/ 21 txxxfdtdx nii =

    where xi , i = 1,2,3,....,n are dependent variables, and t is the independent variable,representing the model time in dynamic systems.

    The boundary conditions for these variables can be as simple as requiring that certainvariables have certain numerical values in a given time instants, or as complicated as a set ofnonlinear algebraic equations among the variables. The nature of the boundary conditionsdetermines which numerical methods will be feasible to solve the problem. Boundaryconditions divide into two broad categories.

    * Initial value problems where all the dependent variables are given at some starting timeinstant and it is desired to calculate their changes over some time interval or in some fixedtime instants.

    * Two-pointboundary value problems, where the conditions are specified at more than onetime instant. Typically, some of the conditions are specified at a starting point and other at

    the final time.

    The simplest way to solve the initial value problem is to rewrite the dxs and dts as finite stepsDx andDt. Then, multiply the equations byDt. This gives algebraic formulas for the changein the dependent variables, when the time is incremented by the step size Dt. In the limit ofmaking the step size nearly zero, the solution may be a good approximation of the real one.The implementation of this method is theEuler's method. The Euler's method is simple but

  • 7/31/2019 Sim Course

    26/49

    not recommended for several reasons; the most important one is the fact that theapproximation errors may accumulate during the iteration process.

    Runge-Kutta methods propagate a solution over an interval by combining the informationfrom several Euler-style steps (each involving one evaluation of the right-hand sides of the

    equations. Then, the information obtained from these evaluations is used to match a Taylorseries expansion of the solution to some higher order.For example, thefourth-order Runge-Kutta algorithm is given by the following formula.

    )(6/3/3/6/

    ),(

    )2/,2/(

    )2/,2/(

    ),(

    5

    43211

    34

    23

    12

    1

    hOkkkkxx

    htkxhfk

    htkxhfk

    htkxhfk

    txhfk

    jj

    jj

    jj

    jj

    jj

    +++++=

    ++=

    ++=

    ++=

    =

    +

    where h is the integration step (time increment),

    )(),( 1 htxxtxx jjjj +== +j=1,2,3,.... is the consecutive step number, and the k are auxiliary variables. O(z) is afunction that tends to zero at least so fast as its argument zdoes. This means that the abovealgorithm will approximate well any real solution that is a curve of 4-th order.There are many modifications and higher order versions of the Runge-Kutta method. Forexample, a widely used 5-th order algorithm of Runge-Kutta-Fehlberg provides a highaccuracy solution and also an estimate of the error. Using this estimate the program canrepeat the integration step with smaller time increments to achieve the desired accuracy.One of the disadvantages of the Runge-Kutta methods is the fact that for one step evaluation

    we need several evaluations (e.g. four for the fourth order method) of the system right-handsides. The regularity assumptions for these methods consist in the continuous differentiabilityassumption (up to order N) that the right-hand sides of the equations must satisfy inside theintegration step. On the other hand, the method has no "memory" that is, no information fromprevious steps is used, what makes the method somewhat more robust compared to otheralgorithms, like the multistep predictor-corrector methods.

    Richardson approximations (not illustrated on the slides). It is a method for improving theaccuracy of an approximated solution to a set of the first order ordinary differential equations.It is supposed that the true solution is an analytic function of the integration step size h. Thefunction can be evaluated with various values ofh, none of them small enough to yield the

    accuracy we desire. Then, we fit the obtained solutions to some analytic function and thenevaluate it at the point h = 0. For example, the points can be the results of evaluating thesolution by the Euler's method in 2, 4, and 6 steps. These three points can be used to evaluatethe solution with h = 0 supposing the solution is a second order polynomial function of h.

    Predictor-Corrector methods. These methods belong to the family of multistep methods.They are mostly used in the problems with very "smooth" equations with very complicated

  • 7/31/2019 Sim Course

    27/49

    right-hand sides. If it is not the case, the Runge-Kutta or Richardson approximatio methodsdominate.In the multistep methods we approximate the equation right-hand side by a polynomialpassing through several previous points and possibly through the actual point, beingevaluated at t = (n+1)h. If this point is included, the method is said to be implicit, otherwise

    it is explicit.The implicit methods must solve an algebraic equation for

    ))1((1 hnxxn +=+because this value has not been calculated yet. Normally, the Newton-Raphson method isused. If the value ofx at (n+1)h is not used, the approximation can be calculated in one step,and the method is explicit.The predictor-corrector method use both approximations; first, an explicit method is used toestimate the value ofx((n+1)h), and then the implicit method calculates (corrects) it usingthis approximation as the starting point for the Newton-Raphson method. This procedureseems to be complicated, but you should note that all this operations need only oneevaluation of the equation right-hand side per integration step. If the model is complicated,

    the cost of computing (real CPU time) depends mainly on the number of right-hand sideevaluations, which makes the multistep methods several times faster than other, e.g. Runge-Kutta. On the other hand, any multi-step method must use some previously stored values ofthe dependent variable. If the equations are not regular enough over these consecutive steps,the method fails. In particular, if our model receives discontinuous excitations, or changes itsstructure (for example switching controllers), the multi-step methods are not recommended.As an example, see the following Adams-Bashworth-Moulton corrector-predictor scheme.

    ( )

    ( ) )(8512

    )(5162312

    111

    211

    correctorXXX

    h

    xx

    predictorXXXh

    xx

    nnnnn

    nnnnn

    ++

    +

    ++=

    ++=

    Here Xkdenotes f(xk, tk). Note that in the corrector part the value ofx at (n+1)h is takenfrom the predictor formula, so that the corrector needs no Newton-Raphson iterations to beperformed (xn+1does not appear at the right-hand side of the corrector equation).

    5.5.A, 5.5.B. Direct programming for continuous simulation.The slide 5.5.A shows a possible flow diagram of a program you can code in any algorithmiclanguage. Note that if you do this, you should separate the model (equations right-hand sides)from the numerical algorithm you use. Doing this, you will be able to re-use your code forother models.HOWEVER, (slide 5.5.B) Do NOT waste time creating your own code in C++, Pascal,Basic or other algorithmic language, unless absolutely necessary.Use an adequate simulation package. You will complete your project up to 20 times faster!!!

    5.6. An exercise.

    Simulate the car suspension model of slide 5.3.2. This exercise can be done using the ODEmodule of the PSM++ system. If you use other continuous simulation package that accepts

  • 7/31/2019 Sim Course

    28/49

    ordinary differential equations, you can use it as well. If so, skip the rest of this section.Remember that the objective of the simulation is to determine the value of the dampercoefficient, to reach a satisfactory behavior of the vehicle. This means that the oscillationsgenerated by an obstacle should have a good damping. On the other hand, with a very rigiddamper we have little oscillation, but the initial vertical impulse growths. Note that this is a

    simplified model, where both the spring and the damper are lineal. Real car suspension hasnon-linear characteristics of these elements. In fact, ODE models can be non-linear as well.As an advancedexercise, you may ask your students to introduce non-linearities to the modelequations. The PSM++ ODE module works with non-linear models too.

    PSM++ offers code generators for models described by block diagrams, signal flow graphsand bond graphs. This means that most of the continuous models need no programming andeven no mathematics provided by the user. Creation of model equations as well as codegeneration is done automatically. However, sometimes the user prefers to use his ownequations to describe the model dynamics. The DIFEQ module can help in creating thePSM++ code forODE (Ordinary Differential Equations) models. The input to DIFEQ isgiven by four sets of specification data: additional process attributes and Pascal declarations,

    auxiliary operations (performed each time before the right-hand sides of model equations areevaluated), model equations (given by the right-hand side expressions) and output operations.DIFEQ can invoke, from its main menu, the other continuous simulation PSM++ modules,like FLOWD (Signal Flow/Block diagrams) and BONDW (Bond graphs). DIFEQ generatesPSM++ code that can run in the following simulation modes.

    Simple simulation run - generates a complete PSM++ program that provides the plotsof selected output variables as functions of time

    Varying parameter - a series of trajectories is integrated, where a selected parameteris changed in given interval. The results are shown as 2D and 3D plots.

    Preparing files for VARAN. While running in this mode, the target simulation

    program repeats the simulation several times. The corresponding trajectories arestored on disk, for further statistical analysis. This mode is used for stochastic models.As the result, various statistics, like variance, confidence intervals etc. are shown asfunctions of time.

    Process only - encapsulate parameters. This creates a PSM++ process declaration,which is "self-sufficient". This means it has the parameters and initial conditionsencapsulated in the code. Such process only needs to be created and activated to run.It is useful as a possible sub-model for the CSS Complex System Simulator.

    Simple process only. A PSM++ process (not program) describing the model dynamicsis created.

    It should be noted that the PSM++ modules FLOWD and BONDW generate equation filesthat are processed by DIFEQ in the same way as the user-provided equations are. This meansthat these modules can generate programs that can run in any of the above DIFEQsimulation modes.For more detail consult the PSM++ FLOWD User's Manual.

    5.7.1. Signal Flow Graphs (SGFs).

  • 7/31/2019 Sim Course

    29/49

    The slide explains the main concepts of SGF. It is very important to emphasize the fact that,unlike in the block diagrams, in a SFG the nodes represent signals (variables) and the arrows(links) are transfer functions or other operators that convert input signal into the outputsignal. The causality (input-output relation) is determined by the direction of the arrow.Though SFGs are very similar to block diagrams, it is recommended to use SGFs, because

    this representation has a quite good theoretical background.

    5.7.2.A. Signal Flow Diagram - example of a model of an automatic control system.

    5.7.2.B. Signal Flow Diagram - example of a model of and electric circuitFor the example of slide 5.7.2.B the gain is

    K

    K

    u

    xG

    +==

    1

    5.7.3.A. CSSL standard.

    In 1968 The Simulation Council Inc. published a report on CSSL (Continuous System

    Simulation Language) Standard. This standard defines the recommended simulation languagestructure (slide 5.7.3A.). CSSL is a simulation language. In the following, we will use alsothe term simulation package referring to a simulation software tool. The only difference isthat using a language you must provide the code for the model specifications, while using apackage you can define the model graphically (using a graphical user interface, GUI), withlittle or no programming. The model is defined by the model frame, that may be given as atextual or graphical model description, mathematical expressions for the derivatives andboundary conditions, and by conventional programming in an algorithmic language. Thestandard mathematical form of the model is

    dx/dt = f(x,t)

    where x is the system state vector, f is a vector-valued function and trepresents thetime.

    The model frame must be provided in such a way that the translator be able to transformthis information into the internal state equations of form, as well as initial and terminalconditions (if any). The user can also explicitely provide the expressions for the derivatives.As the result, the ODE solver will calculate the model trajectory, and produce requiredresults. What the solver does is to advance the time and update the ODE solution inconsecutive integration steps, over a given time interval. The function f should satisfy theregularity conditions to ensure the existence and, if it is possible, the uniqueness of thesolution. Additional conditions are imposed by the particular numerical method used by the

    ODE solver. Providing these conditions are satisfied, the function f defines the modeldynamics. Note that it can depend explicitely on the model time and may include some modelparameters. In some publications on CSSL standard this function is equipped with moreformal parameters, to express its dependence on external input signals u(t) and parameters p,which results in the following state equations (boldface means vector-valued):

    (1.3) dx/dt = f(x(t),u(t),p,t)

  • 7/31/2019 Sim Course

    30/49

    Some more complicated situations arise when the model specification includes someimplicit conditions (for example initial conditions or additional restrictions), given in theform of algebraic equations. Such implicit, differential-algebraic models require more dataand some additional algorithms, like the Newton-Raphson method to used at the beginning orat each integration step. Models of this kind appear, for example, when the model

    specification is given by signal flow graphs or block diagrams where a closed loops ofalgebraic (static) links exist.The experimental frame includes the experiment commands and menus, that define how to

    carry out the simulation (initial and final model time, number of repetitions, output variablesetc.).

    The scheme of slide 5.7.3A can be modified to include discrete event ordiscrete/continuous (combined) models. In fact, the general structure of the package issimilar. The Translator module must process not only the ODEs, but also generate the eventlist for the whole model. The other relevant difference is that a dynamic event list managermust be added to the "simulation engine". This manager must handle the internal event queueand the model time. Note that adding this module we still can simulate continuous models,treating each integration step of the ODE solver as an event, that may be executedconcurrently with other, discrete events.

    The other, more specific requirements are the GUI and model specification modules. Ingeneral, a good, general-purpose simulation package should be able to accept bothcontinuous and discrete models. The continuous models may be defined in terms of blockdiagrams with transfer functions, signal flow graphs, bond graphs of directly the ODEs. Thisis the "conventional" approach. Recently, many new mathematical tools become popular, likedifferential inclusions, stochastic models, models with fuzzy elements, and with uncertainty(do not confuse uncertainty with stochastic elements).As for the discrete models, the GUI should be able to accept models like queuing,manufacturing and mass-service or Petri-nets in graphical form, and generate thecorresponding event list. Anyway, the discrete event specification should be compatible withthe DEVS formalism, mentiond before.

    5.7.3.B. Eliminating mathematics and coding from simulation tasks.Our point is that a simulationist needs not to be neither a mathematician nor a

    programmer. Of course he/she should have a basic knowledge on these topics, but his task isto simulate. Do accomplish the task a simulationist must understand and must be able todescribe exactly the model, no necessarily managing differential equations or othermathematics. The software used should, if possible, generate the equations automatically andgenerate the corresponding computer code. Fortunately, in continuous simulation, these taskscan be done automatically. Such model representations as signal flow graphs and bondgraphs are very useful in this approach.The signal flow and bond graph modules of the PSM++ simulation software are goodexamples of such type of software.

    5.7.4. Link types of PSM++ signal-flow module FLOWD

    5.7.5. FLOWD - exercise

  • 7/31/2019 Sim Course

    31/49

    5.8.1. Bond Graphs

    Bond graph method, introduced by Paynter in 1961 (Paynter H.M., Analysis and design ofengineering systems, MIT Press, Cambridge, Mass., 1961), is the widespread tool inmodeling of physical systems. The fact that a bond connects two variables: the effort and the

    flow, makes this tool the most appropriate for physical systems modeling, because the flowof power is the product of these two variables (e.g. voltage and current, force and velocity,liquid pressure and flow etc.). An excellent overview of bond graphs can be found inFrancois Cellier, Hierarchical non-linear bond graphs: a unified methodology for modelingcomplex physical systems, SIMULATION, April 1992. Recall that a bond graph model iscomposed by the nodes or junctions and by the links named bonds. A bond is a directed linkwith a harpoon. The harpoon is placed on the left of the link (related to its direction). The twovariables are indicated as follows. The effort is placed on the side of the harpoon and the flowis indicated on the other side (slide 5.8.1).

    5.8.2.A - 5.8.2.C Node and bond typesThere are several types of nodes in bond graph models. At the node of type 0 the sum offlows is equal to zero, while the efforts of all connected bonds are equal to each other. At thenode of type 1 the sum of efforts must be zero and the flows of all corresponding bonds arethe same. Thus, we can represent graphically any system that obeys a number of balanceequations.

    The node equations for the node 0 and the node 1 are as follows (slide 5.8.1).b d c = 0 (node type 0) and y a e f = 0 (node type 1).

    The sign of a term in the node equation depends on the direction of the correspondingbond, the outgoing bond having the negative sign of the corresponding variable. Otherpossible nodes accepted by BOND are as follows.

    SE node - effort source, for example an external force, ideal voltage source etc.SF node - flow source, e.g. mandated velocity in a translational system, ideal current source.R node - dissipative element, e.g. damper or electrical resistanceC node - capacitance, e.g. a spring or electrical capacitanceL/I node - Inertia/inductance, for example a moving or rotating mass, electrical inductance.

    The causality in bond graph diagrams is denoted by a stroke at one of the ends of the bond.This means that the flow variable is evaluated at the end with the stroke and the effortvariable at the other end. There are some mandatory causalities, shown on slide 5.8.2.B. Forthe nodes of type o and 1 the following rules should be observed.On a node of type 0 only one bond can have causality. On a node 1 all bonds but onemust have causality stroke.If the causalities cannot be assigned satisfying these rules, then we have the causalityconflict. In this case, most of the bond graph packages issue a warning or stop with en error.

    These causalities may be given by the user. However, the bond graph software shouldassign causalities automatically. Any graph scanned by BOND module of the PSM++package is verified and given causalities, if possible. If the user causalities are wrong they arechanged and the corresponding message appears. If BOND cannot find a solution (causalityconflict), the analysis stops and the error message is issue