PETScSNESSolver example?

Asked by Paul Constantine

Are there any examples of using the PETScSNESSolver? In particular, how to set the initial guess?

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Paul Constantine
Solved:
Last query:
Last reply:
Revision history for this message
Patrick Farrell (pefarrell) said :
#1

Hi,

Take a look at test/unit/nls/python/PETScSNESSolver.py .

The initial guess is supplied in the same variable as the output -- e.g. if you call

solve(F == 0, u, ...)

the value of u before the call to solve is the initial guess, and the value of u after the solve is the solution of the nonlinear problem.

Revision history for this message
Paul Constantine (paul-g-constantine) said :
#2

Turns out the Cahn-Hilliard had most of what I was looking for -- how to set up "initial conditions" and how to set up a nonlinear problem class. Otherwise the syntax looks something like:

nlp = MyNonlinearProblem(a, L, bcs)
solver = PETScSNESSolver()
solver.parameters["maximum_iterations"]=20
solver.parameters["line_search"]="quadratic"

# "ls" is line search, "tr" is trust region method
solver.parameters["method"]="ls"
solver.solve(nlp,u.vector())

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

On 6 February 2013 09:56, Paul Constantine
<email address hidden> wrote:
> Question #221146 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/221146
>
> Status: Answered => Solved
>
> Paul Constantine confirmed that the question is solved:
> Turns out the Cahn-Hilliard had most of what I was looking for

Yes, it's the best example!

Garth

> -- how to
> set up "initial conditions" and how to set up a nonlinear problem class.
> Otherwise the syntax looks something like:
>
> nlp = MyNonlinearProblem(a, L, bcs)
> solver = PETScSNESSolver()
> solver.parameters["maximum_iterations"]=20
> solver.parameters["line_search"]="quadratic"
>
> # "ls" is line search, "tr" is trust region method
> solver.parameters["method"]="ls"
> solver.solve(nlp,u.vector())
>
> --
> 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 :
#4

On Wed, Feb 06, 2013 at 02:55:56PM -0000, Garth Wells wrote:
> Question #221146 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/221146
> Garth Wells posted a new comment:
> On 6 February 2013 09:56, Paul Constantine

>> Question #221146 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/221146
>>
>> Status: Answered => Solved
>>
>> Paul Constantine confirmed that the question is solved:
>> Turns out the Cahn-Hilliard had most of what I was looking for
> Yes, it's the best example!

So why don't you make some more! ;-)

--
Anders

>> -- how to
>> set up "initial conditions" and how to set up a nonlinear problem class.
>> Otherwise the syntax looks something like:
>>
>> nlp = MyNonlinearProblem(a, L, bcs)
>> solver = PETScSNESSolver()
>> solver.parameters["maximum_iterations"]=20
>> solver.parameters["line_search"]="quadratic"
>>
>> # "ls" is line search, "tr" is trust region method
>> solver.parameters["method"]="ls"
>> solver.solve(nlp,u.vector())
>>

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

On 6 February 2013 20:45, Anders Logg
<email address hidden> wrote:
> Question #221146 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/221146
>
> Anders Logg posted a new comment:
> On Wed, Feb 06, 2013 at 02:55:56PM -0000, Garth Wells wrote:
>> Question #221146 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/221146
>> Garth Wells posted a new comment:
>> On 6 February 2013 09:56, Paul Constantine
>
>
>>> Question #221146 on DOLFIN changed:
>>> https://answers.launchpad.net/dolfin/+question/221146
>>>
>>> Status: Answered => Solved
>>>
>>> Paul Constantine confirmed that the question is solved:
>>> Turns out the Cahn-Hilliard had most of what I was looking for
>> Yes, it's the best example!
>
> So why don't you make some more! ;-)
>

Because the C-H demo already has it all . . .

Garth

> --
> Anders
>
>
>>> -- how to
>>> set up "initial conditions" and how to set up a nonlinear problem class.
>>> Otherwise the syntax looks something like:
>>>
>>> nlp = MyNonlinearProblem(a, L, bcs)
>>> solver = PETScSNESSolver()
>>> solver.parameters["maximum_iterations"]=20
>>> solver.parameters["line_search"]="quadratic"
>>>
>>> # "ls" is line search, "tr" is trust region method
>>> solver.parameters["method"]="ls"
>>> solver.solve(nlp,u.vector())
>>>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.