[petsc-users] how to output components of a section

leejearl leejearl at 126.com
Wed Nov 9 23:54:04 CST 2016


Hi, Matt
     Thanks for your reply, and will it be solved in the newest version 
of PETSc?

leejearl

On 2016年11月07日 20:09, Matthew Knepley wrote:
> On Mon, Nov 7, 2016 at 4:17 AM, Sander Arens <Sander.Arens at ugent.be 
> <mailto:Sander.Arens at ugent.be>> wrote:
>
>     Ok, I see what happened.
>     If you create a a vector with 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.
>     But I think it would be better if these VecView operations could
>     be copied from the original vec in VecGetSubVector?
>
>
> You are right. I am moving this to petsc-dev temporarily for discussion.
>
>   Thanks,
>
>     Matt
>
>     Thanks,
>     Sander
>
>     On 7 November 2016 at 09:08, leejearl <leejearl at 126.com
>     <mailto:leejearl at 126.com>> wrote:
>
>         Hi Sander:
>             Thank your for your assistance, but it is still not works.
>         The code is now as follows:
>                 Vec subX, X;
>                 DM subdm;
>                 IS subIS;
>                 PetscInt numSubFields = 2;
>                 PetscInt subFields[2];
>                 subFields[0] = 0; subFields[1] =1 ;
>                 ierr = DMCreateSubDM(dm, numSubFields, subFields,
>         &subIS, &subdm);CHKERRQ(ierr);
>                 ierr = DMGetGlobalVector(dm, &X);CHKERRQ(ierr);
>                 ierr = VecGetSubVector(X,subIS,&subX);CHKERRQ(ierr);
>                 ierr = VecSetDM(subX, dm);CHKERRQ(ierr);
>
>                     ierr = PetscObjectSetName((PetscObject) subX,
>             "sol.");CHKERRQ(ierr);
>                     ierr = PetscViewerSetType(*viewer,
>             PETSCVIEWERVTK);CHKERRQ(ierr);
>                    ierr = PetscViewerPushFormat(*viewer,
>             PETSC_VIEWER_VTK_VTU);CHKERRQ(ierr);
>                     ierr = PetscViewerFileSetName(*viewer,
>             "subsol.vtu");CHKERRQ(ierr);
>                     ierr = VecView(subX, viewer);CHKERRQ(ierr);
>                     ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
>                     ierr = VecRestoreSubVector(X, subIS,
>             &subX);CHKERRQ(ierr);
>                     DMDestroy(&subdm);
>                     ierr = DMRestoreGlobalVector(dm, &X);CHKERRQ(ierr);
>
>
>
>         I have add "VecSetDm", but it has not output file.
>
>         Thanks
>         leejearl
>
>         On 2016年11月07日 15:35, Sander Arens wrote:
>>         Does it work if you put
>>         ierr = VecSetDM(subX, subdm);CHKERRQ(ierr);
>>         before the VecView?
>>
>>         Thanks,
>>         Sander
>>
>>         On 7 November 2016 at 03:50, leejearl <leejearl at 126.com
>>         <mailto:leejearl at 126.com>> wrote:
>>
>>             Hi, Barry:
>>                 I must have some make some mistakes. I post the code
>>             as follows:
>>                     Vec subX, X;
>>                     DM subdm;
>>                     IS subIS;
>>                     PetscInt numSubFields = 2;
>>                     PetscInt subFields[2];
>>                     subFields[0] = 0; subFields[1] =1 ;
>>                     ierr = DMCreateSubDM(dm, numSubFields, subFields,
>>             &subIS, &subdm);CHKERRQ(ierr);
>>                     ierr = DMGetGlobalVector(dm, &X);CHKERRQ(ierr);
>>                     ierr = VecGetSubVector(X,subIS,&subX);CHKERRQ(ierr);
>>                     ierr = PetscObjectSetName((PetscObject) subX,
>>             "sol.");CHKERRQ(ierr);
>>                     ierr = PetscViewerSetType(*viewer,
>>             PETSCVIEWERVTK);CHKERRQ(ierr);
>>                    ierr = PetscViewerPushFormat(*viewer,
>>             PETSC_VIEWER_VTK_VTU);CHKERRQ(ierr);
>>                     ierr = PetscViewerFileSetName(*viewer,
>>             "subsol.vtu");CHKERRQ(ierr);
>>                     ierr = VecView(subX, viewer);CHKERRQ(ierr);
>>                     ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
>>                     ierr = VecRestoreSubVector(X, subIS,
>>             &subX);CHKERRQ(ierr);
>>                     DMDestroy(&subdm);
>>                     ierr = DMRestoreGlobalVector(dm, &X);CHKERRQ(ierr);
>>
>>             There are three fields in dm, and I want to obtain the
>>             vector of the two of them. But, I can not
>>             get the output file “subsol.vtu”. Can you help me with
>>             the code?
>>
>>             Thanks
>>             leejearl
>>
>>             On 2016年11月06日 12:21, Barry Smith wrote:
>>
>>                     On Nov 5, 2016, at 8:36 PM, leejearl
>>                     <leejearl at 126.com <mailto:leejearl at 126.com>> wrote:
>>
>>                     Hi Sander:
>>                          Thank you for your advices, and it works.
>>                     But it is only available in th local vector.
>>
>>                    This should work on the global vector. Please send
>>                 the full output of the error messages when used with
>>                 a global vector.
>>
>>                     Barry
>>
>>                     Is there any methods to reach this purposes in
>>                     the global vector?
>>                          Thanks
>>                     leejearl
>>                     On 2016年11月05日 19:29, Sander Arens wrote:
>>
>>                         You can first obtain an IS with
>>                         http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DM/DMCreateSubDM.html
>>                         <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DM/DMCreateSubDM.html>
>>                         and with that you can obtain a subvector with
>>                         http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetSubVector.html
>>                         <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetSubVector.html>
>>                         which you can then view the usual way.
>>
>>                         Thanks,
>>                         Sander
>>
>>                         On 5 November 2016 at 12:17, leejearl
>>                         <leejearl at 126.com <mailto:leejearl at 126.com>>
>>                         wrote:
>>                         Hi, all:
>>
>>                              I meet a problems which I can not
>>                         overcome. The programe is like the code in
>>
>>                         "http://www.mcs.anl.gov/petsc/petsc-current/src/dm/impls/plex/examples/tutorials/ex1.c.html
>>                         <http://www.mcs.anl.gov/petsc/petsc-current/src/dm/impls/plex/examples/tutorials/ex1.c.html>".
>>
>>                             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?
>>
>>                             Thanks!
>>
>>
>>                         leejearl
>>
>>
>>
>>
>>
>>
>>
>
>
>
>
>
> -- 
> What most experimenters take for granted before they begin their 
> experiments is infinitely more interesting than any results to which 
> their experiments lead.
> -- Norbert Wiener

-- 
李季
西北工业大学航空学院流体力学系
Phone: 17792092487
QQ: 188524324

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20161110/4d417dd4/attachment-0001.html>


More information about the petsc-users mailing list