Subject: [UFL-dev] A basic non-linear problem

From: Harish Narayanan <[email-masked]>
Date: Wed, 15 Apr 2009 21:44:57 +0200

I am trying to learn how to set up a simple non-linear problem using a
UFL form. In order to solve the following (the non-linear Poisson demo
in DOLFIN),

- div[(1+u^2)*grad(u)] = f,

does something like the following look like the right approach?

element = FiniteElement("Lagrange", "triangle", 1)

v = TestFunction(element)
u = TrialFunction(element)
f = Function(element)
U = Function(element)

L = ((1 + U*U)*inner(grad(U), grad(v)) - f*v)*dx
a = derivative(L, U, u)

I have not yet fully understood how derivative() functions.

Harish

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Wed, 15 Apr 2009 21:59:04 +0200

> I have not yet fully understood how derivative() functions.

This looks right.

Alternative (equivalent) notation:
  L = (1 + U**2)*dot(grad(U), grad(v))*dx - f*v*dx
  a = derivative(L, U)

Unless you need the trial function u for something
else, derivative can make one for you.
That would only be the case if you linearize part
of the form manually, something like:
  a = derivative(L, U, u) + foo*u*v*dx

Martin

---

From: Harish Narayanan <[email-masked]>
Date: Wed, 15 Apr 2009 22:30:09 +0200

>   a = derivative(L, U, u) + foo*u*v*dx

And just for closure, this appears to be the right form. I used it
instead of NonlinearPoisson.form in the DOLFIN demo and the compiled C++
demo converges quadratically.

Harish

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Wed, 15 Apr 2009 22:34:35 +0200

> demo converges quadratically.

Great!

I have manually verified all terms in the harmonic map
demo differentiated from a functional, and this is fairly
similar so I was expecting it to work. But that doesn't
mean there aren't bugs lurking in other places...
It's hard to test these things properly.

Martin