Skip to content

Commit

Permalink
clean up logging of NumberProperty values, #58
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Malley <[email protected]>
  • Loading branch information
pixelzoom committed Jun 20, 2018
1 parent 6b2d887 commit 3b7e3e3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion js/common/model/SingleSpringSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define( function( require ) {
// Components of the system

// @public spring
this.spring = new Spring( 'singleSpring', _.extend( {}, springOptions, {
this.spring = new Spring( _.extend( {}, springOptions, {
tandem: tandem.createTandem( 'spring' )
} ) );
assert && assert( this.spring.displacementProperty.get() === 0 ); // spring is at equilibrium
Expand Down
12 changes: 7 additions & 5 deletions js/common/model/Spring.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ define( function( require ) {
var NumberIO = require( 'ifphetio!PHET_IO/types/NumberIO' );

/**
* @param {string} logName - name that appears in log messages
* @param {Object} [options]
* @constructor
*/
function Spring( logName, options ) {
function Spring( options ) {

var self = this;

options = _.extend( {

// name that appears in log messages
logName: null,

// {number} x location of the left end of the spring, units = m
left: 0,

Expand Down Expand Up @@ -151,11 +153,11 @@ define( function( require ) {

// log each PhET-iO instrumented NumberProperty value when it changes
phet.log && this.appliedForceProperty.link(
function( appliedForce ) { phet.log( logName + ' appliedForce=' + appliedForce ); } );
function( appliedForce ) { phet.log( options.logName + ' appliedForce=' + appliedForce ); } );
phet.log && this.springConstantProperty.link(
function( springConstant ) { phet.log( logName + ' springConstant=' + springConstant ); } );
function( springConstant ) { phet.log( options.logName + ' springConstant=' + springConstant ); } );
phet.log && this.displacementProperty.link(
function( displacement ) { phet.log( logName + ' displacement=' + displacement ); } );
function( displacement ) { phet.log( options.logName + ' displacement=' + displacement ); } );

//------------------------------------------------
// Derived properties
Expand Down
8 changes: 6 additions & 2 deletions js/energy/model/EnergyModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ define( function( require ) {
* @constructor
*/
function EnergyModel( tandem ) {
this.system = new SingleSpringSystem( tandem.createTandem( 'system' ), {

var springOptions = {
logName: 'spring',
springConstantRange: new RangeWithValue( 100, 400, 100 ), // units = N/m
displacementRange: new RangeWithValue( -1, 1, 0 ) // units = m
} );
};

this.system = new SingleSpringSystem( tandem.createTandem( 'system' ), springOptions );
}

hookesLaw.register( 'EnergyModel', EnergyModel );
Expand Down
6 changes: 4 additions & 2 deletions js/intro/model/IntroModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ define( function( require ) {
};

// @public
this.system1 = new SingleSpringSystem( tandem.createTandem( 'system1' ), springOptions );
this.system2 = new SingleSpringSystem( tandem.createTandem( 'system2' ), springOptions );
this.system1 = new SingleSpringSystem( tandem.createTandem( 'system1' ),
_.extend( {}, springOptions, { logName: 'spring1' } ) );
this.system2 = new SingleSpringSystem( tandem.createTandem( 'system2' ),
_.extend( {}, springOptions, { logName: 'spring2' } ) );
}

hookesLaw.register( 'IntroModel', IntroModel );
Expand Down
9 changes: 6 additions & 3 deletions js/systems/model/ParallelSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ define( function( require ) {
// Components of the system

// @public
this.topSpring = new Spring( 'topSpring', {
this.topSpring = new Spring( {
logName: 'topSpring',
left: 0, // x location of the left end of the spring, units = m
equilibriumLength: 1.5, // length of the spring at equilibrium, units = m
springConstantRange: new RangeWithValue( 200, 600, 200 ), // range and initial value of k1, units = N/m
Expand All @@ -56,7 +57,8 @@ define( function( require ) {
} );

// @public bottom spring, in parallel with top spring, with identical configuration
this.bottomSpring = new Spring( 'bottomSpring', {
this.bottomSpring = new Spring( {
logName: 'bottomSpring',
left: this.topSpring.leftProperty.get(),
equilibriumLength: this.topSpring.equilibriumLength,
springConstantRange: this.topSpring.springConstantRange,
Expand All @@ -73,7 +75,8 @@ define( function( require ) {
'top and bottom springs must have same equilibrium position' );

// @public the single spring that is equivalent to the 2 springs in parallel
this.equivalentSpring = new Spring( 'equivalentSpring', {
this.equivalentSpring = new Spring( {
logName: 'equivalentSpring',
left: this.topSpring.leftProperty.get(),
equilibriumLength: this.topSpring.equilibriumLength,
// keq = k1 + k2
Expand Down
9 changes: 6 additions & 3 deletions js/systems/model/SeriesSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ define( function( require ) {
// Components of the system

// @public left spring
this.leftSpring = new Spring( 'leftSpring', {
this.leftSpring = new Spring( {
logName: 'leftSpring',
left: 0, // x location of the left end of the spring, units = m
equilibriumLength: 0.75, // length of the spring at equilibrium, units = m
springConstantRange: new RangeWithValue( 200, 600, 200 ), // range and initial value of k1, units = N/m
Expand All @@ -54,7 +55,8 @@ define( function( require ) {
} );

// @public right spring, in series with the left spring, with identical configuration
this.rightSpring = new Spring( 'rightSpring', {
this.rightSpring = new Spring( {
logName: 'rightSpring',
left: this.leftSpring.rightProperty.get(), // attached to the right end of the left spring
equilibriumLength: this.leftSpring.equilibriumLength,
springConstantRange: this.leftSpring.springConstantRange,
Expand All @@ -64,7 +66,8 @@ define( function( require ) {
} );

// @public the single spring that is equivalent to the 2 springs in series
this.equivalentSpring = new Spring( 'equivalentSpring', {
this.equivalentSpring = new Spring( {
logName: 'equivalentSpring',
left: this.leftSpring.leftProperty.get(),
equilibriumLength: this.leftSpring.equilibriumLength + this.rightSpring.equilibriumLength,
// keq = 1 / ( 1/k1 + 1/k2 )
Expand Down

0 comments on commit 3b7e3e3

Please sign in to comment.