[KeldyshGF-svncheckins] [svn commit /var/www/svn/KeldyshGF] r274 - trunk/kgf/exact_diagonalization

svn at fysik.dtu.dk svn at fysik.dtu.dk
Fri Nov 30 15:15:13 CET 2012


Author: strange
Date: 2012-11-30 15:15:13 +0100 (Fri, 30 Nov 2012)
New Revision: 274

Modified:
   trunk/kgf/exact_diagonalization/exactdsparse.py
Log:
minor stuff

Modified: trunk/kgf/exact_diagonalization/exactdsparse.py
===================================================================
--- trunk/kgf/exact_diagonalization/exactdsparse.py	2012-11-18 18:55:26 UTC (rev 273)
+++ trunk/kgf/exact_diagonalization/exactdsparse.py	2012-11-30 14:15:13 UTC (rev 274)
@@ -157,6 +157,7 @@
     def get_expectation_value(self, R, vec, diag_only=False):
         if type(vec)==np.ndarray:
             vec = sp.csr_matrix(vec)
+
         out = vec.T.dot(R).dot(vec)
         if diag_only:
             out = out.diagonal()
@@ -167,11 +168,10 @@
         val, vec = spla.eigsh(H)
         return val[0]
 
-    def get_expectation_values(self, H, indices, iterative=True):
+    def get_expectation_values(self, H, indices, iterative=True, k=25):
         h_nn = self.get_subspace(H, indices)
         if iterative:
-            k = 100
-            if h_nn.shape[0]<100:
+            if h_nn.shape[0]<k:
                 k = h_nn.shape[0]-1
 
             val, vec = spla.eigsh(h_nn, k=k)
@@ -190,9 +190,9 @@
         s_n = -0.5 + np.sqrt(s2_n + 0.25)
         return e_n, sz_n, s_n, s2_n, n_n
 
-    def print_expectation_values(self, H, indices, nmax=5, iterative=True):
+    def print_expectation_values(self, H, indices, nmax=5, iterative=True,k=25):
         e_n, sz_n, s_n, s2_n, n_n = self.get_expectation_values(H, indices,
-                                                                iterative)
+                                                                iterative, k)
         print '--------------------------------'
         print '  E     |  Sz   |  S    |   N'
         print '--------------------------------'
@@ -204,7 +204,7 @@
             nvs = '%.2f' % n
             print es.rjust(9), szs.rjust(7), s2s.rjust(7), nvs.rjust(5)
 
-    def print_occupation_numbers(self, state):
+    def print_occupation_numbers(self, state, indices=None):
         """
             print occupations of single particle states 
             prints: i,  spin, <state|n_{i\sigma}|state> 
@@ -219,6 +219,8 @@
         for i in range(self.nsites):
             for s in range(2):
                 nop = cd[s][i].dot(c[s][i])
+                if indices != None:
+                    nop = self.get_subspace(nop, indices) 
                 n = state.T.dot(nop).dot(state)[0,0]
                 if abs(n)>1.0e-15:
                     print '%.2i %i %.3f' % (i, s, n)
@@ -227,7 +229,6 @@
     calc = ExactDiag(2)
     Sz, pz = calc.get_Sz()
     S2, p2 = calc.get_S2()
-
     h1 = np.array([[ 0.0,-1.0],
                    [-1.0, 0.0]])
     V1 = np.identity(2) * 2.0



More information about the KeldyshGF-svncheckins mailing list