[petsc-users] algorithm to get pure real eigen valule for general eigenvalue problem(Non-hermitian type)

Zhang Wei zhang.wei at chalmers.se
Mon Apr 15 10:25:51 CDT 2013


Hi, thanks for your reply!
Here is my code:
    //  Compute the operator matrix that defines the eigensystem, Ax=kx
    ierr = MatCreateShell(PETSC_COMM_WORLD,n,n,PETSC_DETERMINE,PETSC_DETERMINE,NULL,&A);CHKERRQ(ierr);
    ierr = MatSetFromOptions(A);CHKERRQ(ierr);

    ierr = MatShellSetContext(A, &pa); CHKERRQ(ierr);
    ierr = MatShellSetOperation(A, MATOP_MULT, (void(*)()) MatVecMult); CHKERRQ(ierr);

    ierr = MatGetVecs(A, PETSC_NULL,&xr); CHKERRQ(ierr);
    ierr = MatGetVecs(A, PETSC_NULL,&xi); CHKERRQ(ierr);
    ierr = MatGetVecs(A, PETSC_NULL,&iv); CHKERRQ(ierr);

    //  Create the eigensolver and set various options
    ierr = EPSCreate(PETSC_COMM_WORLD,&eps);CHKERRQ(ierr);

    //  Set operators. In this case, it is a standard eigenvalue problem
    ierr = EPSSetOperators(eps, A, PETSC_NULL);CHKERRQ(ierr);
    ierr = EPSSetProblemType(eps, EPS_NHEP);CHKERRQ(ierr);
    ierr = EPSSetDimensions(eps, nev, ncv, mpd);CHKERRQ(ierr);
    ierr = EPSSetWhichEigenpairs(eps,which);CHKERRQ(ierr);
    ierr = EPSSetType(eps,method.c_str());CHKERRQ(ierr);
    ierr = EPSSetTolerances(eps,s_tol,s_maxit);CHKERRQ(ierr);
    ierr = EPSSetConvergenceTest(eps,cov);CHKERRQ(ierr);
    ierr = EPSKrylovSchurSetRestart(eps,keep);CHKERRQ(ierr);
    //  Set solver parameters at runtime
    ierr = EPSSetFromOptions(eps); CHKERRQ(ierr);

    //  Set initial vector
  ierr = pa.setInitialVector(iv);
  ierr = EPSSetInitialSpace(eps,1,&iv);CHKERRQ(ierr);

    ierr = EPSView(eps, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr);

    //  Solve the eigensystem
    ierr = EPSSolve(eps);CHKERRQ(ierr);

and pa is a class, where I define the OP,  MatVecMult. It actually looks like this:

PetscErrorCode MatVecMult(Mat A, Vec x, Vec y)
{
    linearizedTimeStepper *pa;
    MatShellGetContext(A, &pa);
    return pa->MatVecMult(A, x, y);
}
-----Original Message-----
From: petsc-users-bounces at mcs.anl.gov [mailto:petsc-users-bounces at mcs.anl.gov] On Behalf Of Jose E. Roman
Sent: den 15 april 2013 17:01
To: PETSc users list
Subject: Re: [petsc-users] algorithm to get pure real eigen valule for general eigenvalue problem(Non-hermitian type)


El 15/04/2013, a las 16:50, Zhang Wei escribió:

> Hi 
> Since the case is not that big(size of matrix is 9600x9600. ). I have done test in the first way, which gives me a 2.1 Gb ASCII file. The eigen values I  get from matlab are :
>> In eigs>processEUPDinfo at 1340
>  In eigs at 357 
>>> c
> 
> c =
> 
>        0          
>        0          
>        0          
>        0          
>   1.9405 - 0.4733i
>   1.9405 + 0.4733i
> 
> And what I got from slepc are :
> 
> 0       1.99988
> 1       1.99974 
> 2       1.99971 
> 3       1.99913+0.0370552j      
> 4       1.99913+-0.0370552j     
> 5       1.99894+0.0370115j      
> 
> Non of them is right one. And on the other hand there are lots of small values in the matrix which are almost in order of 1e-7 and even smaller.  
> Could it  be the reason resulting such problem?


Note that if you are trasferring the matrix via a text file, then the matrix loaded in Matlab will differ slightly form the one being handled by SLEPc, so you can expect differences in eigenvalues. For a more equivalent computation you should transfer the matrix in binary format.

Anyway, my impression is that you have a bug in the code that generates the matrix, so I would suggest checking that. Having small nonzero entries in the matrix should not be a problem for the eigensolver.

Jose



More information about the petsc-users mailing list