new solver interface for nonlinear problems

Asked by yk1000

I've noticed that the solver interface for 1.0-beta has been given a complete overhaul.
If I want to solve a nonlinear variational problem directly (using this interface), how do I define which
solver I'd like to use for the newton solver and the tolerance/max iterations, without an explicit approach
like in the Cahn-Hilliard example?
Once I define these, can I just do something like "solve(F == 0, u, bcs, J)" to solve?
Can I specify these in a parameters.xml file and read them in as global parameters?
I couldn't really find this information in the documentation.
Thanks in advance.

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Anders Logg (logg) said :
#1

On Sun, Sep 18, 2011 at 10:20:55PM -0000, yk1000 wrote:
> New question #171575 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/171575
>
> I've noticed that the solver interface for 1.0-beta has been given a complete overhaul.
> If I want to solve a nonlinear variational problem directly (using this interface), how do I define which
> solver I'd like to use for the newton solver and the tolerance/max iterations, without an explicit approach
> like in the Cahn-Hilliard example?
> Once I define these, can I just do something like "solve(F == 0, u, bcs, J)" to solve?
> Can I specify these in a parameters.xml file and read them in as global parameters?
> I couldn't really find this information in the documentation.
> Thanks in advance.

Take a look here:

  http://fenicsproject.org/releases/1.0-beta/index.html

It is currently not possible to specify parameters to the solve()
function so you must use the Linear/NonlinearVariationalProblem/Solver
classes.

At some point in the future, I expect we will extend the solve()
function so one can send parameters to it.

--
Anders

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

In the Python interface you can send parameters to both linear and nonlinear variational solvers. Send them as dictionaries. Take a look at the doctoring for more details.

Johan

On Sep 19, 2011, at 4:25, Anders Logg <email address hidden> wrote:

> Question #171575 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171575
>
> Status: Open => Answered
>
> Anders Logg proposed the following answer:
> On Sun, Sep 18, 2011 at 10:20:55PM -0000, yk1000 wrote:
>> New question #171575 on DOLFIN:
>> https://answers.launchpad.net/dolfin/+question/171575
>>
>> I've noticed that the solver interface for 1.0-beta has been given a complete overhaul.
>> If I want to solve a nonlinear variational problem directly (using this interface), how do I define which
>> solver I'd like to use for the newton solver and the tolerance/max iterations, without an explicit approach
>> like in the Cahn-Hilliard example?
>> Once I define these, can I just do something like "solve(F == 0, u, bcs, J)" to solve?
>> Can I specify these in a parameters.xml file and read them in as global parameters?
>> I couldn't really find this information in the documentation.
>> Thanks in advance.
>
> Take a look here:
>
> http://fenicsproject.org/releases/1.0-beta/index.html
>
> It is currently not possible to specify parameters to the solve()
> function so you must use the Linear/NonlinearVariationalProblem/Solver
> classes.
>
> At some point in the future, I expect we will extend the solve()
> function so one can send parameters to it.
>
> --
> 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
Anders Logg (logg) said :
#3

I forgot I added this already... :-) Or did someone else add it?

--
Anders

On Mon, Sep 19, 2011 at 04:20:52PM -0000, Johan Hake wrote:
> Question #171575 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171575
>
> Johan Hake proposed the following answer:
> In the Python interface you can send parameters to both linear and
> nonlinear variational solvers. Send them as dictionaries. Take a look at
> the doctoring for more details.
>
> Johan
>
> On Sep 19, 2011, at 4:25, Anders Logg
> <email address hidden> wrote:
>
> > Question #171575 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/171575
> >
> > Status: Open => Answered
> >
> > Anders Logg proposed the following answer:
> > On Sun, Sep 18, 2011 at 10:20:55PM -0000, yk1000 wrote:
> >> New question #171575 on DOLFIN:
> >> https://answers.launchpad.net/dolfin/+question/171575
> >>
> >> I've noticed that the solver interface for 1.0-beta has been given a complete overhaul.
> >> If I want to solve a nonlinear variational problem directly (using this interface), how do I define which
> >> solver I'd like to use for the newton solver and the tolerance/max iterations, without an explicit approach
> >> like in the Cahn-Hilliard example?
> >> Once I define these, can I just do something like "solve(F == 0, u, bcs, J)" to solve?
> >> Can I specify these in a parameters.xml file and read them in as global parameters?
> >> I couldn't really find this information in the documentation.
> >> Thanks in advance.
> >
> > Take a look here:
> >
> > http://fenicsproject.org/releases/1.0-beta/index.html
> >
> > It is currently not possible to specify parameters to the solve()
> > function so you must use the Linear/NonlinearVariationalProblem/Solver
> > classes.
> >
> > At some point in the future, I expect we will extend the solve()
> > function so one can send parameters to it.
> >
>

Revision history for this message
yk1000 (ykimura) said :
#4

Thanks Anders and Johan. Since I'd like to use the C++ interface, I guess I'll use the NonlinearVariationalProblem/Solver class for now. Will the solve() function be extended (with support for parameter input) by the 1.0 release?

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

It should be pretty simple to add, with the negative consequence of code
bloat, as we need one such function for each version we have today.

Johan

On Monday September 19 2011 10:25:49 yk1000 wrote:
> Question #171575 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171575
>
> Status: Answered => Solved
>
> yk1000 confirmed that the question is solved:
> Thanks Anders and Johan. Since I'd like to use the C++ interface, I
> guess I'll use the NonlinearVariationalProblem/Solver class for now.
> Will the solve() function be extended (with support for parameter input)
> by the 1.0 release?

Revision history for this message
Anders Logg (logg) said :
#6

On Mon, Sep 19, 2011 at 05:45:41PM -0000, Johan Hake wrote:
> Question #171575 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171575
>
> Johan Hake posted a new comment:
> It should be pretty simple to add, with the negative consequence of code
> bloat, as we need one such function for each version we have today.

Can't we just use a default argument parameters=<something>?

--
Anders

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

On Monday September 19 2011 12:01:08 Anders Logg wrote:
> Question #171575 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171575
>
> Anders Logg posted a new comment:
>
> On Mon, Sep 19, 2011 at 05:45:41PM -0000, Johan Hake wrote:
> > Question #171575 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/171575
> >
> > Johan Hake posted a new comment:
> > It should be pretty simple to add, with the negative consequence of code
> > bloat, as we need one such function for each version we have today.
>
> Can't we just use a default argument parameters=<something>?

Yes I guess so:

 ... , solver_parameters=Parameters()

or

 ... , solver_parameters=_empty_parameters

where _empty_parameters can be a predefined object.

I thought of this first, but rejected it because I have had troubles ignoring
these methods in the Python interface. But now I have found a SWIG directive
which remove all code bloat wrt default argumets in C++, reducing the wrapper
code with 0.3Mb, which is nice :) Will commit soonish.

Johan

Revision history for this message
Anders Logg (logg) said :
#8

On Mon, Sep 19, 2011 at 07:15:46PM -0000, Johan Hake wrote:
> Question #171575 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171575
>
> Johan Hake posted a new comment:
> On Monday September 19 2011 12:01:08 Anders Logg wrote:
> > Question #171575 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/171575
> >
> > Anders Logg posted a new comment:
> >
> > On Mon, Sep 19, 2011 at 05:45:41PM -0000, Johan Hake wrote:
> > > Question #171575 on DOLFIN changed:
> > > https://answers.launchpad.net/dolfin/+question/171575
> > >
> > > Johan Hake posted a new comment:
> > > It should be pretty simple to add, with the negative consequence of code
> > > bloat, as we need one such function for each version we have today.
> >
> > Can't we just use a default argument parameters=<something>?
>
> Yes I guess so:
>
> ... , solver_parameters=Parameters()
>
> or
>
> ... , solver_parameters=_empty_parameters
>
> where _empty_parameters can be a predefined object.
>
> I thought of this first, but rejected it because I have had troubles ignoring
> these methods in the Python interface. But now I have found a SWIG directive
> which remove all code bloat wrt default argumets in C++, reducing the wrapper
> code with 0.3Mb, which is nice :) Will commit soonish.

Sounds good.

--
Anders

Revision history for this message
yk1000 (ykimura) said :
#9

Johan and Anders,

So in the C++ interface, by constructing a NonlinearVariationalProblem object I'm able to change the linear_solver and preconditioner parameters like so:

  NonlinearVariationalProblem problem(F, u, J);
  NonlinearVariationalSolver solver(problem);
  solver.parameters["linear_solver"] = "lu";
  solver.parameters["preconditioner"] = "ilu";

But it appears I can't change the parameters of the underlying newton_solver yet (though in the documentation it appears you can in the python interface):

  solver.parameters["newton_solver"]["maximum_iterations"] = 20;

If I do:
 info(solver.parameters,true);

I can see that the newton_solver parameter set is nested in those of the nonlinear_variational_solver.
So there is no way to access these currently in the C++ interface without explicitly constructing my own NonlinearProblem object? Thanks again.

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

On Tuesday September 20 2011 15:01:01 yk1000 wrote:
> Question #171575 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171575
>
> Status: Solved => Open
>
> yk1000 is still having a problem:
> Johan and Anders,
>
> So in the C++ interface, by constructing a NonlinearVariationalProblem
> object I'm able to change the linear_solver and preconditioner
> parameters like so:
>
> NonlinearVariationalProblem problem(F, u, J);
> NonlinearVariationalSolver solver(problem);
> solver.parameters["linear_solver"] = "lu";
> solver.parameters["preconditioner"] = "ilu";
>
> But it appears I can't change the parameters of the underlying
> newton_solver yet (though in the documentation it appears you can in the
> python interface):
>
> solver.parameters["newton_solver"]["maximum_iterations"] = 20;
>
> If I do:
> info(solver.parameters,true);
>
> I can see that the newton_solver parameter set is nested in those of the
> nonlinear_variational_solver. So there is no way to access these currently
> in the C++ interface without explicitly constructing my own
> NonlinearProblem object? Thanks again.

Yes, the NewtonSolver parameters are as you say nested into the
NonlinearVariationalSolver parameters.

The syntax for nested parameters are slightly different in C++. Try:

  solver.parameters("newton_solver")["maximum_iterations"] = 20;

Note the square brackets are changed to parenthesis.

Johan

Revision history for this message
yk1000 (ykimura) said :
#11

Thanks Johan Hake, that solved my question.

Revision history for this message
Anders Logg (logg) said :
#12

On Tue, Sep 20, 2011 at 10:01:02PM -0000, yk1000 wrote:
> Question #171575 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171575
>
> Status: Solved => Open
>
> yk1000 is still having a problem:
> Johan and Anders,
>
> So in the C++ interface, by constructing a NonlinearVariationalProblem
> object I'm able to change the linear_solver and preconditioner
> parameters like so:
>
> NonlinearVariationalProblem problem(F, u, J);
> NonlinearVariationalSolver solver(problem);
> solver.parameters["linear_solver"] = "lu";
> solver.parameters["preconditioner"] = "ilu";
>
> But it appears I can't change the parameters of the underlying
> newton_solver yet (though in the documentation it appears you can in the
> python interface):
>
> solver.parameters["newton_solver"]["maximum_iterations"] = 20;
>
> If I do:
> info(solver.parameters,true);
>
> I can see that the newton_solver parameter set is nested in those of
> the nonlinear_variational_solver. So there is no way to access
> these currently in the C++ interface without explicitly constructing
> my own NonlinearProblem object? Thanks again.

I don't understand. Do you say that the NewtonSolver parameters are
nested inside the parameters for NonlinearVariationalSolver (it should
be when I look at the code). Then what is the problem?

--
Anders

Revision history for this message
Anders Logg (logg) said :
#13

On Tue, Sep 20, 2011 at 10:25:45PM -0000, yk1000 wrote:
> Question #171575 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171575
>
> Status: Answered => Solved
>
> yk1000 confirmed that the question is solved:
> Thanks Johan Hake, that solved my question.

Didn't see that this was already resolved. This discussion was not
threaded correctly in my mail client.

--
Anders

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

On Monday September 19 2011 12:01:08 Anders Logg wrote:
> Question #171575 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171575
>
> Anders Logg posted a new comment:
>
> On Mon, Sep 19, 2011 at 05:45:41PM -0000, Johan Hake wrote:
> > Question #171575 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/171575
> >
> > Johan Hake posted a new comment:
> > It should be pretty simple to add, with the negative consequence of code
> > bloat, as we need one such function for each version we have today.
>
> Can't we just use a default argument parameters=<something>?

Should be fixed now.

Johan

Revision history for this message
Anders Logg (logg) said :
#15

On Sat, Sep 24, 2011 at 06:41:05AM -0000, Johan Hake wrote:
> Question #171575 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/171575
>
> Johan Hake posted a new comment:
> On Monday September 19 2011 12:01:08 Anders Logg wrote:
> > Question #171575 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/171575
> >
> > Anders Logg posted a new comment:
> >
> > On Mon, Sep 19, 2011 at 05:45:41PM -0000, Johan Hake wrote:
> > > Question #171575 on DOLFIN changed:
> > > https://answers.launchpad.net/dolfin/+question/171575
> > >
> > > Johan Hake posted a new comment:
> > > It should be pretty simple to add, with the negative consequence of code
> > > bloat, as we need one such function for each version we have today.
> >
> > Can't we just use a default argument parameters=<something>?
>
> Should be fixed now.

Nice.

--
Anders