Subject: [FFC-dev] bug in mixed elements

From: Mehdi Nikbakht <[email-masked]>
Date: Wed, 05 Apr 2006 17:37:43 +0200

Hello,

I am trying to solve consolidation problem with Dolphin.  The following is my
simplified form file.

> u_elem=FiniteElement("Vector Lagrange", "triangle", 2)
> P_elem=FiniteElement("Lagrange", "triangle", 1)

> Element = u_elem + P_elem

> (u0, p0) = Functions(Element)
> (u1, p1)= Functions(Element)

> u1test = Function(u_elem)
> u0test = Function(u_elem)

> dpdt= p1 - p0

> dudt_mixed = u1 - u0

> #dudt = u1test - u0test

When I wanted to do operation on u1 and u0, I received this error.(I
didn't recieve any error when I did same thing for p1 and p0)

> TypeError: unsupported operand type(s) for -: 'list' and 'list'

But If I do same operation on variable which are defined based on ordianry
element, I don't receive such error.

Cheers,

-- 
Mehdi

---

From: Anders Logg <[email-masked]>
Date: Thu, 6 Apr 2006 11:56:10 -0500

> element, I don't receive such error.

The problem is that subtraction is not defined for Python lists. A
vector in FFC is represented as a Python list of scalars so when you
do u1 - u0, Python does not know what to do.

I should probably use Numeric.array instead of list. I'll add this to
the TODO list and get to it as soon as I can (or someone send me
patch).

In the meantime, you can do

    dudt_mixed = [u1[i] - u0[i] for i in range(len(u1))]                            

or
                                                                                
    dudt_mixed = list(array(u1) - array(u0))

/Anders