Unit III: Continuous System - Simulation and Modeling - BCA Notes (Pokhara University)

Continuous System Simulation and System Dynamics:

Continuous System Simulation:

Continuous System Simulation describes systematically and methodically how mathematical models of dynamic systems, usually described by sets of either ordinary or partial differential equations possibly coupled with algebraic equations, can be simulated on a digital computer.

Modern modelling and simulation environments relieve the occasional user from having to understand how simulation really works. Once a mathematical model of a process has been formulated, the modelling and simulation environment compiles and simulates the model and curves of result trajectories appear magically on the user’s screen. Yet, magic has a tendency to fail, and it is then that the user must understand what went wrong, and why the model could not be simulated as expected.

System Dynamics:

System Dynamics is a computer-aided approach to policy analysis and design.  It applies to dynamic problems arising in complex social, managerial, economic, or ecological systems, literally any dynamic systems characterized by interdependence, mutual interaction, information feedback, and circular causality.

The System Dynamics Approach Involves:

a. Defining problems dynamically, in terms of graphs over time.

b. Striving for an endogenous, behavioural view of the significant dynamics of a system, a focus inward on the characteristics of a system that themselves generate or exacerbate the perceived problem.

c. Thinking of all concepts in the real system as continuous quantities interconnected in loops of information feedback and circular causality.

d. Identifying independent stocks or accumulations (levels) in the system and their inflows and outflows (rates).

e. Formulating a behavioural model capable of reproducing, by itself, the dynamic problem of concern.  The model is usually a computer simulation model expressed in nonlinear equations, but is occasionally left unquantified as a diagram capturing the stock-and-flow/causal feedback structure of the system.

f. Deriving understandings and applicable policy insights from the resulting model.
g. Implementing changes resulting from model-based understandings and insights.

Continuous System Models:

Continuous system simulation is one, in which predominant activities of the system cause smooth changes in the attributes of the system entities. When such a system is modelled mathematically, the variable of the model representing the attributes are controlled by continuous functions. In general, in continuous, the relationship describes the rate at which attributes changes, so that the model consists of differential equations.

If a system can be represented using simple differential equation model, then it is often possible to solve the model without the use of simulation, otherwise we use simulation to solve those models which are complex to solve analytically.

Differential Equations:

A differential equation is a mathematical equation that relates some function with its derivatives where the functions usually represent physical quantities, the derivatives represent their rates of change, and the equation defines a relationship between the two. Because of such relations are extremely common, differential equations play a prominent role in many disciplines including engineering, physics, economics, and biology.

We can use the differential equation to represent the behaviour of a continuous system. An example of a linear differential equation with constant coefficient is one that describes the wheel suspension of an automobile.

The equation is: Mx ̈+Dx ̇+Kx=KF(t)

Where,
x ̈ = acceleration
x ̇= velocity
x = displacement
K = stiffness of spring
D = measure of viscosity (thickness) of shock absorber
F(t) = input of system depends on independent variable t

When more than one independent variable occurs in a differential equation, the equation is said to be a partial differential equation. It can involve the derivatives of the same dependent variable with respect to each of the independent variables. An example is an equation describing the flow of heat in a three-dimensional body. There are four independent variables, representing the three dimensions and time, and one dependent variable, representing temperature.

Differential equation occurs repeatedly in scientific and engineering studies. The reason for this prominence is that most physical and chemical process involves rates of change, which require differential equations for their mathematical description. Since a differential coefficient can also represent a growth rate, continuous models can also be applied to a problem of a social or economic nature where there is a need to understand the general effect of growth trends.

Ordinary Differential Equations:

An ordinary differential equation (ODE) is an equation containing an unknown function of one real or complex variable x, its derivatives, and some given functions of x. The unknown function is generally represented by a variable (often denoted y), which, therefore, depends on x. Thus x is often called the independent variable of the equation. The term "ordinary" is used in contrast with the term partial differential equation which may be with respect to more than one independent variable.

Linear differential equations are the differential equations that are linear in the unknown function and its derivatives. Their theory is well developed, and, in many cases, one may express their solutions in terms of integrals.

Most ODE that is encountered in physics are linear, and, therefore, most special functions may be defined as solutions of linear differential equations.

Partial Differential Equation (PDE):

Partial Differential Equation is a differential equation that contains unknown multivariable functions and their partial derivatives. (This is in contrast to ordinary differential equations, which deal with functions of a single variable and their derivatives.) PDEs are used to formulate problems involving functions of several variables, and are either solved in closed form or used to create a relevant computer model.

PDEs can be used to describe a wide variety of phenomena in nature such as sound, heat, electrostatics, electrodynamics, fluid flow, elasticity, or quantum mechanics. These seemingly distinct physical phenomena can be formalized similarly in terms of PDEs. Just as ordinary differential equations often model one-dimensional dynamical systems, partial differential equations often model multidimensional systems. PDEs find their generalization in stochastic partial differential equations.

Non-Linear Differential Equations:

Non-linear differential equations are formed by the products of the unknown function and its derivatives are allowed and its degree is > 1. Nonlinear differential equations can exhibit very complicated behaviour over extended time intervals.

Linear Differential Equations:

A linear differential equation with constant coefficients is always of this form, although derivatives of any order may other forms, such as being raised to a power, or are combined in any way- for example, by being multiplied together, the differential equation is said to be non-linear.

Analog Computers:

Analog computers are generally used to solve continuous model but sometimes are also used to solve static models. Some device whose behaviour is equivalent to a mathematical operation such as addition or integration is combined together in a manner specified by a mathematical model of a system to allow the system to be simulated. That combination is used in the simulation of a continuous system is referred to as an analogue computer or when they are used to solve differential equation they are referred to as differential analyzer.

Simulation with an analog computer is more properly described as being based on a mathematical model than as being a physical model. The most widely used form of analog computers is the electronics analog computers based on the operational amplifiers. Voltages in the computers are equated to mathematical variables and the operational amplifiers can add and integrate the voltage.

With appropriate circuits, an amplifier can be made to add several input voltages, each representing a variable of model, to produce a voltage representing the sum of the input variables. Different scale factors can be used on the input to represent the coefficient of the model equations. Such amplifiers are called summer. Another circuit arrangement produces an integrator for which the output is the integral with respect to time of single input voltage or the sum of several input voltages. All voltages can be positive or negative to correspond to the sign of the variable represented. To satisfy the equation of the model, it is sometimes necessary to use a sing inverter.

a. Parallel operation: many signal values can be computed simultaneously.

b. Computation can be done for some applications without the requirement for transducers to convert the inputs/outputs to/from digital electronic form.

c. Setup requires the programmer to scale the problem for the dynamic range of the computer. This can give insight into the problem and the effects of various errors.

a. Computation elements have a limited useful dynamic range, usually not much more than 120 dB, about 6 significant digits of accuracy.

b. Useful solution to problems of any size can take an inordinate amount of setup time (though modern analog computers have interfaces that make setup substantially easier than it used to be).

c. For a given size (mass) and power consumption, digital computers can solve larger problems.

d. Solutions appear in real (or scaled) time, and maybe difficult to record for later use or analysis.

e. The range of useful time constants is limited. Problems that have components operating on vastly different time scales are difficult to deal with accurately.

Components of Analog Computer:

With an appropriate circuit, an amplifier made to add several input voltage each representing the variable of the model to produce a voltage each representing a sum of the input voltage.

2. Subtractor:

With an appropriate circuit, an amplifier made to subtract several input voltage each representing the variable of the model to produce the voltage each representing a difference of input voltage.

3. Differentiator:

An op-amp differentiator or a differentiating the amplifier is a circuit configuration which produces output voltage amplitude that is proportional to the rate of change of the applied input voltage.

4. Integrator:

The circuit arrangement for which the output is integral with respect to time of single input voltage or the sum of several input voltage.

5. Invertor:

It is an amplifier designed to cause the output to reverse the sign of the input.

6. Scale Factor:

This circuit multiplies each input by a factor (the factor is determined by circuit design) and then adds these values together. The factor that is used to multiply each input is determined by the ratio of the feedback resistor to the input resistor.

Analog Method:

The general methods by which analog computer are applied can be demonstrated using the second-order differential equation given as: Mx ̈+Dx ̇+Kx=KF(t)

Solving the equation for the highest order derivate gives:  Mx ̈=KF(t)-Dx ̇-Kx

Suppose a variable representing the input F(t) is supplied, and assume for the time being that there exist variables representing -x and -x ̇. These three variables can be scaled and added with a summer to produce a voltage representing  Mx ̈. Integrating this variable with a scale factor of 1/M  produce ( x) ̇. Changing the sign produce x ̇, which supplies one of the variables initially assumed; and further integration produces -x, which was other assumed variables. For convenience, a further sign inverter is included to produce +x as an output.

A block diagram to solve the problem in this manner is shown below. The symbols used in the figure are standard symbols for drawing block diagrams representing analog computer arrangements. The circle indicates scale factors applied to the variable. The triangular symbol at the left of the figure represents the operating of the adding variables. The triangular symbol with a vertical bar represents integration, and the containing a minus sign is a sign changer.

Draw the analog model of the Liver with following set of equations:
(dx_1)/dt=-k12x_1+k21x_2
(dx_2)/dt=k12x_1-(k21+k23) x_2
(dx_3)/dt=k23x_2

Hybrid Computers:

The term hybrid computers have emerged to describe the combination of traditional analog computer elements (that gives the smooth continuous output and carry out non-linear operations) as well as the circuit components that have the capacity of storing values, switching operations and performing a logical operation. The scope of analog computers has been considerably extended by developments of a solid-logic electronic device. Hybrid computer may be used to simulate a system that is mainly continuous and also have some digital elements. For e.g. an artificial satellite for which both the continuous equation of motion and the digital controls signal must be simulated. A hybrid computer is useful when a system that can be adequately represented by an analog computer model is subject of a repetitive study.

Digital Analog Simulators:

To avoid the disadvantage of analog computers, many digital computer programming languages have written to produce digital-analogue simulator. These allow a continuous model to be programmed on a digital computer in the same way as it is solved on an analog computer. These languages contain macro instructions that carry out the action of address, integrators and sign chargers.

A program uses these macro-instructions to link them together in essentially the same way as operational amplifiers are connected in analog computers. Later more powerful techniques of applying digital computers to the simulation of the continuous system have been developed. Due to these digital-analogue simulators are not now in common uses.

Continuous System Simulation Language:

It is a restriction to keep the digital computer within the limit to a routine that represents as it is done with a digital-analog simulator. To remove the restriction a number of continuous system simulation language have been developed. They use familiar statement type of input for a digital computer, allowing a problem to be programmed directly from the equation of mathematical the model rather than requiring the equation to be broken down in functional elements.

A CSSL include macros or subroutines that forms the function of specific analog elements so that it is possible to incorporate the convenience of an analog simulator. To allow the users to define special-purpose elements that correspond to an operation that are particularly important in a specific type of application.

It includes a variety of algebraic and logical expression to describe the relation between variable. Therefore, they remove the orientation towards linear differential equation which characterizes analog computer. One particular CSSL that illustrates the nature of these languages is the Continuous System Modeling Program.

CSMP III (Continuous System Modeling Programming III):

A CSMP III program is constructed from three general types of statements:

Structural Statement:

It defines the model. They consist of FORTRAN like statement and functional block designed for an operation that frequently occurs in a model definition. It can make use of the operation of addition, subtraction, multiplication, division, and exponential using the same notation and rules used in FORTRAN.

Data Statement:

It assigns numeric values to the parameter constant and initial condition.

Control Statement:

It specifies the option in the assembly and execution of program and the choice of output.
For example, the model includes the equation: X=6Y/W+(Z-2)^2
The following statement would be used: X=6.0*Y⁄W+(Z-2.0)**2.0

Note that real constants are specified in decimal notation. Exponent notation may also be used; for example, 1.2E-4 represents 0.00012. Fixed value constants may also be declared. Variable names may have up to six characters.

Write a CSMP program of following differential equation.
Mx ̈+Dx ̇+Kx=KF(t)

Here,
Structural Statement
Mx ̈=KF(t)-Dx ̇-Kx
x ̈=(KF(t)-Dx ̇-Kx)/M
x_2 dot=  1.0/M [KF(t)-Dx ̇-Kx]
x_2 dot=  1.0/M [K*F(t)-D*x ̇-K*x]
x_2 dot=(1.0/M)*[K*F(t)-D*x ̇-K*x]
x_2 dot=INTGRL (O.O,x_2 dot)
x=INTGRL(0.0,x_1 dot)

Data Statement
M = 3.0
F(t) = 1.0
K = 4.0

Control Statement
DELT (Integral Interval) = 0.05
FINTIME (Finish Time) = 1.5
PRDEL (Integral at which to print result) = 2

Hybrid Statement:

The system to be studied is either continuous or discrete and we have to select the analog or digital computer for the study of the system. There are many advantages and disadvantages of analog and digital computer. To achieve the advantages of both (analog and digital computer) we can combine both analog/digital computer system into a single form and simulate the system through it.

In this case, one computer is simulating the system being studied while others providing the simulation of the environment in which the system is to operate. The hybrid simulation requires some extra technical improvement, high-speed converters are used to convert the signal from one form to another.

Feedback System:

Feedback systems have a closed-loop structure that brings results from past action of the system back to control future action, so feedback systems are influenced by their own past behaviour. Extending the blind control example, a feedback system would be a system that not only opens the blinds when the sun rises but also adjusts the blinds during the day to ensure the room is not subjected to direct sunlight.

Even though the open system can consist of many parts and thus become very complex (these systems have high detail complexity), experience shows that the behaviour of even small feedback systems consisting of only a few parts (and thus low detail complexity) can be very difficult to predict in practice: despite low detail complexity, these systems have high dynamic complexity. In business prototyping, we deal with both kinds of systems; system dynamics is particularly good at capturing the dynamics of feedback systems.

Interactive Systems:

Interactive systems are computer systems characterized by significant amounts of interaction between humans and the computer. Most users have grown up using Macintosh or Windows computer operating systems, which are prime examples of graphical interactive systems. Editors, CAD-CAM (Computer Aided Design-Computer Aided Manufacture) systems and data entry systems are all computer systems involving a high degree of human-computer interaction. Games and simulations are interactive systems. Web browsers and Integrated Development Environments (IDEs) are also examples of very complex interactive systems.

Some estimates suggest that as much as 90 percent of computer technology development effort is now devoted to enhancements and innovations in interface and interaction. To improve efficiency and effectiveness of computer software, programmers, and designers not only need a good knowledge of programming languages, but a better understanding of human information processing capabilities as well. They need to know how people perceive screen colors, why and how to construct unambiguous icons, what common patterns or errors occur on the part of users, and how user effectiveness is related to the various mental models of systems people possess.

Real-Time Simulation:

Real-time simulation refers to a computer model of a physical system that can execute at the same rate as the actual "wall clock" time. In other words, the computer model runs at the same rate as the actual physical system. For example, if a tank takes 10 minutes to fill in the real-world, the simulation would take 10 minutes as well.

Real-time simulation occurs commonly in computer gaming, but also is important in the industrial market for operator training and off-line controller tuning. Computer languages like LabVIEW, VisSim, and Simulink allow quick creation of such real-time simulations and have connections to industrial displays and Programmable Logic Controllers via OLE for process control or digital and analog I/O cards. Several real-time simulators are available on the market like xPC Target and RT-LAB for mechatronic systems and using Simulink, eFPGAsim and eDRIVEsim for power electronic simulation and eMEGAsim, HYPERSIM and RTDS for power grid real-time (RTS) simulation.

Predator-Prey Model:

It is also called the parasite-host model. An environment consists of two population i.e. predator and prey. It is also a mathematical model. The prey is passive but the predator depends on the prey for their source of food.

Let,
x(t) = number of prey population at time t.
y(t) = number of predator population at time t.
r.x(t) = rate of growth of prey for some +ve ‘r’, where r = natural birth and death rate.

Because of the interaction between predator and prey, it will be reasonable to assume that the death rate of prey is proportional to the product of two population size x(t).y(t) or the death rate of prey is a.x(t).y(t). Therefore the overall rate of change of prey population, dx/dt is given by, dx/dt=r.x(t)-a.x(t).y(t).

Where a is positive constant of proportion. Also, the predator population depends on the prey for their existence, the rate of the predator in the absence of prey is –s.y(t) for some positives.

The interaction between two population cause predator population to increase at a rate of proportion x(t).y(t). Thus, overall change predator population  dy/dt=-s.y(t)-b.x(t).y(t). Where, b is positive constant.

As the predator population increases the prey population decreases. This cause a decrease in the rate of an increased predator, which eventually results in a decrease in the number of predators. These in turns cause the number of prey population to increase.