Struggling with vector values bcdirichlet

Note that this is due to the option in the lower left corner, under Masking, where you have chosen Glyph Mode: Uniform Spatial Distribution.

You should change this to all nodes.

Hello @dokken, I also have a related question that I have been struggling with. I am trying to impose Dirichlet boundary conditions on a tagged boundary of a mesh that I provide, in a mixed element space. After saving the resulting solution with the boundary conditions applied to it, I see that the conditions are not imposed on the entire boundary, but rather on a small subset of dofs.

Here is a sample code that reproduces this issue on my machine:


from mpi4py import MPI
from dolfinx.fem import Function, functionspace, locate_dofs_topological, dirichletbc
from dolfinx.io import XDMFFile
from basix.ufl import element, mixed_element
from dolfinx.fem.petsc import set_bc
import numpy as np

########################## Read meshes
comm = MPI.COMM_WORLD
# Blood subdomain
with XDMFFile(comm, 'FluidDomain.xdmf', "r") as xdmf: 
    msh2 = xdmf.read_mesh(name="Grid")
msh2.topology.create_connectivity(msh2.topology.dim-1, msh2.topology.dim)
with XDMFFile(comm, 'FluidDomain_boundary.xdmf', "r") as xdmf: 
    ft2 = xdmf.read_meshtags(msh2,name="Grid")
    

########################## Parameters
# Blood subdomain tags
inlet1 = 6
inlet2 = 1
outlet = 2
noslip = [3,4,5,7,8]


########################## Define function spaces
scalar_cg1_elem_msh2 = element("Lagrange", msh2.basix_cell(), 1)
vector_cg1_elem_msh2 = element("Lagrange", msh2.basix_cell(), 1, shape=(msh2.geometry.dim, ))
mixed_elem_msh2 = mixed_element([vector_cg1_elem_msh2, scalar_cg1_elem_msh2])
Vmix = functionspace(msh2, mixed_elem_msh2)
Q1, _ = Vmix.sub(0).collapse()
Q2, _ = Vmix.sub(1).collapse()


########################## Boundary conditions
fdim = msh2.topology.dim - 1
# BCs velocity
bcu = []
u_inlet2 = Function(Q1)
def velocity1(x):
    values = np.zeros((3, x.shape[1]))
    values[0, :] = 0.5*np.ones_like(x[0])
    return values
u_inlet2.interpolate(velocity1)
bcu += [dirichletbc(u_inlet2,locate_dofs_topological((Vmix.sub(0),Q1), fdim, ft2.find(inlet2)),Vmix.sub(0))]

u_noSlip = Function(Q1)
for tag in noslip:
    bcu += [dirichletbc(u_noSlip,locate_dofs_topological((Vmix.sub(0),Q1), fdim, ft2.find(tag)),Vmix.sub(0))]

# BCs pressure
p_outflow = Function(Q2)
p_outflow.x.array[:] = 0
bcp = [dirichletbc(p_outflow,locate_dofs_topological((Vmix.sub(1),Q2), fdim, ft2.find(outlet)),Vmix.sub(1))]


########################## Define functions
U = Function(Vmix)
set_bc(U.vector,bcu+bcp)


########################## Set output
uh, ph = U.split()
with XDMFFile(comm, 'NSsolution.xdmf', "w") as xdmf: 
    xdmf.write_mesh(msh2)
    xdmf.write_function(uh,0)
    xdmf.write_function(ph,0)


The mesh is provided in my google drive in this link fenicsxTest - Google Drive

I am using the 0.8.0 version of fenicsx that I installed through Anaconda. Thank you in advance for any help. :slight_smile: