Closed Nancy-Salpepi closed 1 year ago
@arouinfar can you please test and comment on which behavior is more physically accurate?
Good find @Nancy-Salpepi. My guess is the culprit may be https://github.com/phetsims/circuit-construction-kit-common/issues/967.
@samreid without a doubt the behavior in the published version is more physically accurate.
In rc.1, there is something very strange going on with the way the resistance of the real bulb gets recomputed in response to the resistance changing elsewhere in the circuit. It doesn't make any sense to me that increasing the resistance of the resistor should cause the current to increase, everything else being equal.
Start with this circuit (all components have default values):
Increase the resistance of the resistor gradually until you reach the max. The current will increase and then decrease, reaching a max of 7.85 A at 46 ohms. At the max resistance of 120 ohms, the current is still higher than when you started, 6.00 A vs. 5.34 A.
I think I found the issue in the physics calculations here. The LTA is first using the REAL_BULB_COLD_RESISTANCE to estimate the voltage across the real bulb, then doing one more iteration using this voltage to find the new resistance of the real bulb, and solving the circuit with this resistance. However, in both of the examples @arouinfar showed above, the voltage across the real bulb would be significantly different than the initial value used by the LTA to calculate its resistance.
One option that I can see here would be to increase the number of iterations used to find the resistance of the real bulb. Each loop should get closer to the actual steady-state value, and we can explore how much this result fluctuates based on the number of iterations. Thoughts @samreid @arouinfar?
Note: I was able to calculate current values consistent with the images above using the following equation from the LTA resistorAdapter.resistance = LightBulb.REAL_BULB_COLD_RESISTANCE + 3 * V / logWithBase( V + 2, 2 );
, with V as the voltage across the real bulb if its resistance was REAL_BULB_COLD_RESISTANCE. The circuit behavior is consistent with all LTA calculations as far as I can see.
I created a patch that appears to solve this issue and get the real bulbs extremely close to their ideal behavior, while still avoiding #967. WebStorm is flagging a no-loop-func TS error, but I think @samreid and I can go over how to get around this.
Confirmed that the real bulb resistance calculcation approaches the correct value with each iteration. The screenshot below shows the logged resistance of the real bulb through 20 LTA iterations in a single frame:
@samreid and I will work on commiting the above patch and send over to @arouinfar for testing in comparison to the current version of the live sim.
@samreid and I investigated this further and found that the published version of the sim also exhibits the behavior that @Nancy-Salpepi and @arouinfar described above. Commit https://github.com/phetsims/circuit-construction-kit-common/commit/b11aeb34eeec7cf56a714474eb6d261ff6a41fee solves the issue and is ready for review.
@arouinfar can you confirm that the updated behavior is correct, and also that the published sim exhibits the same issues as described above?
Code review looks good to me, thanks! @arouinfar if everything looks good, please mark as ready-for-cherry-pick.
Looks good to me too! I made sure to text with extreme batteries, extreme resistors, and long wires with varying resistivity.
For the QA team, please check the cases in the top comment to see that it behaves like "published".
This looks good in rc.3! Closing.
Test device MacBook Air M1 chip
Operating System 13.2.1
Browser Safari/chrome
Problem description For https://github.com/phetsims/qa/issues/908, with the real bulb, regular resistor and high voltage battery, as I increase the resistance, the current increases.
Steps to reproduce
This is different than published.
Visuals