From 83d5b346ac120e2759a1cd919d0c5d2c55c0d3f9 Mon Sep 17 00:00:00 2001
From: Joseph Weston <joseph.weston08@gmail.com>
Date: Tue, 29 Aug 2017 13:47:57 +0200
Subject: [PATCH] divide by the scale factor outside of the tight loop

---
 kwant/plotter.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/kwant/plotter.py b/kwant/plotter.py
index 03ca6260..9f70b1c8 100644
--- a/kwant/plotter.py
+++ b/kwant/plotter.py
@@ -1923,8 +1923,7 @@ def interpolate_current(syst, current, relwidth=None, abswidth=None, n=9):
     if dim > 3:
         raise ValueError("'interpolate_current' only works for systems "
                          "with dimension <= 3.")
-    factors = [16 / 15, np.pi / 3, 32 * np.pi / 105]
-    cross_section_factor = factors[dim - 1]
+    cross_section_factors = [16 / 15, np.pi / 3, 32 * np.pi / 105]
 
     # Interpolate the field for each hopping.
     for i in range(len(current)):
@@ -1949,10 +1948,12 @@ def interpolate_current(syst, current, relwidth=None, abswidth=None, n=9):
         rho *= scale
 
         magns = F(rho, z) - F(rho, z - lens[i])
-        magns *= current[i] * scale / cross_section_factor
+        magns *= current[i]
 
         field[field_slice] += dirs[i] * magns[..., None]
 
+    field *= scale / cross_section_factors[dim - 1]
+
     # 'field' contains contributions from both hoppings (i, j) and (j, i)
     return field, ((region[0][0], region[0][-1]), (region[1][0], region[1][-1]))
 
-- 
GitLab