[petsc-users] Newbie question : complex number with MatView ?
Barry Smith
bsmith at mcs.anl.gov
Mon Feb 20 10:02:18 CST 2017
PETSc must be configured with --with-scalar-type=complex to use complex numbers. Then all PETSc vectors/matrices contain complex numbers. You cannot mix PETSc objects with real numbers and PETSc objects with complex numbers in the same program.
Barry
> On Feb 20, 2017, at 6:27 AM, lixin chu <lixin_chu at yahoo.com> wrote:
>
> Hello,
> Some questions wrt complex number - I have compiled PETSc with complex data type, but having problems of setting/getting the values:
>
> - MatView does not seem to print complex number ?
>
> - Does MATSEQAIJ support row major SetValues for complex number ? I have tested real number, it is ok. I can not get the right values with MatGetRow. Still troubleshooting if it is my program problem...
>
> This is how I set the matrix:
>
> PetscComplex *buffer; // this is the column data buffer, malloc'ed
>
> // setting the values
> buffer [i] = double1 + double2 * PETSC_i;
>
> Then call MatSetValues, passing buffer.
>
> The program is ok for real numbers, btw.
>
>
> I use a 5x5 matrix, when setting buffer for column 2, I can see these are the data passed to MatSetValues (row, col):
> (0, 2) 1 + 0
> (1, 2) 1 + 0
> (3, 2) -1 + 0
>
>
> But MatGetRow return:
> (0, 2) 1. + 1. i
> (1, 2) 0. + 1. i
> (3, 2) 1. + 0. i
>
> (I have used MatRestoreRow after MatGetRow).
>
> for ( i = 0; i < rows; i++ ) {
> MatGetRow ( Z, i, ¤t_doubles, &col_index, &complex_buffer );
> if ( current_doubles > 0 ) {
> for ( j = 0; j < current_doubles; j++ ) {
> PetscPrintf ( PETSC_COMM_WORLD, "(%d, %d) %g + %g i\n", i, col_index[j], PetscRealPart(complex_buffer[j]), PetscImaginaryPart (complex_buffer[j]) );
> }
> }
> MatRestoreRow( Z, i, ¤t_doubles, &col_index, &complex_buffer );
> }
>
>
> thanks !
> LX
More information about the petsc-users
mailing list