@@ -14,9 +14,14 @@ abstract type Lattice{D,T,AT,NC1,NC2,NW} <: AbstractLattice end
1414# include("1D/1Dlatticevector.jl")
1515# include("1D/1Dlatticematrix.jl")
1616
17- struct Shifted_Lattice{D,TS <: NTuple } <: AbstractLattice
17+ struct Shifted_Lattice{D,Dim } <: AbstractLattice
1818 data:: D
19- shift:: TS
19+ shift:: NTuple{Dim,Int64}
20+
21+ function Shifted_Lattice(data, shift, Dim)
22+ return new{typeof(data),Dim}(data, shift)
23+ end
24+
2025end
2126
2227
@@ -45,22 +50,111 @@ include("LatticeMatrices_core.jl")
4550include(" LinearAlgebras/linearalgebra.jl" )
4651include(" TA/TA.jl" )
4752
48- function get_shift(x:: Shifted_Lattice{Tx} ) where {D,T,AT,NC1,NC2,nw,Tx<: LatticeMatrix{D,T,AT,NC1,NC2,nw} }
53+ function get_shift(x:: Shifted_Lattice{Tx,D } ) where {D,T,AT,NC1,NC2,nw,Tx<: LatticeMatrix{D,T,AT,NC1,NC2,nw} }
4954 return x. shift
5055end
5156
52- function get_shift(x:: Adjoint_Lattice{Shifted_Lattice{Tx}} ) where {D,T,AT,NC1,NC2,nw,Tx<: LatticeMatrix{D,T,AT,NC1,NC2,nw} }
57+ function get_shift(x:: Adjoint_Lattice{Shifted_Lattice{Tx,D }} ) where {D,T,AT,NC1,NC2,nw,Tx<: LatticeMatrix{D,T,AT,NC1,NC2,nw} }
5358 return x. data. shift
5459end
5560
5661
5762
5863
59- function Shifted_Lattice(data:: TD , shift) where {D,T,AT,TD<: Lattice{D,T,AT} }
60- return Shifted_Lattice{typeof(data),typeof(shift)}(data, shift)
64+ # function Shifted_Lattice(data::TD, shift::TS) where {D,T,AT,TD<:Lattice{D,T,AT},TS}
65+ # return Shifted_Lattice{typeof(data),D}(data, shift)
66+ # end
67+
68+
69+
70+ @inline function _as_shift_tuple(shift_in, :: Val{D} ) where {D}
71+ if shift_in isa NTuple{D,Int}
72+ return shift_in
73+ elseif shift_in isa AbstractVector{<: Integer }
74+ @assert length(shift_in) == D " shift length must be $D "
75+ return ntuple(i -> Int(shift_in[i]), D)
76+ elseif shift_in isa Tuple
77+ @assert length(shift_in) == D " shift length must be $D "
78+ return ntuple(i -> Int(shift_in[i]), D)
79+ else
80+ error(" Unsupported shift type: $(typeof(shift_in)) . Provide NTuple{$D ,Int} or Vector{Int}." )
81+ end
6182end
6283
84+ function Shifted_Lattice(data:: TL , shift_in:: TS ) where {
85+ D,T,AT,NC1,NC2,nw,DI,
86+ TL<: LatticeMatrix{D,T,AT,NC1,NC2,nw,DI} ,TS
87+ }
88+ shift = _as_shift_tuple(shift_in, Val(D))
89+
90+ @inbounds begin
91+ isinside = true
92+ for i in 1 : D
93+ s = shift[i]
94+ if (s < - nw) | (s > nw)
95+ isinside = false
96+ break
97+ end
98+ end
99+ if isinside
100+ return Shifted_Lattice(data, shift, D)
101+ end
102+ end
103+
104+ sl0 = similar(data)
105+ sl1 = similar(data)
106+ substitute!(sl0, data)
107+
108+ zeroT = ntuple(_ -> 0 , D)
109+
110+ @inbounds for i in 1 : D
111+ s = shift[i]
112+ if s == 0
113+ continue
114+ end
115+
116+ if s > nw
117+ smallshift = s ÷ nw
118+ step = ntuple(j -> (j == i ? nw : 0 ), D)
119+ for _ in 1 : smallshift
120+ sls = Shifted_Lattice(sl0, step, D)
121+ substitute!(sl1, sls)
122+ substitute!(sl0, sl1)
123+ end
124+ rems = s % nw
125+ step2 = ntuple(j -> (j == i ? rems : 0 ), D)
126+ sls = Shifted_Lattice(sl0, step2, D)
127+ substitute!(sl1, sls)
128+ substitute!(sl0, sl1)
129+
130+ elseif s < - nw
131+ as = - s
132+ smallshift = as ÷ nw
133+ step = ntuple(j -> (j == i ? - nw : 0 ), D)
134+ for _ in 1 : smallshift
135+ sls = Shifted_Lattice(sl0, step, D)
136+ substitute!(sl1, sls)
137+ substitute!(sl0, sl1)
138+ end
139+ rems = - (as % nw)
140+ step2 = ntuple(j -> (j == i ? rems : 0 ), D)
141+ sls = Shifted_Lattice(sl0, step2, D)
142+ substitute!(sl1, sls)
143+ substitute!(sl0, sl1)
144+
145+ else
146+ step = ntuple(j -> (j == i ? s : 0 ), D)
147+ sls = Shifted_Lattice(sl0, step, D)
148+ substitute!(sl1, sls)
149+ substitute!(sl0, sl1)
150+ end
151+ end
152+
153+ zeroshift = ntuple(_ -> 0 , D)
154+ return Shifted_Lattice(sl0, zeroshift, D)
155+ end
63156
157+ #=
64158function Shifted_Lattice(data::TL, shift) where {D,T,AT,NC1,NC2,nw,DI,TL<:LatticeMatrix{D,T,AT,NC1,NC2,nw,DI}}
65159 #set_halo!(data)
66160 #error("dd")
@@ -126,6 +220,7 @@ function Shifted_Lattice(data::TL, shift) where {D,T,AT,NC1,NC2,nw,DI,TL<:Lattic
126220 end
127221 return sl
128222end
223+ =#
129224
130225function get_matrix(a:: T ) where {T<: LatticeMatrix }
131226 return a. A
0 commit comments