OPENMODELICA: Going analogue
Computers haven’t always been digital. Mike Bedford reveals the analogue alternative and shows you how to try out this different computation model.
Computers haven’t always been digital. Mike Bedford reveals the analog alternative and shows you how to try out this different computation model.
When we hear the word computer, most of us think intuitively of an electronic digital computer, but it hasn’t always been that way. For many years, digital computers competed with their electronic analogue counterparts for scientific applications involving heavy number-crunching, with the digital approach only prevailing in the late 1970s.
However, after so many decades of digital dominance, some researchers believe that future computers might, once again, involve an element of analogue technology. Irrespective of whether, one day, you’ll be buying a PC with an analogue co-processor, the analogue approach to computing is part of our heritage. As such, it’s something that will surely interest the technically minded computer user.
If this is a total mystery to you, however, we’re here to help you appreciate this different way of computing. What’s more, even though using a real analogue computer isn’t an option for most people, we’ll show you how to delve into the principles using software that can simulate the vital elements of an analogue computer.
An analogue approach
An analogue computer is a device in which a value is represented by some continuously variable physical quantity. So, for example, in an eight-bit digital computer, the value 10 might be represented by the voltages 0V, 0V, 0V, 0V, 3.3V, 0V, 0V and 3.3V (so, 00001001), each on different circuits, but an analogue representation might be 10V on a single electrical circuit. Although it’ll be our emphasis here, that physical quantity doesn’t have to be an electrical voltage. In fact early analogue computers used a whole range of physical quantities including fluid pressure and rotational position. A simple example of an analogue calculator serves to illustrate the principle using length to represent values.
Create two linear scales, divided from 0 to 10 with divisions of 0.1 as shown in yellow ( belowleft), and print them out, ideally on sturdy paper or thin card. It doesn’t matter what absolute length they are. Now place them against each other on a flat surface – you’ve just made an analogue adder or subtractor, as we’re about to see by adding together the two numbers 3.4 and 5.5. So, as shown in the photo, slide the top scale so that 0 lines up with 3.4 on the bottom scale. Now, look along the top scale until you find 5.5 and read off the value below it on the bottom scale. It is, of course, 8.9.
Although this is a simple example of using a mechanical device to carry out a calculation that you could do in your head, a similar principle was used in the slide rule. In principle it was the same as our adding analogue calculator except, instead of linear scales, it had logarithmic scales. Because adding logarithms results in multiplication and subtracting them results in division, the slide rule provided a quick and easy way of multiplication and division. If you feel so inspired, you could try this out yourself by printing out a couple of logarithmic scales as shown in the top part of the photo.
Electronic analogue
Jobs involving just simple calculations like addition, subtraction, multiplication and division would have never justified an electronic analogue computing
approach because there were much better ways, not least of which being the digital computer. However, once we get to scientific calculations such as simulation, analogue methods came into their own and gave digital computers a run for their money for many years.
Simulation tasks – as used in so many branches of engineering, weather forecasting, and scientific research – involve solving differential equations. These require the mathematical function of integration. In the analogue realm, all that’s needed to perform this task is a fairly simple electronic circuit element called an integrator. This assembly of a so-called operational amplifier, or op-amp for short, resistors and a capacitor sums the voltages on its several inputs and generates an output signal which is the integral of that sum with respect to time.
In addition to integrators, analogue computers had, as an absolute minimum, summers, which generated an output voltage equal to the sum of its inputs (actually, it also negated its output so it could be used as an inverter) and potentiometers. A potentiometer is a device like the volume control on a conventional radio, and generates an output voltage that’s equal to its input voltage divided by a constant, which is set by rotating its knob.
Programming an analogue computer was very different to the process we use with digital computers. The inputs and outputs of the integrators, summers and potentiometers weren’t hard-wired to the inputs and outputs of other circuit elements. Instead, they were connected to an array of sockets referred to as a patch panel. Programming the computer involved plugging leads into the patch panel to wire circuit elements together to create a circuit that would solve a particular set of differential equations. The result would be viewed either on an oscilloscope screen or, perhaps, using an analogue pen recorder if a hardcopy was required.
Hands- on analogue computing
Amateur experimenters have built their own analogue computers, but it’s quite an undertaking. However, it’s possible to get a good feel for the process of programming an analogue computer by simulating one digitally. OpenModelica is an open source scientific modelling package that’s available for all major operating systems. It can be programmed by hacking code, but it also has a graphical interface that enables a problem to be solved by connecting functional blocks on screen, which is a good parallel to the analogue programming method.
A vast number of functional blocks are provided but, crucially, blocks broadly equivalent to the analogue computer’s basic circuit elements are included. Here we’ll introduce some examples to get a feel for analogue computing but first, of course, you need to install the software. OpenModelica’s home is at www.openmodelica.org but note that, if installation proves a bit of a chore, as it did for us, virtual machines with the software pre-installed are available for most common Linux distributions. Given that you might not have an application for OpenModelica beyond trying out analogue computing, this might be a good solution.
To use OpenModelica’s graphical way of computing, you’ll need to launch OMEdit, which is referred to as the OpenModelicaConnectionEditor. We’re not going to provide full step-by-step instructions here, so you’ll have to get up to speed with the interface yourself, but we’ll show images of the models you’ll need to create.
As a first example, we’re going to generate a sine wave and the method we’re using relies on the following two mathematical relationships. The integral of cosine is sine and the integral of sine is minus cosine. This being the case, the circuit shown in the OpenModelica screenshot ( left) will generate a sine wave and a cosine wave. To create this circuit yourself you’ll need the Integrator block that you’ll find in the Libraries under Modelica>Blocks>Continuous and the Gain block that you’ll find under Modelica>Blocks>Math.
The only other bit of guidance you need is that you will need to set the parameters of some of these blocks by double-clicking on them. In particular, you should set the initial value of the left-hand integrator in the circuit to 1 from its default value of 0. This is shown as y_start under Initialisation. In addition, you should set the parameter k (gain) of the gain block to -1 so it acts as an inverter and the constant k (integrator gain) of the two
integrator blocks to 10 so their time constant will be shorter. Having saved and run the model by selecting Simulate, display the Plotting window and select the outputs of the two integrators which should then be plotted as shown.
For our next example, we’re going to carry out a simulation exercise. After all, this was one of the most common uses of analogue computer, the other main one being control applications. Our simulation is a simple one, the system being defined by just three differential equations, and relates to radioactive decay. In particular, we have one radioactive material which we shall refer to by the fictitious name Alphium, which decays to create a material Betium, at a rate defined by a, which is related to its half-life. Betium is also radioactive and decays to generate a material Centium at a rate defined by b. Centium is stable.
The following three differential equations define the behaviour of the system, where A, B and C are the masses of the materials Alphium, Betium and Centium at a given time. And if you need a reminder, dA/dt, for example, is defined as the first differential of A with respect to t (time), and is the rate at which the variable A varies over time, a positive value representing an increase and negative representing a decrease.
Solving a differential equation involves integrating the right-hand side and, with this knowledge, the screenshot ( right) of our OpenModelica solution of this problem should start to make sense. We suggest you try this out yourself using values of 0.347 and 0.174 for a and b, respectively, initialising the first integrator to a value of 1 and setting the gain of all the integrators to 20. All being well, you should get a result similar to the one in the screenshot in which the mass of A, B and C in the graph are shown as red, blue and green traces, respectively. We should point out that the horizontal time scale in all our examples is arbitrary and all our models have been allowed to run for OpenModelica’s default simulation time of one second. If an analogue computer was being used to solve a real-world problem, it would be necessary to calculate the scaling between the actual run time and the simulated time.
We have one more example for you to try but, on this occasion, other than defining the problem, we’ll leave you to figure out how to solve it yourself. It involves the spread of an infectious disease. The three differential equations define how the number of people in each of three groups – those who are susceptible, those who are infected, and those who have recovered – changes over time. The three equations are as follows: In these equations, there are three variables – S being the number who are susceptible, I being the number who are infected, and R being the number who have recovered – and there are two constants – i and r – which define the rates of infection and recovery. Each of the equations should make sense. For example, the first equation indicates that the number of susceptible people decreases over time (because the right-hand side of the equation is negative) at a rate that’s proportional to the number of susceptible people and the number of infected people, and the infection constant.
An online search for SIR Model will reveal the results you ought to get. Having got this working, if you want a bit more of a challenge, this model could be extended but here we’ll leave you to do even more yourself by figuring out the changes to the equations. One such extension involves making the disease life-threatening. In this case, there will be an extra equation that defines the death rate, and the second equation will need to be modified to take account of the fact that when infected people die, the number of infected people decreases further by that number.
OpenModelica’s available blocks aren’t identical to those found in an analogue computer, so our circuit is slightly different to what would have been patched together on an analogue computer, but the principles
are the same, In particular, both summers and integrators in analogue computers negated the output because of the way they were implemented, but we have used pure integrator and summers and, where we did require a signal to be negated, we used a gain unit configured for a gain of -1.
We’ve also used a gain block in place of the analogue computer’s potentiometer, setting its gain to a value less than one so it multiplies its input by that constant value. In addition, analogue computer integrators usually had several inputs so they could be used in place of a summer followed by an integrator. If you really do want to simulate an analogue computer more faithfully, though, OpenModelica makes it possible to define your own blocks, although we’ve not done so ourselves. This means it’s possible to create a block called Analogue Computer Integrator, which would be a combination of an adder, integrator and a gain unit configured to multiply by -1 and one called Analogue Computer Summer, which would be a combination of an adder and a gain unit configured to multiply by -1.
The hybrid approach
Running a single simulation was pretty straightforward with an analogue computer, but optimisation tasks were considerably more difficult. As an example, let’s consider a projectile such as a cannon ball fired by a cannon. If the exit velocity is fixed, it transpires that there’s an optimal launch angle that gives a maximum horizontal range.
Finding that ideal angle would be simple using an iterative approach on a digital computer. With an analogue computer, on the other hand, it would be a fairly laborious approach of running lots of simulations, manually altering a potentiometer that defines the launch angle between each run. However, towards the end of the analogue era, analogue computers were interfaced to digital computers to produce hybrid computers that boasted the high-speed integration of the analogue approach and the control capabilities of digital techniques.
As a minimum, the digital part was able to read the outputs of the analogue functional blocks using analogue to digital converters and even this provide a huge benefit. Instead of relying on pen recorders for hard copy, the output of a computation could be stored digitally for subsequent manipulation and display.
Yet this was just a start. In addition, manually operated potentiometers were replaced by servooperated variants which were essentially potentiometers attached to motors that could be adjusted under the control of the digital computer. We now have a fully automated method of solving the projectile optimisation problem, with the digital computer adjusting the angle potentiometer between runs of the analogue model, homing in on the optimal angle to the desired degree of accuracy.
An analogue comeback?
Given the power available in some of the world’s fastest supercomputers, and the problems with the analogue approach that we discuss in the box over on page 74, it would be reasonable to assume that analogue computers are nothing more than a footnote in history. Yet with the increasing difficulty in miniaturising digital circuits as required to provide ever faster processors, some researchers are asking if analogue methods might, once again, have a role to play. Indeed, 21st century experimental analogue computers have seen the light of day, even though they are markedly different from their counterparts of more than half a century ago.
Of course, nobody is predicting that the analogue approach might, one day, be the dominant model of computing. After all, analogue methods might be good at simulation but they’re entirely useless for many of the jobs at which digital computers excel. However, with digital computers possibly approaching the limit of miniaturisation and, therefore, of year-onyear performance gains, some pundits are suggesting that the future of computing will be multi-facetted computing.
If such a model of computation ever becomes a reality, it seems possible that analogue circuitry might provide one important element, alongside conventional digital circuitry, specialised digital co-processors, and perhaps even quantum processors.