# Expecting second argument to be a Function

I came upon this strange error message while running the following code (the error message has been included at the end) :

from dolfin import *

N = 100

alpha = 0.1

mesh = UnitInterval(N)

V = FunctionSpace(

def left(x,

return on_boundary & near(x[0],0)

def right(x,

return on_boundary & near(x[0],1)

# The boundary conditions

bc_left = DirichletBC(

bc_right = DirichletBC(

bcs = [bc_left,bc_right]

# The variational formulation

u = TrialFunction(V)

v = TestFunction(V)

a = (-u.dx(0)*v + alpha*u.

L = Constant(0)*v*dx

# Solve the variational problem

solve(a == L,u,bcs)

#u_ = Function(V)

#solve(a==L,u_,bcs)

The commented code works well. However when I try to solve the variational problem and store the solution in u, which is the trial function, I produce the error message :

>> python convection_

Traceback (most recent call last):

File "convection_

solve(a == L,u,bcs)

File "/usr/lib/

_solve_

File "/usr/lib/

= _extract_

File "/usr/lib/

u = _extract_u(args[1])

File "/usr/lib/

"Expecting second argument to be a Function")

File "/usr/lib/

return _cpp.dolfin_

RuntimeError:

*** -------

*** DOLFIN encountered an error. If you are not able to resolve this issue

*** using the information listed below, you can ask for help at

***

*** https:/

***

*** Remember to include the error message listed below and, if possible,

*** include a *minimal* running example to reproduce the error.

***

*** -------

*** Error: Unable to solve variational problem.

*** Reason: Expecting second argument to be a Function.

*** Where: This error was encountered inside solving.py.

*** -------

Why does this happen ? I have solved plenty of problems using the trialfunction as an argument in different solvers to store the solution inside.

## Question information

- Language:
- English Edit question

- Status:
- Answered

- For:
- DOLFIN Edit question

- Assignee:
- No assignee Edit question

- Last query:
- 2013-05-05

- Last reply:
- 2013-05-05

Jan Blechta (blechta) said : | #1 |

On Sun, 05 May 2013 11:11:33 -0000

imranal <email address hidden> wrote:

> New question #228187 on DOLFIN:

> https:/

>

> I came upon this strange error message while running the following

> code (the error message has been included at the end) :

>

> from dolfin import *

>

>

> N = 100

> alpha = 0.1

> mesh = UnitInterval(N)

> V = FunctionSpace(

>

> def left(x,

> return on_boundary & near(x[0],0)

> def right(x,

> return on_boundary & near(x[0],1)

>

> # The boundary conditions

> bc_left = DirichletBC(

> bc_right = DirichletBC(

> bcs = [bc_left,bc_right]

>

> # The variational formulation

> u = TrialFunction(V)

> v = TestFunction(V)

> a = (-u.dx(0)*v + alpha*u.

> L = Constant(0)*v*dx

>

> # Solve the variational problem

> solve(a == L,u,bcs)

> #u_ = Function(V)

> #solve(a==L,u_,bcs)

>

> The commented code works well. However when I try to solve the

> variational problem and store the solution in u, which is the trial

> function, I produce the error message :

>

> >> python convection_

>

> Traceback (most recent call last):

> File "convection_

> solve(a == L,u,bcs)

> File "/usr/lib/

> 250, in solve _solve_

> File "/usr/lib/

> 261, in _solve_varproblem = _extract_

> File "/usr/lib/

> 368, in _extract_args u = _extract_u(args[1])

> File "/usr/lib/

> 418, in _extract_u "Expecting second argument to be a Function")

> File "/usr/lib/

> in dolfin_error return _cpp.dolfin_

> RuntimeError:

>

> ***

> -------

> *** DOLFIN encountered an error. If you are not able to resolve this

> issue *** using the information listed below, you can ask for help at

> *** *** https:/

> ***

> *** Remember to include the error message listed below and, if

> possible, *** include a *minimal* running example to reproduce the

> error. ***

> ***

> -------

> *** Error: Unable to solve variational problem. *** Reason:

> Expecting second argument to be a Function. *** Where: This error

> was encountered inside solving.py. ***

> -------

>

> Why does this happen ? I have solved plenty of problems using the

> trialfunction as an argument in different solvers to store the

> solution inside.

>

TrialFunction is an argument of form in which the form is linear and in

particular it is the first argument of form - TestFunction being last.

So TrialFunction is used in definitions of bilinear forms.

On the other hand finite element functions (i.e. linear combinations

of basis functions) are handled via Function object. So your

outcommented code is correct. You could also label solution as u

instead if u_

u = TrialFunction(V)

v = TestFunction(V)

a = ...

L = ...

u = Function(V)

solve(a==L, u, bcs)

This is in fact a canonical way how to solve linear problem.

Jan

## Can you help with this problem?

Provide an answer of your own, or ask imranal for more information if necessary.