[petsc-users] Example for MatInvertBlockDiagonal

Barry Smith bsmith at mcs.anl.gov
Mon Sep 19 12:40:11 CDT 2016


> On Sep 19, 2016, at 10:43 AM, Cyrill Vonplanta <cyrill.von.planta at usi.ch> wrote:
> 
> Barry,
> 
> Thanks a lot. I’d like to use this for a nonlinear variant of a block-gauss-seidel smoother. I would like to use MatInvertBlockDiagonal for speeding up my variant.
> 
> I think I can work with this, however I also have the problem to turn my initial matrix into one with a blocksize of 3.When I call:
> 
> MatConvert(A, MATBAIJ, MAT_INITIAL_MATRIX, Dinverse);

   MatConvert() creates a new matrix so you should not create the Dinverse beforehand; anything you put in Dinverse before is lost..m 

   block size > 1 really only makes sense if the block size is really greater than one. So if A has blocks of size 3 you should create A as BAIJ and thus never need to call the convert routine.

   You can also set the block size for AIJ matrix to 3 and use MatInvertBlockDiagonal() on that matrix and not use the BAIJ matrix. 

   Finally note that MatInvertBlockDiagonal() ends up calling (for block size 3) PetscKernel_A_gets_inverse_A_3() for each block. It sounds to me like that is what you would want for nonlinear variant of a block-gauss-seidel smoother..

   Barry

> 
> 
> Then the matrix Dinverse has blocksize 1 which comes from A. I checked the blocksize before the conversion and it was 3, so it seems to get lost.
> 
> What is the correct (and elegant) way to turn a matrix into a block matrix?
> 
> 
> Best
> Cyrill
> 
> 
> 
> On 19/09/16 17:18, "Barry Smith" <bsmith at mcs.anl.gov> wrote:
> 
>> 
>> Cyrill,
>> 
>>   This is very specialized for implementing point block Jacobi; I don't think it is something you would want to use directly. 
>> 
>>    If you do want to use it, it simply returns the inverses of the block diagonals in column major form. You can then call MatSetValues() with with each of those blocks into another PETSc matrix. values[i*bs*bs] is the starting point of each block in the array.
>> 
>>  Barry
>> 
>>> On Sep 19, 2016, at 4:55 AM, Cyrill Vonplanta <cyrill.von.planta at usi.ch> wrote:
>>> 
>>> Dear PETSc-Users,
>>> 
>>> I would like to use the inverted block diagonals of a a matrix. I have seen the function MatInvertBlockDiagonal() but I don’t know how to create a matrix out of them or an array of block matrizes.
>>> 
>>> Does anyone have an example on how to use  **values to create a PETSc matrix?
>>> 
>>> Thanks
>>> Cyrill
>> 



More information about the petsc-users mailing list