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 How can I resolve the issue? Any reading material to that effect? Thanks. Angwenyi
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
Dear Lawrence It is working, but there could be something I am not doing right. I get the error: ", line 146, in get_so Compile errors in %s""" % (e.cmd, e.returncode, logfile, errfile)) pyop2.exceptions.CompilationError: Command "['mpicc', '-std=c99', '-fPIC', '-Wall', '-framework', 'Accelerate', '-march=native', '-O3', '-I/Users/master/firedrake/lib/python2.7/site-packages/petsc/include', '-I/Users/master/firedrake/lib/python2.7/site-packages/pyop2', '-msse', '-o', '/var/folders/8q/tv2c50fj0n3_27j_3yjmyv7c0000gp/T/pyop2-cache-uid502/d2907754592af67f96e4cc4f25058e4e_p743.so.tmp', '/var/folders/8q/tv2c50fj0n3_27j_3yjmyv7c0000gp/T/pyop2-cache-uid502/d2907754592af67f96e4cc4f25058e4e_p743.c', '-dynamiclib', '-L/Users/master/firedrake/lib/python2.7/site-packages/petsc/lib', '-Wl,-rpath,/Users/master/firedrake/lib/python2.7/site-packages/petsc/lib', '-lpetsc', '-lm']" return error status 1. Unable to compile code Compile log in /var/folders/8q/tv2c50fj0n3_27j_3yjmyv7c0000gp/T/pyop2-cache-uid502/d2907754592af67f96e4cc4f25058e4e_p743.log Compile errors in /var/folders/8q/tv2c50fj0n3_27j_3yjmyv7c0000gp/T/pyop2-cache-uid502/d2907754592af67f96e4cc4f25058e4e_p743.err Kindly check the script attached and let me know where I am amiss.
On 18 Jan 2016, at 14:16, Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> wrote:
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
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
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. note that if you want to change the value used for t in this expression, you will then also need to re-interpolate it: while t < T: expr.t = new_value_for_t f.interpolate(expr) Cheers, Lawrence
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?
note that if you want to change the value used for t in this expression, you will then also need to re-interpolate it:
while t < T:
expr.t = new_value_for_t
f.interpolate(expr)
Cheers,
Lawrence
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
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)
Dear Lawrence, There is this error: Traceback (most recent call last): File "<stdin>", line 22, in <module> File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/io.py", line 110, in __lshift__ self._file << data File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/io.py", line 524, in __lshift__ self._update_PVD(data) File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/io.py", line 542, in _update_PVD new_vtk << function File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/io.py", line 180, in __lshift__ mesh = function.function_space().mesh() AttributeError: 'Sum' object has no attribute 'function_space' Could there be something amiss?
On 18 Jan 2016, at 15:55, Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> wrote:
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)
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk <mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake <https://mailman.ic.ac.uk/mailman/listinfo/firedrake>
participants (2)
- 
                
                Angwenyi David
- 
                
                Lawrence Mitchell