Subject: [UFL-dev] Upwinding function

From: "Garth N. Wells" <[email-masked]>
Date: Fri, 24 Apr 2009 12:00:12 +0100

To get upwinding in a DG formulation of the advection-diffusion eqn with 
the FFC .form language, we used

vector = VectorElement("Lagrange", "triangle", 2)
scalar = FiniteElement("Discontinuous Lagrange", "triangle", 1)
constant = FiniteElement("Discontinuous Lagrange", "triangle", 0)

u  = TrialFunction(scalar)
b  = Function(vector)
of = Function(constant)

def upwind(u, b):
   return [b[i]('+')*(of('+')*u('+') + of('-')*u('-')) for i in range(2)]

to return the product b*u, with u taken from the 'upwind' side. How 
should the function 'upwind' look using UFL?

Garth

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Fri, 24 Apr 2009 13:11:36 +0200

> should the function 'upwind' look using UFL?

Lets see...

def upwind(u, b):
    s = of('+')*u('+') + of('-')*u('-')
    return [b[i]('+')*s for i in range(2)]

This returns a list, so it's a vector-valued expression?
s is a scalar expression, and b is a vector-valued expression,
so I would simply do

def upwind(u, b):
    s = of('+')*u('+') + of('-')*u('-')
    return b('+')*s

Does that look right?

Martin

---

From: "Garth N. Wells" <[email-masked]>
Date: Fri, 24 Apr 2009 12:22:29 +0100

>     s = of('+')*u('+') + of('-')*u('-')

Yes. Even simpler: return b('+')*(of('+')*u('+') + of('-')*u('-')).

I keep forgetting that simple things are simple with UFL ;).

Garth

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Fri, 24 Apr 2009 13:38:26 +0200

> I keep forgetting that simple things are simple with UFL ;).

:)

In general, if you have a list you can make an ufl expression
of it using as_vector(mylist), or as_matrix or as_tensor.

Martin