Skip to content

Commit

Permalink
Fixing the update of particle rays, see #53
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Nov 1, 2024
1 parent 1620d31 commit 22dd1bd
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions js/spin/model/SpinModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ export default class SpinModel implements TModel {
Multilink.multilink(
[
this.currentExperimentProperty,
this.particleSourceModel.sourceModeProperty
this.particleSourceModel.sourceModeProperty,
this.particleSourceModel.particleAmmountProperty,
this.particleSourceModel.spinStateProperty
],
( experiment, sourceMode ) => {
( experiment, sourceMode, particleAmmount ) => {
this.particleRays.reset();
this.particleRays.isShortExperiment = experiment.isShortExperiment;
this.particleRays.updateExperiment();
Expand All @@ -167,38 +169,27 @@ export default class SpinModel implements TModel {
this.measurementLines.forEach( line => line.measurementStateProperty.reset() );

this.singleParticles.forEach( particle => particle.reset() );
}
);

this.particleSourceModel.particleAmmountProperty.link( particleAmmount => {
updateProbabilities( particleAmmount );
} );

this.singleParticles.forEach( particle => particle.reset() );

this.currentExperimentProperty.link( experiment => {
this.singleParticles.forEach( particle => particle.reset() );

this.sternGerlachs.forEach( ( SternGerlach, index ) => {
if ( experiment.experimentSetting.length > index ) {
// TODO: Should visibility be only handled via the View? https://github.com/phetsims/quantum-measurement/issues/53
SternGerlach.isVisibleProperty.set( experiment.experimentSetting[ index ].active );
SternGerlach.isZOrientedProperty.set( experiment.experimentSetting[ index ].isZOriented );
}
else {
SternGerlach.isVisibleProperty.set( false );
}
} );

// Set the probabilities of the experiment. In the continuous case, this immediately alters the shown rays
// In the single case, this prepares the probabilities for the particle that will be shot
this.prepare();
this.sternGerlachs.forEach( ( SternGerlach, index ) => {
if ( experiment.experimentSetting.length > index ) {
// TODO: Should visibility be only handled via the View? https://github.com/phetsims/quantum-measurement/issues/53
SternGerlach.isVisibleProperty.set( experiment.experimentSetting[ index ].active );
SternGerlach.isZOrientedProperty.set( experiment.experimentSetting[ index ].isZOriented );
}
else {
SternGerlach.isVisibleProperty.set( false );
}
} );

updateProbabilities( this.particleSourceModel.particleAmmountProperty.value );
} );
// Set the probabilities of the experiment. In the continuous case, this immediately alters the shown rays
// In the single case, this prepares the probabilities for the particle that will be shot
this.prepare();

this.particleSourceModel.spinStateProperty.link( () => {
this.prepare();
} );
updateProbabilities( particleAmmount );
}
);

// Find the first inactive single particle and activate it
this.particleSourceModel.currentlyShootingParticlesProperty.link( shooting => {
Expand Down

0 comments on commit 22dd1bd

Please sign in to comment.