Skip to content

Commit

Permalink
Make voltage source internal resistance independent of current, see #245
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Apr 1, 2021
1 parent b7fa22a commit 1d70a71
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 35 deletions.
19 changes: 0 additions & 19 deletions js/CCKCQueryParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,6 @@ const CCKCQueryParameters = window.QueryStringMachine.getAll( {
type: 'flag'
},

// if any battery exceeds its current threshold, increase its resistance and run the solution again.
// see https://github.com/phetsims/circuit-construction-kit-common/issues/245
batteryCurrentThreshold: {
type: 'number',
defaultValue: 4000
},

// See previous comment
batteryInternalResistanceWhenCurrentThresholdExceededOffset: {
type: 'number',
defaultValue: 4E-5
},

// See previous comment
batteryInternalResistanceWhenCurrentThresholdExceededVoltageScaleFactor: {
type: 'number',
defaultValue: 2E-4
},

batteryMinimumResistance: {
type: 'number',
defaultValue: 1E-6
Expand Down
2 changes: 0 additions & 2 deletions js/model/ModifiedNodalAnalysisAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ class ModifiedNodalAnalysisAdapter {
for ( let i = 0; i < circuit.circuitElements.length; i++ ) {
const branch = circuit.circuitElements.get( i );
if ( branch instanceof VoltageSource ) {
branch.passProperty.reset(); // also resets the internalResistance for the first pass computation
resistiveBatteryAdapters.push( new ResistiveBatteryAdapter( circuit, branch ) );
}
else if ( branch instanceof Resistor ||
Expand Down Expand Up @@ -192,7 +191,6 @@ class ModifiedNodalAnalysisAdapter {

resistiveBatteryAdapters.forEach( batteryAdapter => {
if ( Math.abs( circuitResult.getTimeAverageCurrent( batteryAdapter ) ) > CCKCQueryParameters.batteryCurrentThreshold ) {
batteryAdapter.battery.passProperty.value = 2;
batteryAdapter.resistance = batteryAdapter.battery.internalResistanceProperty.value;
needsHelp = true;
}
Expand Down
15 changes: 1 addition & 14 deletions js/model/VoltageSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
* @author Sam Reid (PhET Interactive Simulations)
*/

import DerivedProperty from '../../../axon/js/DerivedProperty.js';
import NumberProperty from '../../../axon/js/NumberProperty.js';
import merge from '../../../phet-core/js/merge.js';
import CCKCQueryParameters from '../CCKCQueryParameters.js';
import circuitConstructionKitCommon from '../circuitConstructionKitCommon.js';
import FixedCircuitElement from './FixedCircuitElement.js';

Expand Down Expand Up @@ -39,19 +37,8 @@ class VoltageSource extends FixedCircuitElement {
// @public {NumberProperty} - the voltage of the battery in volts
this.voltageProperty = new NumberProperty( options.voltage, options.voltagePropertyOptions );

// @public - keeps track of which solve iteration pass is in process, see https://github.com/phetsims/circuit-construction-kit-common/issues/245
this.passProperty = new NumberProperty( 1 );

// @public {Property.<number>} the internal resistance of the battery
this.internalResistanceProperty = new DerivedProperty( [ this.voltageProperty, internalResistanceProperty, this.currentProperty, this.passProperty ],
( voltage, internalResistance, current, pass ) => {

const result = pass === 2 ? CCKCQueryParameters.batteryInternalResistanceWhenCurrentThresholdExceededOffset +
CCKCQueryParameters.batteryInternalResistanceWhenCurrentThresholdExceededVoltageScaleFactor * Math.abs( voltage ) :
internalResistance;
// console.log( `voltage: ${voltage}, internalResistance: ${internalResistance}, current: ${current}, pass: ${pass}, result: ${result}` );
return result;
} );
this.internalResistanceProperty = internalResistanceProperty;

// @public (read-only) {string} - track which way the battery "button" (plus side) was facing the initial state so
// the user can only create a certain number of "left" or "right" batteries from the toolbox.
Expand Down

0 comments on commit 1d70a71

Please sign in to comment.