Subject: [UFL-dev] Problems with lhs/rhs and mixed elements

From: Harish Narayanan <[email-masked]>
Date: Wed, 12 Aug 2009 15:08:24 +0200

I'm running into an error when I attempt to use lhs() and rhs() with
mixed elements. I have attached two small .ufl files, one for the
Poisson equation (which works) and the other for the Stokes equations
(which fails with the following error).

Preprocessing form file: stokes-broken.ufl --> stokes-broken.py

Wrapping non-UFL expression. This is experimental and will likely break
many algorithms!
Expecting Python scalar, not
set([BasisFunction(MixedElement(*[VectorElement('Lagrange',
Cell('triangle', 1, Space(2)), 2, 2), FiniteElement('Lagrange',
Cell('triangle', 1, Space(2)), 1)], **{'value_shape': (3,) }), -2)]).

FAILURE in reuse_if_possible:
type(o) = <class 'ufl.tensors.ListTensor'>
operands =

(Indexed(BasisFunction(MixedElement(*[VectorElement('Lagrange',
Cell('triangle', 1, Space(2)), 2, 2), FiniteElement('Lagrange',
Cell('triangle', 1, Space(2)), 1)], **{'value_shape': (3,) }), -2),
MultiIndex((FixedIndex(0),), {FixedIndex(0): 3})),
set([BasisFunction(MixedElement(*[VectorElement('Lagrange',
Cell('triangle', 1, Space(2)), 2, 2), FiniteElement('Lagrange',
Cell('triangle', 1, Space(2)), 1)], **{'value_shape': (3,) }), -2)]))

(Indexed(BasisFunction(MixedElement(*[VectorElement('Lagrange',
Cell('triangle', 1, Space(2)), 2, 2), FiniteElement('Lagrange',
Cell('triangle', 1, Space(2)), 1)], **{'value_shape': (3,) }), -2),
MultiIndex((FixedIndex(1),), {FixedIndex(1): 3})),
set([BasisFunction(MixedElement(*[VectorElement('Lagrange',
Cell('triangle', 1, Space(2)), 2, 2), FiniteElement('Lagrange',
Cell('triangle', 1, Space(2)), 1)], **{'value_shape': (3,) }), -2)]))

stack =
////////////////////////////////////////////////////////////////////////////////
Visit stack in Transformer:
<class 'ufl.algebra.Sum'> ; -1 * (sum_{i_8} ((w_0)[i_8]) * (([[
(v_{-2})[0], (v_
<class 'ufl.algebra.Product'> ; -1 * (sum_{i_8} ((w_0)[i_8]) * (([[
(v_{-2})[0],
<class 'ufl.indexsum.IndexSum'> ; sum_{i_8} ((w_0)[i_8]) * (([[
(v_{-2})[0], (v_
<class 'ufl.algebra.Product'> ; ((w_0)[i_8]) * (([[ (v_{-2})[0],
(v_{-2})[1] ]])
<class 'ufl.indexed.Indexed'> ; ([[ (v_{-2})[0], (v_{-2})[1] ]])[i_8]
<class 'ufl.tensors.ListTensor'> ; [[ (v_{-2})[0], (v_{-2})[1] ]]
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

*** FFC: Expecting Python scalar, not
set([BasisFunction(MixedElement(*[VectorElement('Lagrange',
Cell('triangle', 1, Space(2)), 2, 2), FiniteElement('Lagrange',
Cell('triangle', 1, Space(2)), 1)], **{'value_shape': (3,) }), -2)]).
*** FFC: To get more information about this error, rerun FFC with --debug.

Harish
cell = triangle
vector = VectorElement("Lagrange", cell, 2)
scalar = FiniteElement("Lagrange", cell, 1)
system = vector + scalar

v = TestFunction(vector)
u = TrialFunction(vector)

f = Function(vector)

F = (inner(grad(v), grad(u)) - inner(v, f))*dx

a = lhs(F)
L = rhs(F)

cell = triangle
vector = VectorElement("Lagrange", cell, 2)
scalar = FiniteElement("Lagrange", cell, 1)
system = vector + scalar

(v, q) = TestFunctions(system)
(u, p) = TrialFunctions(system)

f = Function(vector)

F = (inner(grad(v), grad(u)) - div(v)*p + q*div(u))*dx - inner(v, f)*dx

a = lhs(F)
L = rhs(F)

---

From: Anders Logg <[email-masked]>
Date: Tue, 1 Sep 2009 10:59:42 +0200

Should be fixed now. I added a missing expand_indices.

--
Anders

> _______________________________________________
> UFL-dev mailing list
> [email-masked]
> http://fenics.org/mailman/listinfo/ufl-dev

---

From: Harish Narayanan <[email-masked]>
Date: Tue, 01 Sep 2009 11:10:10 +0200

> Should be fixed now. I added a missing expand_indices.

Cool. Thanks!

Harish

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Wed, 9 Sep 2009 19:28:26 +0200

Calling expand_indices is not a good idea.
This removes all free indices from the expression,
leaving the compiler with less information.
This function is intended for use in the compilation
step, _if_ it is needed by the form compiler.

Martin

On Tue, Sep 1, 2009 at 10:59 AM, Anders Logg<[email-masked]> wrote:
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkqc4n4ACgkQTuwUCDsYZdE/6gCfXreDc/Oe97fHvZqTR3zl4QLR
> h9oAn3CQ12bh5r2y0uvDUMjI2otoGNN0
> =mQ3f
> -----END PGP SIGNATURE-----
>

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Wed, 9 Sep 2009 19:29:05 +0200

> Wrapping non-UFL expression. This is experimental and will likely break

By the way, I recommend removing this experimental feature.
It hides the proper errors. Anders asked for it, but I don't think it's
used anywhere, and I don't believe it can be properly handled
in most algorithms.

Martin

---

From: Anders Logg <[email-masked]>
Date: Wed, 9 Sep 2009 19:51:27 +0200

> used anywhere, and I don't believe it can be properly handled

I don't even remember what this feature is. Is it intended for things
like

  L = v*sin(x)*dx

?

--
Anders

---

From: Anders Logg <[email-masked]>
Date: Wed, 9 Sep 2009 19:52:36 +0200

It seemed to be a simple fix and it worked. The resulting code was
also the same (except for a minor difference in the quadrature code).

Which is the proper way to fix it?

--
Anders

On Wed, Sep 09, 2009 at 07:28:26PM +0200, Martin Sandve Alnæs wrote:
> FFC-dev mailing list
> [email-masked]
> http://www.fenics.org/mailman/listinfo/ffc-dev

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Wed, 9 Sep 2009 20:27:37 +0200

Unless my memory fails me, expand_indices converts

v[i]*u[i] -> v[0]*u[0] + v[1]*u[1]
etc.

I don't have time to understand and fix the issue.
Removing the experimental feature "something scalar"
as I suggested should lead to a better error message.

Martin

On Wed, Sep 9, 2009 at 7:52 PM, Anders Logg<[email-masked]> wrote:
> iEYEARECAAYFAkqn62QACgkQTuwUCDsYZdGZpwCfS1yVc0iBTmuD+e2Oyf6FlyBg
> PGAAn0mAnYA7ZAtadnXHo7U7yFaQXGPx
> =E2ve