[petsc-users] Reading Vectors from a PETSc Vec

Matthew Knepley knepley at gmail.com
Mon Nov 14 18:43:41 CST 2022


On Mon, Nov 14, 2022 at 7:39 PM Mohammad Ali Yaqteen <mhyaqteen at sju.ac.kr>
wrote:

> I am using the following procedure to read from Vec, but it keeps giving
> me the same values! I was told that using VecGetValues gives wrog output.
>

By who? It does not give the wrong output.

You do not show where in the code you define tdof and ei[].

If not this, then what function should be used to read the contents of a
> vector?
>

I think it would be simpler for you to use VecGetArrayRead(), unless you
want values from other processes.

  Thanks,

    Matt


> for (int i = 0; i < nconv; i++)
>         {
>             PetscCall(EPSGetEigenpair(eps,i,&kr,&ki,xr,xi));
>             PetscCall(EPSComputeError(eps,i,EPS_ERROR_RELATIVE,&error1));
>
>             #if defined(PETSC_USE_COMPLEX)
>                 re = PetscRealPart(kr);
>                 im = PetscImaginaryPart(kr);
>             #else
>                 re = kr;
>                 im = ki;
>             #endif
>             if (im!=0.0) PetscCall(PetscPrintf(PETSC_COMM_WORLD," %9f%+9fi
> %12g\n",(double)re,(double)im,(double)error1));
>             else PetscCall(PetscPrintf(PETSC_COMM_WORLD,"   %12f
> %12g\n",(double)re,(double)error1));
>             eval(i) = re;
>             VecGetValues(xr, tdof, ei, eveci);
>             for (int j = 0; j < tdof; j++)
>             {
>                 evec(j, i) = eveci[j];
>             }
>         }
>         PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n"));
>
> Thank you
> Ali
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20221114/16060c27/attachment-0001.html>


More information about the petsc-users mailing list