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

User-defined Expression

0 votes

Hi,

I need to update my expression at each time step.

The expression is similar to this one:

class MyExpression(Expression):
    def __init__(self, t=0):
        self._t = t

    def eval(self, value, x):
        tmax = 100.
        tt = self._t - x[0]
        value[0] =  tt * (conditional(lt(tt,0),0,1)) * (conditional(gt(tt,tmax),0,1))

And since it is not a JIT-compiled expression, my simulations are supeeer slow. I tried to rewrite it using a cppcode but I did not succeed.

Please help =)

Thank you!

upd:
Ok, I rewrote it using cppcode. It does not help. It is still slow =((

asked Oct 8, 2016 by lulio FEniCS Novice (450 points)
edited Oct 8, 2016 by lulio

What is the C version?

1 Answer

0 votes

What are you trying to accomplish? Provide a minimal example. Is

 t = Expression("tt*(tt < 0 ?. 0. 1.)*(tmax < tt ? 0. : 1.), tt=tt, tmax = Constant(tmax)")

useful to you?

answered Oct 10, 2016 by KristianE FEniCS Expert (12,900 points)
...