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

Error: simple implementation of time loop

0 votes

Hi all,

I am trying to run the following loop for timestepping and getting this error:

Here $u$ = solution, $p$ = velocity, $a$ = acceleration

p0.vector()[:] = p_new
File "/usr/lib/python2.7/dist-packages/dolfin/cpp/la.py",line 1405, in setslice
raise IndexError("can only set full slices v[:]") IndexError: can only set full slices v[:]

u = TrialFunction(V) 
v = TestFunction(V)  
u_new = Function(V)
p_new = Function(V)
a_new = Function(V)
u0 = interpolate(ui, V)                      #initial condition
p0 = interpolate(Constant(0.0),V)    #initial velocity
a0 = Function(V)                       #initial accn is calculated as shown in full code at link below

while t <= T:
    file << (u0,t)

  # Perform predictor step (gamma = 1/2)
    u_p = u0_vec + dt*p0_vec + dt*dt/2*(1-2*beta)*a0_vec     
    p_p = p0_vec + dt*a0_vec/2 
  # Solve algebric system of equations
    L = K*u_p
    bc.apply(L)
    Bsolve.solve(a_new.vector(), L)
    t += dt
  # Perform corrector step
    u_new.vector()[:] = u_p + dt**2*beta*a_new.vector()
    p_new.vector()[:] = p_p + dt/2*a_new.vector()   
    u0.assign(u_new) # update old vector
    p0.vector()[:] = p_new   

The entire code is posted on the below link where I have been trying to implement wave equation using newmark time stepping without any success. ANY HELP IS HIGHLY APPRECIATED.

http://fenicsproject.org/qa/8578/implementing-discretised-wave-equation-in-linear-form

asked Nov 19, 2015 by Chaitanya_Raj_Goyal FEniCS User (4,150 points)
edited Nov 19, 2015 by Chaitanya_Raj_Goyal

Hi, use p0.assign(p_new) or assign vector to vector. What you are doing at the moment is assigning to vector a function.

Hi MiroK,

I tried doing that before and it gave me a different error. Now, I tried doing the same thing again and it ran but gave wrong results. Being an expert, you must have definitely dealt with wave equations before. Can you please please help me correct my code.

It is posted at this link!

http://fenicsproject.org/qa/8578/implementing-discretised-wave-equation-in-linear-form

...