[petsc-users] Switching between sections of the same DM

Aldo Bonfiglioli aldo.bonfiglioli at unibas.it
Mon Feb 9 06:24:27 CST 2026


Hi there,

I am trying to switch btw two different sections (section_l(1:2)) 
defined on the same DM (one section for the dependent variable, the 
other for their gradient)

> !
> ! dependent variables and their nodal gradient
> !
>   PetscCall(DMSetLocalSection(dm, section_l(1), ierr)) ! dependent 
> variables
>   PetscCall(DMGetLocalVector(dm, localu, ierr)) ! dependent variables
>   PetscCall(DMGlobaltoLocal(dm, u, INSERT_VALUES, localu, ierr))
>   PetscCall(VecSet(gradu, 0.d0, ierr))
>   PetscCall(DMSetLocalSection(dm, section_l(2), ierr)) ! gradient of 
> the dependent variables
>   PetscCall(DMGetLocalVector(dm, localdu, ierr)) ! gradient of the 
> dependent variables
>   PetscCall(VecSet(localdu, 0.d0, ierr))
> !
> callinnerloop(dm, localu, localdu, section_l, ierr)
>
subroutine innerloop is supposed to do work on both Vecs.

When trying to do so, I get the following error:

> [0]PETSC ERROR: --------------------- Error Message 
> --------------------------------------------------------------
> [0]PETSC ERROR: Object is in wrong state
> [0]PETSC ERROR: Clearing DM of local vectors that has a local vector 
> obtained with DMGetLocalVector()
>
as if two sections living simultaneously on the same DM are not allowed.

Should I instead clone the DM and create the "second" section of the clone?

Thanks,

Aldo

-- 
Dr. Aldo Bonfiglioli
Associate professor of Fluid Mechanics
Dipartimento di Ingegneria
Universita' della Basilicata
V.le dell'Ateneo Lucano, 10 85100 Potenza ITALY
tel:+39.0971.205203 fax:+39.0971.205215
web:https://urldefense.us/v3/__http://docenti.unibas.it/site/home/docente.html?m=002423__;!!G_uCfscf7eWS!YVPmxuMFuutpshSi89LXW-8W6oF1lauFcuN2HzqwcvecXbGkhDoRlhVqyIdHvFHEXN7_zUPSCbdoeElWRBtO1fQ_1q-v4pzF0QU$ 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20260209/071f1f5a/attachment-0001.html>


More information about the petsc-users mailing list