# Problem setting DirichletBC with 'complex' condition

**URL:** https://fenicsproject.discourse.group/t/problem-setting-dirichletbc-with-complex-condition/2357
**Category:** Uncategorized
**Created:** [February 5, 2020, 12:44pm UTC](https://fenicsproject.discourse.group/t/problem-setting-dirichletbc-with-complex-condition/2357 "2020-02-05T12:44:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Florian.g](https://avatars.discourse-cdn.com/v4/letter/f/a6a055/32.png) [@Florian.g](https://fenicsproject.discourse.group/u/Florian.g)
#### Post date: [February 5, 2020, 12:44pm UTC](https://fenicsproject.discourse.group/t/problem-setting-dirichletbc-with-complex-condition/2357/1 "2020-02-05T12:44:30Z")

</div>

Hello,

I tried to select nodes for dirichlet condition as `y=x and on_boundary` with the following code:

```python
from fenics import *

mesh = UnitSquareMesh(2,2)
V = FunctionSpace(mesh , 'P', 1)

def f(x, on_boundary):
    return near(x[1], x[0]) and on_boundary

dir = DirichletBC(V, 0, f)
print(dir.get_boundary_values())
# Output: {}

```

But I was not able to mark the nodes even if the method in `DirichletBC` is change to `"pointwise"`.  
I would have expect that the top-right and low-left nodes are returned.

Anyone know what is happening ?

Thanks.

---

<div class="post-metadata">

### Author: ![volkerk](https://avatars.discourse-cdn.com/v4/letter/v/9d8465/32.png) [@volkerk](https://fenicsproject.discourse.group/u/volkerk)
#### Post date: [February 5, 2020, 1:18pm UTC](https://fenicsproject.discourse.group/t/problem-setting-dirichletbc-with-complex-condition/2357/2 "2020-02-05T13:18:10Z")

</div>

When choosing ‘pointwise’, on\_boundary is always False, i.e. your function f always returns False. To mark all dofs with x = y you can try

```python
def f(x):
    return near(x[1], x[0])

bc = DirichletBC(V, Constant(0.0), f, method='pointwise')

```

---

<div class="post-metadata">

### Author: ![Florian.g](https://avatars.discourse-cdn.com/v4/letter/f/a6a055/32.png) [@Florian.g](https://fenicsproject.discourse.group/u/Florian.g)
#### Post date: [February 5, 2020, 1:35pm UTC](https://fenicsproject.discourse.group/t/problem-setting-dirichletbc-with-complex-condition/2357/3 "2020-02-05T13:35:35Z")

</div>

Ok thank you !  
But i don’t want the node at the center of the square (0.5, 0.5) to be constrain.  
Is it possible ? Using `near(x[1], x[0])` ?

---

<div class="post-metadata">

### Author: ![volkerk](https://avatars.discourse-cdn.com/v4/letter/v/9d8465/32.png) [@volkerk](https://fenicsproject.discourse.group/u/volkerk)
#### Post date: [February 5, 2020, 3:00pm UTC](https://fenicsproject.discourse.group/t/problem-setting-dirichletbc-with-complex-condition/2357/4 "2020-02-05T15:00:25Z")

</div>

```python
def f(x):
    return near(x[1], x[0]) and (near(x[0],0) or near(x[0],1))

```

---

<div class="post-metadata">

### Author: ![Florian.g](https://avatars.discourse-cdn.com/v4/letter/f/a6a055/32.png) [@Florian.g](https://fenicsproject.discourse.group/u/Florian.g)
#### Post date: [February 5, 2020, 4:27pm UTC](https://fenicsproject.discourse.group/t/problem-setting-dirichletbc-with-complex-condition/2357/5 "2020-02-05T16:27:31Z")

</div>

I don’t really understand why such condition with the `near(x[1], x[0]) and on_boundary` is not working.  
Thank you for your reply !
