@@ -308,6 +308,72 @@ SpinBasis(spinnumber) = SpinBasis(convert(Rational{Int}, spinnumber))
308308
309309Base.:(== )(b1:: SpinBasis , b2:: SpinBasis ) = b1. spinnumber== b2. spinnumber
310310
311+ abstract type ParticleBasis <: Basis end
312+
313+ """
314+ PositionBasis(xmin, xmax, Npoints)
315+ PositionBasis(b::MomentumBasis)
316+
317+ Basis for a particle in real space.
318+
319+ For simplicity periodic boundaries are assumed which means that
320+ the rightmost point defined by `xmax` is not included in the basis
321+ but is defined to be the same as `xmin`.
322+
323+ When a [`MomentumBasis`](@ref) is given as argument the exact values
324+ of ``x_{min}`` and ``x_{max}`` are due to the periodic boundary conditions
325+ more or less arbitrary and are chosen to be
326+ ``-\\ pi/dp`` and ``\\ pi/dp`` with ``dp=(p_{max}-p_{min})/N``.
327+ """
328+ struct PositionBasis{X1,X2,T,F} <: ParticleBasis
329+ shape:: Vector{T}
330+ xmin:: F
331+ xmax:: F
332+ N:: T
333+ function PositionBasis {X1,X2} (xmin:: F , xmax:: F , N:: T ) where {X1,X2,F,T<: Integer }
334+ @assert isa (X1, Real) && isa (X2, Real)
335+ new {X1,X2,T,F} ([N], xmin, xmax, N)
336+ end
337+ end
338+ function PositionBasis (xmin:: F1 , xmax:: F2 , N) where {F1,F2}
339+ F = promote_type (F1,F2)
340+ return PositionBasis {xmin,xmax} (convert (F,xmin),convert (F,xmax),N)
341+ end
342+
343+ """
344+ MomentumBasis(pmin, pmax, Npoints)
345+ MomentumBasis(b::PositionBasis)
346+
347+ Basis for a particle in momentum space.
348+
349+ For simplicity periodic boundaries are assumed which means that
350+ `pmax` is not included in the basis but is defined to be the same as `pmin`.
351+
352+ When a [`PositionBasis`](@ref) is given as argument the exact values
353+ of ``p_{min}`` and ``p_{max}`` are due to the periodic boundary conditions
354+ more or less arbitrary and are chosen to be
355+ ``-\\ pi/dx`` and ``\\ pi/dx`` with ``dx=(x_{max}-x_{min})/N``.
356+ """
357+ struct MomentumBasis{P1,P2,T,F} <: ParticleBasis
358+ shape:: Vector{T}
359+ pmin:: F
360+ pmax:: F
361+ N:: T
362+ function MomentumBasis {P1,P2} (pmin:: F , pmax:: F , N:: T ) where {T<: Integer ,F,P1,P2}
363+ @assert isa (P1, Real) && isa (P2, Real)
364+ new {P1,P2,T,F} ([N], pmin, pmax, N)
365+ end
366+ end
367+ function MomentumBasis (pmin:: F1 , pmax:: F2 , N) where {F1,F2}
368+ F = promote_type (F1,F2)
369+ return MomentumBasis {pmin,pmax} (convert (F,pmin), convert (F,pmax), N)
370+ end
371+
372+ PositionBasis (b:: MomentumBasis ) = (dp = (b. pmax - b. pmin)/ b. N; PositionBasis (- pi / dp, pi / dp, b. N))
373+ MomentumBasis (b:: PositionBasis ) = (dx = (b. xmax - b. xmin)/ b. N; MomentumBasis (- pi / dx, pi / dx, b. N))
374+
375+ == (b1:: PositionBasis , b2:: PositionBasis ) = b1. xmin== b2. xmin && b1. xmax== b2. xmax && b1. N== b2. N
376+ == (b1:: MomentumBasis , b2:: MomentumBasis ) = b1. pmin== b2. pmin && b1. pmax== b2. pmax && b1. N== b2. N
311377
312378"""
313379 SumBasis(b1, b2...)
@@ -399,6 +465,14 @@ function show(stream::IO, x::NLevelBasis)
399465 write (stream, " NLevel(N=$(x. N) )" )
400466end
401467
468+ function show (stream:: IO , x:: PositionBasis )
469+ write (stream, " Position(xmin=$(x. xmin) , xmax=$(x. xmax) , N=$(x. N) )" )
470+ end
471+
472+ function show (stream:: IO , x:: MomentumBasis )
473+ write (stream, " Momentum(pmin=$(x. pmin) , pmax=$(x. pmax) , N=$(x. N) )" )
474+ end
475+
402476function show (stream:: IO , x:: SumBasis )
403477 write (stream, " [" )
404478 for i in 1 : length (x. bases)
0 commit comments