PeriodicBC problem

Asked by Praveen C

Hello

I am getting an error in implementing periodic bc. I must be making a silly mistake but cannot find it. Here is the code

from dolfin import *

degree = 1

# Height of channel = 2 h
h = 0.1
# Length of channel = 2 L
L = 1.0

class PeriodicBoundary(SubDomain):
   # Left side x = -L
   def inside(self, x, on_boundary):
      return x[0]+L < DOLFIN_EPS and on_boundary

   # Map right side x=+L to left side
   def map(self, x, y):
      y[0] = x[0] - 2*L
      y[1] = x[1]

mesh = Rectangle(-L, -h, L, h, 25, 26)

V = FunctionSpace(mesh, "CG", degree)

perbc = PeriodicBC(V, PeriodicBoundary())

The error I get is

Building mapping between periodic degrees of freedom.
At coordinate: x = -2.92 -0.1
Traceback (most recent call last):
  File "test.py", line 23, in <module>
    perbc = PeriodicBC(V, pp)
  File "/Applications/FEniCS.app/Contents/Resources/lib/python2.6/site-packages/dolfin/cpp.py", line 19175, in __init__
    _cpp.PeriodicBC_swiginit(self,_cpp.new_PeriodicBC(*args))
RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** https://answers.launchpad.net/dolfin
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to apply periodic boundary condition.
*** Reason: Could not find a pair of matching degrees of freedom.
*** Where: This error was encountered inside PeriodicBC.cpp.
*** -------------------------------------------------------------------------

But the point x = -2.92 -0.1 is on the top boundary.

praveen

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Thomas Fraunholz (sleater) said :
#1

Hi,

I think you missed your channel's boundary. Here is an example how I connected left and right side of a UnitSquare [0,1]**2:

class BoundaryHorz(SubDomain):
    def inside(self, x, on_boundary):
        return bool(x[0] < DOLFIN_EPS and x[0] > -DOLFIN_EPS and on_boundary)
    def map(self, y, x):
        x[0] = y[0] - 1.0
        x[1] = y[1]

Thomas

Revision history for this message
Martins Bruveris (martins-bruveris) said :
#2

I am having a similar problem in 1D. Here is the sample code

from dolfin import *
from numpy import pi

n = 339

mesh = Interval(n, 0, 2*pi)
V = FunctionSpace(mesh, 'Lagrange', 1)

class PerBcs(SubDomain):
    def inside(self, x, on_boundary):
        return bool(x[0] < DOLFIN_EPS and
                    x[0] > -DOLFIN_EPS and
                    on_boundary)
    def map(self, x, y):
        y[0] = x[0] - 2*pi

pbc = PerBcs()
bcs = PeriodicBC(V, pbc)

The code works for n=340 and it also works if one replaces the replaces 2*pi by 6.28318530717958, which is 2*pi with the last digit set to 0. The error message I get is

Building mapping between periodic degrees of freedom.
At coordinate: x = 0
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)

/home/martins/diss/prog/kurtek/p/<ipython console> in <module>()

/home/martins/diss/prog/kurtek/p/dolfin_bug.py in <module>()
     26
     27 pbc = PerBcs()
---> 28 bcs = PeriodicBC(V, pbc)
     29
     30

/usr/lib/python2.7/dist-packages/dolfin/cpp.pyc in __init__(self, *args)
  19191
  19192 """
> 19193 _cpp.PeriodicBC_swiginit(self,_cpp.new_PeriodicBC(*args))
  19194 __swig_destroy__ = _cpp.delete_PeriodicBC
  19195 def apply(self, *args):

RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** https://answers.launchpad.net/dolfin
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to apply periodic boundary condition.
*** Reason: Could not find a pair of matching degrees of freedom.
*** Where: This error was encountered inside PeriodicBC.cpp.
*** -------------------------------------------------------------------------

Is this a bug in dolfin due to some rounding errors?

Can you help with this problem?

Provide an answer of your own, or ask Praveen C for more information if necessary.

To post a message you must log in.