From 79d994be4d8f18402e6a0d7826fcb0b9752e9b08 Mon Sep 17 00:00:00 2001 From: Michael Wimmer <wimmer@lorentz.leidenuniv.nl> Date: Fri, 30 Aug 2013 17:57:28 +0200 Subject: [PATCH] fix ordering of modes and momenta --- kwant/physics/leads.py | 7 ++++--- kwant/physics/tests/test_leads.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/kwant/physics/leads.py b/kwant/physics/leads.py index 970b172..49b276d 100644 --- a/kwant/physics/leads.py +++ b/kwant/physics/leads.py @@ -498,9 +498,10 @@ def make_proper_modes(lmbdainv, psi, extract, tol=1e6): raise RuntimeError("Numbers of left- and right-propagating " "modes differ, possibly due to a numerical " "instability.") - momenta = np.angle(lmbdainv) - order = np.lexsort([np.sign(velocities), -np.sign(velocities) * momenta, - velocities]) + momenta = -np.angle(lmbdainv) + order = np.lexsort([velocities, -np.sign(velocities) * momenta, + np.sign(velocities)]) + # The following is necessary due to wrong numpy handling of zero length # arrays, which is going to be fixed in numpy 1.8. if not len(order): diff --git a/kwant/physics/tests/test_leads.py b/kwant/physics/tests/test_leads.py index adadc8b..399cb62 100644 --- a/kwant/physics/tests/test_leads.py +++ b/kwant/physics/tests/test_leads.py @@ -226,7 +226,7 @@ def test_modes(): assert stab.nmodes == 1 assert stab.sqrt_hop is None np.testing.assert_almost_equal(prop.velocities, [-v, v]) - np.testing.assert_almost_equal(prop.momenta, [-k, k]) + np.testing.assert_almost_equal(prop.momenta, [k, -k]) # Test for normalization by current. np.testing.assert_almost_equal( 2 * (stab.vecs[0] * stab.vecslmbdainv[0].conj()).imag, [1, -1]) -- GitLab