krylov solver parameters

Asked by Chaffra Affouda

It looks like the Krylov solver parameters cannot be updated from a VariationalProblem or the global parameters. The solver always uses it's default parameters. Is this correct?

Chaffra

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Chaffra Affouda
Solved:
Last query:
Last reply:
Revision history for this message
Chaffra Affouda (chaffra) said :
#1

The newton_solver is no longer accessible from VariationalProblem. I used to be able to set the linear_solver parameters via
problem.newton_solver().linear_solver().parameters ... Is there a new way of doing this?

Thanks,
Chaffra

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

On Tuesday April 19 2011 09:45:58 Chaffra wrote:
> Question #153459 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/153459
>
> Chaffra gave more information on the question:
> The newton_solver is no longer accessible from VariationalProblem. I used
> to be able to set the linear_solver parameters via
> problem.newton_solver().linear_solver().parameters ... Is there a new way
> of doing this?

I think Garth is the man to answer this, but I recall he removed that options
because it became difficult to maintain as the linear solver can be of many
different types.

The solution, I think, is to create the linear solver before you create the
NewtonSolver, grab the parameters, create the NewtonSolver, change whatever
parameters to the LinearSolver you need through the grabed paraemters.

Johan

Revision history for this message
Chaffra Affouda (chaffra) said :
#3

How about the following changes to dolfin... This works for me.

void NonlinearVariationalSolver::solve(Function& u,
                                       const VariationalProblem& problem,
                                       const Parameters& parameters)
{
  begin("Solving nonlinear variational problem.");

  // Create nonlinear problem
  _NonlinearProblem nonlinear_problem(problem, parameters);

  // Create Newton solver and set parameters
  NewtonSolver newton_solver(parameters["linear_solver"],
                             parameters["preconditioner"]);
  newton_solver.parameters.update(parameters("newton_solver"));

//update linear_solver parameters
  std::string solver_type = parameters["linear_solver"];
  if (solver_type == "lu" || solver_type == "cholesky"){
   newton_solver.linear_solver().parameters.update(parameters("lu_solver"));
  }
  else{
   newton_solver.linear_solver().parameters.update(parameters("krylov_solver"));
  }

  // Solve nonlinear problem using Newton's method
  newton_solver.solve(nonlinear_problem, u.vector());

  end();
}

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

On Tue, Apr 19, 2011 at 09:54:43AM -0700, Johan Hake wrote:
> On Tuesday April 19 2011 09:45:58 Chaffra wrote:
> > Question #153459 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/153459
> >
> > Chaffra gave more information on the question:
> > The newton_solver is no longer accessible from VariationalProblem. I used
> > to be able to set the linear_solver parameters via
> > problem.newton_solver().linear_solver().parameters ... Is there a new way
> > of doing this?
>
> I think Garth is the man to answer this, but I recall he removed that options
> because it became difficult to maintain as the linear solver can be of many
> different types.
>
> The solution, I think, is to create the linear solver before you create the
> NewtonSolver, grab the parameters, create the NewtonSolver, change whatever
> parameters to the LinearSolver you need through the grabed paraemters.

I think I made a change recently to include the Newton solver
parameters in the parameter list for a VariationalProblem.

If you use

  info(problem.parameters, True)

then you should see the parameters for the Newton solver.

The solver type and preconditioner cannot be set by parameters at the
moment. The problem is that the Newton solver gets these parameters in
the constructor. It should use the parameter system instead.

--
Anders

Revision history for this message
Chaffra Affouda (chaffra) said :
#5

It looks like using the code above I can now do

problem = VariationalProblem(F, J, bcs, form_compiler_parameters)
 problem.parameters['solver']['newton_solver'].update(...)
problem.parameters['solver']['krylov_solver'].update(...)
 problem.parameters['solver'].update(...)

Thanks.