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

How to write correct math expression for this body force in Fenics

0 votes

I am trying to imply the following body force on a cube. But the code gives me an error for what I have scripted. Is there something wrong with what I have written? Is there a more efficient/ correct way?

enter image description here

r1 = 5.0/6.0-DOLFIN_EPS;

if x[0] >= r1: 
 f= Expression(("0.0", "0.0", "-10*exp(2*x[2]+x[1])"))
else:
 f= Expression(("0.0", "0.0", "0.0"))
asked Sep 15, 2015 by Chaitanya_Raj_Goyal FEniCS User (4,150 points)
edited Sep 15, 2015 by Chaitanya_Raj_Goyal

2 Answers

0 votes
 
Best answer

Try this

f =  Expression(("0.0", "0.0", "x[0] >= 5.0/6.0 ? -10*exp(2*x[2]+x[1]) : 0.0"))
answered Sep 15, 2015 by tianyikillua FEniCS User (1,620 points)
selected Sep 16, 2015 by Chaitanya_Raj_Goyal

No, doesn't work. I have the entire code posted here: ( carvedcube.py)

https://github.com/ChaitanyaGoyal/Hollow_Cube_Problem

It is x[0] > = 5.0/6.0 and not x > 5.0/6.0...I corrected my answer 3 sec later...you were fast

Yes, I tried the same thing at the posted link, didn't work :(

Debugging can be so irritating sometimes.

I ran your script. There was an error in your dimension definition. Replace w.cell().d by mesh.geometry().dim().

Thanks tianyikilua, for taking the time to help me out.

Did the script run for you with that change?

I got this error:

Calling DOLFIN just-in-time (JIT) compiler, this may take some time.
In instant.recompile: The module did not compile with command 'make VERBOSE=1', see '/home/page/.instant/error/dolfin_compile_code_9a66ddcce42106682a98919ce5accc6b9fa05991/compile.log'
Traceback (most recent call last):
  File "carvedcube2.py", line 15, in <module>
    b = Expression(("x >= 0.8 ? -10*exp(2*x[2]+x[1]) : 0.0", "0.0", "0.0"))
  File "/usr/lib/python2.7/dist-packages/dolfin/functions/expression.py", line 602, in __new__
    mpi_comm=mpi_comm)
  File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/expressions.py", line 217, in compile_expressions
    mpi_comm=mpi_comm)
  File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/expressions.py", line 145, in compile_expression_code
    mpi_comm=mpi_comm)
  File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 64, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/compilemodule.py", line 458, in compile_extension_module
    **instant_kwargs)
  File "/usr/lib/python2.7/dist-packages/instant/build.py", line 563, in build_module
    recompile(modulename, module_path, new_compilation_checksum, build_system)
  File "/usr/lib/python2.7/dist-packages/instant/build.py", line 165, in recompile
    instant_error(msg % (cmd, compile_log_filename_dest))
  File "/usr/lib/python2.7/dist-packages/instant/output.py", line 85, in instant_error
    raise RuntimeError(text)
RuntimeError: In instant.recompile: The module did not compile with command 'make VERBOSE=1', see '/home/page/.instant/error/dolfin_compile_code_9a66ddcce42106682a98919ce5accc6b9fa05991/compile.log'

Try do a instant-clean in your terminal.

With f = Expression(("0.0", "0.0", "x[0] >= 5.0/6.0 ? -10*exp(2*x[2]+x[1]) : 0.0")) (note x[0]) and mesh.geometry().dim() I was able to run your script.

Thanks a lot tianyikillua for your guidance!

+1 vote

Try something like this:

f = Expression(("0.0", "0.0", "-10*exp(2*x[2]+x[1])*(x[0]>=(5/6))"))
answered Sep 16, 2015 by hernan_mella FEniCS Expert (19,460 points)
...