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

What is the correct subdomain constructor for periodic boundary conditions?

0 votes

Deriving from class SubDomain with a constructor gives an error. What is the correct way
to specify an init function?

 from dolfin import *
 class PeriodicBoundary(SubDomain):
     def __init__(self):
           pass
     def inside(self, x, on_boundary):
           return x[0] < DOLFIN_EPS
     def map(self, x, y):
           y[0] = x[0] - 1.0
           y[1] = x[1]

 periodic_boundary = PeriodicBoundary()
 pbc = PeriodicBoundaryComputation()
 mesh = UnitSquareMesh(4, 4)
 mf = pbc.masters_slaves(mesh, periodic_boundary, 0)
 plot(mf, interactive=True)

Gives the error message:

File
"/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/cpp/mesh.py",
line 5355, in masters_slaves
return _mesh.PeriodicBoundaryComputation_masters_slaves(*args) TypeError: in method 'PeriodicBoundaryComputation_masters_slaves',
argument 2 of type 'dolfin::SubDomain const &'

Without the init (which is needed in some cases) everything works fine.

asked Dec 12, 2013 by monien FEniCS Novice (790 points)

1 Answer

+1 vote
 
Best answer

Hi, change the constructor to

   def __init__(self):                                                           
         SubDomain.__init__(self)    
answered Dec 12, 2013 by MiroK FEniCS Expert (80,920 points)
selected Dec 12, 2013 by Jan Blechta

Thanks, stupid me ;-)

Or even better. Skip the constructor as it will be called automatically anyway.

True, unless you want to give some data to the class ... .

...