Nonlinear and constrained solvers

Asked by corrado maurini

If I have correctly understood currently FEnics uses only the linear solvers of Petsc. Have you any plan to include an interface also for Petsc non-linear solvers (SNES objects)? What SNES objects require are just functions to evaluate the gradient and the Jacobian of the (nonlinear) functional to be minimized. I think it will be extremely interesting for many users because recent versions of Petsc include also bound constrained solvers which may be easily applied to solve variational inequalities (e.g. problem arising in contact or damage mechanics). See http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages/SNES/SNESVI.html#SNESVI

I wonder if you plan to support this in FEnics.

Otherwise, do you think it may be feasible to couple FEnics (for matrix assembly) with petsc4py (for solvers) in a single python program? Has anyone tried to do this?

Sincerely,

Corrado Maurini
University Pierre et Marie Curie

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Anders Logg (logg) said :
#1

On Wed, Sep 07, 2011 at 12:55:56PM -0000, corrado maurini wrote:
> New question #170426 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/170426
>
> If I have correctly understood currently FEnics uses only the linear solvers of Petsc. Have you any plan to include an interface also for Petsc non-linear solvers (SNES objects)? What SNES objects require are just functions to evaluate the gradient and the Jacobian of the (nonlinear) functional to be minimized. I think it will be extremely interesting for many users because recent versions of Petsc include also bound constrained solvers which may be easily applied to solve variational inequalities (e.g. problem arising in contact or damage mechanics). See http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages/SNES/SNESVI.html#SNESVI
>
> I wonder if you plan to support this in FEnics.
>
> Otherwise, do you think it may be feasible to couple FEnics (for
> matrix assembly) with petsc4py (for solvers) in a single python
> program? Has anyone tried to do this?

I think we should add an interface to PETSc SNES. It just hasn't
happened yet and I can't say when it will happen.

--
Anders

Revision history for this message
Garth Wells (garth-wells) said :
#2

On 7 September 2011 15:55, Anders Logg
<email address hidden> wrote:
> Question #170426 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/170426
>
>    Status: Open => Answered
>
> Anders Logg proposed the following answer:
> On Wed, Sep 07, 2011 at 12:55:56PM -0000, corrado maurini wrote:
>> New question #170426 on DOLFIN:
>> https://answers.launchpad.net/dolfin/+question/170426
>>
>> If I have correctly understood currently FEnics uses only the linear solvers of Petsc. Have you any plan to include an interface also for Petsc non-linear solvers  (SNES objects)? What SNES objects require are just functions to evaluate the gradient and the Jacobian of the (nonlinear) functional to be minimized. I think it will be extremely interesting for many users because recent versions of Petsc include also bound constrained solvers which may be easily applied to solve variational inequalities (e.g. problem arising in contact or damage mechanics). See http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages/SNES/SNESVI.html#SNESVI
>>
>> I wonder if you plan to support this in FEnics.
>>
>> Otherwise, do you think it may be feasible to couple FEnics (for
>> matrix assembly) with petsc4py (for solvers) in a single python
>> program? Has anyone tried to do this?
>
> I think we should add an interface to PETSc SNES. It just hasn't
> happened yet and I can't say when it will happen.
>

We had an interface a long time ago, but at the time SNES didn't offer
much special that we couldn't easily construct using our higher-level
abstractions. Plus the old-fashioned SNES interface made the coding
painful.

SNES might now offer something that makes it worth wrapping.

Garth

> --
> Anders
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

Revision history for this message
Johan Hake (johan-hake) said :
#3

On Wednesday September 7 2011 05:55:56 corrado maurini wrote:
> New question #170426 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/170426
>
> If I have correctly understood currently FEnics uses only the linear
> solvers of Petsc. Have you any plan to include an interface also for Petsc
> non-linear solvers (SNES objects)? What SNES objects require are just
> functions to evaluate the gradient and the Jacobian of the (nonlinear)
> functional to be minimized. I think it will be extremely interesting for
> many users because recent versions of Petsc include also bound constrained
> solvers which may be easily applied to solve variational inequalities
> (e.g. problem arising in contact or damage mechanics). See
> http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages
> /SNES/SNESVI.html#SNESVI

You can always do this by using the C++ interface of DOLFIN. Then you can
access the underlying PETSc objects by using the mat() or vec() method.

> I wonder if you plan to support this in FEnics.
>
> Otherwise, do you think it may be feasible to couple FEnics (for matrix
> assembly) with petsc4py (for solvers) in a single python program? Has
> anyone tried to do this?

PETSc is wrapped using cython (I think...) and DOLFIN using SWIG. The wrapped
objects are not compatible with eachother. So you cannot pass a PETSc object
from DOLFIN to petsc4py.

This might be fixed by writing a wrapper in the C layer for PETSc Cython
objects -> PETSc SWIG objects or the other way around. I am not exactly sure
what differs and how we can access one from the other so I do not think it
will be implemented any time soon. But I do admit it would be a cool feature
to have!

DOLFIN and PyTrilinos interfaces very well, as PyTrilinos is wrapped using
SWIG.

Johan

> Sincerely,
>
> Corrado Maurini
> University Pierre et Marie Curie

Revision history for this message
corrado maurini (corrado-maurini) said :
#4

I was so absorbed in the python/FEnics wonderland that I was not even thinking about this possibility.

Indeed, if I understand well, in C++ I can write functions to calculate the gradient and the hessian of a functional with FEnics, access the corresponding PETSc object using vec() and mat() and give them as input to the PETSc SNES. What I have to do directly with petsc is just to initialize and setup the SNES. Is it correct?

Thanks a lot for help.

Corrado

Revision history for this message
Garth Wells (garth-wells) said :
#5

Yes, that is correct.

Can you help with this problem?

Provide an answer of your own, or ask corrado maurini for more information if necessary.

To post a message you must log in.