This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Ternary operator in expression

+3 votes

Hi. My code work fine in Windows. But in ubuntu 13.04 i have problem with

S = Expression('(x[0]<1)?0.1/(0.5*t*t+1):0.0',t=0.0)

Problem in ternary operator.

In instant.recompile: The module did not compile with command 'make VERBOSE=1 ', see '/home/sheva/.instant/error/dolfin_compile_code_42d1ae0f370daad6abfc317bff5c25ea/compile.log'
Traceback (most recent call last):
  File "fallout_4d.py", line 45, in <module>
    S = Expression('(x[0]<1)?0.1/(0.5*t*t+1):0.0',t=0.0)

Without ternary operator code work fine.
Fenics Win version 1.0 and python 2.3.5, ubuntu 13.04 have latest version of fenics and python 2.7.4.

asked Sep 27, 2013 by Sheva FEniCS Novice (910 points)

You should check "/home/sheva/.instant/error/dolfin_compile_code_42d1ae0f370daad6abfc317bff5c25ea/compile.log" and ask again (including the error messages) if it's still unclear.

1 Answer

+5 votes
 
Best answer

Hi, I think your problem is related to spacing. I have the same version of python, Ubuntu and FEniCS as you do and your code does not compile on my machine either. However

S = Expression('(x[0]<1) ? 0.1/(0.5*t*t+1) : 0.0',t=0.0) 

is okay and so is

S = Expression('(x[0]<1)?0.1/(0.5*t*t+1) : 0.0',t=0.0)

(note spaces around colon) or

S = Expression('(x[0]<1)?0.1/(0.5*t*t+1): 0.0',t=0.0)

(note only the trailing space after colon). Finally

S = Expression('(x[0]<1)?0.1/(0.5*t*t+1) :0.0',t=0.0)

(note only the leading space) fails to compile.

answered Sep 28, 2013 by MiroK FEniCS Expert (80,920 points)
selected Sep 28, 2013 by Sheva
...