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

Matthew Knepley knepley at gmail.com
Sat Dec 1 11:25:58 CST 2018


On Fri, Nov 30, 2018 at 10:19 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.
>

For this case, we have support for


https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreateLRC.html

Please let us know if it does not support all the operations you need.


> 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.
>

For bigger, non-dense blocks you could use


https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreateNest.html

However, we recommend assembling into the big matrix directly using


https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatGetLocalSubMatrix.html

That way you can get the matrix as a fully assembled thing that can be
factored for testing, and also
in the MatNest format so that you can extract blocks for string
preconditioning.

  Thanks,

    Matt


> Thanks a lot,
>
> Benoit
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20181201/7c9e4ea6/attachment.html>


More information about the petsc-users mailing list