Hi,

Following on last week's discussion with Jed on petsc-dev, I am looking a 
moving the DM's associated to parameters in a PDE from a user context to the DM 
associated with the solution field, using PetscObjectCompose. 
Let's imagine for a second that I want to solve the PDE
        -div (k(x) \cdot u(x) ) = f + Boundary conditions, 
where k(x) is a a vector-valued coefficient and u(x) is the field I am solving 
for.
Assume that the DM for u is dmU and the one for K is dmK, and that they have 
been created.
Once both DMs are created, I can stash dmK inside dmU, using
        PetscObjectCompose((PetscObject) dmU,"SomeName",(PetscObject) dmK);
At this point, my understanding is that I can safely destroy dmK without 
causing a memory link, am I right?

In my jacobian evaluation, I get a copy of dmK using PetscObjectQuery with the 
proper name:
        PetscObjectQuery((PetscObject) dmU,"SomeName",(PetscObject*) &dmK);
Again, I _can_ safely call DMDestroy(&dmK) at the end of the jacobian. Can I 
simply let dmK fall out of scope?

I assume that dmK gets automatically destroyed when dmU is destroyed, right?

Finally, as far as I understand, I can either set the user context to the 
Jacobian function explicitly in the call to SNESSetJacobian or attach it to the 
DM using DMSetApplicationContext, or to the SNES using 
SNESSetApplicationContext. What would be the pros and cons of each technique? 
The same question would apply to DMCoarsenHookAdd.

Regards,

Blaise
-- 
Department of Mathematics and Center for Computation & Technology
Louisiana State University, Baton Rouge, LA 70803, USA
Tel. +1 (225) 578 1612, Fax  +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin


Reply via email to