Skip to content

Commit

Permalink
Implemented rotation of fields, post facto
Browse files Browse the repository at this point in the history
  • Loading branch information
jagot committed Aug 1, 2023
1 parent 045c895 commit 0913303
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 12 deletions.
13 changes: 12 additions & 1 deletion src/field_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,11 @@ Base.convert(::Type{<:TransverseField}, f::LinearField) =
envelope(f), f.I₀, f.E₀, f.A₀,
I, f.params)

rotate(f::TransverseField, R) =
TransverseField(f.carrier, f.env,
f.I₀, f.E₀, f.A₀,
compute_rotation(R*f.R), f.params)

# * Linearly polarized transverse field

@doc raw"""
Expand Down Expand Up @@ -748,6 +753,9 @@ phase_shift(f::LinearTransverseField, δϕ) =

time_integral(f::LinearTransverseField) = time_integral(envelope(f))

rotate(f::LinearTransverseField, R) =
LinearTransverseField(f.linear_field, compute_rotation(R*f.R))

# * Constant field

@doc raw"""
Expand Down Expand Up @@ -1006,6 +1014,8 @@ transverse_field(::LinearPolarization, f) = LinearTransverseField(f)
transverse_field(::ArbitraryPolarization, f) = f
transverse_field(f) = transverse_field(polarization(f), f)

rotate(f, R) = rotate(transverse_field(f), R)

# * Exports

export LinearPolarization, ArbitraryPolarization, polarization,
Expand All @@ -1020,4 +1030,5 @@ export LinearPolarization, ArbitraryPolarization, polarization,
params, dimensions,
phase_shift, phase,
field_amplitude_spectrum, vector_potential_spectrum,
transverse_field
transverse_field,
rotate, rotation_matrix
2 changes: 2 additions & 0 deletions src/rotations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ function rotation_axis(R::AbstractMatrix)
i = argmin(abs.(ee.values .- 1))
normalize(real(ee.vectors[:,i]))
end

export rotation_angle, rotation_axis, rotation_matrix
1 change: 1 addition & 0 deletions test/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ test_addition(A, B) = test_addition(polarization(A+B), A, B)
test_addition(C, D)
test_addition(A, CpD)
test_addition(ApB, CpD)
test_addition(ApB, rotate(CpD, [1 0 0; 0 1 1; 0 -1 1]))

ApBpCpD = ApB + CpD

Expand Down
56 changes: 45 additions & 11 deletions test/field_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
– Uₚ = 0.0253 Ha = 689.2724 meV => α = 0.1013 Bohr = 5.3617 pm"""
end

@test ElectricFields.rotation_matrix(F) == Matrix(I, 3, 3)
@test rotation_matrix(F) == Matrix(I, 3, 3)

t = [0.4, 0.5]
for fun in (vector_potential, field_amplitude, intensity)
Expand Down Expand Up @@ -119,9 +119,9 @@
– Uₚ = 0.0507 Ha = 1.3785 eV => α = 0.1433 Bohr = 7.5826 pm"""
end

@test ElectricFields.rotation_matrix(F) [1/√2 -1/√2 0
1/√2 1/√2 0
0 0 1]
@test rotation_matrix(F) [1/√2 -1/√2 0
1/√2 1/√2 0
0 0 1]

t = [0.4, 0.5]
for fun in (vector_potential, field_amplitude, intensity)
Expand Down Expand Up @@ -333,7 +333,7 @@
end
end

@testset "Conversion to transverse fields" begin
@testset "Various transverse fields" begin
@field(A) do
λ = 800u"nm"
I₀ = 1e13u"W/cm^2"
Expand Down Expand Up @@ -370,12 +370,46 @@
ApB = A+B
CpD = C+D

tA = transverse_field(A)
@test tA isa ElectricFields.TransverseField
@test transverse_field(B) === B
@test transverse_field(ApB) === ApB
@testset "Conversion to transverse fields" begin
tA = transverse_field(A)
@test tA isa ElectricFields.TransverseField
@test transverse_field(B) === B
@test transverse_field(ApB) === ApB

tCpD = transverse_field(CpD)
@test tCpD isa ElectricFields.LinearTransverseField
tCpD = transverse_field(CpD)
@test tCpD isa ElectricFields.LinearTransverseField
end

@testset "Rotation of fields" begin
R = [1 0 0; 0 0 1; 0 1 0]

rA = rotate(A, R)
@test rA isa ElectricFields.TransverseField
@test rotation_matrix(rA) R
tA = timeaxis(A)
FA = field_amplitude(A, tA)
FrA = field_amplitude(rA, tA)
@test FrA[:,2] FA
@test FrA[:,3] zeros(length(tA)) atol=1e-14

rB = rotate(B, R)
@test rB isa ElectricFields.TransverseField
@test rotation_matrix(rB) R
tB = timeaxis(B)
FB = field_amplitude(B, tB)
FrB = field_amplitude(rB, tB)
@test FrB[:,1] FB[:,1]
@test FrB[:,2] FB[:,3]
@test FrB[:,3] zeros(length(tB)) atol=1e-14

rCpD = rotate(CpD, R)
@test rCpD isa ElectricFields.LinearTransverseField
@test rotation_matrix(rCpD) R
tCpD = timeaxis(CpD)
FCpD = field_amplitude(CpD, tCpD)
FrCpD = field_amplitude(rCpD, tCpD)
@test FrCpD[:,2] FCpD
@test FrCpD[:,3] zeros(length(tCpD)) atol=1e-14
end
end
end

0 comments on commit 0913303

Please sign in to comment.