Esempio n. 1
0
   def __init__(self, op_char='m', label=r'modes', color='b',
                operator=np.array(None), pickled=None):

      if not TRC.init:
         print "WARNING: class Transmission Rows Container not initialized" 
         return None

      self.op_char = op_char
      self.label = label
      self.color = color

      if not operator.any() and not pickled:
         self.operator = np.identity(TRC.refmodes, dtype="complex")
         self.eigvec = scat.inflate_small_mat(np.identity(TRC.refmodes, dtype="complex"), TRC.modes)
         self.Leigvec = scat.inflate_small_mat(np.identity(TRC.refmodes, dtype="complex"), TRC.modes)
      elif not operator.any() and pickled:
         self.operator = np.identity(TRC.refmodes, dtype="complex")
         self.eigvec, self.Leigvec = trans.unpickle_states(pickled, modes, refmodes)
      else:
         self.operator = operator
         self.eigval, self.eigvec, self.Leigvec = trans.calc_eigensystem(self.operator, TRC.modes)

      self.times, self.tisdv = trans.calc_qexpvals(self.eigvec, TRC.q, TRC.qLeigbas,
                                                   TRC.modes, TRC.refmodes, TRC.Nk)
      self.vectransmit, self.vecLtransmit = trans.calc_transmitted_states(TRC.t, TRC.tinv, self.eigvec, self.Leigvec,
                                                                          TRC.modes, TRC.refmodes, TRC.refpos, TRC.Nk)

      self.mu = trans.calc_mu(self.vectransmit, self.vecLtransmit, TRC.refmodes, TRC.Nk)
Esempio n. 2
0
def calc_eigensystem(a, modes):
    '''
    Calculcate eigenvalues, right eigenvectors and left eigenvectors of matrix a.
    Eigenvectors are store column-wise and inflated by appending zeros
    to size modes x modes.
    '''
    aeigval, aeigvec = ut.sort_eig(a)
    aeigvec = aeigvec.transpose()
    aLeigvec = np.linalg.inv(aeigvec).transpose()
    aeigvec = scat.inflate_small_mat(aeigvec, modes)
    aLeigvec = scat.inflate_small_mat(aLeigvec, modes)

    return aeigval, aeigvec, aLeigvec
Esempio n. 3
0
def calc_eigensystem(a, modes):
    '''
    Calculcate eigenvalues, right eigenvectors and left eigenvectors of matrix a.
    Eigenvectors are store column-wise and inflated by appending zeros
    to size modes x modes.
    '''
    aeigval, aeigvec = ut.sort_eig(a)
    aeigvec  = aeigvec.transpose()
    aLeigvec = np.linalg.inv(aeigvec).transpose()
    aeigvec  = scat.inflate_small_mat(aeigvec, modes)
    aLeigvec = scat.inflate_small_mat(aLeigvec, modes)

    return aeigval, aeigvec, aLeigvec
Esempio n. 4
0
    def __init__(self,
                 op_char='m',
                 label=r'modes',
                 color='b',
                 operator=np.array(None),
                 pickled=None):

        if not TRC.init:
            print "WARNING: class Transmission Rows Container not initialized"
            return None

        self.op_char = op_char
        self.label = label
        self.color = color

        if not operator.any() and not pickled:
            self.operator = np.identity(TRC.refmodes, dtype="complex")
            self.eigvec = scat.inflate_small_mat(
                np.identity(TRC.refmodes, dtype="complex"), TRC.modes)
            self.Leigvec = scat.inflate_small_mat(
                np.identity(TRC.refmodes, dtype="complex"), TRC.modes)
        elif not operator.any() and pickled:
            self.operator = np.identity(TRC.refmodes, dtype="complex")
            self.eigvec, self.Leigvec = trans.unpickle_states(
                pickled, modes, refmodes)
        else:
            self.operator = operator
            self.eigval, self.eigvec, self.Leigvec = trans.calc_eigensystem(
                self.operator, TRC.modes)

        self.times, self.tisdv = trans.calc_qexpvals(self.eigvec, TRC.q,
                                                     TRC.qLeigbas, TRC.modes,
                                                     TRC.refmodes, TRC.Nk)
        self.vectransmit, self.vecLtransmit = trans.calc_transmitted_states(
            TRC.t, TRC.tinv, self.eigvec, self.Leigvec, TRC.modes,
            TRC.refmodes, TRC.refpos, TRC.Nk)

        self.mu = trans.calc_mu(self.vectransmit, self.vecLtransmit,
                                TRC.refmodes, TRC.Nk)
Esempio n. 5
0
def unpickle_states(filestr, modes, refmodes):
    '''
    Loads states from pickled files, calculates left states
    and inflates both.
    '''
    try:
        (vec, Lvec) = pickle.load(open(filestr, 'rb'))
        n, m = np.shape(vec)

        eigvec = np.identity(refmodes, dtype="complex")
        Leigvec = np.identity(refmodes, dtype="complex")
        eigvec[:n, :m] = vec
        Leigvec[:n, :m] = Lvec
        eigvec = scat.inflate_small_mat(eigvec, modes)
        Leigvec = scat.inflate_small_mat(Leigvec, modes)
    except:
        print "WARNING: unable to load pickled states"
        eigvec = np.identity(refmodes, dtype="complex")
        Leigvec = np.identity(refmodes, dtype="complex")
        eigvec = scat.inflate_small_mat(eigvec, modes)
        Leigvec = scat.inflate_small_mat(Leigvec, modes)

    return eigvec, Leigvec
Esempio n. 6
0
def unpickle_states(filestr, modes, refmodes):
    '''
    Loads states from pickled files, calculates left states
    and inflates both.
    '''
    try:
        (vec, Lvec) = pickle.load(open(filestr, 'rb'))
        n,m = np.shape(vec)

        eigvec = np.identity(refmodes, dtype="complex")
        Leigvec = np.identity(refmodes, dtype="complex")
        eigvec[:n,:m] = vec
        Leigvec[:n,:m] = Lvec
        eigvec = scat.inflate_small_mat(eigvec, modes)
        Leigvec = scat.inflate_small_mat(Leigvec, modes)
    except:
        print "WARNING: unable to load pickled states"
        eigvec = np.identity(refmodes, dtype="complex")
        Leigvec = np.identity(refmodes, dtype="complex")
        eigvec = scat.inflate_small_mat(eigvec, modes)
        Leigvec = scat.inflate_small_mat(Leigvec, modes)
    
    return eigvec, Leigvec
Esempio n. 7
0
def calc_transmitted_states(t, tinv, vec, Lvec, modes, refmodes, refpos, Nk):
    '''
    Calculate transmitted right vector at each frequency and transmitted
    left vector only at reference frequency. Transmitted right vector is
    normalized, transmitted left vector is normalized such that inner
    product of the two transmitted vectors is equal to one if vectors
    are aligned w.r.t. the considered modes and scattering into modes
    that are not considered is zero.
    '''
    vectransmit = np.zeros((Nk, refmodes, modes), dtype="complex")
    for i in range(Nk):
        t_inf = scat.inflate_small_mat(t[3 * i + 1], modes)
        for j in range(refmodes):
            vectransmit[i][j] = np.dot(t_inf, vec[j]) /\
                np.linalg.norm(np.dot(t_inf, vec[j]))

    vecLtransmit = np.zeros((refmodes, modes), dtype="complex")
    tfull_ref_inf = scat.inflate_small_mat(t[3 * refpos], modes)
    tinv_inf = scat.inflate_small_mat(tinv, modes)
    for j in range(refmodes):
        vecLtransmit[j] = np.dot(Lvec[j], tinv_inf) *\
            np.linalg.norm(np.dot(tfull_ref_inf, vec[j]))

    return vectransmit, vecLtransmit
Esempio n. 8
0
def calc_transmitted_states(t, tinv, vec, Lvec, modes, refmodes, refpos, Nk):
    '''
    Calculate transmitted right vector at each frequency and transmitted
    left vector only at reference frequency. Transmitted right vector is
    normalized, transmitted left vector is normalized such that inner
    product of the two transmitted vectors is equal to one if vectors
    are aligned w.r.t. the considered modes and scattering into modes
    that are not considered is zero.
    '''
    vectransmit = np.zeros((Nk,refmodes,modes), dtype="complex")
    for i in range(Nk):
        t_inf = scat.inflate_small_mat(t[3*i+1], modes)
        for j in range(refmodes):
            vectransmit[i][j] = np.dot(t_inf, vec[j]) /\
                np.linalg.norm(np.dot(t_inf, vec[j]))

    vecLtransmit = np.zeros((refmodes,modes), dtype="complex")
    tfull_ref_inf = scat.inflate_small_mat(t[3*refpos], modes)
    tinv_inf = scat.inflate_small_mat(tinv, modes)
    for j in range(refmodes): 
        vecLtransmit[j] = np.dot(Lvec[j], tinv_inf) *\
            np.linalg.norm(np.dot(tfull_ref_inf, vec[j]))

    return vectransmit, vecLtransmit
Esempio n. 9
0
def calc_qexpvals(eigvec, q, qLeigbas, modes, refmodes, Nk):
    '''
    Calculate proper expectation value of q using its left eigenbasis
    and standard deviations for vectors 'eigvec' at each frequency.
    '''
    times = np.empty((refmodes, Nk), dtype="complex")
    tisdv = np.empty((refmodes, Nk), dtype="complex")

    for w in range(Nk):
        for state in range(refmodes):
            vec = scat.inflate_vec(eigvec[state], modes)
            vecL = 1./np.linalg.norm(np.dot(qLeigbas[w], vec))**2 *\
                np.dot(qLeigbas[w].transpose(), np.dot(qLeigbas[w].conj(), vec.conj()))

            A = scat.inflate_small_mat(q[w], modes)

            times[state][w] = np.dot(vecL, np.dot(A, vec))
            tisqr = np.dot(vecL, np.dot(A, np.dot(A, vec)))
            tisdv[state][w] = sqrt(tisqr - times[state][w]**2)

    return times, tisdv
Esempio n. 10
0
def calc_qexpvals(eigvec, q, qLeigbas, modes, refmodes, Nk):
    '''
    Calculate proper expectation value of q using its left eigenbasis
    and standard deviations for vectors 'eigvec' at each frequency.
    '''
    times = np.empty((refmodes,Nk), dtype="complex")
    tisdv = np.empty((refmodes,Nk), dtype="complex")

    for w in range(Nk):
        for state in range(refmodes):
            vec = scat.inflate_vec(eigvec[state], modes)
            vecL = 1./np.linalg.norm(np.dot(qLeigbas[w], vec))**2 *\
                np.dot(qLeigbas[w].transpose(), np.dot(qLeigbas[w].conj(), vec.conj()))

            A   = scat.inflate_small_mat(q[w], modes)

            times[state][w] = np.dot(vecL, np.dot(A, vec)) 
            tisqr = np.dot(vecL, np.dot(A, np.dot(A, vec)))
            tisdv[state][w] = sqrt(tisqr - times[state][w]**2)

    return times, tisdv
Esempio n. 11
0
      self.times, self.tisdv = trans.calc_qexpvals(self.eigvec, TRC.q, TRC.qLeigbas,
                                                   TRC.modes, TRC.refmodes, TRC.Nk)
      self.vectransmit, self.vecLtransmit = trans.calc_transmitted_states(TRC.t, TRC.tinv, self.eigvec, self.Leigvec,
                                                                          TRC.modes, TRC.refmodes, TRC.refpos, TRC.Nk)
    
         






qeigval, qeigvec, qLeigvec = trans.calc_eigensystem(qref, modes)
teigval, teigvec, tLeigvec = trans.calc_eigensystem(tref, modes)
modesvec = scat.inflate_small_mat(np.identity(refmodes, dtype="complex"), modes)
qyeigvec, qyLeigvec = trans.unpickle_states(pic_direc+'qpeaks.1.p', modes, refmodes)
#trans.print_freq_indep(qeigval, kmin, kmax, Dk)

eigvec = (qeigvec, teigvec, modesvec, qyeigvec)
Leigvec = (qLeigvec, tLeigvec, modesvec, qyLeigvec)

qeigbas, qLeigbas = trans.calc_qeigbas(q, Nk, modes, refmodes)

Nop = np.shape(eigvec)[0]
times = np.empty((Nop,refmodes,Nk), dtype="complex")
tisdv = np.empty((Nop,refmodes,Nk), dtype="complex")
for i in range(Nop):
    times[i], tisdv[i] = trans.calc_qexpvals(
        eigvec[i], q, qLeigbas, modes, refmodes, Nk)
Esempio n. 12
0
teigval = ut.sort_eig(t_q[3*(refpos)+0])[0]
np.savetxt(direc+"teigvals."+filen+".dat", np.array([range(np.shape(teigval)[0]), teigval.real, teigval.imag]).transpose())

qeigvec  = ut.sort_eig(qref)[1].transpose()
teigvec  = ut.sort_eig(tref)[1].transpose()
#teigvec  = np.linalg.eig(tref)[1].transpose()
modesvec = np.identity(refmodes, dtype="complex")

# left eigenvectors are to be calculated before inflating
qLeigvec = np.linalg.inv(qeigvec).transpose()
tLeigvec = np.linalg.inv(teigvec).transpose()


### inflate eigenvectors to maximum size and number by appending zeros ###
qeigvec  = scat.inflate_small_mat(qeigvec, modes)
teigvec  = scat.inflate_small_mat(teigvec, modes)
modesvec = scat.inflate_small_mat(modesvec, modes)

qLeigvec = scat.inflate_small_mat(qLeigvec, modes)
tLeigvec = scat.inflate_small_mat(tLeigvec, modes)

eigvec = (qeigvec, teigvec, modesvec)


taumin = np.min( qeigval.real )
taumax = np.max( qeigval.real )
Dk = (kmax-kmin)/(Nk-1)
print 
print 'estimate for smallest frequency-independence'
print 'wmin =', kmin, 'wmax =', kmax, 'dw =', Dk
Esempio n. 13
0
def write_states(states,
                 nr,
                 n_states,
                 nin_Max,
                 energ,
                 filen,
                 append=0,
                 state_sort=''):
   '''
   write states to file in proper format for Flo's code

   parameters:
   states: ndarray, float
      matrix containing row-wise states to write
   nr: int
      number of different energies = number of data sets
   n_states: int
      number of states to be propagated by Flo's code
   nin_Max: int
      actual number of open modes
   energ: ndarray, float
      scattering energy (k**2/2)
   filen: str
      namestring of calculation
   append: int
      whether coeffs should be appended to existing file
   state_sort: str (optional)
      string containing information which kind of
      states are calculated and to be propagated
   '''

   if (state_sort == ''):
      if (append):
         f = open('coeff.'+filen+'.dat', 'a')
         f.write('\n')
      elif(not append):
         f = open('coeff.'+filen+'.dat', 'w')
         f.write('%i -1\n' % nr)
         f.write('1.0 0.5\n')
   else:
      if (append):
         f = open('coeff.'+filen+'.'+state_sort+'.dat', 'a')
         f.write('\n')
      elif(not append):
         f = open('coeff.'+filen+'.'+state_sort+'.dat', 'w')
         f.write('%i -1\n' % nr)
         f.write('1.0 0.5\n')

   states = scat.inflate_small_mat(states, nin_Max)
   # append zeros to make number and size of vectors match
   # nin_Max = actual number of open modes in system


   f.write(str(energ)+' '+str(nin_Max)+'\n')
   for i in range(nin_Max):
      f.write('\n')
      if (i < n_states):
         f.write('1.0\n')
      else:
         f.write('2.0\n')
      for j in range(nin_Max):
         f.write('(' + str(states[i,j].real)
                 + ', ' + str(states[i,j].imag) + ')\n')
   return
Esempio n. 14
0
qeigval, qeigvec = ut.sort_eig(qref)
teigval, teigvec = ut.sort_eig(tref)

qeigvec  = qeigvec.transpose()
teigvec  = teigvec.transpose()
modesvec = np.identity(refmodes, dtype="complex")

teigval = ut.sort_eig(t_q[3*(refpos)+1])[0]
np.savetxt(data_direc+"teigvals."+filen+".dat", np.array([range(np.shape(teigval)[0]), teigval.real, teigval.imag]).transpose())

# left eigenvectors are to be calculated before inflating, needed for measure \mu
qLeigvec = np.linalg.inv(qeigvec).transpose()
tLeigvec = np.linalg.inv(teigvec).transpose()

### inflate eigenvectors to maximum size and number by appending zeros ###
qeigvec  = scat.inflate_small_mat(qeigvec, modes)
teigvec  = scat.inflate_small_mat(teigvec, modes)
modesvec = scat.inflate_small_mat(modesvec, modes)

qLeigvec = scat.inflate_small_mat(qLeigvec, modes)
tLeigvec = scat.inflate_small_mat(tLeigvec, modes)


# taumin = np.min( qeigval.real )
# taumax = np.max( qeigval.real )
# Dk = (kmax-kmin)/(Nk-1)
# print 
# print 'estimate for smallest frequency-independence'
# print 'wmin =', kmin, 'wmax =', kmax, 'dw =', Dk
# print 'tau_min =', taumin
# print 'tau_max =', taumax