Discussion:
[petsc-users] user defined algorithm for newton solver
Michael Povolotskyi
2015-10-08 17:26:16 UTC
Permalink
Dear Petsc developers and users,
I'm solving a nonlinear system with PETSc.
Often simple Newton iterations do not work and I have to use either
linear search or trust region.
I would like to use my own algorithm to find a next iteration
approximation to solution if the Newton step does not improve the
residual. As far as I can see I have to define my own SNELLineSearch
object. Is there any example that shows how to do it?
Thank you,
Michael.
--
Michael Povolotskyi, PhD
Research Assistant Professor
Network for Computational Nanotechnology
Hall for Discover and Learning Research, Room 441
West Lafayette, IN 47907
Phone (765) 4949396
Barry Smith
2015-10-08 17:58:01 UTC
Permalink
Post by Michael Povolotskyi
Dear Petsc developers and users,
I'm solving a nonlinear system with PETSc.
Often simple Newton iterations do not work and I have to use either linear search or trust region.
I would like to use my own algorithm to find a next iteration approximation to solution if the Newton step does not improve the residual. As far as I can see I have to define my own SNELLineSearch object. Is there any example that shows how to do it?
The line search model is 1) select direction based on approximate solution of approximate Jacobian 2) search in THAT direction for a decrease in the function evaluation. You state "if the Newton step does not improve the residual." so will you be computing the DIRECTION in a different way than (1) or will you be using the same direction but trying somehow to find a decrease in the function evaluation using a different technique then the standard line searchs we provide?

Frankly if the line searches we provide don't work that means the direction is not good and no "special" line search will recover. I really recommend you go through our suggestions on the FAQ http://www.mcs.anl.gov/petsc/documentation/faq.html#newton on trying to figure out why Newton is not converging before you think about writing a special line search.

Barry
Post by Michael Povolotskyi
Thank you,
Michael.
--
Michael Povolotskyi, PhD
Research Assistant Professor
Network for Computational Nanotechnology
Hall for Discover and Learning Research, Room 441
West Lafayette, IN 47907
Phone (765) 4949396
Michael Povolotskyi
2015-10-08 18:05:28 UTC
Permalink
Thank you.
The situation is as follows:
The system I need to solve does not have a unique solution, but only one
makes sense from physical point of view. I need to compute direction in
a different way based on the physics.

In other words it should be like this:

1. Start with a solution guess
2. Do full Newton step
3. If converged, exit
else if the solution improved go to step 2
otherwise "update_solution_in_my_way" ang go to step 2

Is it possible to do this in PETSc?
Michael.
Post by Barry Smith
Post by Michael Povolotskyi
Dear Petsc developers and users,
I'm solving a nonlinear system with PETSc.
Often simple Newton iterations do not work and I have to use either linear search or trust region.
I would like to use my own algorithm to find a next iteration approximation to solution if the Newton step does not improve the residual. As far as I can see I have to define my own SNELLineSearch object. Is there any example that shows how to do it?
The line search model is 1) select direction based on approximate solution of approximate Jacobian 2) search in THAT direction for a decrease in the function evaluation. You state "if the Newton step does not improve the residual." so will you be computing the DIRECTION in a different way than (1) or will you be using the same direction but trying somehow to find a decrease in the function evaluation using a different technique then the standard line searchs we provide?
Frankly if the line searches we provide don't work that means the direction is not good and no "special" line search will recover. I really recommend you go through our suggestions on the FAQ http://www.mcs.anl.gov/petsc/documentation/faq.html#newton on trying to figure out why Newton is not converging before you think about writing a special line search.
Barry
Post by Michael Povolotskyi
Thank you,
Michael.
--
Michael Povolotskyi, PhD
Research Assistant Professor
Network for Computational Nanotechnology
Hall for Discover and Learning Research, Room 441
West Lafayette, IN 47907
Phone (765) 4949396
--
Michael Povolotskyi, PhD
Research Assistant Professor
Network for Computational Nanotechnology
Hall for Discover and Learning Research, Room 441
West Lafayette, IN 47907
Phone (765) 4949396
Barry Smith
2015-10-08 19:41:13 UTC
Permalink
The easiest way for you to implement this is to simply call your update to the solution and then call SNESSolve() again. For example

while (1) {
SNESSolve(snes,x,NULL);
SNESGetConvergedReason(snes,&reason);
if (reason > 0) break; /* since snes has converged */
change x per your way
}

The problem with the code above is that each new call to SNESSolve() resets the rtol convergence factor based on the current latest norm of F so the code above will "oversolve" the problem. You can call SNESSetTolerance() above the while loop with an appropriate atol to get it to exit at the point you want to declare it converged.

It is not worthwhile trying to "weave" your special update code inside the Newton method.

Barry
Post by Michael Povolotskyi
Thank you.
The system I need to solve does not have a unique solution, but only one makes sense from physical point of view. I need to compute direction in a different way based on the physics.
1. Start with a solution guess
2. Do full Newton step
3. If converged, exit
else if the solution improved go to step 2
otherwise "update_solution_in_my_way" ang go to step 2
Is it possible to do this in PETSc?
Michael.
Post by Barry Smith
Post by Michael Povolotskyi
Dear Petsc developers and users,
I'm solving a nonlinear system with PETSc.
Often simple Newton iterations do not work and I have to use either linear search or trust region.
I would like to use my own algorithm to find a next iteration approximation to solution if the Newton step does not improve the residual. As far as I can see I have to define my own SNELLineSearch object. Is there any example that shows how to do it?
The line search model is 1) select direction based on approximate solution of approximate Jacobian 2) search in THAT direction for a decrease in the function evaluation. You state "if the Newton step does not improve the residual." so will you be computing the DIRECTION in a different way than (1) or will you be using the same direction but trying somehow to find a decrease in the function evaluation using a different technique then the standard line searchs we provide?
Frankly if the line searches we provide don't work that means the direction is not good and no "special" line search will recover. I really recommend you go through our suggestions on the FAQ http://www.mcs.anl.gov/petsc/documentation/faq.html#newton on trying to figure out why Newton is not converging before you think about writing a special line search.
Barry
Post by Michael Povolotskyi
Thank you,
Michael.
--
Michael Povolotskyi, PhD
Research Assistant Professor
Network for Computational Nanotechnology
Hall for Discover and Learning Research, Room 441
West Lafayette, IN 47907
Phone (765) 4949396
--
Michael Povolotskyi, PhD
Research Assistant Professor
Network for Computational Nanotechnology
Hall for Discover and Learning Research, Room 441
West Lafayette, IN 47907
Phone (765) 4949396
Matthew Knepley
2015-10-08 19:44:17 UTC
Permalink
Post by Barry Smith
The easiest way for you to implement this is to simply call your update
to the solution and then call SNESSolve() again. For example
while (1) {
SNESSolve(snes,x,NULL);
SNESGetConvergedReason(snes,&reason);
if (reason > 0) break; /* since snes has converged */
change x per your way
}
The problem with the code above is that each new call to SNESSolve()
resets the rtol convergence factor based on the current latest norm of F so
the code above will "oversolve" the problem. You can call
SNESSetTolerance() above the while loop with an appropriate atol to get it
to exit at the point you want to declare it converged.
It is not worthwhile trying to "weave" your special update code inside the Newton method.
Do you know what the non-physical solutions are?

Matt
Post by Barry Smith
Barry
Post by Michael Povolotskyi
Thank you.
The system I need to solve does not have a unique solution, but only one
makes sense from physical point of view. I need to compute direction in a
different way based on the physics.
Post by Michael Povolotskyi
1. Start with a solution guess
2. Do full Newton step
3. If converged, exit
else if the solution improved go to step 2
otherwise "update_solution_in_my_way" ang go to step 2
Is it possible to do this in PETSc?
Michael.
Post by Barry Smith
Post by Michael Povolotskyi
Dear Petsc developers and users,
I'm solving a nonlinear system with PETSc.
Often simple Newton iterations do not work and I have to use either
linear search or trust region.
Post by Michael Povolotskyi
Post by Barry Smith
Post by Michael Povolotskyi
I would like to use my own algorithm to find a next iteration
approximation to solution if the Newton step does not improve the residual.
As far as I can see I have to define my own SNELLineSearch object. Is there
any example that shows how to do it?
Post by Michael Povolotskyi
Post by Barry Smith
The line search model is 1) select direction based on approximate
solution of approximate Jacobian 2) search in THAT direction for a
decrease in the function evaluation. You state "if the Newton step does not
improve the residual." so will you be computing the DIRECTION in a
different way than (1) or will you be using the same direction but trying
somehow to find a decrease in the function evaluation using a different
technique then the standard line searchs we provide?
Post by Michael Povolotskyi
Post by Barry Smith
Frankly if the line searches we provide don't work that means the
direction is not good and no "special" line search will recover. I really
recommend you go through our suggestions on the FAQ
http://www.mcs.anl.gov/petsc/documentation/faq.html#newton on trying to
figure out why Newton is not converging before you think about writing a
special line search.
Post by Michael Povolotskyi
Post by Barry Smith
Barry
Post by Michael Povolotskyi
Thank you,
Michael.
--
Michael Povolotskyi, PhD
Research Assistant Professor
Network for Computational Nanotechnology
Hall for Discover and Learning Research, Room 441
West Lafayette, IN 47907
Phone (765) 4949396
--
Michael Povolotskyi, PhD
Research Assistant Professor
Network for Computational Nanotechnology
Hall for Discover and Learning Research, Room 441
West Lafayette, IN 47907
Phone (765) 4949396
--
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
Michael Povolotskyi
2015-10-09 17:45:30 UTC
Permalink
thank you,
I'll try to do that.

Yes, i have some criteria that can tell that the solution is a
non-physical one.
Basically what I'm trying to do is very similar to a predictor corrector
scheme.
Predictor should move solution to the right direction.
Post by Barry Smith
The easiest way for you to implement this is to simply call
your update to the solution and then call SNESSolve() again. For
example
while (1) {
SNESSolve(snes,x,NULL);
SNESGetConvergedReason(snes,&reason);
if (reason > 0) break; /* since snes has converged */
change x per your way
}
The problem with the code above is that each new call to
SNESSolve() resets the rtol convergence factor based on the
current latest norm of F so the code above will "oversolve" the
problem. You can call SNESSetTolerance() above the while loop with
an appropriate atol to get it to exit at the point you want to
declare it converged.
It is not worthwhile trying to "weave" your special update code
inside the Newton method.
Do you know what the non-physical solutions are?
Matt
Barry
On Oct 8, 2015, at 1:05 PM, Michael Povolotskyi
Thank you.
The system I need to solve does not have a unique solution, but
only one makes sense from physical point of view. I need to
compute direction in a different way based on the physics.
1. Start with a solution guess
2. Do full Newton step
3. If converged, exit
else if the solution improved go to step 2
otherwise "update_solution_in_my_way" ang go to step 2
Is it possible to do this in PETSc?
Michael.
Post by Barry Smith
On Oct 8, 2015, at 12:26 PM, Michael Povolotskyi
Dear Petsc developers and users,
I'm solving a nonlinear system with PETSc.
Often simple Newton iterations do not work and I have to use
either linear search or trust region.
Post by Barry Smith
I would like to use my own algorithm to find a next iteration
approximation to solution if the Newton step does not improve the
residual. As far as I can see I have to define my own
SNELLineSearch object. Is there any example that shows how to do it?
Post by Barry Smith
The line search model is 1) select direction based on
approximate solution of approximate Jacobian 2) search in THAT
direction for a decrease in the function evaluation. You state "if
the Newton step does not improve the residual." so will you be
computing the DIRECTION in a different way than (1) or will you be
using the same direction but trying somehow to find a decrease in
the function evaluation using a different technique then the
standard line searchs we provide?
Post by Barry Smith
Frankly if the line searches we provide don't work that
means the direction is not good and no "special" line search will
recover. I really recommend you go through our suggestions on the
FAQ http://www.mcs.anl.gov/petsc/documentation/faq.html#newton on
trying to figure out why Newton is not converging before you think
about writing a special line search.
Post by Barry Smith
Barry
Thank you,
Michael.
--
Michael Povolotskyi, PhD
Research Assistant Professor
Network for Computational Nanotechnology
Hall for Discover and Learning Research, Room 441
West Lafayette, IN 47907
Phone (765) 4949396 <tel:%28765%29%204949396>
--
Michael Povolotskyi, PhD
Research Assistant Professor
Network for Computational Nanotechnology
Hall for Discover and Learning Research, Room 441
West Lafayette, IN 47907
Phone (765) 4949396 <tel:%28765%29%204949396>
--
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
--
Michael Povolotskyi, PhD
Research Assistant Professor
Network for Computational Nanotechnology
Hall for Discover and Learning Research, Room 441
West Lafayette, IN 47907
Phone (765) 4949396
Loading...