<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Nov 7, 2016 at 4:17 AM, Sander Arens <span dir="ltr"><<a href="mailto:Sander.Arens@ugent.be" target="_blank">Sander.Arens@ugent.be</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Ok, I see what happened.<br></div>If you create a a vector with <span class="m_-4800849206432027758gmail-im">DMGetGlobalVector, the VecView function is overloaded with some DM-specific VecView function (e.g. VecView_Plex), but this doesn't happen with the vec that you get from VecGetSubVector. So one way to solve this would be to create a global vector from your subdm and do the scatters yourself. <br>But I think it would be better if these VecView operations could be copied from the original vec in </span><span class="m_-4800849206432027758gmail-im">VecGetSubVector?<br></span></div></div></div></blockquote><div><br></div><div>You are right. I am moving this to petsc-dev temporarily for discussion.</div><div><br></div><div>  Thanks,</div><div><br></div><div>    Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><span class="m_-4800849206432027758gmail-im"></span></div><span class="m_-4800849206432027758gmail-im">Thanks,<br></span></div><span class="m_-4800849206432027758gmail-im">Sander<br></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 7 November 2016 at 09:08, 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">
  

    
  
  <div>
    Hi Sander:<br>
        Thank your for your assistance, but it is still not works. The
    code is now as follows:<span><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></span>
            ierr = VecSetDM(subX, dm);CHKERRQ(ierr);<span><br>
    <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
              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>
    </blockquote>
    <br>
    <br></span>
    I have add "VecSetDm", but it has not output file. <br>
    <br>
    Thanks<span class="m_-4800849206432027758HOEnZb"><font color="#888888"><br>
    leejearl</font></span><div><div class="m_-4800849206432027758h5"><br>
    <div class="m_-4800849206432027758m_-2963057619777554633moz-cite-prefix">On 2016年11月07日 15:35, Sander Arens
      wrote:<br>
    </div>
    <blockquote type="cite">
      <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="m_-4800849206432027758m_-2963057619777554633HOEnZb"><font color="#888888"><br>
                leejearl</font></span>
            <div class="m_-4800849206432027758m_-2963057619777554633HOEnZb">
              <div class="m_-4800849206432027758m_-2963057619777554633h5"><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>
    </blockquote>
    <br>
  </div></div></div>

</blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</div></div>