Dear David, On 18/01/16 12:33, Angwenyi David wrote:
Hi all,
I wanted to extend the solution to the linear wave equation to a non-linear one. Could someone look at the attached script. I get the following error:
IndexError: tuple index out of range
The problem here is that although Function objects support indexing, it is not in the way you're using it. The indexing is to pull out a particular component of a vector-valued function. To implement this kind of timestepping scheme you need two Functions: pn = Function(V, name="p") pn_1 = Function(V, name="p last") Now use pn and pn_1 instead of p[n] and p[n-1] in your forms. You should now interpolate the initial condition into pn_1 and formulation your timeloop as: while t < T: solve_for_pn(pn, pn_1) ... do_other_things() ... # Update p_{n-1} <- p_n for next timestep pn_1.assign(pn) You will need to do the same for the functions phi and f. Cheers, Lawrence