[petsc-users] Newbie question : complex number with MatView ?
lixin chu
lixin_chu at yahoo.com
Mon Feb 20 18:20:07 CST 2017
Yes, I compiled with complex data type.
Is setting imaginary part 0 ok ? Like this:
1.0 ÷ 0.0 * PETSC_i
Sent from Yahoo Mail on Android
On Tue, 21 Feb 2017 at 0:02, Barry Smith<bsmith at mcs.anl.gov> wrote:
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170221/8aaf00da/attachment.html>
More information about the petsc-users
mailing list