Skip to content

Commit

Permalink
remove explicit interaction type 'none' and use absence of explicit i…
Browse files Browse the repository at this point in the history
…nteractions for this case, see #65
  • Loading branch information
jbphet committed Dec 11, 2024
1 parent acb943c commit 0206d2e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
6 changes: 3 additions & 3 deletions js/photons/model/Mirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export default class Mirror implements TPhotonInteraction {
this.mirrorSurfaceLine = new Line( endpoint1, endpoint2 );
}

/**
* Test for interaction between the provided photon and this mirror.
*/
public testForPhotonInteraction( photon: Photon, dt: number ): Map<PhotonMotionState, PhotonInteractionTestResult> {

const mapOfStatesToInteractions = new Map<PhotonMotionState, PhotonInteractionTestResult>();
Expand All @@ -66,9 +69,6 @@ export default class Mirror implements TPhotonInteraction {
}
} );
}
else {
mapOfStatesToInteractions.set( photonState, { interactionType: 'none' } );
}
} );

return mapOfStatesToInteractions;
Expand Down
25 changes: 12 additions & 13 deletions js/photons/model/PhotonDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ export default class PhotonDetector implements TPhotonInteraction {
} );
}

/**
* Test for interaction between the provided photon and this detector.
*/
public testForPhotonInteraction( photon: Photon, dt: number ): Map<PhotonMotionState, PhotonInteractionTestResult> {

const mapOfStatesToInteractions = new Map<PhotonMotionState, PhotonInteractionTestResult>();
Expand All @@ -103,31 +106,27 @@ export default class PhotonDetector implements TPhotonInteraction {
dt
);

// Assume no interaction until proven otherwise.
let interaction: PhotonInteractionTestResult = { interactionType: 'none' };

// This is where the wave function collapses!
if ( photonIntersectionPoint !== null ) {

// Evaluate the detection result based on the probability of the photon actually being here.
if ( dotRandom.nextDouble() < photonState.probability ) {

// The photon is being absorbed by the detector.
photon.setMotionStateProbability( photonState, 1 );
photonState.probability = 1; // the photon is detected!
interaction = { interactionType: 'absorbed' };
this.detectionCountProperty.value = Math.min( this.detectionCountProperty.value + 1, COUNT_RANGE.max );
this.detectionRateProperty.countEvent();

// Indicate that the photon was absorbed.
mapOfStatesToInteractions.set( photonState, { interactionType: 'absorbed' } );
}
else {

// If the photon is not detected. This state probability goes to 0%, which will make the other state 100%.
// If this photon state does not trigger the detector the associated probability goes to 0%, which will make
// the other state's probability 100%.
photon.setMotionStateProbability( photonState, 0 );
}
}

if ( interaction.interactionType === 'absorbed' ) {
this.detectionCountProperty.value = Math.min( this.detectionCountProperty.value + 1, COUNT_RANGE.max );
this.detectionRateProperty.countEvent();
}

mapOfStatesToInteractions.set( photonState, interaction );
} );

return mapOfStatesToInteractions;
Expand Down
2 changes: 1 addition & 1 deletion js/photons/model/PhotonsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import PhotonsExperimentSceneModel from './PhotonsExperimentSceneModel.js';
type SelfOptions = EmptySelfOptions;
type PhotonsModelOptions = SelfOptions & PickRequired<PhetioObjectOptions, 'tandem'>;

export const PhotonInteractionTypeValues = [ 'none', 'absorbed', 'reflected', 'split' ] as const;
export const PhotonInteractionTypeValues = [ 'absorbed', 'reflected', 'split' ] as const;
export type PhotonInteractionTypes = ( typeof PhotonInteractionTypeValues )[number];
export type PhotonInteractionTestResult = {
interactionType: PhotonInteractionTypes;
Expand Down
15 changes: 7 additions & 8 deletions js/photons/model/PolarizingBeamSplitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export default class PolarizingBeamSplitter implements TPhotonInteraction {
this.polarizingSurfaceLine = new Line( endpoint1, endpoint2 );
}

/**
* Test for photon interactions with the beam splitter.
*/
public testForPhotonInteraction( photon: Photon, dt: number ): Map<PhotonMotionState, PhotonInteractionTestResult> {

const mapOfStatesToInteractions = new Map<PhotonMotionState, PhotonInteractionTestResult>();
Expand All @@ -64,8 +67,6 @@ export default class PolarizingBeamSplitter implements TPhotonInteraction {
dt
);

let interaction: PhotonInteractionTestResult = { interactionType: 'none' };

if ( photonIntersectionPoint !== null ) {

// Calculate the probability of reflection based on the custom angle according to Malus's Law
Expand All @@ -78,20 +79,20 @@ export default class PolarizingBeamSplitter implements TPhotonInteraction {
if ( dotRandom.nextDouble() <= probabilityOfReflection ) {

// The photon is being reflected by the beam splitter. The only direction supported currently is up.
interaction = {
mapOfStatesToInteractions.set( photonState, {
interactionType: 'reflected',
reflectionInfo: {
reflectionPoint: photonIntersectionPoint,
reflectionDirection: UP
}
};
} );
}
}
else {

// This is the quantum case where the photon is split into a superposition of states until observed by one of
// the detectors.
interaction = {
mapOfStatesToInteractions.set( photonState, {
interactionType: 'split',
splitInfo: {
splitPoint: photonIntersectionPoint,
Expand All @@ -106,11 +107,9 @@ export default class PolarizingBeamSplitter implements TPhotonInteraction {
}
]
}
};
} );
}
}

mapOfStatesToInteractions.set( photonState, interaction );
} );

return mapOfStatesToInteractions;
Expand Down
9 changes: 9 additions & 0 deletions js/photons/model/TPhotonInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,14 @@ import { PhotonMotionState } from './PhotonMotionState.js';
import { PhotonInteractionTestResult } from './PhotonsModel.js';

export type TPhotonInteraction = {

/**
* Test for photon interactions with the object that implements this interface. This returns a map of photon states
* to interactions. If a photon state is not in the map, no interaction is detected for that state.
*
* @param photon - The photon that is being tested for interaction.
* @param dt - The time step for the test, in seconds.
* @returns A map of motion states to the results of the interaction tests.
*/
testForPhotonInteraction( photon: Photon, dt: number ): Map<PhotonMotionState, PhotonInteractionTestResult>;
};

0 comments on commit 0206d2e

Please sign in to comment.