On 18/01/16 14:49, Angwenyi David wrote:
Dear Lawrence,
On 18 Jan 2016, at 15:28, Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> wrote:
On 18/01/16 14:07, Angwenyi David wrote:
f = Function(V).interpolate(Expression("x[0]*x[1]*x[2]*t"))
This looks wrong. Expressions by default have access to the coordinates (x[0..2]), but if you want to provide other values, you need to do so like so:
expr = Expression("x[0]*x[1]*x[2]*t", t=value_for_t)
f = Function(V).interpolate(expr)
Although it looks like you don't use the function "f" later at all.
I have used f in defining fn and fn_1 such that fn is f evaluated at time tn and fn_1 is f evaluated at time tn-1; both expressions which have been used in the time-loop. Could there be a way of achieving this end?
Oh, I missed that bit. That didn't do what you wanted, it copied the values of f into fn and fn_1, when you made the new Function objects. I would do something like: fn = Function(V, name="f") fn_1 = Function(V, name="f last") t = 0 f_expr = Expression("x[0]*x[1]*x[2]*t", t=t) # Initially, presumably, fn and fn_1 are both evaluated at t=0 fn.interpolate(f_expr) fn_1.interpolate(f_expr) while t < T: ... t += dt fn_1.assign(fn) f_expr.t = t fn.interpolate(f_expr)