testSmallMatrix.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Jun 22 20:51:40 2020
  4. @author: Ian Lim
  5. """
  6. from statefuncs import State, Basis
  7. from phi1234 import Phi1234
  8. from scipy.constants import pi
  9. import numpy as np
  10. import unittest
  11. class TestSmallMatrix(unittest.TestCase):
  12. def testMatrix(self):
  13. a = Phi1234()
  14. verbose = False
  15. # values chosen to produce an nmax of 3 and a five-element basis
  16. a.buildFullBasis(k=1, Emax=10., L=2*pi, m=4.)
  17. a.buildFullBasis(k=-1, Emax=10., L=2*pi, m=4.)
  18. expected_basis = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0],
  19. [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0],
  20. [1, 0, 0, 0, 0, 0, 1]]
  21. self.assertEqual(len(a.fullBasis[1]),len(expected_basis))
  22. for index, occs in enumerate(expected_basis):
  23. self.assertEqual(a.fullBasis[1][index].occs, occs)
  24. #print([state.occs for state in a.fullBasis[-1]])
  25. a.buildMatrix()
  26. if verbose:
  27. print("Free Hamiltonian:")
  28. print(a.h0[1].M.toarray())
  29. # we could check that the diagonal elements are the expected energies
  30. #order zero is just the mass term, which comes out to 2*pi here.
  31. print("Order zero potential matrix:")
  32. print(a.potential[1][0].M.toarray())
  33. print("Order phi^2 potential matrix:")
  34. print(a.potential[1][2].M.toarray())
  35. print("Order phi^4 potential matrix:")
  36. print(a.potential[1][4].M.toarray())
  37. if __name__ == '__main__':
  38. unittest.main()