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)
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
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.
Hi Ray,
This seems like an interesting project and I too will look forward to seeing how it goes.
All the Best,
David
Ray,
Here is a little example to practice on .... :)
https://www.mbeckler.org/resistor_grid/
Kind regards
Eddy
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
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
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.
Quote from: raymw on March 16, 2017, 12:26:45 PM
... 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.
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.
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.
...it's times like these that I wished I had studied engineering in university instead of accounting.....
:)
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...
:) yup, sounds about right
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 ... ;) )
Here it is.
Let's look at the circuit in the picture.
We see a number of components (resistors and voltage sources in this case) that are connected together.
The points where a number of components (1 or more) are tied together, we call 'nodes'.
In this pic, they are colored blue. We see nodes 11, 1, 2, 22 and 0.
When a circuit is 'stable' or 'in balance', following node criteria are fulfilled:
a) A node can only have one voltage, so all pins of the components connected to this node have the same voltage.
b) Every node obeys Kirchhoff's first law: The sum of the incoming currents equals the sum of the outgoing currents. Logical, because a node can't
'store' current.
Okay, we are going to focus on the voltages of the various nodes.
Regarding to voltages, we have 2 different types of nodes:
- Nodes with a fixed voltage
- Nodes with a 'self-balancing' voltage.
In our case, nodes 11, 22 and 0 are fixed voltage:
* Node 0 = 0 V (could be another voltage though... It is all relative)
* Node 11 = +10 V
* Node 22 = -4 V
That leaves nodes 1 and 2 to be self-balancing. They will adjust themselves so that the whole system is in balance.
If we can determine these 'stable' voltages on these nodes, we have the system completely defined and can calculate every current.
How can we determine these stable voltages?
We start with a completely fresh or unstable system. For example, the voltage on every 'self balancing' node can be 0 V.
We leave the 'fixed voltage nodes' alone. Nothing to be done there.
We are going to iterate through the self-balancing nodes. That means, we are going to do the balancing ...
How are we going to do that?
By simply working with our node criteria.
- We optimise (vary) the node voltage to try and fulfill Kirchhoff's law.
You will increase or decrease the voltage to make the sum of all the node currents as small as possible.
Now, during the first iterations, we will not be able to get the sum of the currents to zero, because the system is still much too unbalanced.
Instead, we will settle for making the error minimal. So the (absolute) sum of the currents in the node has to be minimal.
When we have found this (currently) optimal voltage we will go to the next self-balancing node and do the same.
- Keep doing this over and over again until you notice that the voltages do not change anymore. That's when you have a stable system and you have all the currents and voltages solved.
In this system, you can use voltage sources and current sources.
You can also include the time component for C (capacitors) and L (coils).
Maybe a bit too soon, but I've put some answers below to the three circuits, and hopefully an explanation as how to get there.
I mentioned that assumptions have to be made, - here's a few - where nodes are joined to a solid line (a busbar) then the voltage at each such connected node will be the same. The sum of currents entering and leaving a node/busbar is zero. All power supplies are of infinite capacity, and are completely stable. Any measuring equipment does not impact on the components being tested.
The series one. The total resistance of the 3ohm and 2ohm resistors is 5ohms (for series resistors you sum the individual resistors). From V=I*R , the current through each one is 10/5 = 2 Amp, since 10V is applied across the terminals of that equivalent resistor. The voltage at the bottom terminal of the 5 ohm resistor is maybe a bit of a puzzle, but as that resistor does not have a potential difference across its terminals (the bottom terminal is not connected to anything), no current flows through that resistor, so the voltage will be the same as that at the connected end, in this case 0V.
The parallel circuit. We have 10 - 2 volts (8V) applied across the terminals of the 5 ohm resistor, so the current through that will be 8/5 Amp, or 1.6A . Since the bottom terminal of the 2 ohm resistor is not connected, the voltage there will be the same as at the connected end, and will be 10V.
Now for the headache just for the sake of it, I guess.
By inspection, it can be seen that there are a number of series connected and // connected resistors, so we can simplify the circuit to fewer resistors. So, doing the series ones first- from top left, the 2 + 3 become 5 ohm, below them the 4 + 5 become 9ohm. Now, what about that 21 ohm one in the middle? Well, both terminals of that resistor are connected to the same node, the resistor is 'shorted out', it will carry no current, since each terminal is at the same voltage, so it can be removed from the circuit. We can now see which of the resistors form parallel circuits, and combine them, ending up with four resistance values only. So first, the top row of resistors, the new 5 with the 17 and 6 ohm are equivalent to 1/((1/5)+(1/17)+(1/6)) = 1/(0.2+0.059 +0.167) = 1/(0.426) = 2.347 ohms, and the second, for the bottom pair the new 9 and the 2 become 1/((1/9)+ (1/2)) = 1/(0.111+0.500) = 1.637 ohms but this still has in parallel, the right hand 4 and 8 ohm, which we can not simplify because between the 4 and 8 is a 4.5V supply point. If you are interested, redraw it and recalculate.
It can be simplified, wrt the voltage calculations, if we add 9V to each voltage, (and remember to subtract 9V at he end), thus the top voltage becomes 18V, the bottom 0V, and that between the 4 and 8 ohm resistors, 13.5V. Now, we can see that across the terminals of the bottom right 8ohm resistor is 13.5V, giving a current through the 8 ohm resistor of 1.688A. The same current must also flow through the connected 4 ohm resistor, since it is connected in series to the 8 ohm, and there is no other resistor connected. Therefore we can calculate the voltage asked for, since the voltage across the 4 ohm must be 4*1.688 = 6.752V, giving the voltage at V? of 6.75 + 13.5 = 20.25V (-9V) = 11.25 V. **BANG** -This is clearly wrong, since the maximum voltage in the circuit can not be more than 9V. Where is the error? Well, the node between the 4 and 8 ohm resistor is connected to a 4.5V power supply, and that feed may source or sink current, so although the two resistors are connected in series, the fact that there is a power connection at that node, although it is still true that the sum of currents at a node equals zero, i.e. what goes in must go out, we have no idea as to the current flow from the power supply. Hence we can't say, from the calculations so far, that the current through the 8 ohm resistor will be the same as through the 4 ohm. You will have this problem, wherever there is more than one power feed, in many cases. More generally, interfaces are always a problem, from sea shores to usb connectors/whatever.
What to do? Well, the manual way would be to use some theorem, by Kirchoff, Thevenin, Maxwell, whoever, but we could also have a guess. Our first guess will be most likely wrong, but with a bit of skill and luck, after a few iterations, and applying a suitable algorithm we can get near enough. We can test our guessing, by using a spread sheet, say, but any solution using manual means will need a new set up each time the resistor values change, or more awkwardly if the circuit layout changes.
So, in guessing/iterating/monte-carlo, whatever you want to call it, the first guess is perhaps the tricky part, and then we make sure that subsequent guesses head towards the solution, and not away from it. we can check our guessing, by verifying against the two rules we have. Given that we know the resistance values, the supply voltages and connections, first- the current at each node must sum to zero, second the voltage across each resistor is equal to the current * resistance.
Are we having fun yet?
Crikey - this has taken me back a bit.
I think I still have one of those identical IBM plastic template somewhere - and I even have a mechanical (yes mechanical) Hexadecimal calculator.
I vaguely remember when I started in computing a long long long ... long while ago - there was a program called the IBM Electronic Circuit Analysis Program (ECAP) - which did what it says on the tin (even if electronics was a bit cruder in those days). I never actually used it - but I notice that if you do a Google search for 'IBM ECAP' it comes up with some info and a few references to methodology.
I don't if this is of any help - but its worth mentioning in case it is.
Barry
Eddy's post crossed with mine, and has explained, probably more clearly, the same method of calculating the voltages, etc. as I will be attempting to repeat in ff/fb, so hopefully we can now leave the fundamental description of the problem, and progress towards an ood based solution, or at least my attempt at one... If there is something not explained too well, or you just do not understand then ask. In no way am I suggesting that the proposed solution is ideal, but hopefully it is interesting, and the principles can be adapted to other problems. By selecting a decent design, then we can experiment with other solutions, perhaps by training a neural net, or similar. One thing to remember, is that the 'real world' is analogue, and we are working digitally, but even digital is analogue, or worse, depending on your viewpoint. (its a bit late over here for such philosophical thoughts, maybe.)
Best Wishes,
Ray
Quote from: raymw on March 16, 2017, 10:35:11 PM
...its a bit late over here...
Or (also depending on your viewpoint) a bit early. Either way, it's the night-owl or the early bird that catches the worm. :)
Your photo post also made me dig around to find my old IBM flowchart stencil. It's identical to yours and I was given it nearly thirty years ago. I haven't used it for years but it seeing it again brought back happy memories of documenting my COBOL data manipulation code with it.
I never did commercial/business oriented language. Initially it was a few variants of IBM Formula Translation, then a tad of Programming Language 1 (I think that's more or less the correct acronyms) wrt the flow chart template I noticed on mine I'd 'snowpaked' a corner and written on it 'this way up'. Must have been pulled up for producing erroneous looking printout symbols/whatever...iirc, the total cost of a program was guesstimated to be about £5.00 per fortran statement.
I don't want to spoil anybody's fun. Just make my iteration algorithm more clear.
I have attached an Excel file that defines the shown resistor network.
By changing the 2 node voltages (in the yellow cells) until the error values (the green cells) are as close to zero as possible, you can solve this network.
You can also use Excels Solver add-in for this.
Can't directly attach the Excel file, so download here:
https://apps.memopal.com/e/24H9FJASWM
Something has gone wrong... There's actually a smidgen of code in here (which may be of no use whatsoever)...
Let’s consider the problem by trying to identify objects. Not too difficult in this case. Objects are usually nouns, and so far I’ve talked about resistors, power supplies, nodes, terminals, bus-bars, amps, ohms, volts, current and other items. Not all of these are necessarily objects, but it can depend on the view point we want to take. For example, earlier I mentioned that a node in this electrical example, could be considered as being similar to a branch of a bank, and cash flow equivalent to current. If we were doing a high level accountancy summary for the whole banking corporation, then we may not be interested in whether the cash flow consisted of credit transfers, cheques or hard currency. However, if we needed to also use the data as a means of calculating the frequency of the cash delivery vans, or knowing how many new coins would be required, then maybe it would be worth while looking at the detail of the ‘cash object’ to include a few more attributes, other than merely its value, and direction of flow (debit/credit). Deciding on the granularity of the system, in the real world, can require a fair amount of effort.
As this simple resistor problem is merely a test piece, then I can decide on my own level of detail, and by isolating the calculations and fundamental attributes from the I/O it becomes fairly easy to make later changes.
I’ve decided, for the moment that there are only three main objects â€" the circuit, resistors, power supplies. If it is decided to add other components, such as inductors, capacitors, diodes, etc., then they will most likely be ‘sort of’ resistors, but it should be straightforward to include them later.
Now, unless at more or less absolute zero, or by other means of obtaining superconductivity, most electrical components exhibit some resistance to electrical current. Electricity power lines, house wiring, etc., but for the sake of simplicity, I’ve decided to base this problem on the sort of resistor that is used in electronic circuits, purchased from Farnell/wherever. This is so that I can possibly add in a few other attributes, to demonstrate what happens if a resistor is overloaded, or has a wider tolerance than perhaps was originally specified. If we proceed to perhaps producing a suitable printed circuit board layout, then physical dimensions may be needed too, so I’ve defined our resistor object/class/type whatever we call it, as shown in the attached fb code. Type Resistor
Public:
id as String*8
resistance as Double
Rating as Double
VA as Double ' voltage at A terminal
VB as Double ' voltage at B terminal
CurrentAB as Double 'current A to B
PowerLoss as Double ' =I*I*R
Size as Double ' distance in mm 'twixt terminals A & B
material as String*8 ' type - ceramic, ww, etc
overloaded as boolean ' if current exceeded, set to true
Declare Sub current()
Declare Sub voltage()
Declare Sub calc_overloaded()
End Type
'--------------------------------------------------------------------------------
Sub resistor.current()
this.currentAB = this.resistance/(this.va - this.vb)
End Sub
' --------------------------------------------------------------------------------
Sub resistor.voltage()
this.voltage = this.resistance * this.currentab
Return this.voltage
End Function
'----------------------------------------------------------------------------------
Sub resistor.calc_overloaded ()
If this.currentab > this.rating Then
this.overloaded=True
Else
this.overloaded = False
End If
End Sub
'--------------------------------------------------------------------------------
I’m hoping that the free basic ‘type’ can be used in a similar way as a class, and we can create new instances from it. If not, then we’ll most likely be able to find some work around. I’ve shown the required calculations that each resistor needs to make, as subroutines. The power supply object has not yet been defined. By adopting the mvc paradigm, I do not need to be too concerned at the level of detail required for the model at this stage, it merely puts down a marker so that other aspects of the program can be studied.
Now, the resistors and power supplies are connected together at nodes on the circuit. I’m assuming that these nodes are some standard connector that matches the terminals of the resistors and power supplies, so no need to specify if solder pads, dil, screw terminals, whatever. If we needed that level of detail, then within the circuit object, I would probably add that attribute, and check that the type of node matched the type of component terminal.
The proposed circuit object will be basically a list of nodes, with associated connected component terminals. Examining the circuit diagrams, we see that for each node, there is no more than four terminals connected. In practice, there could be many more, but in the diagrams we show that by drawing in solid lines, representing bus-bars. So, I have to make a choice, in how to describe these node and terminals connections.
If the number of terminals associated with a node is unlimited, as it would be in the original circuit that the schematic diagram represents, then for each node, there will be an attached unknown length list of terminals, and if we are working from a schematic diagram, then some interpretation will need to take place, it is not a case of simply looking at the diagram, and making a node for each ‘blob’. The schematic diagram represents a single node with a multitude of connections by a number of nodes and connecting bus-bars. If we decide to represent the schematic diagram, but not the physical network it represents, it will be easier to annotate the diagram with the calculated results, and we can restrict the list of terminals attached to a node to no more than four, but we need to add a bus-bar component.
A bus-bar can be considered as a resistor with a resistance value of zero, and the voltage at each end is always equal. I could either set up a resistor instance as a bus-bar, when needed, or create another bus-bar object. However, I imagine a bus-bar as being perhaps a part of a node, or more realistically as a connection between nodes. At the moment, my preferred method is, for each node to have up to four associated terminals, any or all of which may or may not be a bus-bar, or other component.
I’m now trying to decide on ‘the best way’ of storing this detail within the circuit object, whether to have say, an intermediate ‘node object’ or just a linked list/whatever. Maybe have a particular terminal for a resistor specified by a comma separated string, e.g. r5,t1 or store the whole node connections as comma separated strings, e.g. r2t1,r3t2,pt2 or have attached to each node, separate variables for each component type and terminal number.
Hi Ray, I am only now getting to look at your post. There a few changes I'd make to the class but I will post them once I get a better opportunity to analyze the situation. :)
There’s no rush, Paul, plenty of other stuff to think about, but it would be nice to mock up a bit of code to prove the possibility of creating new instances of a class, and to be able to iterate through them. This is possible in firefly, using forms and a list of hwnd’s, as you answered in one of my previous questions on this forum, but it needs to be done in the model, whereas the form is a view â€" at least in my way of thinking.
Concerning the circuit model, I think that will be just a linked list of nodes, and connections to each node. There has to be a simple way of manually putting that information into the model, working from a schematic diagram, a method that preferably uses no manual calculation or interpretation. Perhaps a few rules have to be obeyed. If we label each node with an integer, then we will not need to store a list of node names, and if the nodes are numbered sequentially, then it will simplify it even more. If we define that each resistor terminal must have a number or letter, unique to that resistor, and that each resistor name is unique, then a terminal can be r111, or res5a, whatever, and the terminal can be extracted as the last character of the string â€" e.g. resistor r11, terminal 1 and resistor res5, terminal a in previous example. Some neat data entry verification could take place â€" check that for each resistor the terminal numbers are different, that each resistor name in the list of terminals only appears twice, say. The model has to be an accurate representation of reality, else we will get an answer to a question that has not been asked, when we run the calculations.
If we make another rule, such that a power supply terminal is entered as a number followed by V, e.g. -5.6V, 0V, then we can note that the node number to which that is listed, will have all terminals connected to that node as having a fixed voltage at the numeric value (e.g. -5.6, or 0 Volt in the examples).
Initially, I’m thinking I will use windows forms for data entry and display. Although it could make sense to treat each node as an instance of a node class within the circuit, I’ve a feeling that the screen would get cluttered, and it may be better to just have a single form with a list box to enter in a comma delimited string on each line, to represent the terminals on each Node. I’ve not decided anything yet, but whatever method of data entry is used, it will not (or should not) effect the underlying model.
I can’t remember the detail of my previous solution from 20 years ago, and do not want to look it up, but the next consideration, is finding a suitable way of deciding the initial values before carrying out the iterations around the circuit. One method, would be to set the current through each resistor, to one amp, say. This may take a few more iterations before we arrived at a more stable solution, compared to making some other guess. I’m thinking we should be able to make some better guess. Perhaps if we assumed all the resistors were in series, and the software calculated the current if we assumed the maximum voltage was applied across the equivalent terminals, or perhaps we considered the resistors in parallel, possibly we do both calculations, and take the mean current. Initially, whatever we decide on, we can terminate the calculation iterations when the voltage differences at the connected terminals is less than 1%, or after 20 iterations, for example, then decide later. The controller part of the mvc, is where those arguments take place.
Having thought a bit more on how to initially enter values into the circuit model, I’ve decided on a form, shown in the screen grab. If I need more than 16 nodes, then I’ll open another form. For proving the concept 16 nodes should be adequate. I found it a bit tricky lining up the textboxes â€" an ‘undo’ option would be useful… The method I used, to get them arranged in a grid was to create a row of 6 boxes, name them , remove the initial ‘text1’, then copy and paste the row a number of times down the form. Had to make the form well oversize, since the pasting was not too precise. Anyway, I then aligned the bottom row, then column by column equally spaced the boxes, and shrunk the form to suit. I will have forgotten this before I need it again. I expect there is most likely some neater way, but this worked well enough.
I intend only using ff as a means of entering data to the model (and presenting the results) I could equally as well have simply used the dos window and ignored firefly completely. Whichever method is used for the view, then the controller chooses.
Hi Ray, such a form cries out for an editable grid of some sort. Too bad that we don't really have one that works in FF/FB. Another idea would be to make a scrollable form because I imagine that your data entry screen must be very large and may exceed the screen real estate of some users. Jose has posted examples of scrolling forms using his CWindow class. Also on your resister form, it looks like in a couple of cases that the control heights for your labels may be a little large because they are bleeding into the border of the textboxes underneath them.
Yes, agreed on all counts. It would be nice, if also we could have a text box with integrated label. I think it would be useful in many cases, but sometimes you'd need to have a longer label/whatever. wrt the grid, I was considering writing a single row, in ff, then editing the generated form code (copy and paste with a few calculations). It could be done as a separate program. (in c#, M$ comments chunks of the form code saying 'do not alter this code' - guess who goes in and alters it? I vaguely remember I made a form generator for quick basic - typed the text I wanted to be shown on the 80 column screen, with values like xxx.xx for the position to enter values. It was then parsed and the correct basic input statements generated (possibly before your time, and most likely not on your side of the pond, but there was a piece of software, hyped up for a year before release, named 'The Last One' (TLO). It was a software generation system, and was meant to be the last software anyone would need to buy... innovative at the time.)
edited to add -1981 - TLO wiki link https://en.wikipedia.org/wiki/The_Last_One_%28software%29 I still have the original documentation, floppies, and some example code, somewhere, fwiw
I've not had much time to continue with this, as quickly as I would have liked. It's suddenly got to be Spring over here, and outside stuff calls. I will probably 'cheat' by not using oop for the resistors, maybe store their details in lists within the circuit, instead of creating individual instances of the resistor object. By separating the view from the model, it allows either to be readily changed at any stage, so I/you can alter it later on, if we feel like doing so. In the same way, it will be relatively easy to add in other components, diodes, caps, inductors, etc., or change the calculation to something other than using monte-carlo, to perhaps a small trained neural net. (I've a reasonable document on using c# and neural nets which possibly could be plagiarised)
I wish it was spring here. We just finished two late winter snow storms! Ugh! Sorry I haven't been much help on this project, mostly because engineering topics are not my specialty and my interest them is marginal at best :)
Right now, we have 21 ºC / 69 ºF in Valencia, and rising... We will reach 26 ºC next week.
At the height of our summer we reach 26 ºC (sometimes we hit over 30 ºC but not very often). Time for me to move to Spain.
Last year we had 75,3 millions of tourists and this year we expect many more.
What is it with programmers and the weather? Is it 'I'm sat in here, but wish i was outside', or is it - it's a rich source of programming experimentation, forecasting/whatever. I'm not sure if I'm right, but I think it was in the book 'The soul of a new machine', which a read back in 1982ish, that one of the techies made a model of a virtual world, with a model of the weather system. Daily folk would ask what the weather was doing, and I think he published a daily weather forecast around the offices. If it was not in that book, it was in one about 'fuzzy logic', come to think of it, that was more likely. I can't find either book to confirm.
Another irrelevant fact, but most programmers I know, over a certain age, smoke roll-up cigarettes - it gave them a short displacement activity between bouts of concentration.