|
51 | 51 |
|
52 | 52 | """ |
53 | 53 | Given `site1`, `site2` connected by a nearest neighbor bond, |
54 | | -return the bond index and whether it is reversed from the |
55 | | -standard orientation (`site1` on the west/south of `site2`). |
| 54 | +return `(dir, r, c)` where `dir` ∈ {NORTH, EAST, SOUTH, WEST} |
| 55 | +is the direction from `site1` to `site2`. |
| 56 | +`(r, c)` is the position of the source endpoint: |
| 57 | +the west site for x-bonds (`dir == EAST` or `dir == WEST`), |
| 58 | +the south site for y-bonds (`dir == NORTH` or `dir == SOUTH`). |
56 | 59 | """ |
57 | | -function _nn_bondrev(site1::CartesianIndex{2}, site2::CartesianIndex{2}) |
| 60 | +function _nn_bonddir(site1::CartesianIndex{2}, site2::CartesianIndex{2}) |
58 | 61 | diff = site1 - site2 |
59 | | - if diff == CartesianIndex(0, -1) |
| 62 | + if diff == CartesianIndex(0, -1) # site1 west of site2 → site2 to the EAST |
60 | 63 | r, c = site1[1], site1[2] |
61 | | - return (1, r, c), false |
62 | | - elseif diff == CartesianIndex(0, 1) |
63 | | - r, c = site2[1], site2[2] |
64 | | - return (1, r, c), true |
65 | | - elseif diff == CartesianIndex(1, 0) |
| 64 | + return (EAST, r, c) |
| 65 | + elseif diff == CartesianIndex(1, 0) # site1 south of site2 → site2 to the NORTH |
66 | 66 | r, c = site1[1], site1[2] |
67 | | - return (2, r, c), false |
68 | | - elseif diff == CartesianIndex(-1, 0) |
| 67 | + return (NORTH, r, c) |
| 68 | + elseif diff == CartesianIndex(-1, 0) # site1 north of site2 → site2 to the SOUTH |
| 69 | + r, c = site2[1], site2[2] |
| 70 | + return (SOUTH, r, c) |
| 71 | + elseif diff == CartesianIndex(0, 1) # site1 east of site2 → site2 to the WEST |
69 | 72 | r, c = site2[1], site2[2] |
70 | | - return (2, r, c), true |
| 73 | + return (WEST, r, c) |
71 | 74 | else |
72 | 75 | error("`site1` and `site2` are not nearest neighbors.") |
73 | 76 | end |
74 | 77 | end |
75 | 78 |
|
76 | | -function _bond_rotation(x, bonddir::Int, rev::Bool; inv::Bool = false) |
77 | | - return if bonddir == 1 # x-bond |
78 | | - rev ? rot180(x) : x |
79 | | - elseif bonddir == 2 # y-bond |
80 | | - if rev |
81 | | - inv ? rotr90(x) : rotl90(x) |
82 | | - else |
83 | | - inv ? rotl90(x) : rotr90(x) |
84 | | - end |
85 | | - else |
86 | | - error("`bonddir` must be 1 (for x-bonds) or 2 (for y-bonds).") |
| 79 | +""" |
| 80 | +Apply the tensor rotation that maps a bond from orientation `dir_from` |
| 81 | +to orientation `dir_to`, where the directions are one of |
| 82 | +`NORTH`, `EAST`, `SOUTH`, `WEST`. |
| 83 | +""" |
| 84 | +function _rotate_by_dir(x, dir_from::Int, dir_to::Int) |
| 85 | + delta = mod(dir_to - dir_from, 4) |
| 86 | + return if delta == 0 |
| 87 | + x |
| 88 | + elseif delta == 1 |
| 89 | + rotr90(x) |
| 90 | + elseif delta == 2 |
| 91 | + rot180(x) |
| 92 | + else # delta == 3 |
| 93 | + rotl90(x) |
87 | 94 | end |
88 | 95 | end |
89 | | -function _bond_rotation(x::CartesianIndex{2}, bonddir::Int, rev::Bool, unitcell::NTuple{2, Int}) |
90 | | - return if bonddir == 1 |
91 | | - rev ? siterot180(x, unitcell) : x |
92 | | - else |
93 | | - rev ? siterotl90(x, unitcell) : siterotr90(x, unitcell) |
| 96 | + |
| 97 | +""" |
| 98 | +Map a site coordinate from the lattice frame where the bond has orientation |
| 99 | +`dir_from` to the frame where the bond has orientation `dir_to`. |
| 100 | +""" |
| 101 | +function _siterot_by_dir( |
| 102 | + site::CartesianIndex{2}, dir_from::Int, dir_to::Int, |
| 103 | + unitcell::NTuple{2, Int} |
| 104 | + ) |
| 105 | + delta = mod(dir_to - dir_from, 4) |
| 106 | + return if delta == 0 |
| 107 | + site |
| 108 | + elseif delta == 1 |
| 109 | + siterotr90(site, unitcell) |
| 110 | + elseif delta == 2 |
| 111 | + siterot180(site, unitcell) |
| 112 | + else # delta == 3 |
| 113 | + siterotl90(site, unitcell) |
94 | 114 | end |
95 | 115 | end |
96 | 116 |
|
|
0 commit comments