Anush Krishnan <[email protected]> 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.
pgp6rkMwuwikM.pgp
Description: PGP signature
