def test_bloch_call(): b = Bloch([2] * 3) H = get_H() # Manual k_unfold = b.unfold_points([0] * 3) m = b.unfold(np.stack([H.Hk(k, format='array') for k in k_unfold]), k_unfold) m1 = b.unfold([H.Hk(k, format='array') for k in k_unfold], k_unfold) assert np.allclose(m, m1) assert np.allclose(m, b(H.Hk, [0] * 3, format='array'))
def test_bloch_H_same(nx, ny, nz, dtype): H = get_H() b = Bloch([nx, ny, nz]) if dtype == np.complex64: atol = 1e-6 else: atol = 1e-8 HB = H.tile(nx, 0).tile(ny, 1).tile(nz, 2) KX = [0, 0.1, 0.4358923] KY = [0, 0.128359, -0.340925] KZ = [0, 0.445] for kx, ky, kz in product(KX, KY, KZ): K = [kx, ky, kz] k_unfold = b.unfold_points(K) HK = [H.Hk(k, format='array', dtype=dtype) for k in k_unfold] H_unfold = b.unfold(HK, k_unfold) H_big = HB.Hk(K, format='array', dtype=dtype) assert np.allclose(H_big, H_big.T.conj(), atol=atol) assert np.allclose(H_unfold, H_unfold.T.conj(), atol=atol) assert np.allclose(H_unfold, H_big, atol=atol)
def test_bloch_one_direction(nx, ny, nz): H = get_H() b = Bloch([nx, ny, nz]) HB = H.tile(nx, 0).tile(ny, 1).tile(nz, 2) KX = [0, 0.1, 0.4358923] KY = [0, 0.128359, -0.340925] KZ = [0, 0.445] for kx, ky, kz in product(KX, KY, KZ): K = [kx, ky, kz] k_unfold = b.unfold_points(K) HK = [H.Hk(k, format='array') for k in k_unfold] H_unfold = b.unfold(HK, k_unfold) H_big = HB.Hk(K, format='array') assert np.allclose(H_unfold, H_big)
def test_bloch_one_direction(nx, ny, nz, dtype): H = get_H() b = Bloch([nx, ny, nz]) if dtype == np.complex64: atol = 1e-6 else: atol = 1e-8 HB = H.tile(nx, 0).tile(ny, 1).tile(nz, 2) KX = [0, 0.1, 0.4358923] KY = [0, 0.128359, -0.340925] KZ = [0, 0.445] for kx, ky, kz in product(KX, KY, KZ): K = [kx, ky, kz] k_unfold = b.unfold_points(K) HK = [H.Hk(k, format='array', dtype=dtype) for k in k_unfold] H_unfold = b.unfold(np.stack(HK), k_unfold) H_big = HB.Hk(K, format='array', dtype=dtype) print(np.amax(np.absolute(H_unfold - H_big))) assert np.allclose(H_unfold, H_big, atol=atol)