# DirichletBC not working

**URL:** <https://fenicsproject.discourse.group/t/dirichletbc-not-working/8433>\
**Category:** dolfinx\
**Created:** [May 31, 2022, 2:35pm UTC](https://fenicsproject.discourse.group/t/dirichletbc-not-working/8433 "2022-05-31T14:35:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![festv](https://avatars.discourse-cdn.com/v4/letter/f/ce7236/32.png) [@festv](https://fenicsproject.discourse.group/u/festv)\
**Post date:** [May 31, 2022, 2:35pm UTC](https://fenicsproject.discourse.group/t/dirichletbc-not-working/8433/1 "2022-05-31T14:35:08Z")

</div>

Good afternoon,  
Working with dolfinx 0.3.0,  
i tried following [the tutorial](https://jorgensd.github.io/dolfinx-tutorial/chapter2/linearelasticity_code.html)’s example with that code:

```auto
import numpy as np
from dolfinx import fem, cpp, io, mesh, generation
from mpi4py import MPI
import ufl
from petsc4py import PETSc

L, W, H=0.303, 0.19, 0.064
NX, NY, NZ = 30, 19, 6

points=[np.array([0, 0, 0]), np.array([L, W, H])]
domain=generation.BoxMesh(MPI.COMM_WORLD, points, [NX,NY,NZ], cell_type=cpp.mesh.CellType.hexahedron)
dim=domain.topology.dim

def bottom(x):
    return np.isclose(x[2], 0, atol=1e-3)

U=fem.VectorFunctionSpace(domain, ("CG", 1))

bcdofs=fem.locate_dofs_geometrical(U, bottom)
u_0=np.array((0,)*dim, dtype=PETSc.ScalarType)
bc=fem.DirichletBC(u_0, bcdofs, U)

```

But i get :

```auto
Traceback (most recent call last):
  File "/mnt/c/Users/stavfe/Documents/Optimisation/opti.py", line 92, in <module>
    bc=fem.DirichletBC(u_0, bcdofs, U)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfinx/fem/dirichletbc.py", line 147, in __init__
    raise NotImplementedError
NotImplementedError

```

Is it because i need dolfinx 0.4 to for it to work?  
What can be a replacement for Dolfinx 0.3?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [May 31, 2022, 3:33pm UTC](https://fenicsproject.discourse.group/t/dirichletbc-not-working/8433/2 "2022-05-31T15:33:26Z")

</div>

Yes, you need DOLFINx \>= 0.4 for usage of Constants as input to DirichletBC.

A workaround is to use a function, and interpolate the constant value onto that function.

```auto
u_0 = dolfinx.fem.Function(V)
def interpolater(x):
    values = np.zeros((tdim, x.shape[1]))
    values[0] = ... # Change first value of constant
    values[1] = ... # Change second value of constant
    ...
    return values
u_0.interpolate(interpolator)
bc = fem.DirichletBC(u_0, bc_dofs)

```
