[petsc-users] question about creating a block matrix

Randall Mackie rlmackie862 at gmail.com
Tue Aug 11 10:49:31 CDT 2020


> On Aug 10, 2020, at 9:00 PM, Jed Brown <jed at jedbrown.org> wrote:
> 
> Randall Mackie <rlmackie862 at gmail.com> writes:
> 
>> Dear PETSc users -
>> 
>> I am trying to create a block matrix but it is not clear to me what is the right way to do this.
>> 
>> First, I create 2 sparse matrices J1 and J2 using two different DMDAs.
>> Then I compute the products J1^T J1, and J2^T J2, which are different sized matrices.
>> 
>> Since the matrices are already constructed and built, what is the best way to place those matrices into a block matrix?
> 
> Block diagonal or are they coupled?

As you intuit the problem is more complicated and there are indeed off-diagonal blocks, but I wanted to start simply at first before adding more complexity.

> 
>> Does it work to create a composite DM, call DMCreateMatrix on the composite DM, then call MatGetLocalSubMatrix on the blocks, then simply do a MatCopy?
> 
> If the matrices are already assembled and there is no going back on that, it'd be easiest to use MatNest and then MatConvert (if you don't want a split solver).

While the matrices are already assembled, it would be possible (and maybe not as difficult as I first thought) to go back and assemble in local space.
The J2 matrix is the result of an interpolation from grid 2 to grid 1 using an interpolator matrix already assembled. However, I could do the interpolation in local space without the interpolator matrix. This would have the benefit of not assuming any particular matrix format, which I think is what you’re suggesting (and what is suggested in the manual).

In the meantime, I will try to use a MatNest just to confirm that everything is working as it should.


Thanks for your help,

Randy M.



More information about the petsc-users mailing list