Skip to content

Commit

Permalink
Adding tandem to the particles, see #63
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Nov 22, 2024
1 parent 2e31e9e commit 4d68347
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
16 changes: 11 additions & 5 deletions js/spin/model/ParticleSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import dotRandom from '../../../../dot/js/dotRandom.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import { BlockingMode } from './BlockingMode.js';
import { ParticleWithSpin } from './ParticleWithSpin.js';
Expand Down Expand Up @@ -37,18 +38,23 @@ export class ParticleSystem {
private fractionalEmissionAccumulator = 0;

public constructor(
model: SpinModel
model: SpinModel,
tandem: Tandem
) {

this.model = model;

// Create all particles that will be used in the experiment. It works better for phet-io if these are created at
// construction time and activated and deactivated as needed, rather than creating and destroying them.
this.singleParticles = _.times( MAX_NUMBER_OF_SINGLE_PARTICLES, () => {
return new ParticleWithSpin( Vector2.ZERO );
const singleParticlesTandem = tandem.createTandem( 'singleParticles' );
const multipleParticlesTandem = tandem.createTandem( 'multipleParticles' );
this.singleParticles = _.times( MAX_NUMBER_OF_SINGLE_PARTICLES, index => {
const particleTandem = singleParticlesTandem.createTandem( 'particle' + index );
return new ParticleWithSpin( Vector2.ZERO, particleTandem );
} );
this.multipleParticles = _.times( MAX_NUMBER_OF_MULTIPLE_PARTICLES, () => {
return new ParticleWithSpin( new Vector2( PARTICLE_RAY_WIDTH * ( dotRandom.nextDouble() * 2 - 1 ), PARTICLE_RAY_WIDTH * ( dotRandom.nextDouble() * 2 - 1 ) ) );
this.multipleParticles = _.times( MAX_NUMBER_OF_MULTIPLE_PARTICLES, index => {
const particleTandem = multipleParticlesTandem.createTandem( 'particle' + index );
return new ParticleWithSpin( new Vector2( PARTICLE_RAY_WIDTH * ( dotRandom.nextDouble() * 2 - 1 ), PARTICLE_RAY_WIDTH * ( dotRandom.nextDouble() * 2 - 1 ) ), particleTandem );
} );

}
Expand Down
15 changes: 11 additions & 4 deletions js/spin/model/ParticleWithSpin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import Vector2Property from '../../../../dot/js/Vector2Property.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import quantumMeasurement from '../../quantumMeasurement.js';

export class ParticleWithSpin {
Expand All @@ -34,10 +35,16 @@ export class ParticleWithSpin {
public velocityProperty: Vector2Property;
public speed = 1;

public constructor( private readonly offset: Vector2 ) {
this.activeProperty = new BooleanProperty( false );
this.positionProperty = new Vector2Property( Vector2.ZERO );
this.velocityProperty = new Vector2Property( Vector2.ZERO );
public constructor( private readonly offset: Vector2, tandem: Tandem ) {
this.activeProperty = new BooleanProperty( false, {
tandem: tandem.createTandem( 'activeProperty' )
} );
this.positionProperty = new Vector2Property( Vector2.ZERO, {
tandem: tandem.createTandem( 'positionProperty' )
} );
this.velocityProperty = new Vector2Property( Vector2.ZERO, {
tandem: tandem.createTandem( 'velocityProperty' )
} );

this.startPosition = Vector2.ZERO;
this.endPosition = new Vector2( 1, 0 );
Expand Down
2 changes: 1 addition & 1 deletion js/spin/model/SpinModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class SpinModel implements TModel {

this.particleSourceModel = new ParticleSourceModel( new Vector2( -0.5, 0 ), providedOptions.tandem.createTandem( 'particleSourceModel' ) );

this.particleSystem = new ParticleSystem( this );
this.particleSystem = new ParticleSystem( this, providedOptions.tandem );

this.derivedSpinStateProperty = new DerivedProperty(
[
Expand Down

0 comments on commit 4d68347

Please sign in to comment.