<div dir="ltr"><div><div><div>Does it work if you put<br> ierr = VecSetDM(subX, subdm);CHKERRQ(ierr);<br></div>before the VecView?<br><br></div>Thanks,<br></div>Sander<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 7 November 2016 at 03:50, leejearl <span dir="ltr"><<a href="mailto:leejearl@126.com" target="_blank">leejearl@126.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, Barry:<br>
    I must have some make some mistakes. I post the code as follows:<br>
        Vec subX, X;<br>
        DM subdm;<br>
        IS subIS;<br>
        PetscInt numSubFields = 2;<br>
        PetscInt subFields[2];<br>
        subFields[0] = 0; subFields[1] =1 ;<br>
        ierr = DMCreateSubDM(dm, numSubFields, subFields, &subIS, &subdm);CHKERRQ(ierr);<br>
        ierr = DMGetGlobalVector(dm, &X);CHKERRQ(ierr);<br>
        ierr = VecGetSubVector(X,subIS,&subX)<wbr>;CHKERRQ(ierr);<br>
        ierr = PetscObjectSetName((PetscObjec<wbr>t) subX, "sol.");CHKERRQ(ierr);<br>
        ierr = PetscViewerSetType(*viewer, PETSCVIEWERVTK);CHKERRQ(ierr);<br>
       ierr = PetscViewerPushFormat(*viewer, PETSC_VIEWER_VTK_VTU);CHKERRQ(<wbr>ierr);<br>
        ierr = PetscViewerFileSetName(*viewer<wbr>, "subsol.vtu");CHKERRQ(ierr);<br>
        ierr = VecView(subX, viewer);CHKERRQ(ierr);<br>
        ierr = PetscViewerDestroy(&viewer);CH<wbr>KERRQ(ierr);<br>
        ierr = VecRestoreSubVector(X, subIS, &subX);CHKERRQ(ierr);<br>
        DMDestroy(&subdm);<br>
        ierr = DMRestoreGlobalVector(dm, &X);CHKERRQ(ierr);<br>
<br>
There are three fields in dm, and I want to obtain the vector of the two of them. But, I can not<br>
get the output file “subsol.vtu”. Can you help me with the code?<br>
<br>
Thanks<span class="HOEnZb"><font color="#888888"><br>
leejearl</font></span><div class="HOEnZb"><div class="h5"><br>
On 2016年11月06日 12:21, Barry Smith wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Nov 5, 2016, at 8:36 PM, leejearl <<a href="mailto:leejearl@126.com" target="_blank">leejearl@126.com</a>> wrote:<br>
<br>
Hi Sander:<br>
     Thank you for your advices, and it works. But it is only available in th local vector.<br>
</blockquote>
   This should work on the global vector. Please send the full output of the error messages when used with a global vector.<br>
<br>
    Barry<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Is there any methods to reach this purposes in the global vector?<br>
     Thanks<br>
leejearl<br>
On 2016年11月05日 19:29, Sander Arens wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
You can first obtain an IS with<br>
<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DM/DMCreateSubDM.html" rel="noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/p<wbr>etsc-current/docs/manualpages/<wbr>DM/DMCreateSubDM.html</a><br>
and with that you can obtain a subvector with<br>
<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetSubVector.html" rel="noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/p<wbr>etsc-current/docs/manualpages/<wbr>Vec/VecGetSubVector.html</a><br>
which you can then view the usual way.<br>
<br>
Thanks,<br>
Sander<br>
<br>
On 5 November 2016 at 12:17, leejearl <<a href="mailto:leejearl@126.com" target="_blank">leejearl@126.com</a>> wrote:<br>
Hi, all:<br>
<br>
     I meet a problems which I can not overcome. The programe is like the code in<br>
<br>
"<a href="http://www.mcs.anl.gov/petsc/petsc-current/src/dm/impls/plex/examples/tutorials/ex1.c.html" rel="noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/<wbr>petsc-current/src/dm/impls/ple<wbr>x/examples/tutorials/ex1.c.htm<wbr>l</a>".<br>
<br>
    The code create a section which has three fields: u,v,w. How can I output the fields u and v without together with w?<br>
<br>
    Thanks!<br>
<br>
<br>
leejearl<br>
<br>
<br>
<br>
<br>
</blockquote></blockquote></blockquote>
<br>
<br>
</div></div></blockquote></div><br></div>