• Welcome to PlanetSquires Forums.
 

resistance is futile

Started by raymw, March 14, 2017, 07:25:27 PM

Previous topic - Next topic

raymw

Having had Paul’s approval, I’ve decided to document on here the steps involved in my latest project, since as I’m a newbie on here, I’ll always being asking for your help, and thought you may as well understand where I’m try to go with freebasic and firefly. This may involve more than the usual sparse background discussion, but that is one of the advantages of a forum such as this, I think. I no longer write software for others, but find it to be interesting, and a reasonably safe mental exercise.

So, some background.

20 years or so ago, I decided to get a software related qualification. At that time I was involved with OS2, and I decided to use IBM visual Age Smalltalk, to devise what I thought was a unique method for solving current flow in a network of resistors. There were other methods around at that time, but I wanted to demonstrate the application of object oriented design and programming. I had considerable help from a couple of folk at IBM, and was told it would take a year for me to unplug my brain, and plug it in sideways to get into the oo way of thinking. They were right, in what they said. 30 years before that, I was operating, for a few months, a large network analyser, a sort of network simulator/analogue computer, programmed by plugging leads, and setting values by dials, analysing current flow in cable networks for an electricity supply company â€" any calculations were undertaken by using a slide rule.

If you don’t understand electrickery, there are only a few basic principles you’ll need to know. The first is to learn a bit of Latin â€" Vir â€" which translates to ‘man’, as I recall from my school days.
It is just one short step to then remember that V=I*R where V is volts, I is current, and R is resistance. This is a fundamental principle in any electrical calculation for a direct current system. (For alternating current, other characteristics come into play, such as inductance and capacitance, but we can go into that later, if necessary, but let’s keep it simple.)

So,  VIR is stating, that for any resistor, the current flowing through the resistor depends on it’s resistance value, and the potential difference (voltage) at it’s two terminals. The units are Volts, Amps and ohms. There are standard values for these, and the standards change every few years, voltage used to be standardised to a particular type of chemical primary cell, and current, iirc depended on the force exerted by a current flowing through a conductor, but you can find more precise definitions, most likely on the ‘iso standards ‘pages, but for the purpose of my puzzle, V=I*R is all that is needed.

Now, it is not often that a circuit consists of just one resistor,  but it is relatively easy, for simple networks consisting of say, half a dozen resistors, to calculate the current flow through each resistor and the voltages, given the  supply points and the supply voltage. For each resistor in series (that is connected end to end, in a long string), the total resistance is the sum of all the individual resistances, the circuit then behaves as one resistance from the point of view in calculating the current, which will be the same for each resistor. For resistors in parallel, the sums are bit more complex, in as much as 1/rt = 1/r1 +1/r2 +1/r3 +1/r… where rt is the total resistance value, and r1, r2, etc are the individual resistances. Are you with me so far? There are plenty of  references on the web referring to series // connections, but just concern yourself with the basic V=I*R.

However, in a complex network, back then, with maybe 50 or so resistors, connected in any fashion, it was necessary to manually go through the various branches at each node, and simplify the network by converting the sub-nets into series and parallel connections, until you had one equivalent resistance value, and then if the supply point moved, you had to go through the whole thing again â€" hence the use of the network analyser. This machine filled a room, and it would take a week to set it up (but it was an analyser for ac currents, so somewhat more complex.) Other than that, you would attempt, by inspection, to reduce the circuit to a stage such that you could apply rules, such as those devised by Maxwell, Kirchoff or Thevenin. Generally you would get the answer wrong, more often than right, and the best guess in three seemed to be most popular.

So, having spent six months or so, trying at different analogies , water flowing through pipes, crowd management, herding sheep, fishing (all of which are similar problems) I decided to analyse the fundamentals of what was actually happening in electrical circuits, at almost a molecular level, but I then threw out all those ideas, and decided to go back to guessing, in a sort of more controlled way.

So, breaking the problem down, the fundamentals become fairly simple. We have three types of components â€" a resistor, a power supply and a circuit. We needn’t constrict ourself to any specifics, but a single circuit can consist of any number of resistors and any number of power supplies, connected in any way you like. These connection points we can call nodes, and they are not part of the resistors or power supplies, but are, if you like, the circuit.

We can connect the resistor terminals to nodes in the circuit, and connect the power supplies to any nodes. The problem becomes how to calculate the voltage at each node, and the current flow through each resistor.

All we know is the value of each resistor, the voltage at the power supply terminals, and the circuit nodes to which they are connected. We also know that the current through the resistor depends on the voltage across it’s terminals and its resistance value, and the voltage across the terminals depends on the current through the resistor, and its resistance â€" chicken and egg, which comes first â€" hence my explorations at the molecular level. We also know, that for each circuit node, since we can not have more than one voltage at each node (since we assume it is a perfect connection â€" well you have to assume some things to get started), that the sum of currents flowing into any given node equals the sum of currents leaving said node. If you can’t visualise this, think of folk arriving at a railway station, say (Not Southern in UK) folk arrive and depart, but at the end of the day, hopefully they’ve all cancelled each other out â€" the station is the circuit node.

Hopefully you have an idea of the problem, if not I’ll have to sort out some way of showing it in a diagrammatic form.

It is useful to be able to separate the calculation side of things from the data I/O, and if we can apply the model view controller paradigm (MVC), once we have really drilled down to the essential nub of the problem, we can more readily add different user interfaces, including the usual windows form type of interface, or more graphical representation of the resistors (including the colour coding if you really enjoy this sort of fun) which will mean getting into fb graphics, I guess.

I’m sorry if it appears that I am a bit inebriated in the exuberance of my own verbosity, but you can get your own back by explaining in great detail the succinct coding that hopefully you will be writing for this.

(to be continued)

Eddy Van Esch

Ray,

Long story, and I haven't read every word of it, but I think I more or less understand what you want to say. (or maybe not if I read your story more carefully tomorrow morning  ;D)

I have programmed simulations of electric circuits that were actually equivalent models of pneumatic circuits ....  :)
And also simulations of heat-transfer problems.
I also programmed them as time-dependant models , i.e. dynamic in time .. by using a number of iterations where every iteration tried to calculate the model as being 'in balance' but it was a dynamic balance ...

Pff ... too late in the evening ... too difficult to explain .... off to bed now ...  :o  ;)

Kind regards
Eddy
Eddy

Paul Squires

Hi Ray,

Thanks for the introductory information. Looking forward to helping and offering suggestions for building the program. I bet others are looking forward to seeing a project develop from nothing to something. Along the way we can all learn much about designing and developing an application using Firefly and FreeBASIC in general. Should be an interesting and fun experience.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

David Warner

Hi Ray,

This seems like an interesting project and I too will look forward to seeing how it goes.

All the Best,

David

Eddy Van Esch

Ray,

Here is a little example to practice on ....  :)
https://www.mbeckler.org/resistor_grid/

Kind regards
Eddy
Eddy

raymw

Hi Eddy,

Thanks for sharing, it looks to be a very similar method, at first glance.  Hopefully you'll be able to 'correct the errors of my ways' as time goes on...

Best wishes,

Ray

Eddy Van Esch

Ray,

Typically, these problems are calculated by solving a system of equations.
I am looking for a different approach: an iterative method.
The benefit is that it should work for any arbitrary network of components (R, C, L). No need to build all the equations.
Just brute calculation force would be needed...
Not sure if it can be done though...

Kind regards
Eddy

raymw

#7
Hi Eddy,

That was the way I did it in Smalltalk, back then an iterative process (the Monte-Carlo method). I'm not wanting to refer back to the detail of my previous solution, since I intend doing it in ff and fb, but I will need a bit? of help with the code. When I had completed it, I realised that the concept could be readily extended to include more dynamic situations, instead of the basic 'steady state' dc/resistor network. The purpose of re-describing it on here, is to show the beauty in ood and the mvc paradigm (although I am no purist/expert in either), to encourage newbies into exploring the wonders of ff/fb, and for me (and others)  to get some help in how to improve my knowledge of ff/fb/win api's etc.

Although I've chosen a network of resistors, the problem presented is similar to traffic flow, warehouse conveyor belts, and many other real world examples.

I intend next to post a few diagrams, to show what I was describing, so that those that are interested, but still puzzled, can better understand the problem domain, and then we can sort out the various parts of the problem, the objects, the model, the views and the controller, in a basic (sic) fashion. If you understand the language, the major part of projects such of these takes place before any serious code is written, and if a correct segregation is chosen between objects, then it is trivial to later extend the system, if needed. The other big advantage, is that various parts of the software can be written by different people, or at different times, since altering one part does not effect another (encapsulation?) (e.g. once the attributes of an object has been defined, then different views can be produced, e.g. forms, graphics, charts/whatever while at the same time the calculations within the model are being programmed - not as necessary in a simple one man problem such as this, but more useful in a larger problem, perhaps.) As I've no idea of other folks' understanding of ohm's law, I feel it is necessary to (perhaps for some) labour the point, so to speak.

Paul Squires

Quote from: raymw on March 16, 2017, 11:56:45 AM
... As I've no idea of other folks' understanding of ohm's law, I feel it is necessary to (perhaps for some) labour the point, so to speak.

Well, I know very little about the subject so it is an opportunity for me to learn and hopefully offer some suggestions regarding how to apply that knowledge into the FF, FB tools.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

raymw

Here, attached, are a series, a parallel and a more complex mesh for you to solve. I've given the resistance values (in ohms) in the centre of the resistors, the voltages from the power supply to their nodes in red, and current (and direction) in black. Using the previous background, with the rules concerning V= I*R and the currents entering/leaving a node (shown by black dots) balance out, you should be able to calculate the requested values of V and I, and otherwise solve the network. Think carefully about the third network, but not too much! There are numerous assumptions being made here, compared to an actual circuit, but it is not needed to go into those, unless anyone is particularly interested.

raymw

As an interlude, somewhat off topic, here's a photo of my IBM 360 flowchart template (50 years old or so, and still working :)) most of us never dreamed that progress in electronics would be so rapid. There must be a few of you out there with similar old memorabilia. (it's sort of relevant, since I used it to draw the rectangles representing the resistors.
(In case you're beginning to worry about image overload, I promise no kittens.

Paul Squires

...it's times like these that I wished I had studied engineering in university instead of accounting.....

:)

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

raymw

The same sort of problems, I guess. Here we have an electrical circuit, you have a corporation, or an international bank. The nodes are branches of said bank. The current is the flow of money, you alter the resistance by varying interest rates or other incentives. In both cases, if you get the answers wrong, it's a bit of a disaster...

Paul Squires

:)  yup, sounds about right
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Eddy Van Esch

Hm .. I think I have thought of an iterative algorithm to solve these networks. Should work in the time domain too .. Will explain in a next post...
( When the stock markets are closed ...  ;) )

Eddy