Re: [petsc-dev] One DM two SNES

2017-11-01 Thread Jed Brown
Blaise A Bourdin  writes:

> On Nov 1, 2017, at 7:46 PM, Jed Brown 
> mailto:j...@jedbrown.org>> wrote:
>
> Matthew Knepley mailto:knep...@gmail.com>> writes:
>
> On Wed, Nov 1, 2017 at 6:50 PM, Blaise A Bourdin 
> mailto:bour...@lsu.edu>> wrote:
>
> Hi,
>
> I have just spent 2h helping a student debugging a code, and I think that
> the problem is not ours…
> See the attached example: 1 create 1 DM and 2 SNES.
> If I assign the same DM to both SNES, the function and Jacobean of the
> second are ignored, and the first one is used.
> Replace the block l 138 - l. 149 with the one commented above, and the
> result is even weirder.
>
> Is this the intended behavior? If so, should there be a note of this
> behavior in the SNESSetDM man page?
>
> You can DMClone() when solving the other problem.
>
> I am not sure I understand everything this is doing, but I want to make an
> upfront point:
>
>  SNESSetFunction() is intended for use without a DM
>
> When the solver has a DM, we intend you to use
>
>  DMSNESSetFunctionLocal() and DMSNESSetJacobianLocal()
>
> This doesn't really matter -- SNESSetFunction just calls
> DMSNESSetFunction.  Getting rid of SNESSetFunction would save the
> confusion but break every existing PETSc code.
>
> However, now I think I see what is happening. The DMSNES is a structure
> that is intended to mediate between the solver
> and mesh. When you do SNESSetDM(), it copies over the DMSNES context. This
> context is already holding the formfunction
> and formjacobian pointers. Yes, this is confusing.
>
> Jed, how should this be documented?
>
> I don't know of a simple rule to prevent this in code.  You can have
> several SNES that are "related" in the sense that they help solve a
> given problem (nonlinear preconditioners, for example) and they can
> share a DM.  If you are solving different problems, you need to create a
> different DM.  Does this documentation help?
>
> https://bitbucket.org/petsc/petsc/commits/e03a659ce1e595e4412d70ada3603101a46e94e2
>
> Yes, I think it does. How about adding a  statement in the main DM man page 
> stating that each field should get its SNES and its DM, possibly through 
> cloning a main DM?

What is "each field"?  Normally we would recommend making one DM for all
the fields you are solving for, then solve it using one SNES (possibly
using some field-splitting decomposition).


Re: [petsc-dev] One DM two SNES

2017-11-01 Thread Blaise A Bourdin


On Nov 1, 2017, at 7:46 PM, Jed Brown 
mailto:j...@jedbrown.org>> wrote:

Matthew Knepley mailto:knep...@gmail.com>> writes:

On Wed, Nov 1, 2017 at 6:50 PM, Blaise A Bourdin 
mailto:bour...@lsu.edu>> wrote:

Hi,

I have just spent 2h helping a student debugging a code, and I think that
the problem is not ours…
See the attached example: 1 create 1 DM and 2 SNES.
If I assign the same DM to both SNES, the function and Jacobean of the
second are ignored, and the first one is used.
Replace the block l 138 - l. 149 with the one commented above, and the
result is even weirder.

Is this the intended behavior? If so, should there be a note of this
behavior in the SNESSetDM man page?

You can DMClone() when solving the other problem.

I am not sure I understand everything this is doing, but I want to make an
upfront point:

 SNESSetFunction() is intended for use without a DM

When the solver has a DM, we intend you to use

 DMSNESSetFunctionLocal() and DMSNESSetJacobianLocal()

This doesn't really matter -- SNESSetFunction just calls
DMSNESSetFunction.  Getting rid of SNESSetFunction would save the
confusion but break every existing PETSc code.

However, now I think I see what is happening. The DMSNES is a structure
that is intended to mediate between the solver
and mesh. When you do SNESSetDM(), it copies over the DMSNES context. This
context is already holding the formfunction
and formjacobian pointers. Yes, this is confusing.

Jed, how should this be documented?

I don't know of a simple rule to prevent this in code.  You can have
several SNES that are "related" in the sense that they help solve a
given problem (nonlinear preconditioners, for example) and they can
share a DM.  If you are solving different problems, you need to create a
different DM.  Does this documentation help?

https://bitbucket.org/petsc/petsc/commits/e03a659ce1e595e4412d70ada3603101a46e94e2

Yes, I think it does. How about adding a  statement in the main DM man page 
stating that each field should get its SNES and its DM, possibly through 
cloning a main DM?
I should have thought about it.

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









Re: [petsc-dev] One DM two SNES

2017-11-01 Thread Jed Brown
Matthew Knepley  writes:

> On Wed, Nov 1, 2017 at 6:50 PM, Blaise A Bourdin  wrote:
>
>> Hi,
>>
>> I have just spent 2h helping a student debugging a code, and I think that
>> the problem is not ours…
>> See the attached example: 1 create 1 DM and 2 SNES.
>> If I assign the same DM to both SNES, the function and Jacobean of the
>> second are ignored, and the first one is used.
>> Replace the block l 138 - l. 149 with the one commented above, and the
>> result is even weirder.
>>
>> Is this the intended behavior? If so, should there be a note of this
>> behavior in the SNESSetDM man page?

You can DMClone() when solving the other problem.

> I am not sure I understand everything this is doing, but I want to make an
> upfront point:
>
>   SNESSetFunction() is intended for use without a DM
>
> When the solver has a DM, we intend you to use
>
>   DMSNESSetFunctionLocal() and DMSNESSetJacobianLocal()

This doesn't really matter -- SNESSetFunction just calls
DMSNESSetFunction.  Getting rid of SNESSetFunction would save the
confusion but break every existing PETSc code.

> However, now I think I see what is happening. The DMSNES is a structure
> that is intended to mediate between the solver
> and mesh. When you do SNESSetDM(), it copies over the DMSNES context. This
> context is already holding the formfunction
> and formjacobian pointers. Yes, this is confusing.
>
> Jed, how should this be documented?

I don't know of a simple rule to prevent this in code.  You can have
several SNES that are "related" in the sense that they help solve a
given problem (nonlinear preconditioners, for example) and they can
share a DM.  If you are solving different problems, you need to create a
different DM.  Does this documentation help?

https://bitbucket.org/petsc/petsc/commits/e03a659ce1e595e4412d70ada3603101a46e94e2


Re: [petsc-dev] One DM two SNES

2017-11-01 Thread Matthew Knepley
On Wed, Nov 1, 2017 at 6:50 PM, Blaise A Bourdin  wrote:

> Hi,
>
> I have just spent 2h helping a student debugging a code, and I think that
> the problem is not ours…
> See the attached example: 1 create 1 DM and 2 SNES.
> If I assign the same DM to both SNES, the function and Jacobean of the
> second are ignored, and the first one is used.
> Replace the block l 138 - l. 149 with the one commented above, and the
> result is even weirder.
>
> Is this the intended behavior? If so, should there be a note of this
> behavior in the SNESSetDM man page?
>

I am not sure I understand everything this is doing, but I want to make an
upfront point:

  SNESSetFunction() is intended for use without a DM

When the solver has a DM, we intend you to use

  DMSNESSetFunctionLocal() and DMSNESSetJacobianLocal()

However, now I think I see what is happening. The DMSNES is a structure
that is intended to mediate between the solver
and mesh. When you do SNESSetDM(), it copies over the DMSNES context. This
context is already holding the formfunction
and formjacobian pointers. Yes, this is confusing.

Jed, how should this be documented?

   Matt


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


-- 
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://www.cse.buffalo.edu/~knepley/ 


[petsc-dev] One DM two SNES

2017-11-01 Thread Blaise A Bourdin
Hi,

I have just spent 2h helping a student debugging a code, and I think that the 
problem is not ours…
See the attached example: 1 create 1 DM and 2 SNES.
If I assign the same DM to both SNES, the function and Jacobean of the second 
are ignored, and the first one is used.
Replace the block l 138 - l. 149 with the one commented above, and the result 
is even weirder.

Is this the intended behavior? If so, should there be a note of this behavior 
in the SNESSetDM man page?

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









twosnes.c
Description: twosnes.c