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

Adjoint assemble not assigning properly

0 votes

Hi, I'm trying to solve time dependent problem with adjoint equation for backward difference scheme. For that case assemble matrix b not assigning properly. Here is a program that shows the problem.

from dolfin import*
mesh = UnitSquare(8,8)
X = FunctionSpace(mesh, "RT", 2)
Y = FunctionSpace(mesh, "CG", 1)
W = MixedFunctionSpace([X,Y,Y,Y])
(p, y, p1, z) = TrialFunctions(W)
(pt, yt, p1t, zt) = TestFunctions(W)
#Define Dirichlet boundary conditions here, then assumed some value for pd, yd
dt = 0.02
T = 2
z_0 = 0.0
pd0 = Expression(('(sin(2*pi*x[0])+2*pi*x[0]*cos(2*pi*x[0]))*x[1]*sin(2*pi*x[1])*sin(pi*t0)','(sin(2*pi*x[1])+2*pi*x[1]*cos(2*pi*x[1]))*x[0]*sin(2*pi*x[0])*sin(pi*t0)'), t0 = 0.0)
pd = interpolate(pd0, X)
yd = y + ((z-z_0)/dt) - div(grad(z) - p + pd)
a1 = inner(zt, p1t)*dx 
a2 = inner(z_0, p1t)*dx 
a3 = inner(dt*grad(z),grad(p1t))*dx 
a4 = inner(dt*div(p-pd),p1t)*dx
a5 = inner(dt*(y-yd),p1t)*dx
A1 = a1 - a2 + a3 - a4 + a5 
a6 = inner(zt, p3)*dx
a7 = inner(z_0, p3)*dx
a8 = inner(dt*grad(zt),grad(p3))*dx
A2 = a6 - a7 + a8
form = A1+A2
a = lhs(form)
L = rhs(form)
A = assemble(a)
while t <= T:
    b = assemble(L) 
    t0 = t
    bc.apply(A, b)
    solve(A, u.vector(), b)
    t += dt
    u0.assign(u)
    p, y, p1, z = u.split()    

With the above code I get the following error message.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Unable to extract all indices.
Traceback (most recent call last):
File "time.py", line 72, in
b = assemble(L)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/assembling.py", line 169, in assemble
common_cell=common_cell)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/form.py", line 56, in init
common_cell)
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 66, in mpi_jit
return local_jit(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 154, in jit
return jit_compile(form, parameters=p, common_cell=common_cell)

Something like this. Could someone explain to me what's i am do wrongly with this code or I have misunderstood something?
Thank You

asked Feb 20, 2014 by Manickam FEniCS Novice (450 points)

Hi, what is p3?

Try to identify which integral is causing the error by assembling a1, a2, ..., a8 by itself.

Hi, sorry its p1 as trialfucntion

1 Answer

+2 votes

I think the problem lies in:

a1 = inner(zt, p1t)*dx 

Where you have the inner-product of two TestFunctions.

answered Feb 20, 2014 by christianv FEniCS User (2,460 points)

Thanks to christianv, that ill solved. If we have three boundary condition like

bc = [bc0, bc1, bc2]

How define simple way in time dependent problem inserted of

bc.apply(A, b)

I'm not sure, what you mean? But for multiple boundary conditions you have to add them one by one. Like:

[bc_temp.apply(A, b) for bc_temp in bc]
...