<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Several years ago I asked a similar question and this is what Barry told me:<div class=""><br class=""></div><div class=""><br class=""></div><div class="">>>>>>>>>>></div><div class=""> Randy,<br class=""><br class=""> Take a look at DMDAGetRay() in src/dm/impls/da/dasub.c (now called DMDACreateRay()) this takes a row or column from a 2d DADM. You can use the same kind of approach to get a slice from a 3d DMDA.<br class=""><br class=""> Barry</div><div class=""><<<<<<<<<<</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div>Maybe this would help you?</div><div><br class=""></div><div><br class=""></div><div>Randy</div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 23, 2021, at 4:45 PM, Sajid Ali <<a href="mailto:sajidsyed2021@u.northwestern.edu" class="">sajidsyed2021@u.northwestern.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class="">Hi PETSc-developers, <br class=""><br class=""></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 class=""><br class=""></div><div class="">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 class=""></div><div class=""><br clear="all" class=""><div class=""><div class="">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 class=""><br class=""></div><div class="">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 class="">|---------|<br class="">| A | C |<br class="">| B | D |<br class=""></div><div class="">|---------|<br class=""><br class=""></div><div class=""><br class=""></div><div class="">Thank You,<br class=""></div><div class=""><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div style="font-size:12.8px" class="">Sajid Ali (he/him) | PhD Candidate<br class=""></div><div style="font-size:12.8px" class="">Applied Physics<br class=""></div><div style="font-size:12.8px" class="">Northwestern University</div><div style="font-size:12.8px" class=""><a href="http://s-sajid-ali.github.io/" target="_blank" class="">s-sajid-ali.github.io</a></div></div></div></div></div></div></div></div></div></div></div></div></div>
<span id="cid:f_kkaf3rqq0"><ex53.c></span></div></blockquote></div><br class=""></div></body></html>