Computer Simulation Fundamentals

Introduction to Computer Simulation

Introduction

When someone has the responsibility of running a system, such as a bank or a city transportation system, they must continually make decisions about the actions performed on the system. These decisions should result in the best possible objectives for the system’s behavior. To decide properly, you need to know how the system will respond to a certain action. This could be done by experimentation with the system itself, but cost factors, security, and other issues generally make this option infeasible. To overcome these drawbacks, the real system is replaced by a simplified version, called a model. The model is used to perform the necessary experiments without the drawbacks outlined above. The process of experimenting with a model is called simulation. The process of designing the experimental plan to make the best decision is called optimization. If the experimental plan is carried out solely to learn to drive the system, it is called training.

At this point, the following definitions should be made:

System: A set of objects or ideas interrelated as a unit to achieve an end (Shannon, 1988). It can also be defined as the portion of the universe that will be simulated.

Model: An object X is a model of object Y for observer Z if Z can use X to answer questions of interest about Y (Minsky).

Simulation: Simulation is the process of designing a model of a real system and conducting experiments with it to learn the system’s behavior or evaluate various operational strategies (Shannon, 1988).

Simulation Applications

Simulation is useful when:

  • There is no analytically solvable mathematical formula. Many real systems, such as the behavior of a bank client, cannot be modeled mathematically with currently available tools.
  • There is a mathematical formula, but it is difficult to obtain an analytical solution. Mathematical models for a nuclear reactor or a chemical plant are impossible to solve analytically without serious simplifications.
  • There is no real system. An engineer designing a new system will significantly improve the design if a suitable model is available for experiments.
  • Experiments are impossible due to economic constraints, safety, quality, or ethics. In this case, the real system is available for experiments, but the difficulty of these experiments rules out this option. Examples include inducing faults in a real aircraft to assess pilot behavior or changing a tax to assess market reaction.
  • The system evolves very slowly or too quickly. An example of slow dynamics is scientists studying climate trends. They must predict future climate behavior given current conditions and cannot wait for a tornado to raze a city before issuing a warning. Conversely, very fast phenomena, such as an explosion, need to be simulated to be observed in detail.

Potential disadvantages of simulation include:

  • The development of a model can be expensive, laborious, and slow.
  • There is the possibility of errors. The experiment is carried out with a model, not the real system, so if the model is wrong or errors are made in its handling, the results will be incorrect.
  • The degree of inaccuracy of the results may be unknown. The model is often used to experiment with things never raised in the real system, so there is no prior information to estimate the correspondence between the model’s response and the real system.

Currently, simulation provides invaluable service in almost every possible area, including:

Manufacturing processes: Helps detect bottlenecks, distribute personnel, and determine production policy.

Industrial plants: Provides information to establish optimum operating conditions and develop procedures for emergency operation.

Public systems: Predicts energy demand during different times of the year, forecasts weather patterns, and predicts the spread of disease.

Transport systems: Identifies areas of possible congestion, areas with higher accident risk, and predicts demand for each hour of the day.

Construction: Predicts the effects of winds and earthquakes on building stability, provides information on lighting and environmental conditions within buildings, and detects parts of structures that need strengthening.

Design: Enables the proper selection of materials and shapes. Allows studying the sensitivity of the design to uncontrollable parameters.

Education: An excellent tool to help understand real systems because it can expand, compress, or stop time, and provide information on variables that cannot be measured in the real system.

Training: Because the risk and costs are almost nil, a person can use a simulator to learn by themselves using the most natural method for learning: trial and error.

The importance of simulation is clear when considering the impact of jobs such as:

Perestroika: Simulation studies in Russia in the 70s and 80s convinced leaders of the need for significant economic change.

The 1988 New York stock market crash: The use of simulation programs by stockbrokers caused a false instability that led to the crash.

The return of Apollo 13: Simulation played a key role in determining the plan. The spacecraft returned successfully despite serious damage.

The Voyagers: Simulation established optimal routes for these aircraft with minimal power consumption, taking advantage of the gravitational pull of planets.

Monte Carlo Project: Von Neumann and Ulam (1945) used simulation to study nuclear reactions.

Planetary models: Some raise the prospect of global warming due to greenhouse gases, while others suggest the possibility of cooling and predict a new ice age.

Troop training: In Operation Desert Storm, troops from all U.S. forces were trained on simulators.

Police training: Virtual environments are used for officers to learn to behave in risky situations.

Flight Simulator: One of the first simulator applications, now used to train commercial airline and combat pilots.

Types of Simulation

According to the nature of the model used, simulation can be (Fishman, 1978):

Identity: The model is an exact replica of the system under study, used by automotive companies for car crash tests with real units.

Quasi-identity: Uses a slightly simplified version of the real system, such as military training that includes equipment and troop mobilization but not a real battle.

Laboratory: Models used under controlled laboratory conditions. Two types of simulations are:

Operational game: People compete with each other, forming part of the model, while the other part consists of computers, machinery, etc. This is the case in a business simulation where computers collect information generated by each participant and present it in an orderly manner.

Man-Machine: Studies the relationship between people and machines. People are part of the model, and the computer generates information, not just collects it. An example is the flight simulator.

Computer simulation: The model is completely symbolic and implemented in a computer language. People are excluded from the model. An example is a communication network simulator where user behavior is modeled statistically. This type can be:

Digital: Using a digital computer.

Analog: Using an analog computer or physical models.

The Computer Simulation

This book focuses on computer simulation. A computer simulator has the following parts:

A model: A symbolic model, which can be a set of equations, logical rules, or a statistical model.

The Evaluator: Procedures to process the model for simulation results, including routines for solving equations, random number generators, and statistical routines.

The interface: The part dedicated to interacting with the user, receiving actions, and presenting simulation results appropriately. This unit can be as complex as the car used in professional flight simulators.

Stages of a Simulation


In the development of a simulation can distinguish the following stages (Banks et al., 1996):

Formulation of the problem: This step must be well established for the purpose of the simulation. The customer and the developer should agree as much detail as possible, the following factors: the expected results of the simulator, the experimental plan, the time available, the variables of interest, the type of disturbances studied, the statistical treatment of results The complexity of the interface of the simulator, etc. Must be established if the simulator will be operated by the user or the user will only receive the results. Finally, we must determine whether the user requests a job or a job simulation optimization.

System Definition: The simulated system must be well defined. The customer and the developer should agree where is the boundary of the system under study and interactions with the environment to be considered.

Model Formulation: This step is an art and will be discussed later. It begins with the development of a simple model that captures relevant aspects of the real system. Relevant aspects of the real system depends on the formulation of the problem for a safety engineer relevant aspects of a car are different from the issues considered by a mechanical engineer for the same system. This simple model will be enriched as a result of several iterations.

Data collection: The nature and amount of data required are determined by the formulation of the problem and model. Data can be provided by historical records, laboratory experiments or measurements in the real system. They must be processed properly to give the format required by the model.

Implementation of the computer model: The model is implemented using a computer language. There are specific simulation languages that facilitate this task, too, there are programs that already have implemented models for special cases.

Verification: At this stage it is found that no errors have been committed during the implementation of the model. To do this, you use the debugging tools provided by the programming environment.

Validation: In this stage checks the accuracy of the model developed. This is done by comparing the model predictions, measurements in real systems, historical data or data from similar systems. As a result of this stage may be a need to modify the model or collect additional data.

Experimental design: In this stage, decide the characteristics of the experiments to be done: starting time, the simulation time and the number of simulations. Do not include here the development of the set of alternatives to try to select the best, the development of this list and task management is optimization rather than simulation. It should be clear when formulating the problem if the customer wants is a simulation or optimization.

Experimentation: In this stage the simulations are performed under the previous design. The results are collected and processed properly.

Interpretation: We analyze the sensitivity of the model with respect to the parameters that are associated with greater uncertainty. If necessary, additional data should be collected to refine the estimation of critical parameters.

Implementation: client should accompany the implementation stage to avoid mishandling of the simulator or the misuse of the results.

Documentation: Includes the development of technical documentation and user manuals. The technical documentation must include a detailed description of the model


Systems

A system is a section of reality that is the primary focus of a study and is composed of components that interact with others according to certain rules within a boundary identified for the purpose of the study. A system may perform a function that is not achievable by individual components.
Objects or components that are part of the system are called entities, for example, a car consists of a motor, wheels, bodywork, etc.. These entities have properties namedattributes, eg engine power, and relate to each other through relationships or functions. These relationships can be:

Static or structural: a car has four wheels.

Dynamic or functional: a car consumes gasoline if the engine is started.
The values assumed by the attributes of entities in a given time determine the state of the system. The state can be static or stationary, this means that is constant in time or otherwise, can be dynamic or transient if it evolves over time. A system may have two types of behavior, usually, when you start your work goes through a dynamic state and then reaches a steady state or regime.
A steady state is stable if the system returns to him after a disturbance. By contrast, a steady state is unstable if the system moves away from him after a disturbance. This departure may result in a cumulative response (increase or decrease continuously, or reaches steady-state) or an oscillatory response (increases and decreases continuously). An example of steady state, is a pendulum in its resting position, whereas the inverted pendulum is an example of unstable state. If the pendulum is frictionless, the disturbance response is oscillatory, whereas if the response is damped friction.
Attributes are also called variables or parameters. The parameters (P) are attributes that were set during the design of the system either by the designer or by nature, for example, engine displacement, acceleration of gravity. The variables are classified into:

Input or exogenous variables, are set by the system environment. Can be manipulated (U)-are set at will, or no (D). An example of the former is the position of the accelerator pedal and the second case is the wind speed. A non-manipulable input variable is called a disturbance.

Output variables (Y) are the state variables, or combination thereof, which are measures or cross the system boundary.

Internal variables: These are system variables that are neither input or output, or parameters.

State variables (X): as the minimum set of internal system variables necessary to fully describe its internal state.
Then we analyze the electric water heater, it is assumed that power is not enough to reach the boiling point. The classification scheme is:
Parameters: the voltage V, the resistance Rc, the dimensions of the vessel, the overall coefficient of heat transfer U, heat capacity Cp water, the thickness of the cable, etc.

Manipulated input variables: p switch position, the flow of input current Fe and temperature Te, the flow of output current Fs.

Output variables: the temperature Tm given by the thermometer, the dissipated power Wd, the temperature of the output current Ts.

State variables: the mass of water M, T fluid temperature. Note that the intensity I and the heating power W are internal variables of the system, but not state it can be calculated from other variables. So they do not belong to a minimum set of variables that must be specified and, therefore, are not state variables. In contrast, the initial valuesM and T must be specified for the state of the system is completely determined.

Disturbances: ambient temperature Ta.

During operation of the system is able to observe the following states:

Initial state: The switch is open, empty container, no fluid enters or leaves. The system state does not change during this phase. Is a steady state.

Head of water: It is Fe> 0, the recipient receives water and M increases continuously during this time. Is a dynamic state.

Full container: When the water level is the desired power is interrupted. Again the system is in a steady state.

Heating: Once you reach the desired water level, the switch is closed. The water temperature T is continuously growing. Is a dynamic state.

Conditions: As the system temperature increases, the power dissipated to the outside Wd increases. This power also depends on Ta, the size of container and U. When the power dissipated equals the power W of heating, the temperature of the system also takes a constant value. Thus, the system reaches a new steady state.

Flushing: After reaching the desired temperature and maintained for the required time, the switch opens and the system is discharged by Fs> 0. M decreases continuously until be zero. The temperature also decreases. This is a dynamic state that ends when the system is completely empty, returning to its initial state.


Classification systems
According to its nature, a system can be (Law and Kelton, 1991):

Deterministic: If the system contains no random element is a deterministic system. In this type of system, the output and internal variables are perfectly certain to specify the input variables, parameters and state variables. That is, the functional relationships between system variables are well defined. Studied the electric heater is a deterministic system.

Stochastic: In this case some element of the system has a random behavior. Then, for known entries can not be sure the output values. An example of a stochastic system is a slot machine in which the same action (pulling the lever) generates an uncertain outcome (win or lose). When a deterministic system is fed with stochastic inputs, the response of the system is also stochastic. For example, the ambient temperature is a random variable that affects the response of the electric heater. In the real world, systems are always stochastic elements either by nature or because they are currently understood phenomena, such as a caveman it might seem that the eclipses were random phenomena, today they are predicted. However, one can consider a real system with a deterministic system if its uncertainty is less than an accepted value.

Ongoing: There is a continuous system where the functional relationships between the variables of the system only allows the state evolves in time continuously (sufficient for an evolving continuously variable). Mathematically, the state changes in infinite points of time. The heater vessel is a continuous subsystem because both M and T evolve continuously during operation of the system.

Discrete: There is a discrete system where the functional relationships of the system only allows the statevaries in a finite (countable) of time points. The causes instantaneous state changes are called events. The heater switch is a discrete subsystem because the intensity I can only change in the moments that opens or closes the switch. The opening and closing of the switch are events. A continuous system can behave discreetly if the inputs are discrete. The real systems are combinations of continuous and discrete. The treatment of them is adopted according to the dominant feature.

Simulation Modes

As stated earlier, when simulating experiments are performed with a model to achieve certain results. A model is also a system, according to the type of output variables of the model simulation mode will be:

Analysis: This is the most used, in him the model output variables represent the output variables of the real system. This mode is used to estimate the real system response to specified inputs. Because it mimics a system that really works, the model is mathematically more stable and ensures the existence of a solution.

Design: In this mode the model outputs represent the real system parameters. It is used in the design stage of a team where the problem is to determine the parameters for which the system will produce the desired outputs for specified inputs.

Control: The model output variables represent input variables of the real system. This mode is used to determine the values they should adopt the system inputs to produce the desired results. Use when you want to determine the operating conditions of a system.
In general, simulators are operating in design mode allowing the user the task of iterating to obtain the results provided by other modes. For example, to estimate the required voltage for the heater (design mode), you can perform several simulations for analysis as a set of voltage settings, and select the one that produces the desired output.


Modeling

Modeling is the process of building a model. A model is a representation of an object, system, or idea. Usually, their purpose is to help explain, understand or improve a system (Shannon, 1988). The models are useful for:

Thought: When building a model necessarily must order and complete knowledge of the real system is owned.

Communication: A model eliminates the ambiguity of language to communicate with experts.

The training and instruction: A model can be used to train with almost zero cost and risk. For example, submarines scale used by the German navy to train in secret before the Second World War and also the system of vessels at scales currently used in France to train captains of oil tankers.

The prediction: A model used to predict the behavior of the real system. This is the case of the models used to predict, through simulation, the evolution of global climate. The model of the theory of relativity predicts, without doing a simulation, it is not possible to exceed the speed of light.

Experimentation: Experimentation with a model is inexpensive and safe. It is frequently used in the design of a system, for example, tests performed in a wind tunnel with a scale model of an airplane or a car.
Modeling is an art. Any set of rules to develop models have limited utility and can only serve as a guide suggested. The art of modeling is the ability to analyze a problem, summarize its essential features, select and modify the basic assumptions that characterize the system, then enrich and develop the model to obtain a useful approximation. The suggested steps for this process are:

1. Establish a clear definition of objectives.
2. Analyze the real system.
3. Divide the problem of the system in simple problems.
4. Look for analogies.
5. Consider a specific numerical example of the problem.
6. Determine the variables of interest.
7. Write the clear data.
8. Write theoretical or empirical equations describing these phenomena and relate the variables of interest.
9. If you have a tractable model, enrich. Otherwise, simplify.
Usually, a simplified model involves:

Convert variables constant.
Eliminate or combine variables.
Assume linearity.
Add more powerful assumptions and constraints.
Restrict the limits of the system.
To enrich the proceeds in the opposite way. During the modeling process must strike a balance between the degree of detail and the risk of inaccuracy. The best model is the simplest model that can solve the problem with the degree of accuracy required.

A model should be:
Easy to understand by the user.
Directed to specific goals or objectives.
Wise, no response as absurd.
Easy to manipulate and control by the user. Ie, it must be easy to communicate with the model.
Complete, with regard to important issues.
Adaptable, with a simple procedure to modify or update the model.
Evolution, must be simple at first and become more complex over time.
As an example of what has been, consider that you want to build a model to determine the time and speed of contact with the floor of a paratrooper. The objective is under way. The system will be a paratrooper. The essential features are the speed of descent, friction force, the initial height, etc. To keep the model as simple as possible will be negligible change in the acceleration of gravity with respect to height, it will also negligible rise in temperature caused by friction, assuming a standard body for paratrooper, etc. Then, identify the variables that represent the essential characteristics: v, Fr, h 0, etc. The next step will be to develop equations linking these variables, where g is the acceleration of gravity, h is the height, m is the mass of the parachutist, t is time, and Cr is the coefficient of friction.
The model is manageable, but can be simplified if it is determined that the terminal velocity (which balances the weight force of friction) is reached soon. If so, you can use a simple model considering the velocity is constant.