Subject: [FFC-dev] Re: FFC

From: Anders Logg <[email-masked]>
Date: Tue, 3 May 2005 10:40:27 -0500

You were right, there was a (serious) bug in FFC for handling constant
indices. Thanks for pointing this out.

It has been fixed in the latest CVS version of FFC. However, the new
version of FFC uses FIAT directly to generate vector-valued elements
(previously handled in FFC), and FIAT assumes that a vector-valued
Lagrange element on a triangle has two components. I think Rob will
fix this shortly. Until then, try the following forms and see that you
get the expected results:

element = FiniteElement("Vector Lagrange", "triangle", 1)

v  = BasisFunction(element)
u1 = BasisFunction(element)

# Form 1
#a = v[1] *(u1[0].dx(0) + u1[1].dx(1)) * dx

#Form 2
#a = v[1] *(u1[0] + u1[1]) * dx

#Form 3
a = v[1] *(u1[0].dx(0) + u1[1].dx(1)) * dx

#Form 4
#a = v[1] *(u1[i].dx(i) ) * dx

/Anders

On Mon, May 02, 2005 at 05:19:37PM +0200, Garth N. Wells wrote:
> Dear Anders,
> 
> I've been trying to use FFC for some forms which cannot be written using
> summation convention, so I've been writing out the forms explicitly.
> However, I have a problem with terms that involve a derivative, e.g.
> u1[0].dx(0). Terms like u1[i].dx(i) (using indices) work fine.
> 
> Below is the code from an FFC file. What I've labelled Form 1 is basically the
> continuity equation for 2D Navier-Stokes. Form 1 and Form 2 produce erroneously
> exactly the same header file. In the case of Form 1, the resulting header file
> does not involve any terms from the Jacobian (g00, g10, etc.) which it should
> do. I would expect Form 3 and Form 4 to produce the same result. However, Form 4
> produces the expected result, and Form 3 does not. Is there something wrong with
> the synatax that I'm using? Notably, terms like u1[0].dx() do produce the
> expected result (no index between the round brackets).
> 
> We're having some trouble with our mail server here, so I'd be grateful if you
> could send a cc of any response to [email-masked].
> 
> Regards,
> Garth
> 
> name = "Test"
> vector = FiniteElement("Lagrange", "triangle", 1, 3)
> 
> v    = BasisFunction(vector)
> u1   = BasisFunction(vector)
> 
> # Form 1
> a = v[2] *(u1[0].dx(0) + u1[1].dx(1)) * dx
> 
> #Form 2
> #a = v[2] *(u1[0] + u1[1]) * dx
> 
> #Form 3
> #a = v[2] *(u1[0].dx(0) + u1[1].dx(1) + u1[2].dx(2)) * dx
> 
> #Form 4
> #a = v[2] *(u1[i].dx(i) ) * dx
> 
> 

-- 
Anders Logg
Research Assistant Professor
Toyota Technological Institute at Chicago
http://www.tti-c.org/logg/

---

From: Anders Logg <[email-masked]>
Date: Tue, 3 May 2005 16:53:15 -0500

I think this is a Python 2.3 problem. Can you update to Python 2.4?

The built-in data type set was added in Python 2.4. If you are unable
to upgrade to Python 2.4, I can change to use the class Set from the
module sets which should work with both 2.3 and 2.4.

Also note that you need the latest CVS version of FFC to run the test
problems (0.1.7 was released before the bug fix).

/Anders

	On Tue, May 03, 2005 at 11:35:35PM +0200, Garth N. Wells wrote:
> Anders,
> 
> I can't try the forms that you gave, because I can't get FFC 0.1.7 + FIAT 0.2.1
> to run. The output from 'ffc Poisson.form' (using the Poisson.form demo in
> ffc-0.1.7/src/demo) is 
> 
> mech136/<4>ffc-0.1.7/src/demo>ffc Poisson.form
> This is FFC, the FEniCS Form Compiler, version 0.1.7.
> For further information, go to http://www/fenics.org/ffc/.
> 
> Parsing Poisson.form
> Output written to Poisson.py
> 
> Compiling form: (dXa0/dxb0)(dXa1/dxb0) | ((d/dXa0)vi1)*((d/dXa1)vi0)*dX
> Finite element of test space:  Lagrange finite element of degree 1 on a Triangle
> Finite element of trial space: Lagrange finite element of degree 1 on a Triangle
> Computing 36 integrals, this may take some time
> ...............................................................................
> Traceback (most recent call last):
>   File "/usr/bin/ffc", line 80, in ?
>     main(sys.argv[1:])
>   File "/usr/bin/ffc", line 58, in main
>     execfile(outname)
>   File "Poisson.py", line 38, in ?
>     compile([a, L], name, "0.1.7", "C++", "GNU GPL Version 2")
>   File "/usr/lib/python2.3/site-packages/ffc/compiler/compiler.py", line 75, in
> compile
>     form.AKi = ElementTensor(form.sum, "interior", format)
>   File "/usr/lib/python2.3/site-packages/ffc/compiler/elementtensor.py", line
> 41, in __init__
>     gK_used = set()
> NameError: global name 'set' is not defined
> 
> Garth
> 
> 
> Quoting Anders Logg <[email-masked]>:
>

---

From: "Garth N. Wells" <[email-masked]>
Date: Tue, 03 May 2005 23:57:10 +0200

I'll look into Python 2.4.

I don't however have access to the CVS version of FFC.

Quoting Anders Logg <[email-masked]>:

> > > > Below is the code from an FFC file. What I've labelled Form 1 is
> basically
> > > the
> > > > exactly the same header file. In the case of Form 1, the resulting
> header
> > > file
> > > > do. I would expect Form 3 and Form 4 to produce the same result.
> However,
> > > Form 4
> > > > produces the expected result, and Form 3 does not. Is there something
> wrong
> > > with
> > > > We're having some trouble with our mail server here, so I'd be grateful
> if
> > > you

---

From: Anders Logg <[email-masked]>
Date: Tue, 3 May 2005 17:03:48 -0500

> I don't however have access to the CVS version of FFC.

Oops. It should be in the download section on fenics.org but it's not.
It's been fixed now:

    http://www.fenics.org/pub/software/ffc/cvs/

Grab the file ffc-cvs-current.tar.gz.

It's automatically updated from CVS each hour.

/Anders

> _______________________________________________
> FFC-dev mailing list
> [email-masked]
> http://www.fenics.org/cgi-bin/mailman/listinfo/ffc-dev
>

---

From: Anders Logg <[email-masked]>
Date: Tue, 3 May 2005 18:43:20 -0500

On Tue, May 03, 2005 at 06:26:35PM -0500, Robert Kirby wrote:
> if this is a "set" in the mathematical sense, Python 2.3 supports them
> 
> from sets import Set, ImmutableSet

Yes.

> I haven't looked at sets in 2.4 -- is there a built-in set that isn't  
> part of a module?

Yes, it's a built-in data type and it was added in Python 2.4.

> Anders, little things like this change from time to time in Python --  
> it's best to be backward compatible a little ways...

Yes, you're probably right. I'll make the change tomorrow.

/Anders

---

From: "Garth N. Wells" <[email-masked]>
Date: Tue, 03 May 2005 23:35:35 +0200

Anders,

Parsing Poisson.form

Garth

---

From: Robert Kirby <[email-masked]>
Date: Tue, 3 May 2005 18:26:35 -0500

Robert C. Kirby
Assistant Professor
Department of Computer Science
The University of Chicago
http://people.cs.uchicago.edu/~kirby
On May 3, 2005, at 4:53 PM, Anders Logg wrote:

>>   File  
>> "/usr/lib/python2.3/site-packages/ffc/compiler/elementtensor.py",  
>> line
>> 41, in __init__
>>     gK_used = set()
>>>> does not involve any terms from the Jacobian (g00, g10, etc.) which  
>>>> it
>>> should
>>>> produces the expected result, and Form 3 does not. Is there  
>>>> something wrong
>>> with
>>>> We're having some trouble with our mail server here, so I'd be  
>>>> grateful if
>>> you

---

From: "Garth N. Wells" <[email-masked]>
Date: Wed, 04 May 2005 12:19:01 +0200

Anders,

It runs with Python 2.4. The test bilinear forms with constant indices seem to
give the correct result now.

An idea for FFC might be to allow Matlab/Fortran95 style syntax for summation.
For example, u[1] + u[2] could be expressed as u[1:2].

Garth

Quoting Anders Logg <[email-masked]>:

> > > > I can't try the forms that you gave, because I can't get FFC 0.1.7 +
> FIAT
> > > 0.2.1
> > > > Finite element of test space:  Lagrange finite element of degree 1 on
> a
> > > Triangle
> > > > Finite element of trial space: Lagrange finite element of degree 1 on
> a
> > > Triangle
> > > >   File "/usr/lib/python2.3/site-packages/ffc/compiler/compiler.py",
> line
> > > 75, in
> > > > compile
> > > > > > continuity equation for 2D Navier-Stokes. Form 1 and Form 2
> produce
> > > > > erroneously
> something
> > > > > > the synatax that I'm using? Notably, terms like u1[0].dx() do
> produce
> > > the
> grateful

---

From: Anders Logg <[email-masked]>
Date: Wed, 4 May 2005 08:51:50 -0500

On Wed, May 04, 2005 at 12:19:01PM +0200, Garth N. Wells wrote:
> Anders,
> 
> It runs with Python 2.4. The test bilinear forms with constant
> indices seem to give the correct result now.

Good to know.

> An idea for FFC might be to allow Matlab/Fortran95 style syntax for
> summation.  For example, u[1] + u[2] could be expressed as u[1:2].

I'll think about it, but I want to keep the syntax minimal and only
allow a very limited set of operations. There are also plans to add a
layer on top of FFC and then the syntax of FFC won't really matter.
(Matt Knepley at Argonne has a parser that we might want to hook up
with FFC.)

/Anders