Use matplotlib inline so that plots show up in the notebook.
In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import scipy.sparse as sp
import scipy.sparse.linalg as sla
Next import the dvr_1d
module. We import dvr_1d using a series of ipython notebook magic commands so that we can make changes to the module file and test those changes in this notebook without having to restart the notebook kernel.
In [2]:
# autoreload the lattice module so that we can make changes to it
# without restarting the ipython notebook server
%load_ext autoreload
%autoreload 1
%aimport dvr_1d
%aimport dvr_2d
%aimport dvr_3d
First, we'll test the 1-D sinc function DVR on a simple harmonic oscillator potential.
In [7]:
d = dvr_1d.SincDVR(npts=200, L=14)
d.sho_test(precision=12)
Let's try the same potential but with a Hermite basis. We see that since the Hermite polynomials are the exact solutions to the SHO problem, we can use npts == num_eigs
. The eigenvectors will look horrible but the eigenvalues will be very accurate.
In [5]:
d = dvr_1d.HermiteDVR(npts=5)
d.sho_test(k=1., precision=11)
Next we'll test the 1-D Sinc DVR on a finite and an infinite square well. "Infinite" here just means really really huge.
In [5]:
d = dvr_1d.SincDVR(npts=500, L=20)
d.square_well_test(precision=6)
d.inf_square_well_test(precision=6)
And we might as well try it out with the Hermite basis set too.
In [6]:
d = dvr_1d.HermiteDVR(npts=268)
d.square_well_test(precision=6)
d.inf_square_well_test(precision=6)
Let's repeat all these tests with the 1-D Fourier Sine DVR.
In [7]:
d = dvr_1d.SineDVR(npts=1000, xmin=-15, xmax=15)
d.sho_test(precision=12)
d.square_well_test(precision=6)
d.inf_square_well_test(precision=6)
Let's test the Bessel DVR
In [8]:
d = dvr_1d.BesselDVR(npts=100, R=20., dim=3, lam=1)
d.sho_test(xmin=0., xmax=8., ymin=0., ymax=12.)
We're going to be using 3D plots so let's change the matplotlib backend so the we can look at the plots in a separate window and manipulate them.
In [9]:
%matplotlib osx
Now we'll construct a 2-D Sinc DVR from a product basis of 1-D Sinc DVRs.
In [49]:
d1d = dvr_1d.SincDVR(npts = 30, L=10)
d2d = dvr_2d.DVR(dvr1d=d1d)
E, U = d2d.sho_test(num_eigs=5, precision=14)
In [48]:
d1d = dvr_1d.HermiteDVR(npts=5)
d2d = dvr_2d.DVR(dvr1d=d1d)
E, U = d2d.sho_test(num_eigs=5, precision=14)
In [36]:
d1d = dvr_1d.SincDVR(npts = 30, L=10)
d2d = dvr_2d.DVR(dvr1d=d1d)
E, U = d2d.sho_test(num_eigs=5, precision=10, uscale=3.5, doshow=True)
In [11]:
d1d = dvr_1d.SineDVR(npts = 30, xmin=-5., xmax=5.)
d2d = dvr_2d.DVR(dvr1d=d1d)
E, U = d2d.sho_test(num_eigs=5, uscale=3., doshow=False)
In [20]:
#plt.spy(d2d.t().toarray(), markersize=.1);
#plt.savefig('/Users/Adam/Dropbox/amath585_final/K_2D_sparsity.png', bbox_inches='tight', dpi=400)
In [13]:
d1d = dvr_1d.SincDVR(npts = 16, L=10)
d3d = dvr_3d.DVR(dvr1d=d1d, spf='csr')
E, U = d3d.sho_test(num_eigs=5)
In [21]:
#plt.spy(d3d.t().toarray(), markersize=.1);
#plt.savefig('/Users/Adam/Dropbox/amath585_final/K_3D_sparsity.png', bbox_inches='tight', dpi=400)
In [ ]: