Nonlinear convective term UFL file

Asked by Charles Cook

Hello,

I am working on solving a nonlinear convective diffusion (Burger's) equation by linearizing the PDE (following suite of the fenics-book tutorial chapter).

For the convective term,

u*grad(u)

after linearizing with u^(k+1) = u^k+du with du small so that Higher order terms may be neglected, multiplying by a test function, and integrating over d_omega, I have a term

int(uk*grad(du) v, d_omega)

My best guess for my bilinear term is

uk*grad(du)*v*dx

however, I receive indexing errors (assuming this term is of the wrong dimension).

My first question is obvious, how did I go wrong, and the second, is there a tutorial/guide for writing UFL files?

Thank you!

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Marie Rognes
Solved:
Last query:
Last reply:
Revision history for this message
Marie Rognes (meg-simula) said :
#1

On 06/27/11 20:56, Charles Cook wrote:
> New question #162950 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/162950
>
> Hello,
>
> I am working on solving a nonlinear convective diffusion (Burger's) equation by linearizing the PDE (following suite of the fenics-book tutorial chapter).
>
> For the convective term,
>
> u*grad(u)
>
> after linearizing with u^(k+1) = u^k+du with du small so that Higher order terms may be neglected, multiplying by a test function, and integrating over d_omega, I have a term
>
> int(uk*grad(du) v, d_omega)
>
> My best guess for my bilinear term is
>
> uk*grad(du)*v*dx
>
> however, I receive indexing errors (assuming this term is of the wrong dimension).
>
> My first question is obvious, how did I go wrong,

Unfortunately, it is not obvious for us to tell you unless you provide
us with

(i) A more complete sample code (including definition of uk, du, and v)
(ii) The precise error message you are getting from running (i)

> and the second, is there a tutorial/guide for writing UFL files?
>

Have you tried taking a look at the UFL chapter (Chapter 17) in the
FEniCS book? In addition, there are the UFL and the FFC demos.

--
Marie

> Thank you!
>

Revision history for this message
Charles Cook (charles-4w) said :
#2

(i) My apologies, my entire UFL file

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

du = TrialFunction(element)
uk = TrialFunction(element)
v = TestFunction(element)
f = Coefficient(element)
g = Coefficient(element)
nu = Coefficient(element)

#Nonlinear
a = nu*inner(grad(du), grad(v))*dx \
 + uk*grad(du)*v*dx

L = f*v*dx + g*v*ds

Note that it works sans uk on the second line defining a.

(ii)

The error message:

*** FFC: Unable to extract all indices.

Thank you, I am going through those chapters now.

Revision history for this message
Best Marie Rognes (meg-simula) said :
#3

On 06/27/11 21:25, Charles Cook wrote:
> Question #162950 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/162950
>
> Charles Cook posted a new comment:
>
> (i) My apologies, my entire UFL file
>
>
> element = FiniteElement("Lagrange", interval, 1)
>
> du = TrialFunction(element)
> uk = TrialFunction(element)
> v = TestFunction(element)
> f = Coefficient(element)
> g = Coefficient(element)
> nu = Coefficient(element)
>
>
> #Nonlinear
> a = nu*inner(grad(du), grad(v))*dx \
> + uk*grad(du)*v*dx
>
> L = f*v*dx + g*v*ds
>
>
> Note that it works sans uk on the second line defining a.
>
>
> (ii)
>
> The error message:
>
> *** FFC: Unable to extract all indices.
>
>

Try this instead for a:

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

    du = TrialFunction(element)
    v = TestFunction(element)
    nu = Coefficient(element)

    # Define "solution" as Coefficient (not as [Trial|Test]Function
    uk = Coefficient(element)

    a = nu*inner(grad(du), grad(v))*dx + uk*grad(du)*v*dx

> Thank you, I am going through those chapters now.
>

Enjoy :-)

--
Marie

Revision history for this message
Charles Cook (charles-4w) said :
#4

Thank you very much! That of course did the trick :-)

My updated UFL file (which has all terms so as to not mislead someone)

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

# perturbation in u, du
du = TrialFunction(element)
v = TestFunction(element)

# diffusion coefficient
nu = Coefficient(element)

# previous solution of u
uk = Coefficient(element)

#Nonlinear
a = nu*inner(grad(du), grad(v))*dx \
 + uk*grad(du)*v*dx \
 + du*grad(uk)*v*dx \
 - nu*grad(du)*v*ds

L = -uk*grad(uk)*v*dx \
 + nu*grad(uk)*v*ds \
 - nu*inner(grad(uk),grad(v))*dx

Revision history for this message
Charles Cook (charles-4w) said :
#5

Thanks Marie Rognes, that solved my question.