Closed Nancy-Salpepi closed 1 year ago
Since the realistic bulb resistance is a function of the current, it seems there is some hysteresis in the system. In time step T0, there is R0 resistance which causes Current I0. The changed current causes the resistance to become R1 in the next time step, which changes the current again. The relevant code for the light bulb resistance is here: https://github.com/phetsims/circuit-construction-kit-common/blob/28f65baf912836279c52f483b5aaeff81d7070d6/js/model/analysis/LinearTransientAnalysis.ts#L158-L163
Is this to be expected? Do we need to try to circumvent the hysteresis? Or just document it? @arouinfar or @matthew-blackman please advise.
@samreid, @zepumph and I agree that this issue warrants a collaborative effort, since it may result in some deep-level changes to the model.
While discussing this issue, the question came up as to whether this could be fixed by implementing SPICE. Tagging the issue here to reopen this discussion if we move ahead with SPICE migration https://github.com/phetsims/circuit-construction-kit-common/issues/228
@matthew-blackman and @zepumph and I investigated this. We primarily tried adding a window for smoothing the resistance values of the real bulb. But we were still able to create situations where there was a fluctuation in the readouts. The smoothing window didn't seem to move the fluctuation as far out as we expected, so we aren't sure if we implemented it correctly or if there is a flaw in that logic. We would like to discuss ideas with @arouinfar for how to proceed.
@matthew-blackman also recommends one more idea: Computing the bulb resistance once based on the topology of the circuit and what it is connected to, but only updating it once.
UPDATE: We also saw a former algorithm that used to run one solution with the cold value to determine the operating value. Then runs the circuit solution again with the operating value. We reverted that in https://github.com/phetsims/circuit-construction-kit-common/commit/040a20eb083b74756899f54a47457e90c33b2a3b, possibly (though it's unclear that was working as we expect). More details about non-ohmic behavior and oscillation in https://github.com/phetsims/circuit-construction-kit-common/issues/10
I explored the following code this morning in LinearTransitAnalysis:
const dI = circuitResult.getFinalState().ltaSolution!.getCurrent( resistorAdapter );
const newResistance = 10 + 10 * Math.abs( dI );
circuitElement.resistanceProperty.value += 0.001 * ( newResistance - resistorAdapter.resistance );
resistorAdapter.resistance = circuitElement.resistanceProperty.value;
Setting the resistance of the real bulb based on the current through it doesn't appear to affect this issue, but adding the "drag" to the resistance change with the line circuitElement.resistanceProperty.value += 0.001 * ( newResistance - resistorAdapter.resistance );
appears to have the same affect as the RunningAverage, but with less code.
A major piece of evidence is the fact that bumping the 'Wire Resistivity' up even slightly from the minimum value has a huge effect (factor of 10^6 or more) on the current fluctuation. Could this be a deeper issue within the LTA?
I believe I have found a viable solution that does not impact any other behavior in either screen.
Setting the minimum wire resistivity to 1E-7 (was originally 1E-10) causes the fluctuations in the real bulb to be undetectable by any sensors or values displays. The rest of the circuit behavior is unchanged in my testing (eg the voltage across all wires is still 0.000 V when the resistivity is set to 'tiny').
This appears to be a workable and low-cost solution. @samreid and @zepumph let's discuss if this is viable for the current RC. We could implement a more robust solution in the future with SPICE, but if this works then I think it's a reasonable stopgap fix for the PhET-iO release.
We would like to discuss with @arouinfar before moving ahead with possible options.
Patch for discussion:
@samreid's patch above appears to fix the fluctuation issue entirely. @arouinfar and I will investigate to confirm that the real bulb's current-voltage curve matches the intended logarithmic behavior. If the IV curve looks good, we believe that this issue is nearing completion.
@samreid and I tested the above patch and completed the following tests: 1) We compared the behavior to production - it matches perfectly 2) We plotted I vs V for a real bulb to confirm logarithmic relationship
Since the updated behavior does not fluctuate and matches the desired behavior, we agree that this issue can be closed after documenting the updates to LinearTransitAnalysis.
@arouinfar this is looking good on my end. Feel free to close this issue if it looks good to you.
@samreid @matthew-blackman looks great! I no longer see instability in the real bulb's currentProperty
and I confirmed we are maintaining a logarithmic relationship between I and V.
Test device Dell and MacBook Air
Operating System Win10 and macOS 13.1
Browser FF and Safari
Problem description For https://github.com/phetsims/qa/issues/900, when a circuit is built with an extreme resistor and high voltage battery, the current and voltage can both fluctuate. EDIT: With 'Values' checked, I also see the Real Bulb value fluctuate.
This isn't seen in published.
Steps to reproduce
Visuals
https://user-images.githubusercontent.com/87318828/219471534-36fec864-782c-447f-8e0f-00b2e04c3a6b.mp4