Example #1
0
def FindEigenvalues(**args):
    prop = SetupProblem(**args)
    tempPsi = prop.GetTempPsi()

    solver = pyprop.PiramSolver(prop)
    solver.Solve()
    print solver.Solver.GetEigenvalues().real

    #test if the find eigenvectors are really eigenvectors
    for i in range(len(solver.Solver.GetEigenvalues())):
        solver.SetEigenvector(prop.psi, i)

        tempPsi.GetData()[:] = 0
        prop.MultiplyHamiltonian(tempPsi)
        n1 = tempPsi.GetNorm()
        n2 = prop.psi.GetNorm()
        lindep = prop.psi.InnerProduct(tempPsi) / (n1 * n2)

        E = prop.GetEnergyExpectationValue()

        print "E = %f, cos(theta) = %f" % (E, abs(lindep))

        #Propagate the eigenstate to see if it remains in the same state
        #args['silent'] = True
        #args['initPsi'] = prop.psi
        #Propagate(**args)

    return solver
Example #2
0
def FindEigenstates(**args):
    prop = SetupProblem(**args)
    solver = pyprop.PiramSolver(prop)
    numEigs = prop.Config.Arpack.krylov_eigenvalue_count
    outFile = prop.Config.Arpack.hdf5_filename

    #Find eigenvectors
    solver.Solve()

    if pyprop.ProcId == 0:
        h5file = tables.openFile(outFile, "w")
        try:
            #Save eigenvectors
            for i in range(numEigs):
                prop.psi.GetData()[:] = solver.GetEigenvector(i)
                prop.psi.Normalize()
                h5file.createArray("/", "eigenvector%03i" % i,
                                   prop.psi.GetData())

            #Save eigenvalues
            h5file.createArray("/", "eigenvalues", solver.GetEigenvalues()[:])

            #Store config object
            h5file.setNodeAttr("/", "configObject", prop.Config.cfgObj)
        finally:
            h5file.close()

    return solver
Example #3
0
def FindEigenstates(**args):
    """
	Use PIRAM to calculate some eigenstates. Then store these and the 
	corresponding energies to HDF5 files.
	"""

    #Setup problem and call PIRAM solver
    prop = SetupProblem(**args)
    solver = pyprop.PiramSolver(prop)
    solver.Solve()

    #Create output dir if it does not exist
    try:
        os.mkdir("eigenvectors")
    except:
        pass

    #Proc 0 saves the eigenvalues
    if pyprop.ProcId == 0:
        print solver.GetEigenvalues()
        h5file = tables.openFile("eigenvectors/eigenvalues.h5", "w")
        h5file.createArray("/", "eigenvalues", solver.GetEigenvalues())
        h5file.close()

    for i in range(size(solver.GetEigenvalues())):
        solver.SetEigenvector(prop.psi, i)
        SaveWavefunction("eigenvectors/eigenvector%02i.h5" % i,
                         "/wavefunction%02i" % i, prop.psi)

    return solver
Example #4
0
def FindEigenvalues(**args):
    prop = SetupProblem(**args)
    solver = pyprop.PiramSolver(prop)
    solver.Solve()

    for E in solver.GetEigenvalues():
        print "%.17f" % E

    return solver
Example #5
0
def FindEigenvalues(useArpack=False, **args):
    prop = SetupProblem(**args)
    if useArpack:
        solver = pyprop.ArpackSolver(prop)
    else:
        solver = pyprop.PiramSolver(prop)
    solver.Solve()
    print solver.GetEigenvalues()
    return solver
Example #6
0
def FindEigenvalues(**args):
    prop = SetupProblem(**args)
    solver = pyprop.PiramSolver(prop)
    solver.Solve()
    print solver.GetEigenvalues()

    solver.SetEigenvector(prop.psi, 0)
    prop.SaveWavefunctionHDF("groundstate.h5", "/wavefunction")

    return solver
Example #7
0
def FindEigenvalues():
    conf = pyprop.Load("find_groundstate.ini")
    conf.Propagation.silent = pyprop.ProcId != 0
    prop = pyprop.Problem(conf)
    prop.SetupStep()
    solver = pyprop.PiramSolver(prop)
    solver.Solve()

    print "Eigenvalues = ", solver.Solver.GetEigenvalues().real
    return solver
Example #8
0
def TestFindEigenvalues():
    #Custom matvec product
    def matvec(psi, tmpPsi, t, dt):
        tmpPsi.Clear()
        potMatrix.Multiply(psi, tmpPsi)
        tmpPsi.GetRepresentation().SolveOverlap(tmpPsi)

    pyprop.PrintOut("")
    pyprop.PrintOut("Now testing eigenvalue computation...")

    #Setup problem
    Print("  Setting up problem...", [0])
    prop = SetupProblem(config='config_eigenvalues.ini', silent=True)
    psi = prop.psi
    pyprop.Redirect.Enable(silent=True)

    #Setup Epetra potential and copy Tensor potential data into it
    Print("  Converting tensor potential to Epetra matrix...", [0])
    potMatrix = EpetraPotential_3()
    potMatrix.Setup(psi)
    for pot in prop.Propagator.BasePropagator.PotentialList:
        localBasisPairs = pot.BasisPairs
        potMatrix.AddTensorPotentialData(pot.PotentialData, localBasisPairs, 0)
        del pot.PotentialData
    potMatrix.GlobalAssemble()

    #Setup PIRAM
    Print("  Setting up Piram...", [0])
    prop.Config.Arpack.matrix_vector_func = matvec
    solver = pyprop.PiramSolver(prop)

    #Find eigenvalues
    Print("  Calculating eigenvalues...", [0])
    solver.Solve()
    eigs = solver.GetEigenvalues()
    Print("    Eigenvalues = %s" % str(eigs), [0])

    #Test first eigenvalue
    prop.psi.Clear()
    tmpPsi = prop.psi.Copy()
    solver.SetEigenvector(prop.psi, 0)
    prop.psi.Normalize()
    matvec(prop.psi, tmpPsi, 0, 0)
    eigRes = abs(prop.psi.InnerProduct(tmpPsi) - solver.GetEigenvalues()[0])
    Print("    ||H * v - lambda * v|| = %s" % eigRes, [0])

    #finish and cleanup
    pypar.barrier()
    pyprop.Redirect.Disable()
    pyprop.PrintOut("\n...done!")
Example #9
0
def FindEigenstates(useARPACK=False, **args):
    """
	Uses pIRAM to find the the lowest eigenvectors of the
	problem specified in **args
	"""
    prop = SetupProblem(**args)

    #use custom initial residual if provided
    initialResidual = args.get("initialResidual")
    if initialResidual != None:
        prop.psi.GetData()[:] = initialResidual.GetData()

    #find eigenstates
    solver = None
    if useARPACK:
        solver = pyprop.ArpackSolver(prop)
    else:
        solver = pyprop.PiramSolver(prop)
    solver.Solve()
    return solver
Example #10
0
def FindEigenvalues(**args):
	prop = SetupProblem(**args)

	solver = pyprop.PiramSolver(prop)
	print "Solving..."
	solver.Solve()

	print sort(solver.GetEigenvalues().real)

	evCount = len(solver.GetEigenvalues())

	sortIndex = argsort(solver.GetEigenvalues())

	m = 0
	for i in sortIndex:
		shape = prop.psi.GetData().shape
		prop.psi.GetData()[:] = reshape(solver.GetEigenvector(i), shape)
		prop.psi.Normalize()
		print "E%i = %s" % (m, prop.GetEnergyExpectationValue())
		m += 1

	return solver;
Example #11
0
def FindEigenvalues(**args):
    prop = SetupProblem(**args)
    solver = pyprop.PiramSolver(prop)
    solver.Solve()
    print solver.GetEigenvalues()
    return solver