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

assemble a bilinear form returns a vector

0 votes

The following minimal example doesn't work
because the assembled bilinearform A is of type

<class 'dolfin.cpp.la.Vector'>

Why? How can I fix this?

The code reads:

from dolfin import *
mesh = UnitSquareMesh(20, 20)
U = FunctionSpace(mesh, "CG", 1)
u = Function(U)
v = TestFunction(U)

rhs = Constant(1.)
bc = DirichletBC(U, 0. , "on_boundary")

A = assemble(inner(grad(u), grad(v))*dx)
b = assemble(rhs*v*dx)
bc.apply(A, b)
solve(A, u.vector(), b)
asked Sep 9, 2016 by aldapa FEniCS Novice (380 points)

1 Answer

0 votes
 
Best answer

I think you got your Functions and TrialFunctions mixed up

from dolfin import *
mesh = UnitSquareMesh(20, 20)
U = FunctionSpace(mesh, "CG", 1)
u = TrialFunction(U)
v = TestFunction(U)

rhs = Constant(1.)
bc = DirichletBC(U, 0. , "on_boundary")

A = assemble(inner(grad(u), grad(v))*dx)
b = assemble(rhs*v*dx)
bc.apply(A, b)

soln = Function(U)
solve(A, soln.vector(), b)
answered Sep 9, 2016 by nate FEniCS Expert (17,050 points)
selected Sep 9, 2016 by aldapa

thanks, that solves the problem

...