Friday, April 26, 2013

User defined objects

While examining current sources, I figured that since the basis for the circuit solver is mesh analysis, the current source will have to be converted to a voltage source in series with a resistance. This means a voltage source and a resistance in series connected in parallel with a voltmeter. So essentially the voltage source has to be adjusted with respect to the voltage measured so as to produce the necessary current.

So this starts another task that I was planning to do just before I released a major version. That is of user defined objects. Suppose, a user wants to create an object which is a voltage source in series with an RLC network and make a dozen copies of it in the circuit, how would that be done? As of now, the entire solver works on the basis of cell positions on the spreadsheet. But now these cell positions won't exist in real but fictitious cell positions will have to be created.

Suppose such an object is to be defined. How would the details be internally? Suppose it is placed at position 7E in the spreadsheet. How would each element be defined as cell positions in the loop as it may be more than one loop if there is a parallel element. One possibility is to go ahead with just one cell position but replicate the loop by the number of parallel elements in the loop (essentially the number of branches in parallel). So every time the object is called, an identifier needs to be created to know which parallel element to consider.

So essentially a third dimension needs to be added. This makes sense as we are adding layers to the spreadsheet. But this might need a complete rework of the entire solver! Need to think over this.

Monday, April 22, 2013

Capacitor class

Been a long time since I updated the blog.

To add another element to the library - the capacitor. Anyway, the code is just an extension/combination of the voltmeter/voltage source classes. Here is the code (click on "view raw" below the code box to see it in a new window):



I'll release another version after completing the current source class which I hope will be in a few days.

For the current source class, my guess it would be best to exclude it from the branch list so that it doesn't appear in any of the loops. For every current source a simple nodal equation can then be added.

Friday, April 5, 2013

Version 0.1.4 released

Released another version:
http://sourceforge.net/projects/pythonpowerelec/files/

Next step:
Complete the passive library - include capacitor and current source. Current source is extremely important for us power electronics guys and that might be a bit of a challenge as the loops will be refined every time a current source is found.

Simulation speed

Before the topic of simulation speed, a minor check to be performed on components that have polarity like voltage sources, ammeters and voltmeters.

Until now, the only check on the polarity of these elements is that it is within the physical circuit map. But now that branches have been defined, another check can be enforced about whether the polarity element is in the same branch as the component. This is the code (click on "view raw" below the box to see the code in a new window):



For this to happen, the main program "circuit_solver.py" has been rearranged a bit. No changes to the code as such. Just that the network interpreter is called immediately after the circuit layout file is interpreted and checked for basic errors like componenents not found in library or duplicate components. The idea is that polarity errors should be picked up at the design stage before the simulation starts.

Now the other change of simulation speed. My concept has been similar to an interrupt driver program. Instead of an interrupt vector, generate an "event vector". This event vector will be "yes" corresponding to a branch is an element has changed in the branch. Otherwise, it will remain "no". If there is a single "yes", this would mean the all the system matrices A, B and E would be calculated completely. Currently, this might be necessary. At a later stage, I could think of ways to recalculate only the parts that are affected.



So, the branch_events vector is reset to "no" at the end of the code block. This vector is initialized to "yes" at the beginning to ensure that at least one computation takes place. With passive circuits, there won't be any event generation and therefore, there will be no recalculation.

This has speeded up the execution quite a bit but still not as much as I would have liked. Need to figure which of the code blocks can be done away with. A fairly simple circuit like "testckt7.csv" in the example list which results in a 4x4 system takes around 2 minutes to solve for a run time of 0.5s and a time step of 10 microseconds. Which is quite slow. At later stages, this might be a problem when simulating an inverter with a time step of 1 microsecond. If the inverter has a switching frequency of 5 kHz, an event would be generated around every 30 microseconds. No idea how it is going to be.

Tuesday, April 2, 2013

Version 0.1.3 released

Been incredibly busy with my official research project. Will continue to be busy for another week until my PCBs are sent out for fabrication. Thought I would release another version just so that I don't loose track of what I have done.

http://sourceforge.net/projects/pythonpowerelec/

Created a voltmeter model that you can use to measure voltage. The concept is it is a large resistance is parallel with the nodes across which voltage is to be measured. The parameter taken as input is the rated voltage of the system. This is just an approximate value so as to choose the voltmeter resistance large enough that a negligible current of 1 microampere flows through the voltmeter.