# Setting initial guess for nonlinear problem

**URL:** <https://fenicsproject.discourse.group/t/setting-initial-guess-for-nonlinear-problem/1614>\
**Category:** Uncategorized\
**Created:** [September 24, 2019, 7:01pm UTC](https://fenicsproject.discourse.group/t/setting-initial-guess-for-nonlinear-problem/1614 "2019-09-24T19:01:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![msjuhasznora](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/msjuhasznora/32/547_2.png) [@msjuhasznora](https://fenicsproject.discourse.group/u/msjuhasznora)\
**Post date:** [September 24, 2019, 7:01pm UTC](https://fenicsproject.discourse.group/t/setting-initial-guess-for-nonlinear-problem/1614/1 "2019-09-24T19:01:18Z")

</div>

Hi,

Is there a way to tell the solver of a NonlinearVariationalProblem that in the form of a up\_initguess of type Function(VP) I have a really good initial guess?

I use the NonlinearVariationalProblem to solve a scheme with the built-in Newton method. The method does not converge when applied to the scheme, I get  
“Newton iteration 1: r (abs) = -nan (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)” and so on.

I was wondering if I could make the scheme converge if I could use what I have, which is a good initial guess in the form of a function (not an Expression). I found something similar here: [https://fenicsproject.org/qa/9536/how-to-set-initial-guess-for-nonlinear-variational-problem/](https://fenicsproject.org/qa/9536/how-to-set-initial-guess-for-nonlinear-variational-problem/), but I don’t have an Expression, only an initial guess Function(VP), up\_initguess. But when I try to use it analogously as seen in the link attached, I get a runtime error.

up = TrialFunction(VP)  
u,p = split(up)  
u1, u2 = split(u)  
(v, q) = TestFunctions(VP)  
v1, v2 = split(v)

up\_ = Function(VP)  
(u\_, p\_) = split(up\_)  
(u1\_, u2\_) = split(u\_)

(load initial guess into the trialfunctions in the scheme. here we don’t need to interpolate, as both sides are coordinates of functions defined in VP.)

u1 = u1\_initguess  
u2 = u2\_initguess  
u = u\_initguess  
p = p\_initguess

F = inner(u, grad(u1)) \* v1 \* dx + inner(grad(u1),grad(v1)) \* dx - p \* div(v) \* dx + q \* div(u) \* dx  
F = action(F, up\_)  
J = derivative(F, up\_, up)  
problem = NonlinearVariationalProblem(F, up\_, bcu, J)  
solver = NonlinearVariationalSolver(problem)  
solver.solve()

Thank you so much for any help.

---

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [September 25, 2019, 2:30pm UTC](https://fenicsproject.discourse.group/t/setting-initial-guess-for-nonlinear-problem/1614/2 "2019-09-25T14:30:54Z")

</div>

Whatever is in the `up_` vector will be used as the initial guess.

---

<div class="post-metadata">

**Author:** ![msjuhasznora](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/msjuhasznora/32/547_2.png) [@msjuhasznora](https://fenicsproject.discourse.group/u/msjuhasznora)\
**Post date:** [September 25, 2019, 3:24pm UTC](https://fenicsproject.discourse.group/t/setting-initial-guess-for-nonlinear-problem/1614/3 "2019-09-25T15:24:31Z")

</div>

Thank you so much nate!!
