Chapter 1.5: Different materials tutorial

Asked by Essi Colo

Hi,

I'm trying to implement a model with different materials. I tried the example in Chapter 1.5 of the FeniCS book, but got an error statement.

from dolfin import *

mesh=UnitSquare(1,1)
V = FunctionSpace(mesh, 'Lagrange', 1)

class Boundary(SubDomain):
    def inside(x, on_boundary):
        tol = 1E-14
        return on_boundary and abs(x[0])<tol

boundary = Boundary()
bc = DirichletBC(V, Constant(0), boundary)

Traceback (most recent call last):
  File "chapter_1.5.py", line 13, in <module>
    bc = DirichletBC(V, Constant(0), boundary)
  File "/usr/lib/python2.7/dist-packages/dolfin/fem/bcs.py", line 100, in __init__
    cpp.DirichletBC.__init__(self, *args)
  File "/usr/lib/python2.7/dist-packages/dolfin/cpp.py", line 18912, in __init__
    _cpp.DirichletBC_swiginit(self,_cpp.new_DirichletBC(*args))
TypeError: inside() takes exactly 2 arguments (3

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Anders Logg
Solved:
Last query:
Last reply:
Revision history for this message
Best Anders Logg (logg) said :
#1

You forgot the "self" argument to the inside function.

--
Anders

On Sat, May 05, 2012 at 03:35:44PM -0000, Serge-Étienne Parent wrote:
> New question #196142 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/196142
>
> Hi,
>
> I'm trying to implement a model with different materials. I tried the example in Chapter 1.5 of the FeniCS book, but got an error statement.
>
>
> from dolfin import *
>
> mesh=UnitSquare(1,1)
> V = FunctionSpace(mesh, 'Lagrange', 1)
>
> class Boundary(SubDomain):
> def inside(x, on_boundary):
> tol = 1E-14
> return on_boundary and abs(x[0]<tol)
>
> boundary = Boundary()
> bc = DirichletBC(V, Constant(0), boundary)
>
>
> Traceback (most recent call last):
> File "chapter_1.5.py", line 13, in <module>
> bc = DirichletBC(V, Constant(0), boundary)
> File "/usr/lib/python2.7/dist-packages/dolfin/fem/bcs.py", line 100, in __init__
> cpp.DirichletBC.__init__(self, *args)
> File "/usr/lib/python2.7/dist-packages/dolfin/cpp.py", line 18912, in __init__
> _cpp.DirichletBC_swiginit(self,_cpp.new_DirichletBC(*args))
> TypeError: inside() takes exactly 2 arguments (3
>

Revision history for this message
Essi Colo (essicolo) said :
#2

Thanks Anders Logg, that solved my question.