[petsc-users] sqrt for a PetscScalar

Umut Tabak u.tabak at tudelft.nl
Wed Apr 7 06:03:14 CDT 2010


Matthew Knepley wrote:
>
>
> My guess is that you want
>
> PetscReal xTMx;
>
>   
Dear Matthew,

Thanks for the quick reply, Not sure, here is the code for the related 
part, I used a VecTDot before that so I need PetscScalar I guess.

  PetscErrorCode ierr;
  Vec x, Bx;
  int rSz, cSz;
  PetscScalar xTMx;
  ierr = MatGetSize(modalMat.getMatrix(), &rSz, &cSz);    CHKERRQ(ierr);
  // create the vectors to be used
  ierr = VecCreate(MPI_COMM_SELF, &x);         CHKERRQ(ierr);
  ierr = VecCreate(MPI_COMM_SELF, &Bx);        CHKERRQ(ierr);
  ierr = VecSetSizes(x, rSz, PETSC_DECIDE);    CHKERRQ(ierr);
  ierr = VecSetSizes(Bx, rSz, PETSC_DECIDE);   CHKERRQ(ierr);
  VecSetFromOptions(x);
  VecSetFromOptions(Bx);
  //
  for(int k=0; k<nev; k++)
  {
    // retrive the mode vector
    MatGetColumnVector(modalMat.getMatrix(), x, k);
    MatMult(B, x, Bx);
    VecTDot(Bx, x, &xTMx);
    VecScale(x, 1/sqrt(xTMx));

Best regards,
Umut


More information about the petsc-users mailing list