Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

[Ktechlab-devel] Calculating the currents in a circuit

 [Ktechlab-devel] Calculating the currents in a circuit From: P Zoltan - 2010-10-03 21:17:08 ``` Hello, I've looked into the problem of finding the currents in a circuit, on the minimalistic simulator branch. Because I couldn't understand the existing code, I've looked at the previous, working version. There the following is the idea: - solve the circuit with modified nodal analysis - after having a solution, calculate the currents in the following way: - call a calculateCurrents() method on all the elements. This way the currents flowing from the elements into the CNodes are calculated, but they are stored in the elements. The CNodes are not a good storage for the currents, because one CNode is associated with more elements. See the orignal method, for a resistance, here, at the end of the file: http://ktechlab.svn.sourceforge.net/viewvc/ktechlab/branches/ktechlab-0.3.7/src/electronics/simulation/resistance.cpp?revision=172&view=markup - next, these values for currents are tranferred from the elements, to the pins, by the component::setNodelCurrents() method, line 152: http://ktechlab.svn.sourceforge.net/viewvc/ktechlab/branches/ktechlab-0.3.7/src/electronics/component.cpp?revision=172&view=markup From there, calculating the currents throught the wires is easy. So, in order to have a reliable current calculation, I'd like to apply the ideas from the version 0.3.7. The following changes are needed: - add a method to Element: double nodeCurrent(int nodeNumber) const ; and implement it, by using a doube m_nodeCurrent[4]; protected member. - in all the lements, updaete the m_nodeCurrent member, in the updateCurrents() method, instead of updating the node currents. As explained earlier, the node currents will get updated by many elements, so setting the current there is meaningless. - add a double sourceCurrent() const; method to the Pin class, and a setter method for it. The returned value should be interpreted as the current flowing from the element into the pin. If the pin has no attached element, then this value must be 0. A currentIsKnown() method already exists, so that can be also reused. - i don't really understand why is the ElementMap a separate class. Maybe someone can explain it. That class is a helper for Element, that connects the Element to Pins. Wouldn't it be more simple to make the element aware of pins? I won't research that, but a wrapper class is needed that sets up an element and tranfers the value of currents into the pins. - after having all these in place, the void Circuit::updateCurrents() method could be updated such that calculate all the currents flowing from the elements in the pins, and also all the currents flowing through the wires. Any comments, ideas and suggestions are welcome. Zoltan ```

 [Ktechlab-devel] Calculating the currents in a circuit From: P Zoltan - 2010-10-03 21:17:08 ``` Hello, I've looked into the problem of finding the currents in a circuit, on the minimalistic simulator branch. Because I couldn't understand the existing code, I've looked at the previous, working version. There the following is the idea: - solve the circuit with modified nodal analysis - after having a solution, calculate the currents in the following way: - call a calculateCurrents() method on all the elements. This way the currents flowing from the elements into the CNodes are calculated, but they are stored in the elements. The CNodes are not a good storage for the currents, because one CNode is associated with more elements. See the orignal method, for a resistance, here, at the end of the file: http://ktechlab.svn.sourceforge.net/viewvc/ktechlab/branches/ktechlab-0.3.7/src/electronics/simulation/resistance.cpp?revision=172&view=markup - next, these values for currents are tranferred from the elements, to the pins, by the component::setNodelCurrents() method, line 152: http://ktechlab.svn.sourceforge.net/viewvc/ktechlab/branches/ktechlab-0.3.7/src/electronics/component.cpp?revision=172&view=markup From there, calculating the currents throught the wires is easy. So, in order to have a reliable current calculation, I'd like to apply the ideas from the version 0.3.7. The following changes are needed: - add a method to Element: double nodeCurrent(int nodeNumber) const ; and implement it, by using a doube m_nodeCurrent[4]; protected member. - in all the lements, updaete the m_nodeCurrent member, in the updateCurrents() method, instead of updating the node currents. As explained earlier, the node currents will get updated by many elements, so setting the current there is meaningless. - add a double sourceCurrent() const; method to the Pin class, and a setter method for it. The returned value should be interpreted as the current flowing from the element into the pin. If the pin has no attached element, then this value must be 0. A currentIsKnown() method already exists, so that can be also reused. - i don't really understand why is the ElementMap a separate class. Maybe someone can explain it. That class is a helper for Element, that connects the Element to Pins. Wouldn't it be more simple to make the element aware of pins? I won't research that, but a wrapper class is needed that sets up an element and tranfers the value of currents into the pins. - after having all these in place, the void Circuit::updateCurrents() method could be updated such that calculate all the currents flowing from the elements in the pins, and also all the currents flowing through the wires. Any comments, ideas and suggestions are welcome. Zoltan ```
 Re: [Ktechlab-devel] Calculating the currents in a circuit From: Alan Grimes - 2010-10-03 21:47:19 ```chrome://messenger/locale/messengercompose/composeMsgs.properties: > - call a calculateCurrents() method on all the elements. This way the > currents flowing from the elements into the CNodes are calculated, but > they are stored in the elements. The CNodes are not a good storage for the > currents, because one CNode is associated with more elements. The element doesn't really care unless it needs the information for the next simulation step. In general, I have been working to minimize the amount of state in each element. > See the original method, for a resistance, here, at the end of the file: > http://ktechlab.svn.sourceforge.net/viewvc/ktechlab/branches/ktechlab-0.3.7/src/electronics/simulation/resistance.cpp?revision=172&view=markup hmm. I don't remember the rationale behind that design. > - add a method to Element: > double nodeCurrent(int nodeNumber) const ; > and implement it, by using a doube m_nodeCurrent[4]; protected member. Okay, might be a good test. > - in all the lements, updaete the m_nodeCurrent member, in the > updateCurrents() method, instead of updating the node currents. As > explained earlier, the node currents will get updated by many elements, so > setting the current there is meaningless. > - add a double sourceCurrent() const; method to the Pin class, and a > setter method for it. The returned value should be interpreted as the > current flowing from the element into the pin. If the pin has no attached > element, then this value must be 0. A currentIsKnown() method already > exists, so that can be also reused. All pins have 0 current. I used the pin class only to help pipe information about currents between elements and wires. (and there may be more than one of each.) Because the pointer-tool needs a current to read, I simply sum the currents in the wires to obtain the current at a pin, it sometimes works... > - i don't really understand why is the ElementMap a separate class. Maybe > someone can explain it. That class is a helper for Element, that connects > the Element to Pins. Wouldn't it be more simple to make the element aware > of pins? I won't research that, but a wrapper class is needed that sets up > an element and tranfers the value of currents into the pins. Yeah, there are a number of sub-optimal things going on there. In the svn version, you can set "show current animation" to true to see what the UI thinks the flow of currents are. -- DO NOT USE OBAMACARE. DO NOT BUY OBAMACARE. Powers are not rights. ```