Build a block matrix

Hi,

I have given 4 objects of dolfin::GenericMatrix called A B C D and I would like to create a new object M of type dolfin::GenericMatrix which has the block structure:

M = [A B; C D]

How can I do that? I am writing in c++

For any help I would be very thankful!
Best, moerni

PS: The class BlockMatrix does really help me. It easily allows to define a block matrix, but the object then is not a dolfin::GenericMatrix as far as I can see it.

Rather than reinventing the wheel with old DOLFIN, I recommend using dolfin-x (part of FEniCS-x) which has support for monolithic-block and nested-block matrix types. See for example the assembly and solution schemes in the Stokes demo.

1 Like

Hi nate,

thanks for the suggestion. However, I don’t really see this as a solution for my problem, as far as I understand it. My Code is not written in the latest FEniCS version and it is a very large complex code, so updating all libraries will take a lot of time. The demo that you have suggested is written in python, but I am using c++. And I don’t see the functionality to define a block GenericMatrix in dolfin-x as well. Do you know a way how to define a new dolfin::GenericMatrix which has a block structure of 4 given dolfin::GenericMatrix objects? This sounds so simple, yet I wasn’t able to do it.

Any help is very much appreciated. Thanks in advance!

Old dolfin GenericMatrix is just an abstract base class, as I’m sure you can tell. I guess you could try to shoe-horn your ideas with a PETScNestMatrix, e.g. this Stokes demo.