Skip to content

Commit

Permalink
convenience constructor for vacuum OccupationNumberFS
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimbrand committed Feb 1, 2025
1 parent 32174b9 commit aa7a87f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/BitStringAddresses/occupationnumberfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ particles is runtime data, and can be retrieved with `num_particles(address)`.
- `OccupationNumberFS{[M,T]}(onr)`: Construct from collection `onr` with `M` occupation
numbers with type `T`. If unspecified, the type `T` of the occupation numbers is inferred
from the type of the arguments.
- `OccupationNumberFS{M[,T]}(onr)`: Construct a vacuum state with `M` modes. If `T` is
unspecified, `UInt8` is used.
- `OccupationNumberFS(fs::BoseFS)`: Construct from [`BoseFS`](@ref).
- With shortform macro [`@fs_str`](@ref). Specify the number of
significant bits in braces. See example below.
Expand All @@ -24,6 +26,9 @@ true
julia> num_particles(ofs)
6
julia> OccupationNumberFS{5}() # vacuum state with 5 modes
OccupationNumberFS{5, UInt8}(0, 0, 0, 0, 0)
```
"""
struct OccupationNumberFS{M,T<:Unsigned} <: SingleComponentFockAddress{missing,M}
Expand Down Expand Up @@ -54,6 +59,13 @@ function OccupationNumberFS(fs::BoseFS{N,M}) where {N,M}
return OccupationNumberFS{M,select_int_type(N)}(onr(fs))
end

# convenience constructors for vacuum state
function OccupationNumberFS{M,T}() where {M,T}
return OccupationNumberFS(SVector{M,T}(Tuple(zero(T) for _ in 1:M)))
end

OccupationNumberFS{M}() where {M} = OccupationNumberFS{M,UInt8}()

function print_address(io::IO, ofs::OccupationNumberFS{M,T}; compact=false) where {M,T}
if compact
BITS = sizeof(T) * 8
Expand Down

0 comments on commit aa7a87f

Please sign in to comment.