1use crate::gamma::*;
4use crate::{CMat, Model, c64, combine};
5use caroli_lattice::Lattice;
6
7#[derive(Clone, Copy, Debug, PartialEq)]
12pub struct BhzParams {
13 pub a: f64,
15 pub b: f64,
17 pub c: f64,
19 pub d: f64,
21 pub mass: f64,
23 pub lambda: f64,
25}
26
27impl Default for BhzParams {
28 fn default() -> Self {
29 Self { a: 1.0, b: -0.376406, c: 0.0, d: -0.280933, mass: -0.137, lambda: 0.0 }
30 }
31}
32
33pub fn bhz(p: BhzParams) -> Model {
40 let r = |x: f64| c64::new(x, 0.0);
41 let i = |x: f64| c64::new(0.0, x);
42 let onsite = combine(&[(r(p.c - 4.0 * p.d), &gamma0()), (r(p.mass - 4.0 * p.b), &gamma55())]);
43 let tx = combine(&[
44 (r(p.d), &gamma0()),
45 (r(p.b), &gamma55()),
46 (i(-0.5 * p.a), &gamma33()),
47 (i(0.5 * p.lambda), &gamma13()),
48 ]);
49 let ty = combine(&[
50 (r(p.d), &gamma0()),
51 (r(p.b), &gamma55()),
52 (i(0.5 * p.a), &gamma44()),
53 (i(-0.5 * p.lambda), &gamma14()),
54 ]);
55 Model::new(Lattice::square(1.0, 4)).onsite(0, onsite).hopping(0, 0, [1, 0, 0], tx).hopping(
56 0,
57 0,
58 [0, 1, 0],
59 ty,
60 )
61}
62
63#[derive(Clone, Copy, Debug, PartialEq, Eq)]
65pub enum GFactors {
66 Same,
68 Opposite,
70}
71
72pub fn bhz_spin(coupling: GFactors) -> [CMat; 3] {
75 match coupling {
76 GFactors::Same => [gamma23(), gamma31(), gamma12()],
77 GFactors::Opposite => [gamma23p(), gamma31p(), gamma12p()],
78 }
79}
80
81pub fn bhz_exchange(coupling: GFactors, j: f64, n: [f64; 3]) -> CMat {
83 let [sx, sy, sz] = bhz_spin(coupling);
84 combine(&[(c64::new(j * n[0], 0.0), &sx), (c64::new(j * n[1], 0.0), &sy), (c64::new(j * n[2], 0.0), &sz)])
85}
86
87#[derive(Clone, Copy, Debug, PartialEq, Eq)]
89pub enum Spin {
90 Up,
92 Down,
94}
95
96pub fn bhz_block(p: BhzParams, spin: Spin) -> Model {
105 let full = bhz(BhzParams { lambda: 0.0, ..p });
106 let o = if spin == Spin::Up { 0 } else { 2 };
107 let sub = |m: &CMat| CMat::from_fn(2, 2, |i, j| m[(o + i, o + j)]);
108 let site = caroli_lattice::Site { cell: [0, 0, 0], sub: 0 };
109 let onsite = sub(&full.onsite_matrix(&site));
110 let (tx, ty) = (sub(&full.hoppings()[0].matrix), sub(&full.hoppings()[1].matrix));
111 Model::new(Lattice::square(1.0, 2)).onsite(0, onsite).hopping(0, 0, [1, 0, 0], tx).hopping(
112 0,
113 0,
114 [0, 1, 0],
115 ty,
116 )
117}
118
119#[cfg(test)]
120mod tests {
121 use super::*;
122 use caroli_lattice::Region;
123 use faer::Side;
124
125 #[test]
127 fn blocks_make_up_the_full_model() {
128 let p = BhzParams::default();
129 let full = bhz(p);
130 let region = Region::cuboid(full.lattice(), [4, 3, 0]);
131 let mut e4 = full.hamiltonian(®ion).self_adjoint_eigenvalues(Side::Lower).unwrap();
132 let mut e2 = Vec::new();
133 for spin in [Spin::Up, Spin::Down] {
134 let m = bhz_block(p, spin);
135 let r = Region::cuboid(m.lattice(), [4, 3, 0]);
136 e2.extend(m.hamiltonian(&r).self_adjoint_eigenvalues(Side::Lower).unwrap());
137 }
138 e2.sort_by(f64::total_cmp);
139 e4.sort_by(f64::total_cmp);
140 assert!(e2.iter().zip(&e4).all(|(a, b)| (a - b).abs() < 1e-12));
141 }
142}