|
1 | 1 | import Base: position # TODO is it a good idea to abuse the Base namespace for a different use? |
2 | 2 | using FFTW |
3 | 3 |
|
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 | | - |
72 | 4 | """ |
73 | 5 | gaussianstate([T=ComplexF64,] b::PositionBasis, x0, p0, sigma) |
74 | 6 | gaussianstate([T=ComplexF64,] b::MomentumBasis, x0, p0, sigma) |
|
0 commit comments