VariationalProblem(J, F, bc, nonlinear=True) do not work

Asked by Anne Kværnø

The test program nlPoisson_vp2.py do not work. I got the following error message

Traceback (most recent call last):
  File "nlPoisson_vp2.py", line 55, in <module>
    problem = VariationalProblem(J, F, bc, nonlinear=True)
TypeError: __init__() got an unexpected keyword argument 'nonlinear'

I am using Ubuntu 10.10, python 2.6.6 and dolfin 0.9.10

On a different computer, using Ubuntu 10.04, python 2.6.5 and dolfin 0.9.9, this test program worked perfectly fine.

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:
Revision history for this message
Kent-Andre Mardal (kent-and) said :
#1

Anne,

I think you should remove the nonlinear keyword.

Kent

On 3 May 2011 16:23, Anne Kværnø <email address hidden>wrote:

> New question #155708 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/155708
>
> The test program nlPoisson_vp2.py do not work. I got the following error
> message
>
> Traceback (most recent call last):
> File "nlPoisson_vp2.py", line 55, in <module>
> problem = VariationalProblem(J, F, bc, nonlinear=True)
> TypeError: __init__() got an unexpected keyword argument 'nonlinear'
>
> I am using Ubuntu 10.10, python 2.6.6 and dolfin 0.9.10
>
> On a different computer, using Ubuntu 10.04, python 2.6.5 and dolfin 0.9.9,
> this test program worked perfectly fine.
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
Best Johan Hake (johan-hake) said :
#2

On Tuesday May 3 2011 07:23:20 Anne Kværnø wrote:
> New question #155708 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/155708
>
> The test program nlPoisson_vp2.py do not work. I got the following error
> message
>
> Traceback (most recent call last):
> File "nlPoisson_vp2.py", line 55, in <module>
> problem = VariationalProblem(J, F, bc, nonlinear=True)
> TypeError: __init__() got an unexpected keyword argument 'nonlinear'
>
> I am using Ubuntu 10.10, python 2.6.6 and dolfin 0.9.10
>
> On a different computer, using Ubuntu 10.04, python 2.6.5 and dolfin 0.9.9,
> this test program worked perfectly fine.

The interface to a nonlinear VariationalProblem changed between these two
releases. Take a look at the docstring of VariationalProblem.

In essence: Just change the order of the forms. Put the nonlinear (linear in
the test function) form first, and the linearised Jacobian as the second form.
Then will the VariationalProblem be interpreted as a Nonlinear problem. Also
skip the "nonlinear" argument.

If you ask me, I think this change is abit too magic and it is not clear at
all that this is what to do ;)

Johan

Revision history for this message
Garth Wells (garth-wells) said :
#3

On 03/05/11 17:15, Johan Hake wrote:
> Question #155708 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/155708
>
> Johan Hake proposed the following answer:
> On Tuesday May 3 2011 07:23:20 Anne Kværnø wrote:
>> New question #155708 on DOLFIN:
>> https://answers.launchpad.net/dolfin/+question/155708
>>
>> The test program nlPoisson_vp2.py do not work. I got the following error
>> message
>>
>> Traceback (most recent call last):
>> File "nlPoisson_vp2.py", line 55, in <module>
>> problem = VariationalProblem(J, F, bc, nonlinear=True)
>> TypeError: __init__() got an unexpected keyword argument 'nonlinear'
>>
>> I am using Ubuntu 10.10, python 2.6.6 and dolfin 0.9.10
>>
>> On a different computer, using Ubuntu 10.04, python 2.6.5 and dolfin 0.9.9,
>> this test program worked perfectly fine.
>
> The interface to a nonlinear VariationalProblem changed between these two
> releases. Take a look at the docstring of VariationalProblem.
>
> In essence: Just change the order of the forms. Put the nonlinear (linear in
> the test function) form first, and the linearised Jacobian as the second form.
> Then will the VariationalProblem be interpreted as a Nonlinear problem. Also
> skip the "nonlinear" argument.
>
> If you ask me, I think this change is abit too magic and it is not clear at
> all that this is what to do ;)
>

I agree. I think that it's very unclear.

Why not just have

    LinearVariationalProblem

and

    NonlinearVariationalProblem

They could share common code behind the scenes.

Garth

> Johan
>

Revision history for this message
Kyle (kylekyle) said :
#4

After reading Johan's post I was able to get past the nonlinear problem but now my program crashes. Could anyone help me with this?

Here is my program:

#!/usr/bin/python

from dolfin import *
import numpy, sys

# MESHING
mesh = Rectangle(0.0, -0.5, 1.0, 0.5, 10, 10, "right/left")

# FUNCTION SPACE
scalar = FunctionSpace(mesh, "CG", 1) #Pressure
vector = VectorFunctionSpace(mesh, "CG", 2) #Velocity
system = vector * scalar #Mixed Function Space

# BOUNDARIES
right = compile_subdomains('x[0] == 1.0')
left = compile_subdomains('x[0] == 0.0')
top = compile_subdomains('x[1] == 0.5')
bottom = compile_subdomains('x[1] == -0.5')

# INFLOW VELOCITY BC FOR TOP
bc1 = DirichletBC(system.sub(0), Constant((1.0, 0.0)), top)

# NO-SLIP BC FOR TOP-BOTTOM
noslip = Constant((0.0, 0.0))
bc0 = DirichletBC(system.sub(0), noslip, left)
bc3 = DirichletBC(system.sub(0), noslip, bottom)
bc2 = DirichletBC(system.sub(0), noslip, right)

# STORAGE OF BCs
bcs = [bc1, bc2, bc0, bc3]

# VARIATIONAL PROBLEM
ts = TestFunction(system)
ds = TrialFunction(system)
s = Function(system)

v, q = split(ts)
dv, dq = split(ds)
u , p = split(s)

f = Constant((0, 0))
nu = 0.001

#F = (nu*inner(grad(v), grad(u)) - div(v)*p + q*div(u) - inner(v,f))*dx # Stokes
F = (nu*inner(grad(v), grad(u)) - div(v)*p + q*div(u) + inner(dot(u,grad(u)),v) - inner(v,f))*dx # Navier-Stokes
J = derivative(F,s,ds)

# SET UP PDE
problem = VariationalProblem(F, J, bcs)
#problem.is_nonlinear=True

# SOLVE PDE
(U, P) = problem.solve().split()

# FILES FOR PARAVIEW
ufile_pvd = File("velocity.pvd")
ufile_pvd << U
pfile_pvd = File("pressure.pvd")
pfile_pvd << P

# PLOTS
plot(U)
plot(P)
interactive()

Revision history for this message
Garth Wells (garth-wells) said :
#5

On 03/05/11 17:12, Kent-Andre Mardal wrote:
>
> Anne,
>
> I think you should remove the nonlinear keyword.
>

This change will make the code work, but it will produce an incorrect
result. DOLFIN will assume that the equation is linear, based on the
order of J and F (which as I've already posted I think is bad).

Garth

> Kent
>
> On 3 May 2011 16:23, Anne Kværnø <<email address hidden>
> <mailto:<email address hidden>>> wrote:
>
> New question #155708 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/155708
>
> The test program nlPoisson_vp2.py do not work. I got the following
> error message
>
> Traceback (most recent call last):
> File "nlPoisson_vp2.py", line 55, in <module>
> problem = VariationalProblem(J, F, bc, nonlinear=True)
> TypeError: __init__() got an unexpected keyword argument 'nonlinear'
>
> I am using Ubuntu 10.10, python 2.6.6 and dolfin 0.9.10
>
> On a different computer, using Ubuntu 10.04, python 2.6.5 and dolfin
> 0.9.9, this test program worked perfectly fine.
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> <https://launchpad.net/%7Edolfin>
> Post to : <email address hidden>
> <mailto:<email address hidden>>
> Unsubscribe : https://launchpad.net/~dolfin
> <https://launchpad.net/%7Edolfin>
> More help : https://help.launchpad.net/ListHelp
>
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#6

Kyle,
you will get faster answers if you post
the error messages you get in addition
to the program. :)

Martin

On 3 May 2011 18:27, Kyle <email address hidden> wrote:
> Question #155708 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/155708
>
> Kyle requested more information:
> After reading Johan's post I was able to get past the nonlinear problem
> but now my program crashes. Could anyone help me with this?
>
> Here is my program:
>
> #!/usr/bin/python
>
> from dolfin import *
> import numpy, sys
>
> # MESHING
> mesh = Rectangle(0.0, -0.5, 1.0, 0.5, 10, 10, "right/left")
>
> # FUNCTION SPACE
> scalar = FunctionSpace(mesh, "CG", 1) #Pressure
> vector = VectorFunctionSpace(mesh, "CG", 2) #Velocity
> system = vector * scalar #Mixed Function Space
>
> # BOUNDARIES
> right = compile_subdomains('x[0] == 1.0')
> left = compile_subdomains('x[0] == 0.0')
> top = compile_subdomains('x[1] == 0.5')
> bottom = compile_subdomains('x[1] == -0.5')
>
> # INFLOW VELOCITY BC FOR TOP
> bc1 = DirichletBC(system.sub(0), Constant((1.0, 0.0)), top)
>
> # NO-SLIP BC FOR TOP-BOTTOM
> noslip = Constant((0.0, 0.0))
> bc0 = DirichletBC(system.sub(0), noslip, left)
> bc3 = DirichletBC(system.sub(0), noslip, bottom)
> bc2 = DirichletBC(system.sub(0), noslip, right)
>
> # STORAGE OF BCs
> bcs = [bc1, bc2, bc0, bc3]
>
> # VARIATIONAL PROBLEM
> ts = TestFunction(system)
> ds = TrialFunction(system)
> s = Function(system)
>
> v, q = split(ts)
> dv, dq = split(ds)
> u , p = split(s)
>
> f = Constant((0, 0))
> nu = 0.001
>
> #F = (nu*inner(grad(v), grad(u)) - div(v)*p + q*div(u) - inner(v,f))*dx # Stokes
> F = (nu*inner(grad(v), grad(u)) - div(v)*p + q*div(u) + inner(dot(u,grad(u)),v) - inner(v,f))*dx # Navier-Stokes
> J = derivative(F,s,ds)
>
> # SET UP PDE
> problem = VariationalProblem(F, J, bcs)
> #problem.is_nonlinear=True
>
> # SOLVE PDE
> (U, P) = problem.solve().split()
>
> # FILES FOR PARAVIEW
> ufile_pvd = File("velocity.pvd")
> ufile_pvd << U
> pfile_pvd = File("pressure.pvd")
> pfile_pvd << P
>
> # PLOTS
> plot(U)
> plot(P)
> interactive()
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : <email address hidden>
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp
>

Revision history for this message
Anne Kværnø (anne-math) said :
#7

Thanks Johan Hake, that solved my question.

Revision history for this message
Anne Kværnø (anne-math) said :
#8

Thanks, this solved the problem.