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

Why this code " f =Expression("x[0]**2") " does not work ? T^T

+1 vote

I have a long Expression of "f" , but the code does not work . So , I test some operators, and at last I find the power operator " ** " can not work, like

 f =Expression("x[0]**2") 

I use FEniCS in my Ubuntu 12.04 . Thanks

The error information :

Traceback (most recent call last):
File "/home/sthuashan/Desktop/Cavity.py", line 48, in <module>
f =Expression("x[0]**2")
File "/usr/lib/python2.7/dist-packages/dolfin/functions/expression.py", line 527, in __new__
cpp_base, members = compile_expressions([cppcode], [constant_members])
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/expressions.py", line 198, in compile_expressions
additional_declarations))
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/expressions.py", line 124, in compile_expression_code
code, additional_declarations=additional_declarations)
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 66, in mpi_jit
return local_jit(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/compilemodule.py", line 452, in compile_extension_module
**instant_kwargs)
File "/usr/lib/python2.7/dist-packages/instant/build.py", line 541, in build_module
recompile(modulename, module_path, new_compilation_checksum, build_system)
File "/usr/lib/python2.7/dist-packages/instant/build.py", line 150, in recompile
instant_error(msg % (cmd, compile_log_filename_dest))
File "/usr/lib/python2.7/dist-packages/instant/output.py", line 49, in instant_error
raise RuntimeError(text)
asked Nov 26, 2013 by HS.Sheng FEniCS Novice (570 points)

1 Answer

+5 votes
 
Best answer

That is because ** is not C++ syntax. Try "pow(x[0],2)" instead.

answered Nov 26, 2013 by johanhake FEniCS Expert (22,480 points)
selected Nov 26, 2013 by johanhake

Or of course x[0]*x[0].

Thanks ! Now, my codes is running :)

...