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

Boundary conditions using polar coordinates

+1 vote

I have the following L shape domain
from dolfin import *
square1 = Rectangle(-1, -1, 1, 1)
square2 = Rectangle(0,-0.5,0.5, 0)
mesh = Mesh(square1-square2, 8)

How can I define (in FEniCS) the boundary conditions if I am using polar coordinates?

asked Jan 24, 2014 by John1977 FEniCS Novice (250 points)

1 Answer

+4 votes

As you would do in any other language... Transform the coordinates.

from math import *
def transform(x, o):
  r = hypot(x[0] - o[0], x[1] - o[1])
  phi = atan2(x[1] - o[1], x[0] - o[0])
  if phi < 0: phi = phi + 2*pi # if you want phi in [0, 2pi]
  return r, phi

class ExactSolution(Expression):
  def __init__(self, origin, a):
    self.origin, self.a = origin, a
  def eval(self, values, x):
    r, phi = transform (x, origin)
    values[0] = r**self.a*sin(self.a*phi)
    return
answered Jan 24, 2014 by Christian Waluga FEniCS Expert (12,310 points)
...