UFL

Support for "and" and "or"

Asked by Johan Hake

I wonder if it is possible to support "and" and "or" in conditional statements?

from ufl import *
fe = FiniteElement("Lagrange", triangle, 1)
c = coefficient(fe)
expr = conditional(lt(c, 8) and gt(c,4), c, 0.0)

sympy overloads & and | for these operations.

Johan

Question information

Language:
English Edit question
Status:
Solved
For:
UFL Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:
Revision history for this message
Martin Sandve Alnæs (martinal) said :
#1

and/or is not possible because of how they work in python.
&/| is bug prone because of their precedence level (see below).
UFL uses And(a,b) and Or(a,b) instead.

In [1]: from ufl import *

In [2]: x = triangle.x[0]

In [4]: x < 3 & x > 2
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-1442b929afd2> in <module>()
----> 1 x < 3 & x > 2

TypeError: unsupported operand type(s) for &: 'int' and 'Indexed'

In [5]: And(x < 3, x > 2)
Out[5]: AndCondition(...)

Revision history for this message
Johan Hake (johan-hake) said :
#2

Ahh!