[petsc-users] create a block matrix from existing petsc matrices and/or vectors

Smith, Barry F. bsmith at mcs.anl.gov
Fri Nov 30 18:25:58 CST 2018


    There really isn't any way in PETSc to generate the new matrix from the old matrix easily/trivially. You can create a new matrix with one additional column and extra row (on the final process) and have each process use MatGetRow() MatSetValues() to move the values to the new matrix for its local rows. 

   Barry


> On Nov 30, 2018, at 9:18 AM, NENNIG Benoit via petsc-users <petsc-users at mcs.anl.gov> wrote:
> 
> Dear petsc users,
> 
> I have parallel matrix A (mpiaij) and I would like to create a matrix B like
> B = [A v 
>     wT 0 ]
> where wT and v are vectors.
> A is involved in eigenvalue computation (slepc4py) and B will be used by a direct solver.
> Currently, the matrix A is built from a sparse scipy matrix thanks to A.createAIJ, but I would like to avoid to create B from scipy. I am looking for a more _petscic_ way to solve this problem.
> 
> I have read that it seems not possible to change a matrix structure after its assembly. However
> 
> - Is there a way to build directly in petsc this kind of block matrix B to reuse A ?
> - Is there a way to convert the petsc matrix A into csr form and to create B as new petsc matrix ?
> - Is there a way to copy a matrix into another one with a different structure ?
> - ...
> 
> My second question is similar, suppose I have three matrices A1, A2, C resulting form coupled 2 FEM problems, what is the good way to create the coupled global system 
> B = [A1 C
>     CT A2]
> to use it with direct solver.
> 
> Thanks a lot,
> 
> Benoit



More information about the petsc-users mailing list