setting complex numbers

zhifeng sheng z.sheng at ewi.tudelft.nl
Mon Sep 8 10:15:07 CDT 2008


exactly :) thanks a lot.

Matthew Knepley wrote:
> You have not called PetscInitialize() so PETSC_i has not been defined.
>
>    Matt
>
> On Mon, Sep 8, 2008 at 9:44 AM, zhifeng sheng <z.sheng at ewi.tudelft.nl> wrote:
>   
>> 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