# Boundary conditions about Mixed space

**URL:** <https://fenicsproject.discourse.group/t/boundary-conditions-about-mixed-space/10538>\
**Category:** General\
**Created:** [February 27, 2023, 9:00am UTC](https://fenicsproject.discourse.group/t/boundary-conditions-about-mixed-space/10538 "2023-02-27T09:00:34Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [February 27, 2023, 12:35pm UTC](https://fenicsproject.discourse.group/t/boundary-conditions-about-mixed-space/10538/2 "2023-02-27T12:35:09Z")

</div>

Please make the example reproducible. Currently you have only posted snippets of code, which doesn’t make it easy for people to reproduce the problem.

An example of how to make your code reproducible is:

```python
import dolfinx
from mpi4py import MPI
import ufl
from petsc4py import PETSc
import numpy as np
domain = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
Ve = ufl.VectorElement("CG", domain.ufl_cell(), 2)
Pe = ufl.FiniteElement("CG", domain.ufl_cell(), 1)
We = ufl.MixedElement([Ve, Pe])
W = dolfinx.fem.FunctionSpace(domain, We)

def no_slip(x):
    return np.logical_or(np.logical_or(np.isclose(x[0], 0), np.isclose(x[0], 1)),
                         np.isclose(x[1], 0))

noslip_v = np.zeros(domain.geometry.dim, dtype=PETSc.ScalarType)
facets = dolfinx.mesh.locate_entities_boundary(domain, 1, no_slip)
bc_noslip = dolfinx.fem.dirichletbc(
    noslip_v, dolfinx.fem.locate_dofs_topological(W.sub(0), 1, facets), W.sub(0))

```

The issue here is that the block size of `W.sub(0)` is 1. You can check this by looking at `W.sub(0).dofmap.bs`. This means that it has unrolled all it’s dofs with respect to the dimension of the vector space.

To create a bc for your case, I would:

```auto
from IPython import embed
import dolfinx
from mpi4py import MPI
import ufl
from petsc4py import PETSc
import numpy as np
domain = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
Ve = ufl.VectorElement("CG", domain.ufl_cell(), 2)
Pe = ufl.FiniteElement("CG", domain.ufl_cell(), 1)
We = ufl.MixedElement([Ve, Pe])
W = dolfinx.fem.FunctionSpace(domain, We)

def no_slip(x):
    return np.logical_or(np.logical_or(np.isclose(x[0], 0), np.isclose(x[0], 1)),
                         np.isclose(x[1], 0))

# Set zero BC
noslip_v = np.zeros(domain.geometry.dim, dtype=PETSc.ScalarType)
V, _ = W.sub(0).collapse()
u_bc = dolfinx.fem.Function(V)
u_bc.x.set(0)
facets = dolfinx.mesh.locate_entities_boundary(domain, 1, no_slip)
bc_noslip = dolfinx.fem.dirichletbc(
    u_bc, dolfinx.fem.locate_dofs_topological((W.sub(0), V), 1, facets), W.sub(0))

w = dolfinx.fem.Function(W)
# Fill with non-zero data to illustrate input
w.x.set(2)

dolfinx.fem.petsc.set_bc(w.vector, [bc_noslip])

with dolfinx.io.VTXWriter(domain.comm, "output.bp", [w.sub(0).collapse()]) as vtx:
    vtx.write(0)

```

---

_[View the full topic](https://fenicsproject.discourse.group/t/boundary-conditions-about-mixed-space/10538)._
