Compiling certain forms multiple times fails
jpdean opened this issue · 3 comments
jpdean commented
The following code
import ufl
import ffcx.codegeneration.jit
for i in range(10):
print("i = ", i)
fe = ufl.FiniteElement("Lagrange", ufl.triangle, 1)
f = ufl.Coefficient(fe)
g = ufl.Coefficient(fe) # Commenting this line fixes the issue
forms = [f * ufl.dx]
compiled_forms, module, code = ffcx.codegeneration.jit.compile_forms(
forms, options={"scalar_type": "double"})
fails after five loops with the error
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
999 | static ufcx_function_space functionspace_w_{10} =
from the compiler. I'm not sure why the generated code is being incorrectly written. Strangely, the error does not occur if the line g = ufl.Coefficient(fe)
is removed, despite g
not being in the form.
chrisrichardson commented
Yes, this is occuring because the coefficient number has gone above 9. For whatever reason (maybe LaTeX compatibility) the coefficients are labelled w_1, w_2, ... w_9, w_{10}, w_{11}...
etc. and the curly brackets are confusing the python string formatting. I guess this can be worked around in ffcx by scrubbing the coefficient name before using it. But maybe the problem originates in ufl
.
chrisrichardson commented
Fixed by FEniCS/ufl#142