error on solving mixed formulation

Asked by Pratik Mallya

I'm trying to solve a mixed formulation of a 2 point poisson problem (in one dimension):

-u'' = f(x); f(x) = (pi/2)^2 cos(pi*x/2)
-1 < x < 1, u(-1) = u(1) = 0

The code that I have written is :

"""
Solve
-u'' = f(x); f(x) = (pi/2)^2 cos(pi*x/2)
-1 < x < 1, u(-1) = u(1) = 0
14 subintervals
"""

from dolfin import *
import matplotlib as mpl
mesh = Interval(14, -1, 1)
V = FunctionSpace(mesh, 'Lagrange', 2)
V1 = FunctionSpace(mesh, 'DG', 0)
W = V*V1

(sigma, u) = TrialFunctions(W)
(tau, v) = TestFunctions(W)
u0 = Expression('0')
def u0_boundary(x, on_boundary):
    return on_boundary

bc = DirichletBC(W.sub(1), u0, u0_boundary)

f = Expression('((pi*pi)/4)*cos((pi*x[0])/2)')

equation = (dot(sigma, tau) - tau.dx(0)*u + sigma.dx(0)*v)*dx == f*v*dx
w = Function(W)
#solve(a == L, w, bc)
solve(equation, w, bc)
(sigma, u) = w.split()
#plot(sigma)
#plot(u)
#plot(mesh)
interactive()

I'm using dolfin 0.8.3 (one you get in debian squeeze repo). Running this throws up an error:

Traceback (most recent call last):
  File "problem5.py", line 30, in <module>
    solve(equation, w, bc)
  File "/usr/lib/python2.6/dist-packages/dolfin/cpp.py", line 4546, in solve
    return _cpp.solve(*args)
TypeError: in method 'solve', argument 1 of type 'dolfin::GenericMatrix const &'

What might be the problem?

Question information

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

On 15 March 2012 07:25, Pratik Mallya
<email address hidden>wrote:

> New question #190740 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/190740
>
> I'm trying to solve a mixed formulation of a 2 point poisson problem (in
> one dimension):
>
> -u'' = f(x); f(x) = (pi/2)^2 cos(pi*x/2)
> -1 < x < 1, u(-1) = u(1) = 0
>
> The code that I have written is :
>
> """
> Solve
> -u'' = f(x); f(x) = (pi/2)^2 cos(pi*x/2)
> -1 < x < 1, u(-1) = u(1) = 0
> 14 subintervals
> """
>
> from dolfin import *
> import matplotlib as mpl
> mesh = Interval(14, -1, 1)
> V = FunctionSpace(mesh, 'Lagrange', 2)
> V1 = FunctionSpace(mesh, 'DG', 0)
> W = V*V1
>
> (sigma, u) = TrialFunctions(W)
> (tau, v) = TestFunctions(W)
> u0 = Expression('0')
> def u0_boundary(x, on_boundary):
> return on_boundary
>
> bc = DirichletBC(W.sub(1), u0, u0_boundary)
>
>
> f = Expression('((pi*pi)/4)*cos((pi*x[0])/2)')
>
> equation = (dot(sigma, tau) - tau.dx(0)*u + sigma.dx(0)*v)*dx == f*v*dx
> w = Function(W)
> #solve(a == L, w, bc)
> solve(equation, w, bc)
> (sigma, u) = w.split()
> #plot(sigma)
> #plot(u)
> #plot(mesh)
> interactive()
>
> I'm using dolfin 0.8.3 (one you get in debian squeeze repo). Running this
> throws up an error:
>
>
You have a very old dolfin and the == is not supported in that version.
Try solve(a, L, ..)

Kent

Traceback (most recent call last):
> File "problem5.py", line 30, in <module>
> solve(equation, w, bc)
> File "/usr/lib/python2.6/dist-packages/dolfin/cpp.py", line 4546, in solve
> return _cpp.solve(*args)
> TypeError: in method 'solve', argument 1 of type 'dolfin::GenericMatrix
> const &'
>
> What might be the problem?
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

Revision history for this message
Anders Logg (logg) said :
#2

On Thu, Mar 15, 2012 at 06:25:50AM -0000, Pratik Mallya wrote:
> New question #190740 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/190740
>
> I'm trying to solve a mixed formulation of a 2 point poisson problem (in one dimension):
>
> -u'' = f(x); f(x) = (pi/2)^2 cos(pi*x/2)
> -1 < x < 1, u(-1) = u(1) = 0
>
> The code that I have written is :
>
> """
> Solve
> -u'' = f(x); f(x) = (pi/2)^2 cos(pi*x/2)
> -1 < x < 1, u(-1) = u(1) = 0
> 14 subintervals
> """
>
> from dolfin import *
> import matplotlib as mpl
> mesh = Interval(14, -1, 1)
> V = FunctionSpace(mesh, 'Lagrange', 2)
> V1 = FunctionSpace(mesh, 'DG', 0)
> W = V*V1
>
> (sigma, u) = TrialFunctions(W)
> (tau, v) = TestFunctions(W)
> u0 = Expression('0')
> def u0_boundary(x, on_boundary):
> return on_boundary
>
> bc = DirichletBC(W.sub(1), u0, u0_boundary)
>
>
> f = Expression('((pi*pi)/4)*cos((pi*x[0])/2)')
>
> equation = (dot(sigma, tau) - tau.dx(0)*u + sigma.dx(0)*v)*dx == f*v*dx
> w = Function(W)
> #solve(a == L, w, bc)
> solve(equation, w, bc)
> (sigma, u) = w.split()
> #plot(sigma)
> #plot(u)
> #plot(mesh)
> interactive()
>
> I'm using dolfin 0.8.3 (one you get in debian squeeze repo). Running this throws up an error:

Wow! That's an antique. I don't think it even exists. The last version
of the 0.8 series was 0.8.1 and released in 2008...

--
Anders

> Traceback (most recent call last):
> File "problem5.py", line 30, in <module>
> solve(equation, w, bc)
> File "/usr/lib/python2.6/dist-packages/dolfin/cpp.py", line 4546, in solve
> return _cpp.solve(*args)
> TypeError: in method 'solve', argument 1 of type 'dolfin::GenericMatrix const &'
>
> What might be the problem?
>
>

Revision history for this message
Johannes Ring (johannr) said :
#3

I think he meant 0.9.8-3. That's at least what's available in Debian squeeze repository. DOLFIN 1.0.0 is in testing and will be available in the next stable Debian release.

@Pratik: To get the latest DOLFIN, you should probably try out Dorsal (bzr lp:dorsal).

Revision history for this message
Pratik Mallya (pratik-mallya-ml) said :
#4

oops yes 0.9 is what i meant. Sorry!

Revision history for this message
Pratik Mallya (pratik-mallya-ml) said :
#5

I get the same error :(:

Traceback (most recent call last):
  File "problem5.py", line 29, in <module>
    solve(a, L, w, bc)
  File "/usr/lib/python2.6/dist-packages/dolfin/cpp.py", line 4546, in solve
    return _cpp.solve(*args)
TypeError: in method 'solve', argument 1 of type 'dolfin::GenericMatrix const &'

Revision history for this message
Pratik Mallya (pratik-mallya-ml) said :
#6

OK, so this works with the latest version of Fenics.

Revision history for this message
Kent-Andre Mardal (kent-and) said :
#7

solve is expecting matrices and vectors

matrix can be made as:
A = assemble(a)
b = assemble(L)

Then you can do
solve(A, w.vector(), b)

You should have a look at the demo examples that comes with your dolfin
installation.

Kent

On 15 March 2012 13:01, Pratik Mallya
<email address hidden>wrote:

> Question #190740 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/190740
>
> Pratik Mallya posted a new comment:
> I get the same error :(:
>
>
> Traceback (most recent call last):
> File "problem5.py", line 29, in <module>
> solve(a, L, w, bc)
> File "/usr/lib/python2.6/dist-packages/dolfin/cpp.py", line 4546, in solve
> return _cpp.solve(*args)
> TypeError: in method 'solve', argument 1 of type 'dolfin::GenericMatrix
> const &'
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>