Updating function of coordinates each time step

Hello,
I would like to introduce the function of coordinates that at the initial time step is given by

class f(UserExpression):
def eval(self, values, x):
if x[0] > 0.5:
values[0] = 1.0
else:
values[0] = 0.0

i.e. the theta-function in x-direction .Then each new time step I want

f(x, t+dt) = f (x - v(x,t) * dt)

where v is coming from the solution of the variational problem. Physically, v is velocity field, and f indicates which type of fluid is where, so this update says that the fluid at the point x is one that came there from the point x - v(x)*dt with velocity v. Two fluids have different mechanical parameters, so f will be a parameter in the solving of the variational equation. Any ideas how can I do it? Thank you!

I would suggest using ufl.conditional, see: How to implement function with condition? - #3 by dokken

2 Likes

Thank you, but I don’t see how would it solve the problem of updating the function each time step by the rule f(x) = f(x - v(x) * dt ). Thank you!