Skip to content

Commit

Permalink
Fix span for sum of disjoint fields (#17)
Browse files Browse the repository at this point in the history
* Fix timeaxis for zero-length intervals

* Fix span for sum of disjoint fields

* Bump version
  • Loading branch information
jagot authored Oct 6, 2021
1 parent c6f61b5 commit 626fcd1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ElectricFields"
uuid = "2f84ce32-9bb1-11e8-0d9f-3dce90a4beca"
authors = ["Stefanos Carlström <[email protected]>"]
version = "0.1.3"
version = "0.1.4"

[deps]
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
Expand Down
6 changes: 5 additions & 1 deletion src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ vector_potential(f::SumField, t::Number) =

polarization(f::SumField) = polarization(f.a)

span(f::SumField) = span(f.a) span(f.b)
function span(f::SumField)
sa = span(f.a)
sb = span(f.b)
min(sa.left,sb.left)..max(sa.right,sb.right)
end
steps(f::SumField, ndt::Int) = steps(f, ndt/min(austrip.(period.((f.a,f.b)))...))

for fun in [:wavelength, :period, :frequency, :wavenumber, :fundamental, :photon_energy]
Expand Down
7 changes: 4 additions & 3 deletions src/time_axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ frequency `fs`.
"""
function timeaxis(f::AbstractField, fs::Number=default_sampling_frequency(f))
num_steps = steps(f, fs)
if num_steps > 1
range(span(f), length=num_steps)
s = span(f)
if num_steps > 1 || s.left == s.right
range(s, length=num_steps)
else
# This hack is mainly useful for calculations where exactly
# one time step should be taken, (b-a) becomes the step
# length.
a,b = endpoints(span(f))
a,b = endpoints(s)
a:(b-a):a
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@
Z = X + delay(Y, 3/2π)

@test field_amplitude(Z, 4.0) field_amplitude(X, 4.0) + field_amplitude(Y, 4.0 - 3/2π)

W = X + delay(Y, 35.0)
@test span(W) == span(X).left..(span(Y).right+35.0)
end

@testset "Padded fields" begin
Expand Down
7 changes: 7 additions & 0 deletions test/field_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@
@test photon_energy(F) == 2π

@test dimensions(F) == 1

@field(Fzero) do
I₀ = 4.0
tmax = 0.0
kind = :constant
end
@test timeaxis(Fzero) == range(0, stop=0, length=0)
end

@testset "Ramps" begin
Expand Down

2 comments on commit 626fcd1

@jagot
Copy link
Owner Author

@jagot jagot commented on 626fcd1 Oct 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/46195

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.4 -m "<description of version>" 626fcd1beebf472487f11cd588661e2d5303de7d
git push origin v0.1.4

Please sign in to comment.