FEniCS / ffcx

Next generation FEniCS Form Compiler for finite element forms
https://fenicsproject.org
Other
144 stars 38 forks source link

[BUG]: When compiling forms with nested conditionals, parentheses are omitted #652

Closed mikesha2 closed 4 months ago

mikesha2 commented 7 months ago

Summarize the issue

Nested conditionals are compiled so that the user has to think about C++ operator precedence. Additionally, because of the cache, you only get the warning once, which can be easy to miss if running code multiple times.

How to reproduce the bug

With a cleared compilation cache, you get a warning with the following code

image

Minimal Example (Python)

import dolfinx
from mpi4py import MPI
domain = dolfinx.mesh.create_unit_interval(MPI.COMM_WORLD, 10)

from ufl import FiniteElement, Measure, TestFunction, TrialFunction, conditional, lt, And, Or
V = dolfinx.fem.functionspace(domain, FiniteElement('Lagrange', domain.ufl_cell(), 1))
f = dolfinx.fem.Function(V)
g = TestFunction(V)

dx = Measure('dx', domain=domain)
form = conditional(Or(lt(0, f), And(lt(1, f), lt(f, 2))), 0, 1) * dx
form = dolfinx.fem.form(form)

Output (Python)

No response

Version

0.7.2

DOLFINx git commit

No response

Installation

No response

Additional information

No response

garth-wells commented 4 months ago

Fixed in #651

Re-open if still and issue.