setting complex numbers
Marco Schauer
m.schauer at tu-bs.de
Mon Sep 8 10:19:48 CDT 2008
try this
int main(int argc, char *argv[])
{
#if !defined(PETSC_USE_COMPLEX)
SETERRQ(1,"This example requires complex numbers");
#endif
PetscInitialize(&argc,&argv,0,help);
PetscScalar ee = 3.0*PETSC_i;
PetscScalar x = 4.0 + ee;
std::cout<<" "<<PetscRealPart(x)<<"
"<<PetscImaginaryPart(x)<<std::endl;
}
marco
zhifeng sheng schrieb:
> 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