From f3773ceb9d80d9aab1ae1de2db9c9dbc45b60ab9 Mon Sep 17 00:00:00 2001 From: pixelzoom Date: Fri, 29 Mar 2024 14:54:36 -0600 Subject: [PATCH] proposed fix for incorrect EMF in State wrapper, https://github.com/phetsims/faradays-electromagnetic-lab/issues/149 --- js/transformer/model/Transformer.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/js/transformer/model/Transformer.ts b/js/transformer/model/Transformer.ts index 3fa3d854..7084d34b 100644 --- a/js/transformer/model/Transformer.ts +++ b/js/transformer/model/Transformer.ts @@ -19,6 +19,7 @@ import RangeWithValue from '../../../../dot/js/RangeWithValue.js'; import PickRequired from '../../../../phet-core/js/types/PickRequired.js'; import optionize from '../../../../phet-core/js/optionize.js'; import ConstantDtClock from '../../common/model/ConstantDtClock.js'; +import isSettingPhetioStateProperty from '../../../../tandem/js/isSettingPhetioStateProperty.js'; type SelfOptions = { electromagnetPosition: Vector2; @@ -73,9 +74,11 @@ export default class Transformer extends PhetioObject { // Workaround for https://github.com/phetsims/faradays-electromagnetic-lab/issues/92, to ignore the EMF induced // by switching power supplies. Step the pickup coil twice, so that there is effectively no induced EMF. this.electromagnet.currentSourceProperty.lazyLink( () => { - this.pickupCoil.step( ConstantDtClock.DT ); // EMF may be induced by changing from oldCurrentSource to newCurrentSource. - this.pickupCoil.step( ConstantDtClock.DT ); // No EMF is induced because there is no flux change in newCurrentSource. - assert && assert( this.pickupCoil.emfProperty.value === 0, `unexpected emfProperty.value: ${this.pickupCoil.emfProperty.value}` ); + if ( !isSettingPhetioStateProperty.value ) { + this.pickupCoil.step( ConstantDtClock.DT ); // EMF may be induced by changing from oldCurrentSource to newCurrentSource. + this.pickupCoil.step( ConstantDtClock.DT ); // No EMF is induced because there is no flux change in newCurrentSource. + assert && assert( this.pickupCoil.emfProperty.value === 0, `unexpected emfProperty.value: ${this.pickupCoil.emfProperty.value}` ); + } } ); }