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

2D boundary condition

+2 votes

Hi,

I have a 2D region, on one side I want to impose Dirichlet boundary condition only in one direction. For both direction I do the following(suppose our boundary values are zero):

u1 = constant((0.0,0.0))
bc = DirichletBC(V, u1, boundary)

To only impose zero boundary condition only in one direction(say X direction) I think of the following:

class bound(Expression):
   def eval(self, values, x):
      value[0] = 0
   def value_shape(self):
      return(2,)

then I instantiate this class and impose it on the boundary:

u2 = bound()
bc = DirichletBC(V, u2, boundary)

I don't know whether this method is correct in defining such boundary conditions or not? In my case I do not get correct results with my code and I suspect this part of my code.

asked Mar 20, 2016 by babak FEniCS Novice (380 points)

1 Answer

0 votes
 
Best answer

Hi,
you can apply a boundary condition in $x$ or $y$ direction using V.sub(0) or V.sub(1) respectively. In your case, consider:

# Dirichlet bc in the x direction
bc = DirichletBC(V.sub(0), Constant(0.0), boundary)

Regards.

answered Mar 20, 2016 by hernan_mella FEniCS Expert (19,460 points)
selected Mar 20, 2016 by babak

Great, it worked. thanks a lot.
But I don't know why my method does not provide correct results?

Because when you call the bound expression the value values[1] by default is set to zero. In other words, your definition of bound() is equivalent to

class bound(Expression):
   def eval(self, values, x):
       values[0] = 0.0
       values[1] = 0.0
   def value_shape(self):
       return(2,)
...