import _ from 'lodash' ; import { IXYOperator } from './interfaces' ; import Vector from './Vector' ; import Operator from './Operator' ; import Dimension from './Dimension' ; import Photons from './Photons' ; import { incoherentLightOperator } from './Elements' ; import { Cx } from './Complex' ; /**
 * For classic, incoherent light:
 * only intensity, not phase or polarization
 */ export default class IncoherentLight { vector : Vector ; param sizeX param sizeY param vector constructor ( vector ) { this . vector = vector ; } param sizeX param sizeY static emptySpace ( sizeX , sizeY ) { const vector = Vector . zeros ( [ Dimension . position ( sizeX , 'x' ) , Dimension . position ( sizeY , 'y' ) , Dimension . direction ( ) ] ) ; return new IncoherentLight ( vector ) ; } /**
     * Dimension x.
     */ get dimX ( ) : Dimension { return this . vector . dimensions [ 0 ] ; } /**
     * Dimension x.
     */ get dimY ( ) : Dimension { return this . vector . dimensions [ 1 ] ; } /**
     * Size x ('width') of the board.
     */ get sizeX ( ) : number { return this . dimX . size ; } /**
     * Size y ('height') of the board.
     */ get sizeY ( ) : number { return this . dimY . size ; } returns copy ( ) { return new IncoherentLight ( this . vector . copy ( ) ) ; } /**
     * Total intensity
     */ get totalIntensity ( ) : number { return this . vector . entries . map ( ( entry ) => entry . value ) . reduce ( ( a , b ) => a . add ( b ) , Cx ( 0 ) ) . re ; } returns normalize ( ) { this . vector = this . vector . mulByReal ( 1 / this . totalIntensity ) ; return this ; } param sizeX param sizeY param posX param posY param dirDirection returns static vectorFromIndicator ( sizeX , sizeY , posX , posY , dir ) { const dimensions = [ Dimension . position ( sizeX , 'x' ) , Dimension . position ( sizeY , 'y' ) , Dimension . direction ( ) ] ; const state = [ posX . toString ( ) , posY . toString ( ) , dir ] ; return Vector . indicator ( dimensions , state ) ; } /**
     * Add one more photon to the state, using  Photons . vectorFromIndicator .
     *
     *  param posX param posY param dir returns addIntensityFromIndicator ( posX , posY , dir , intensity = 1 ) { const newIntensity = IncoherentLight . vectorFromIndicator ( this . sizeX , this . sizeY , posX , posY , dir ) . mulConstant ( Cx ( intensity ) ) ; this . vector = this . vector . add ( newIntensity ) ; return this ; } /**
     * Create a propagator, given the board size. Same as for  Photons . propagator param sizeX param sizeY param yDirMeansDown return An operator, with dimensions [dimX, dimY,  Dimension . direction ].
      static propagator ( sizeX , sizeY , yDirMeansDown = true ) { return Photons . propagator ( sizeX , sizeY , yDirMeansDown ) ; } /**
     * Propagate all particles, using  createPhotonPropagator .
     *  param yDirMeansDown returns propagateBeam ( yDirMeansDown = true ) { const photonPropagator = Photons . propagator ( this . sizeX , this . sizeY , yDirMeansDown ) ; this . vector = photonPropagator . mulVec ( this . vector ) ; return this ; } param sizeX param sizeY param posX param posY param op returns static localizeOperator ( sizeX , sizeY , posX , posY , op ) { const dimX = Dimension . position ( sizeX , 'x' ) ; const dimY = Dimension . position ( sizeY , 'y' ) ; return Operator . outer ( [ Operator . indicator ( [ dimX , dimY ] , [ `${ posX }` , `${ posY }` ] ) , op ] ) ; } param sizeX param sizeY param opsWithPos static interactionOperator ( sizeX , sizeY , opsWithPos ) { const localizedOpsShifted = opsWithPos . map ( ( d ) => { const { x , y , op } = d ; const idDirPol = Operator . identity ( [ Dimension . direction ( ) ] ) ; const shiftedOp = op . sub ( idDirPol ) ; return Photons . localizeOperator ( sizeX , sizeY , { x , y , op : shiftedOp } ) ; } ) ; const dimX = Dimension . position ( sizeX , 'x' ) ; const dimY = Dimension . position ( sizeY , 'y' ) ; return Operator . add ( [ Operator . identity ( [ dimX , dimY , Dimension . direction ( ) ] ) , ... localizedOpsShifted ] ) ; } remark param opsWithPos returns interact ( opsWithPos ) { const interactionOperator = IncoherentLight . interactionOperator ( this . sizeX , this . sizeY , opsWithPos ) ; this . vector = interactionOperator . mulVec ( this . vector ) ; return this ; } static opsWithPosMakeIncoherent ( opsWithPos ) { return opsWithPos . map ( ( { x , y , op } ) => ( { x , y , op : incoherentLightOperator ( op ) , } ) ) ; } param precision returns ketString ( precision = 2 ) { return this . vector . toString ( 'cartesian' , precision , ' + ' , false ) . replace ( /\(/g , '' ) . replace ( / \+0\.0*i\)/g , '' ) ; } }