[petsc-users] Creating a larger matrix from submatrices

Jed Brown jedbrown at mcs.anl.gov
Fri Nov 8 21:22:49 CST 2013


Anush Krishnan <anush at bu.edu> writes:

> Hi all,
>
> I'm trying to solve the Navier-Stokes equations on a staggered grid. I've
> created three DA vectors U, V and P to store the values of the x- and
> y-components of velocity and the pressure. Each of these has different
> global dimensions. I have assembled matrices Gx and Gy to calculate each
> component of the gradient of the pressure field:
>
> Gx * P = Rx
> Gy * P = Ry
>
> Rx and Ry have the same lengths and distributed structures of U and V.
>
> I would like to create matrix G and vector R such that
>
> G*P = R
>
> where
>
> G = /Gx\
>     \Gy/
> and
>
> R = /Rx\
>     \Ry/
>
> and vector R is created from the DMComposite of the DAs of U and V.

DMCreateGlobalVector() gives you the vector R.  Then use MatCreate() and
MatSetSizes() where the local and global row sizes match R and the
column sizes match P.  For your staggered grid, you should be able to
preallocate simply by using MatSeqAIJSetPreallocation() and
MatMPIAIJSetPreallocation() with a constant row size of 2 for the
"diagonal block" and 1 in the off-diagonal block.  (You can also
preallocate exactly to be more accurate with memory, but may as well
know you are assembling the correct thing first.)

You can call DMCompositeGetGlobalISs() to get index sets holding the
global indices for the U and V rows of your matrix, or just compute them
From the ownership range and the sizes.  The column indices will come
From the DMDA that holds P.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20131108/d99dfaaa/attachment.pgp>


More information about the petsc-users mailing list