Skip to content

Commit a836f8d

Browse files
authored
import PositionBasis and MomentumBasis (#200)
1 parent 3141ded commit a836f8d

File tree

3 files changed

+1
-77
lines changed

3 files changed

+1
-77
lines changed

src/bases.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import QuantumInterface: Basis, basis, GenericBasis, CompositeBasis,
1+
import QuantumInterface: Basis, basis, GenericBasis, CompositeBasis, ParticleBasis, PositionBasis, MomentumBasis,
22
equal_shape, equal_bases, IncompatibleBases, @samebases, samebases, check_samebases,
33
multiplicable, check_multiplicable, reduced, ptrace, permutesystems

src/particle.jl

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,6 @@
11
import Base: position # TODO is it a good idea to abuse the Base namespace for a different use?
22
using FFTW
33

4-
abstract type ParticleBasis <: Basis end
5-
6-
"""
7-
PositionBasis(xmin, xmax, Npoints)
8-
PositionBasis(b::MomentumBasis)
9-
10-
Basis for a particle in real space.
11-
12-
For simplicity periodic boundaries are assumed which means that
13-
the rightmost point defined by `xmax` is not included in the basis
14-
but is defined to be the same as `xmin`.
15-
16-
When a [`MomentumBasis`](@ref) is given as argument the exact values
17-
of ``x_{min}`` and ``x_{max}`` are due to the periodic boundary conditions
18-
more or less arbitrary and are chosen to be
19-
``-\\pi/dp`` and ``\\pi/dp`` with ``dp=(p_{max}-p_{min})/N``.
20-
"""
21-
struct PositionBasis{X1,X2,T,F} <: ParticleBasis
22-
shape::Vector{T}
23-
xmin::F
24-
xmax::F
25-
N::T
26-
function PositionBasis{X1,X2}(xmin::F, xmax::F, N::T) where {X1,X2,F,T<:Integer}
27-
@assert isa(X1, Real) && isa(X2, Real)
28-
new{X1,X2,T,F}([N], xmin, xmax, N)
29-
end
30-
end
31-
function PositionBasis(xmin::F1, xmax::F2, N) where {F1,F2}
32-
F = promote_type(F1,F2)
33-
return PositionBasis{xmin,xmax}(convert(F,xmin),convert(F,xmax),N)
34-
end
35-
36-
"""
37-
MomentumBasis(pmin, pmax, Npoints)
38-
MomentumBasis(b::PositionBasis)
39-
40-
Basis for a particle in momentum space.
41-
42-
For simplicity periodic boundaries are assumed which means that
43-
`pmax` is not included in the basis but is defined to be the same as `pmin`.
44-
45-
When a [`PositionBasis`](@ref) is given as argument the exact values
46-
of ``p_{min}`` and ``p_{max}`` are due to the periodic boundary conditions
47-
more or less arbitrary and are chosen to be
48-
``-\\pi/dx`` and ``\\pi/dx`` with ``dx=(x_{max}-x_{min})/N``.
49-
"""
50-
struct MomentumBasis{P1,P2,T,F} <: ParticleBasis
51-
shape::Vector{T}
52-
pmin::F
53-
pmax::F
54-
N::T
55-
function MomentumBasis{P1,P2}(pmin::F, pmax::F, N::T) where {T<:Integer,F,P1,P2}
56-
@assert isa(P1, Real) && isa(P2, Real)
57-
new{P1,P2,T,F}([N], pmin, pmax, N)
58-
end
59-
end
60-
function MomentumBasis(pmin::F1, pmax::F2, N) where {F1,F2}
61-
F = promote_type(F1,F2)
62-
return MomentumBasis{pmin,pmax}(convert(F,pmin), convert(F,pmax), N)
63-
end
64-
65-
PositionBasis(b::MomentumBasis) = (dp = (b.pmax - b.pmin)/b.N; PositionBasis(-pi/dp, pi/dp, b.N))
66-
MomentumBasis(b::PositionBasis) = (dx = (b.xmax - b.xmin)/b.N; MomentumBasis(-pi/dx, pi/dx, b.N))
67-
68-
==(b1::PositionBasis, b2::PositionBasis) = b1.xmin==b2.xmin && b1.xmax==b2.xmax && b1.N==b2.N
69-
==(b1::MomentumBasis, b2::MomentumBasis) = b1.pmin==b2.pmin && b1.pmax==b2.pmax && b1.N==b2.N
70-
71-
724
"""
735
gaussianstate([T=ComplexF64,] b::PositionBasis, x0, p0, sigma)
746
gaussianstate([T=ComplexF64,] b::MomentumBasis, x0, p0, sigma)

src/printing.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ end
2020
set_printing(standard_order=false, rounding_tol=1e-17)
2121

2222

23-
function show(stream::IO, x::PositionBasis)
24-
write(stream, "Position(xmin=$(x.xmin), xmax=$(x.xmax), N=$(x.N))")
25-
end
26-
27-
function show(stream::IO, x::MomentumBasis)
28-
write(stream, "Momentum(pmin=$(x.pmin), pmax=$(x.pmax), N=$(x.N))")
29-
end
30-
3123
function show(stream::IO, x::SubspaceBasis)
3224
write(stream, "Subspace(superbasis=$(x.superbasis), states:$(length(x.basisstates)))")
3325
end

0 commit comments

Comments
 (0)