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

Solving a Simple 3D Poisson Equation

0 votes

Hi,

I am attempting to solve a simple 3D poisson equation, but I am encountering a runtime error I am unsure how to resolve.

from dolfin import *

mesh = Mesh("./test.xml")
V = FunctionSpace(mesh, 'Lagrange', 1)

# Subdomains are defined in the mesh file with labels 1028,1031,1030, and 1032
bc1 = DirichletBC(V,Constant(0.0),1028)
bc2 = DirichletBC(V,Constant(0.0),1031)
bc3 = DirichletBC(V,Constant(0.0),1030)
bc4 = DirichletBC(V,Constant(-0.65),1032)
bcs = [bc1,bc2,bc3,bc4]

u = TrialFunction(V)
v = TestFunction(V)
a  = inner(grad(u),grad(v))*dx
L = v*dx

solve(a == L,u,bcs)

When I run this, I get the following error

File "testFen.py", line 24, in
solve(a == L,u,bcs)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/solving.py", line 268, in solve
_solve_varproblem(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/solving.py", line 285, in _solve_varproblem
= _extract_args(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/solving.py", line 392, in _extract_args
u = _extract_u(args[1])
File "/usr/lib/python2.7/dist-packages/dolfin/fem/solving.py", line 442, in _extract_u
"Expecting second argument to be a Function")
File "/usr/lib/python2.7/dist-packages/dolfin/cpp/common.py", line 2294, in dolfin_error
return _common.dolfin_error(*args)
RuntimeError:

asked Mar 29, 2014 by sixtysymbols FEniCS User (2,280 points)

1 Answer

+3 votes
 
Best answer

Hi, you need

u = Function(V)
solve(a == L, u, bcs)

The error is telling you that u needs to be a Function object, but in your code it is a
TrialFunction object.

answered Mar 29, 2014 by MiroK FEniCS Expert (80,920 points)
selected Mar 29, 2014 by sixtysymbols

Hi,

Thanks for the reply: This worked!

...