diff --git a/kwant/builder.py b/kwant/builder.py index 86570a7e47589f0d6e9d226035ecab44646e9113..3f89c002d617e3545806a8b8ab627c6f90cf8159 100644 --- a/kwant/builder.py +++ b/kwant/builder.py @@ -1066,6 +1066,9 @@ class Builder: The lead numbering starts from zero and increments from there, i.e. the leads are numbered in the order in which they are attached. """ + if self.symmetry.num_directions: + raise ValueError("Leads can only be attached to finite systems.") + if add_cells < 0 or int(add_cells) != add_cells: raise ValueError('add_cells must be an integer >= 0.') diff --git a/kwant/physics/leads.py b/kwant/physics/leads.py index 4342316e103967a24736b26fabe51063610f5e19..2d975ec506219710f5a0b8b48e4821171bdfb47b 100644 --- a/kwant/physics/leads.py +++ b/kwant/physics/leads.py @@ -578,8 +578,8 @@ def modes(h_cell, h_hop, tol=1e6, stabilization=None): raise ValueError("Incompatible matrix sizes for h_cell and h_hop.") if not complex_any(h_hop): - v = np.zeros((0, m)) - return (PropagatingModes(np.zeros((0, n)), np.zeros((0,)), + v = np.zeros((m, 0)) + return (PropagatingModes(np.zeros((n, 0)), np.zeros((0,)), np.zeros((0,))), StabilizedModes(np.zeros((0, 0)), np.zeros((0, 0)), 0, v)) diff --git a/kwant/physics/tests/test_leads.py b/kwant/physics/tests/test_leads.py index 15da9dc3d1e92e9e3be7c6065cd7a435b63624db..ed09ea1779e11fa808329135dbfe01c50fa94b5e 100644 --- a/kwant/physics/tests/test_leads.py +++ b/kwant/physics/tests/test_leads.py @@ -324,3 +324,19 @@ def test_dtype_linsys(): lsys = kwant.physics.leads.setup_linsys(h_cell - 0.3*np.eye(2), h_hop) assert lsys.eigenproblem[0].dtype == np.complex128 + + +def test_zero_hopping(): + h_cell = np.identity(2) + h_hop = np.zeros((2, 1)) + expected = (leads.PropagatingModes(np.zeros((2, 0)), np.zeros((0,)), + np.zeros((0,))), + leads.StabilizedModes(np.zeros((0, 0)), np.zeros((0, 0)), 0, + np.zeros((1, 0)))) + actual = leads.modes(h_cell, h_hop) + assert all(np.alltrue(getattr(actual[1], attr) == + getattr(expected[1], attr)) for attr + in ('vecs', 'vecslmbdainv', 'nmodes', 'sqrt_hop')) + assert all(np.alltrue(getattr(actual[0], attr) == + getattr(expected[0], attr)) for attr + in ('wave_functions', 'velocities', 'momenta'))