[petsc-users] Newbie question : complex number with MatView ?

lixin chu lixin_chu at yahoo.com
Mon Feb 20 06:27:24 CST 2017


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, &current_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, &current_doubles, &col_index, &complex_buffer );}
 thanks !
LX
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170220/4a62fdc1/attachment.html>


More information about the petsc-users mailing list