[petsc-users] How to fetch right values of a local vector

袁煕 yuanxi at advancesoft.jp
Fri Feb 23 19:40:20 CST 2024


Great!

I got the right answer now after adding  MSetSectionSF(dm, PETSC_NULL_SF,
ierr)  .

Thanks for your help!

2024年2月24日(土) 0:09 Matthew Knepley <knepley at gmail.com>:

> On Fri, Feb 23, 2024 at 9:54 AM 袁煕 <yuanxi at advancesoft.jp> wrote:
>
>> Hello, I cannot fetch right values of a local vector after a second time
>> calling DMSetLocalSection.   My program runs like ==================== call
>> PetscSectionSetup(section1,ierr) call
>> DMSetLocalSection(dm_mesh,section1,ierr)call PetscSectionDestroy(section1,ierr)call
>>
>> ZjQcmQRYFpfptBannerStart
>> This Message Is From an External Sender
>> This message came from outside your organization.
>>
>> ZjQcmQRYFpfptBannerEnd
>> Hello,
>>
>> I cannot fetch right values of a local vector after a second time
>> calling DMSetLocalSection.  My program runs like
>>
>> ====================
>> call PetscSectionSetup(section1,ierr)
>> call DMSetLocalSection(dm_mesh,section1,ierr)
>> call PetscSectionDestroy(section1,ierr)
>>
>> call DMCreateGlobalVector(dm_mesh,vec_a,ierr)
>>
>> call VecDestroy(vec_a,ierr)
>> call DMClearLocalVectors(dm_mesh, ierr);
>>
>
> You also need to wipe out the SF,
>
>   call DMSetSectionSF(dm, PETSC_NULL_PETSCSF, ierr)
>
>
>> call PetscSectionSetup(section2,ierr)
>> call DMSetLocalSection(dm_mesh,section2,ierr)
>>
>> call DMCreateGlobalVector(dm_mesh,vec_a,ierr)
>> call DMGetLocalVector(dm_mesh,lvec,ierr);
>> call DMGlobalToLocal(dm_mesh,vec_a,INSERT_VALUES,lvec,ierr)
>> call VecGetArrayReadF90(lvec,tempv,ierr)
>> call VecGetArrayReadF90(vec_a,tempv1,ierr)
>> ========================
>>
>> In this program, I got two Fortran style arrays, *tempv* and *tempv1*,
>> from a Vec *vec_a*. When only 1 cpu is used, those two arrays should be
>> completely the same. Am I right? But I found there are differences as
>> follows:
>>
>> *  In array *tempv*,  dofs newly introduced by section2 are zero valued.
>> Looks like those values are ignored by DMGlobalToLocal. But in array
>> *tempv1*, all dofs values are set correctly.
>>
>> Did I do something wrong in the above code?
>>
>
> We do not usually reset the section on a DM. Instead, when we want to use
> a different function space,
> we clone the DM, using DMClone(), and make a new function space on the new
> DM.
>
>   Thanks,
>
>      MAtt
>
> Much thanks for your help.
>>
>> X. Yuan, Ph.D. in Solid Mechanics
>>
>
>
> --
> 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
>
> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!evESqBlm5Zicyq1vyvKH4U3lb8mmr4oJ0g8wD2frNpVrXRZBquQvmaKByiIqNUAUIRjp663x-unmEZQzM96NE96GKLk$ 
> <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!evESqBlm5Zicyq1vyvKH4U3lb8mmr4oJ0g8wD2frNpVrXRZBquQvmaKByiIqNUAUIRjp663x-unmEZQzM96NDlq-o4E$ >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240224/765c3aa1/attachment-0001.html>


More information about the petsc-users mailing list