[petsc-users] number of converged eigenpairs

Soumya Mukherjee soumyamechanics at gmail.com
Thu Sep 24 11:01:48 CDT 2015


 Hi.

The following code generates nconv numbers of eigenpairs. This number, for
my case is so few. And I am afraid, there are more important eigenmodes. Is
it possible to generate all (or more) eigenpairs?

Also, I was wondering, which eigenvalues/ eigenvectors does it calculate in
this code, whose number is given by nconv?

    MatCreateSeqAIJ( MPI_COMM_SELF, Natom * Norbit, Natom * Norbit,
Nneighbor * Norbit, PETSC_NULL, &H );
    MatSetFromOptions( H );

    MatCreateSeqAIJ( MPI_COMM_SELF, Natom * Norbit, Natom * Norbit,
Nneighbor * Norbit, PETSC_NULL, &S );
    MatSetFromOptions( S );

Hamiltonian ( );
// MatView(H,PETSC_VIEWER_STDOUT_WORLD);
// VecView(H0,PETSC_VIEWER_STDOUT_WORLD);

//-------------------------------------------------------------------------------------------------------
    /*Setup the Ax=cBx generalized eigenproblem*/

//-------------------------------------------------------------------------------------------------------
    EPSCreate( PETSC_COMM_WORLD, &eps );
    EPSSetOperators( eps, H, S);
    MatGetVecs(H,NULL,&xr);
    MatGetVecs(H,NULL,&xi);

    EPSGetST( eps, &st);
    STSetType(st,STCAYLEY);
    STCayleySetAntishift(st,1);

    EPSSetDimensions( eps, nev, ncv, PETSC_DECIDE);
    EPSSetTarget( eps,5.0);
    EPSSetFromOptions( eps );
    EPSSolve( eps );
    EPSPrintSolution(eps,PETSC_NULL);
    EPSGetConverged( eps, &nconv );

    eigenval = new complex<double>[ nconv ];
    eigenvec = new complex<double>*[ nconv ];
    for (int i = 0; i < nconv; i ++ ) {
        eigenvec[ i ] = new complex<double>[ Norbit * Natom ];
    }

    for ( jjj = 0; jjj < nconv; jjj ++ ) {
        /* Get converged eigenpairs: j-th eigenvalue is stored in kr (real
part) and ki (imaginary part) */
        EPSGetEigenpair(eps, jjj, &kr, &ki, xr, xi);
        eigenval[ jjj ] = complex
<double>(PetscRealPart(kr),PetscImaginaryPart(kr));

        VecGetArray(xr, &Xr);
        for ( int i = 0; i < Norbit * Natom; i ++ ) {
            eigenvec[ jjj ][ i ] = complex
<double>(PetscRealPart(Xr[i]),PetscImaginaryPart(Xr[i]));
        }
        VecRestoreArray(xr, &Xr);
    }
//--------------------------
/*finalizing*/
//--------------------------
outputs( true );
    VecDestroy(&xr);
    VecDestroy(&xi);
    EPSDestroy(&eps);
    MatDestroy(&H);
    MatDestroy(&S);
    SlepcFinalize();
    PetscFinalize();
return 0;
}

Regards,
Soumya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150924/628be04c/attachment-0001.html>


More information about the petsc-users mailing list