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

Periodic BC's fail with TypeError

0 votes

When I create a simple demo of periodic BC's, it works. However, when I incorporate this into my main code, I get the following error:

Traceback (most recent call last):
...
fs = dolfin.FunctionSpace(self, "Lagrange", 1, constrained_domain=self.constrained_domain)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/functions/functionspace.py", line 403, in init
FunctionSpaceBase.init(self, mesh, element, constrained_domain)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/functions/functionspace.py", line 93, in init
dolfin_dofmap = cpp.DofMap(ufc_dofmap, mesh, constrained_domain)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/cpp/fem.py", line 656, in init
_fem.DofMap_swiginit(self,_fem.new_DofMap(*args))
TypeError: in method 'new_DofMap', argument 3 of type 'boost::shared_ptr< dolfin::SubDomain const >'

I am using a 2D periodic domain with a UnitSquareMesh. My SubDomain for the boundary is this:

class unitSquareMeshPeriodicBoundary(dolfin.SubDomain):
    """ Sub domain for Periodic boundary condition """
    def __init__(self, Lx=1.0, Ly=1.0):
        self.Lx = Lx
        self.Ly = Ly

    def inside(self, x, on_boundary):
        """ Left boundary is "target domain" G """
        # return True if on left or bottom boundary AND NOT on one of the two corners (0, 1) and (1, 0)
        return bool((dolfin.near(x[0], 0) or dolfin.near(x[1], 0)) and
                (not ((dolfin.near(x[0], 0) and dolfin.near(x[1], 1)) or
                        (dolfin.near(x[0], 1) and dolfin.near(x[1], 0)))) and on_boundary)

    def map(self, x, y):
        ''' # Map right boundary G (x) to left boundary H (y) '''
        if dolfin.near(x[0], self.Lx) and dolfin.near(x[1], self.Ly):
            y[0] = x[0] - self.Lx
            y[1] = x[1] - self.Ly
        elif dolfin.near(x[0], self.Lx):
            y[0] = x[0] - self.Lx
            y[1] = x[1]
        else:   # near(x[1], 1)
            y[0] = x[0]
            y[1] = x[1] - self.Ly

My call to FunctionSpace is as follows:

        self.mesh.constrained_domain =  unitSquareMeshPeriodicBoundary()
 ...
        fs = dolfin.FunctionSpace(self, "Lagrange", 1, constrained_domain=self.constrained_domain)

Any help would be greatly appreciated!

asked Mar 11, 2014 by briandrawert FEniCS Novice (120 points)

1 Answer

0 votes

You need to put this

    dolfin.SubDomain.__init__(self)

inside your __init__ method.

answered Mar 11, 2014 by mikael-mortensen FEniCS Expert (29,340 points)

This worked, thanks! Simple, obvious solution.

...