← Back to team overview

ffc team mailing list archive

Re: mixed element issue?

 

On Wed, Apr 16, 2008 at 09:41:38PM +0200, Marie Rognes wrote:
> Robert Kirby wrote:
> >
> > It seems that if you put a vector element into a mixed element and 
> > then take it back out, you can no longer index it.
> >
> > On the other hand, if I do:
> > # start new .form file here
> > vel_element = VectorElement("Lagrange","triangle",2)
> > pre_element = FiniteElement("Lagrange","triangle",1)
> > element = vel_element + pre_element
> > (u,p) = TrialFunctions( element )
> > (v,q) = TestFunctions( element )
> > u0 = Function( vel_element )
> >
> > a = D(v[i],j)*D(u[i],j)*dx + v[i]*u0[j]*D(u[i],j)*dx
> > # end new .form file
> >
> 
> What happens is that TestFunction (and TrialFunction) returns an object 
> (BasisFunction) that has a well-defined operator for taking components 
> with arbitrary indices.
> 
> TestFunctions (and TrialFunctions), however, returns "all the 
> components" structured as a tuple of lists. Taking "an arbitrary index" 
> of a python list doesn't work that well.
> 
> Will think some more about whether this is 
> trivial/easy/difficult/impossible to change.
> 
> PS: If you want something like this to work *right* now try iterating 
> over i and j manually ;) Simplify will contract it back for you.

Yes. In some more detail, when you do

  element = vel_element + pre_element

FFC first creates a vector-valued element (mixed element) with three
components, the first two for u and the last for p. Then when you do

  (u, p) = TrialFunctions(element)

FFC picks out the three components of the vector-valued function
w = (u, p), indexes w and returns ([w[0], w[1]], w[2]).

This breaks the index notation since Python lists obviously can't
be index by an FFC Index.

I'd recommend doing something like

  a = sum([D(v[i],j)*D(u[i],j)*dx + v[i]*u0[j]*D(u[i],j)*dx for i in range(2) for j in range(2)])

Does that work for you?

I'm pretty sure we won't invest much time in improving the FFC form
language before switching to UFL. We (mostly Martin) have done some
work on it. You can follow the progress here:

  http://www.fenics.org/dev/ufl

-- 
Anders


Follow ups

References