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;

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?


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.


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.