Subject: [Ffc] bug in MixedElement.tabulate()

From: [email-masked]
Date: Tue, 26 Jan 2010 16:08:07 +0100 (CET)

MixedElement.tabulate() produces some mysterious results. Try the following in a ufl file:

from ffc.fiatinterface import create_element
elem = FiniteElement("Lagrange", triangle, 1)
print create_element(elem).tabulate(1, [(0.333, 0.333)])

This gives:

{(0, 1): array([[-1.0],
       [0.0],
       [1.0]], dtype=object), (1, 0): array([[-1.0],
       [1.0],
       [0.0]], dtype=object), (0, 0): array([[0.334],
       [0.333],
       [0.333]], dtype=object)}

which is correct.

For a vector (mixed) element

elem = VectorElement("Lagrange", triangle, 1)

 the result is

{(0, 1): array([[[ 0.334],                           
        [ 0.   ]],                                   

       [[ 0.333],
        [ 0.   ]],

       [[ 0.333],
        [ 0.   ]],

       [[ 0.   ],
        [ 0.334]],

       [[ 0.   ],
        [ 0.333]],

       [[ 0.   ],
        [ 0.333]]]), (1, 0): array([[[ 0.334],
        [ 0.   ]],                            

       [[ 0.333],
        [ 0.   ]],

       [[ 0.333],
        [ 0.   ]],

       [[ 0.   ],
        [ 0.334]],

       [[ 0.   ],
        [ 0.333]],

       [[ 0.   ],
        [ 0.333]]]), (0, 0): array([[[ 0.334],
        [ 0.   ]],

       [[ 0.333],
        [ 0.   ]],

       [[ 0.333],
        [ 0.   ]],

       [[ 0.   ],
        [ 0.334]],

       [[ 0.   ],
        [ 0.333]],

       [[ 0.   ],
        [ 0.333]]])}

which is very wrong. I had a look at the code in MixedElement.tabulate(), but couldn't figure out what was going on.

Kristian

---

From: Anders Logg <[email-masked]>
Date: Tue, 26 Jan 2010 16:14:25 +0100

I'm just about to take off for the Depeche Mode concert in Göteborg
but let's discuss it tomorrow. Or feel free to figure out what
tabulate should do... :-)

--
Anders

On Tue, Jan 26, 2010 at 04:08:07PM +0100, [email-masked] wrote:
> {(0, 1): array([[[ 0.334],                                  [ 0.
> ]],
>
>       [[ 0.333],
>        [ 0.   ]],
>
>       [[ 0.333],
>        [ 0.   ]],
>
>       [[ 0.   ],
>        [ 0.334]],
>
>       [[ 0.   ],
>        [ 0.333]],
>
>       [[ 0.   ],

> _______________________________________________
> Mailing list: https://launchpad.net/~ffc
> Post to     : [email-masked]
> Unsubscribe : https://launchpad.net/~ffc
> More help   : https://help.launchpad.net/ListHelp

---

From: Kristian Oelgaard <[email-masked]>
Date: Tue, 26 Jan 2010 16:18:19 +0100 (CET)

> tabulate should do... :-)

OK enjoy, I might have  a look although I have an important Handball match to watch tonight, but I guess you don't follow the championships anymore in Sweden? :)

Kristian

> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAktfBtEACgkQTuwUCDsYZdE/DACfYRm5wWiLHtVoRDMmw9syr9vA
> JnYAnjJHHAtl0oST5d9aMjJ0acbtb7rE
> =qBbe
> -----END PGP SIGNATURE-----
>
>

---

From: "Garth N. Wells" <[email-masked]>
Date: Tue, 26 Jan 2010 15:19:19 +0000

Kristian Oelgaard wrote:
> OK enjoy, I might have  a look although I have an important Handball
> match to watch tonight, 

Are you joking?

Garth

> but I guess you don't follow the championships
> anymore in Sweden? :)
> 
> Kristian
> 
>> -- 
>> Anders
>>
>>
>>> which is very wrong. I had a look at the code in
>>> MixedElement.tabulate(), but couldn't figure out what was going on.
>>>
>>> Kristian
>>>
>>
>>
>>
> ------------------------------------------------------------------------
>

---

From: Kristian Oelgaard <[email-masked]>
Date: Tue, 26 Jan 2010 16:28:33 +0100 (CET)

>> OK enjoy, I might have  a look although I have an important Handball

Hmm, I guess handball is still not very popular (or even known?) in Great Britain.
Denmark is playing Norway and only the winner has a chance of qualifying for the semi-finals in the mens European championships.

Kristian

---

From: Johan Hake <[email-masked]>
Date: Tue, 26 Jan 2010 08:22:33 -0800

On Tuesday 26 January 2010 07:28:33 Kristian Oelgaard wrote:
> Hmm, I guess handball is still not very popular (or even known?) in Great
>  Britain. Denmark is playing Norway and only the winner has a chance of
>  qualifying for the semi-finals in the mens European championships.

*laugh*

God kamp!

Johan

---

From: Kristian Oelgaard <[email-masked]>
Date: Tue, 26 Jan 2010 17:52:43 +0100 (CET)

The error was related to the following type of code:

table_shape = (self.space_dimension(), self.num_components(), len(points))
zeros = numpy.zeros(table_shape)
for element in self._elements:
  table = element.tabulate(order, points)
  for dtuple in table.keys():
      if not dtuple in mixed_table:
          mixed_table[dtuple] = zeros
              # Insert non-zero values
              if (crange[1] - crange[0]) > 1:
                  mixed_table[dtuple][irange[0]:irange[1], crange[0]:crange[1]] = table[dtuple]

This would cause the zeros array to be update every time we assigned to it because the mixed_element[dtuple] holds a reference
to zeros, not the values.

Changing the line:
          mixed_table[dtuple] = zeros
to

          mixed_table[dtuple] = numpy.zeros(table_shape)

fixed the problem.

Kristian

2010/1/26  <[email-masked]>:
> {(0, 1): array([[[ 0.334],                                 [ 0.   ]],      
>                            
>      [[ 0.333],
>       [ 0.   ]],
>
>      [[ 0.333],
>       [ 0.   ]],
>
>      [[ 0.   ],
>       [ 0.334]],
>
>      [[ 0.   ],
>       [ 0.333]],
>
>      [[ 0.   ],
> which is very wrong. I had a look at the code in MixedElement.tabulate(),
> but couldn't figure out what was going on.
>
> Kristian
>
>

---

From: Anders Logg <[email-masked]>
Date: Wed, 27 Jan 2010 02:04:16 +0100

>          mixed_table[dtuple] = numpy.zeros(table_shape)

ok! Nice.

--
Anders

---

From: Anders Logg <[email-masked]>
Date: Wed, 27 Jan 2010 02:05:57 +0100

> OK enjoy, I might have  a look although I have an important Handball match to watch tonight, but I guess you don't follow the championships anymore in Sweden? :)

Yes...

--
Anders