2
$\begingroup$

The version of Petsc installed on my machine has PetscScalar set to be complex. I am making a matrix which has all real entries.

Something like the following code compiles:

PetscScalar value_for_matrix;
value_for_matrix=some+expression+that*returns_PetscReal;

Is the real value returned by the right hand side put into the real part of the PetscScalar value?

If this doesn't work, how should I put a PetscReal value into the real part of a complex PetscScalar?

$\endgroup$
3
$\begingroup$

Yes, this does exactly what you would expect. If you want to create a complex number explicitly, you can multiply real values by PETSC_i. Note that you can use PetscRealPart(), PetscImaginaryPart(), PetscAbsScalar(), and PetscConj() to manipulate complex numbers.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.