setting complex numbers

zhifeng sheng z.sheng at ewi.tudelft.nl
Mon Sep 8 09:44:31 CDT 2008


Dear all

I am now working with the complex version of Petsc but have some serious 
problems...

It turned out that I could not set the imaginary part of a PetscScalar.  
Check the following code:

int main(int argc, char *argv[])
{
    #if !defined(PETSC_USE_COMPLEX)
        SETERRQ(1,"This example requires complex numbers");
    #endif
      PetscScalar ee = 3.0*PETSC_i;
      PetscScalar x = 4.0 + ee;
      std::cout<<PetscRealPart(x)<<" "<<PetscImaginaryPart(x)<<std::endl;
}

after compiling and run, it produces


4 0

which means that the imaginary part is set to be zero....

does anyone have this problem before, or could you please tell me what I 
did wrong in this piece of code.

Thanks a lot
Best regards
Zhifeng Sheng




More information about the petsc-users mailing list