Skip to content

Commit

Permalink
added polariations and adjusted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe Hernandez Acosta committed Nov 1, 2023
1 parent b62b8b9 commit e0975ae
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 24 deletions.
4 changes: 3 additions & 1 deletion src/QEDfields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ end
export AbstractBackgroundField, AbstractPulsedPlaneWaveField
export reference_momentum, domain, phase_duration, pulse_envelope, amplitude, generic_spectrum

export polarization_vector

include("interfaces/background_field_interface.jl")
include("polarisation.jl")
include("polarization.jl")

end
2 changes: 1 addition & 1 deletion src/interfaces/background_field_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ end
# amplitude functions

function _amplitude(field::AbstractPulsedPlaneWaveField, pol::AbstractDefinitePolarization, phi::Real)
return _oscillator(pol,phi)*_pulse_envelope(field,phi)
return oscillator(pol,phi)*_pulse_envelope(field,phi)
end

function _amplitude(field::AbstractPulsedPlaneWaveField, pol::AbstractDefinitePolarization, phi::AbstractVector{T}) where T<:Real
Expand Down
21 changes: 0 additions & 21 deletions src/polarisation.jl

This file was deleted.

21 changes: 21 additions & 0 deletions src/polarization.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#################
# polarization vectors
#
# In this file, we provide an extension of the Polarizations of Photons from
# QEDbase to define polarization states of background fields
################
#
# TODO:
# * write doc strings
# * implement elliptical/circular polarisation

@inline polarization_vector(pol::AbstractDefinitePolarization, mom) = base_state(Photon(),Incoming(), mom, pol)

@inline oscillator(::PolX, x) = cos(x)
@inline oscillator(::PolY, x) = sin(x)
@inline function oscillator(::AbstractIndefinitePolarization,x)
sincos_res = sincos(x)
@inbounds cossin_res = (sincos_res[2], sincos_res[1])
return cossin_res
end

15 changes: 14 additions & 1 deletion test/downstream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ import QEDbase
@testset "Integration: QEDbase" begin

QEDbase_exports = names(QEDbase)
@test :SFourMomentum in QEDbase_exports

@testset "General" begin
@test :SFourMomentum in QEDbase_exports
@test :base_state in QEDbase_exports
end

@testset "Polarizations" begin
@test :PolarizationX in QEDbase_exports
@test :PolX in QEDbase_exports
@test :PolarizationY in QEDbase_exports
@test :PolY in QEDbase_exports
@test :AllPolarization in QEDbase_exports
@test :AllPol in QEDbase_exports
end
end

29 changes: 29 additions & 0 deletions test/polarization.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

using QEDbase
using QEDfields
using Random
using IntervalSets

RNG = MersenneTwister(137)
ATOL = eps()
RTOL = sqrt(eps())

RND_MOM = SFourMomentum(rand(RNG,4))
POL_SET = [PolX(), PolY()]

@testset "polarization vectors" begin
@testset "$mom" for mom in [SFourMomentum(1,0,0,1),RND_MOM]
@testset "single $pol" for pol in POL_SET
pol_vec = polarization_vector(pol,mom)
@test isapprox(pol_vec*pol_vec, -one(eltype(pol_vec)), atol = ATOL, rtol = RTOL)
@test isapprox(pol_vec*mom, zero(eltype(mom)), atol = ATOL, rtol = RTOL)
end

@testset "both polarizations" begin
pol_vec1 = polarization_vector(PolX(),mom)
pol_vec2 = polarization_vector(PolY(),mom)

@test isapprox(pol_vec1*pol_vec2, zero(eltype(pol_vec1)), atol = ATOL, rtol = RTOL)
end
end
end
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ end
include("interfaces/background_field_interface.jl")
end

@time @safetestset "polarization" begin
include("polarization.jl")
end

0 comments on commit e0975ae

Please sign in to comment.