Skip to content
Snippets Groups Projects
Commit b6e89534 authored by Anton Akhmerov's avatar Anton Akhmerov Committed by Christoph Groth
Browse files

make closed system tutorial use sparse eigenvalues

parent 169eac13
No related branches found
No related tags found
No related merge requests found
--- original
+++ modified
@@ -17,6 +17,7 @@
@@ -18,6 +18,7 @@
# For plotting
from matplotlib import pyplot
......@@ -8,9 +8,9 @@
def make_system(a=1, t=1.0, r=10):
@@ -69,19 +70,24 @@
# we only plot the 15 lowest eigenvalues
energies.append(ev[:15])
@@ -70,19 +71,24 @@
energies.append(ev)
- pyplot.figure()
+ fig = pyplot.figure()
......
......@@ -10,11 +10,12 @@
from cmath import exp
import numpy as np
import kwant
# For eigenvalue computation
#HIDDEN_BEGIN_tibv
import scipy.linalg as la
import scipy.sparse.linalg as sla
#HIDDEN_END_tibv
# For plotting
......@@ -67,12 +68,12 @@ def plot_spectrum(sys, Bfields):
B = Bfield
# Obtain the Hamiltonian as a dense matrix
ham_mat = sys.hamiltonian_submatrix()
ham_mat = sys.hamiltonian_submatrix(sparse=True)
ev = la.eigh(ham_mat, eigvals_only=True)
# we only calculate the 15 lowest eigenvalues
ev = sla.eigsh(ham_mat, k=15, which='SM', return_eigenvectors=False)
# we only plot the 15 lowest eigenvalues
energies.append(ev[:15])
energies.append(ev)
pyplot.figure()
pyplot.plot(Bfields, energies)
......
......@@ -56,16 +56,17 @@ Hamiltonian is approximating.
Closed systems
..............
Although kwant is (currently) mainly aimed towards transport problem, it
Although kwant is (currently) mainly aimed towards transport problema, it
can also easily be used to compute properties of closed systems -- after
all, a closed system is nothing more than a scattering region without leads!
In this example, we compute the spectrum of a closed, (approximately)
circular quantum dot as a function of magnetic field
(Fock-Darwin spectrum).
In this example, we compute the wave functions of a closed, (approximately)
circular quantum dot and its spectrum as a function
of magnetic field (Fock-Darwin spectrum).
To compute the eigenenergies, we will make use of the linear algebra
functionality of `scipy <www.scipy.org>`_:
To compute the eigenenergies and eigenstates, we will make use of the sparse
linear algebra functionality of `scipy <www.scipy.org>`_, which interfaces
the ARPACK package:
.. literalinclude:: closed_system.py
:start-after: #HIDDEN_BEGIN_tibv
......@@ -90,9 +91,8 @@ system using `~kwant.system.System.hamiltonian_submatrix`:
:start-after: #HIDDEN_BEGIN_yvri
:end-before: #HIDDEN_END_yvri
In this toy model we use dense matrices and dense matrix algebra since
the system is very small. (In a real application one would probably
want to use sparse matrix methods.) Finally, we obtain the result:
Note that we use sparse linear algebra to efficiently calculate only a
few lowest eigenvalues. Finally, we obtain the result:
.. image:: ../images/closed_system_result.*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment