Skip to content

Commit

Permalink
disable pump when container too small, see #256
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Jun 16, 2020
1 parent cfb714d commit 2e88875
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
17 changes: 9 additions & 8 deletions js/common/model/MultipleParticleModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,12 @@ class MultipleParticleModel extends PhetioObject {
this.numMoleculesQueuedForInjectionProperty,
this.isExplodedProperty,
this.maxNumberOfMoleculesProperty,
this.containerHeightProperty,
this.targetNumberOfMoleculesProperty
],
( isPlaying, numberOfMoleculesQueuedForInjection, isExploded, maxNumberOfMoleculesProperty, containerHeight, targetNumberOfMolecules ) => {
( isPlaying, numberOfMoleculesQueuedForInjection, isExploded, maxNumberOfMoleculesProperty, targetNumberOfMolecules ) => {
return isPlaying &&
numberOfMoleculesQueuedForInjection < MAX_MOLECULES_QUEUED_FOR_INJECTION &&
!isExploded &&
( containerHeight / this.particleDiameter ) > this.injectionPointY &&
targetNumberOfMolecules < maxNumberOfMoleculesProperty;
}
);
Expand Down Expand Up @@ -265,13 +263,14 @@ class MultipleParticleModel extends PhetioObject {
// @public, normalized velocity at which lid is moving in y direction
this.normalizedLidVelocityY = 0;

// @protected (read-only) {Vector2} - the location where new molecules are injected, in normalized coordinates
this.injectionPoint = Vector2.ZERO.copy();

// @private, various internal model variables
this.particleDiameter = 1;
this.minModelTemperature = null;
this.residualTime = 0;
this.moleculeInjectionHoldoffTimer = 0;
this.injectionPointX = 0;
this.injectionPointY = 0;
this.heightChangeThisStep = 0;
this.moleculeInjectedThisStep = false;

Expand Down Expand Up @@ -559,8 +558,10 @@ class MultipleParticleModel extends PhetioObject {
this.updateNormalizedContainerDimensions();

// Adjust the injection point based on the new particle diameter. These are using the normalized coordinate values.
this.injectionPointX = CONTAINER_WIDTH / this.particleDiameter * INJECTION_POINT_HORIZ_PROPORTION;
this.injectionPointY = CONTAINER_INITIAL_HEIGHT / this.particleDiameter * INJECTION_POINT_VERT_PROPORTION;
this.injectionPoint.setXY(
CONTAINER_WIDTH / this.particleDiameter * INJECTION_POINT_HORIZ_PROPORTION,
CONTAINER_INITIAL_HEIGHT / this.particleDiameter * INJECTION_POINT_VERT_PROPORTION
);

// Add the atoms and set their initial positions.
this.initializeAtoms( phase );
Expand Down Expand Up @@ -703,7 +704,7 @@ class MultipleParticleModel extends PhetioObject {

// Set the position(s) of the atom(s).
const atomsPerMolecule = this.moleculeDataSet.atomsPerMolecule;
const moleculeCenterOfMassPosition = new Vector2( this.injectionPointX, this.injectionPointY );
const moleculeCenterOfMassPosition = this.injectionPoint.copy();
const moleculeVelocity = new Vector2( xVel, yVel );
const atomPositions = [];
for ( let i = 0; i < atomsPerMolecule; i++ ) {
Expand Down
9 changes: 9 additions & 0 deletions js/phase-changes/PhaseChangesModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import BooleanProperty from '../../../axon/js/BooleanProperty.js';
import DerivedProperty from '../../../axon/js/DerivedProperty.js';
import NumberProperty from '../../../axon/js/NumberProperty.js';
import Range from '../../../dot/js/Range.js';
import Utils from '../../../dot/js/Utils.js';
Expand Down Expand Up @@ -56,6 +57,14 @@ class PhaseChangesModel extends MultipleParticleModel {
range: new Range( MIN_ALLOWABLE_CONTAINER_HEIGHT, MultipleParticleModel.PARTICLE_CONTAINER_INITIAL_HEIGHT )
} );

// @public (read-only) - a derived property that indicates whether the lid is higher than the injection point
this.lidAboveInjectionPointProperty = new DerivedProperty( [ this.containerHeightProperty ], containerHeight => {

// This may appear a little suspect, but the model is designed such that the container height is always reset
// to its max when the particle diameter and injection change, so this can be trusted.
return ( containerHeight / this.particleDiameter ) > this.injectionPoint.y;
} );

// reset the target container height in the event of an explosion
this.isExplodedProperty.lazyLink( isExploded => {
if ( isExploded ) {
Expand Down
4 changes: 3 additions & 1 deletion js/phase-changes/view/PhaseChangesScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,14 @@ function PhaseChangesScreenView( model, isPotentialGraphEnabled, tandem ) {
[
model.isPlayingProperty,
model.isExplodedProperty,
model.lidAboveInjectionPointProperty,
model.maxNumberOfMoleculesProperty,
model.targetNumberOfMoleculesProperty
],
( isPlaying, isExploded, maxNumberOfMoleculesProperty, targetNumberOfMolecules ) => {
( isPlaying, isExploded, lidAboveInjectionPoint, maxNumberOfMoleculesProperty, targetNumberOfMolecules ) => {
return isPlaying &&
!isExploded &&
lidAboveInjectionPoint &&
targetNumberOfMolecules < maxNumberOfMoleculesProperty;
}
);
Expand Down

0 comments on commit 2e88875

Please sign in to comment.