<div dir="ltr"><div><div><div><div>Hi PETSc-developers, <br><br></div>For an application, I'd like to extract a 2D slice from a 3D DMDA vector, perform a `MatMult` on it (a discretized rotation on the 2D vector) and place the resulting vector back into the 3D vector. The approach I'd taken was to use `DMDACreatePatchIS` to create an IS that selects the slice (say this slice is [:,:,n_z] with no loss of generality). This IS is then used to extract the 2D slice via the `VecGetSubVector` utility. The issue that arises from this scheme is that the extracted 2D vector does not represent a flattened 2D vector, it is instead ordered as a DMDA vector (aka each rank having the portion of vector it owns in a column major ordering). How do I convert this DMDA ordered 2D subvector to a vector that represents a flattened 2D array? Since I can't predict how the extracted sub-vector <br><br></div><div>While PETSc provides `DMDAGlobalToNatural` routines, those don't apply to extracted sub-vectors and extracting the 2D slice from a natural vector (filled by a scatter from the global vector) does not work either. On the other hand, converting the output of DMDACreatePatchIS to a natural IS via `AOPetscToApplicationIS` before extracting a subvector extracts the wrong indices from the 3D vector. <br></div><div><br clear="all"><div><div>Could someone tell me how I can achieve the desired goal (converting a 2D vector ordered as per a 3D DMDA grid onto a natural flattened index) ? Thanks in advance for the help!<br><br></div><div>PS : Should it help, I'm attaching a slightly modified version of `src/dm/tests/ex53.c` to demonstrate the issue. The array I wish to obtain (the [:,:,2]) slice is : `[196., 194., 192., 190., 198., 197., 196., 195., 200., 200., 200.,200., 202., 203., 204., 205.]` (a row-major flattening of the 2D slice or alternatively a column-major flattening). What I obtain from the program (by creating the PatchIS and extracting the subvector) instead is : `[0 (A)] 196,198,194,197 [1 (B)] 200,202,200,203 [2 (C)] 192,196,190,195 [3 (D)] 200,204,200,205` (where each square bracket represents the rank and portion of the 2D vector being flattened via a column-major formatting with the layout shown below)<br>|---------|<br>| A | C  |<br>| B | D  |<br></div><div>|---------|<br><br></div><div><br></div><div>Thank You,<br></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div style="font-size:12.8px">Sajid Ali (he/him) | PhD Candidate<br></div><div style="font-size:12.8px">Applied Physics<br></div><div style="font-size:12.8px">Northwestern University</div><div style="font-size:12.8px"><a href="http://s-sajid-ali.github.io" target="_blank">s-sajid-ali.github.io</a></div></div></div></div></div></div></div></div></div></div></div></div></div>