← Back to team overview

ufl team mailing list archive

Re: A basic non-linear problem

 

On Wed, Apr 15, 2009 at 10:30 PM, Harish Narayanan
<harish.mlists@xxxxxxxxx> wrote:
> Martin Sandve Alnæs wrote:
>> On Wed, Apr 15, 2009 at 9:44 PM, Harish Narayanan
>> <harish.mlists@xxxxxxxxx> wrote:
>>> 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
>>
>> 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
>
> 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

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


References