Dirichlet BC in DOLFINX

Hi,
I would like anyone to verify my implementation. I am currently performing a multi-physical analysis where am supposed to consider mixed element space. I want to apply for Dirichlet bc as shown below. I find that my results are wrong and I doubt the implementation of Dirichlet bc of the mixed element space. Can anyone help me to verify it? I want to apply component-wise and scalar values ad Dirichlet BC.

import dolfinx
import numpy as np
from mpi4py import MPI
import dolfinx.fem as fem
from petsc4py import PETSc
import ufl
from ufl import (Form, SpatialCoordinate, VectorElement, FiniteElement, TensorElement, MixedElement,as_tensor,as_vector,dot,TestFunctions, TrialFunctions,dx, ds, grad, FacetNormal,inner, max_value,nabla_grad, nabla_div, Identity)
rom ufl import (Circumradius, FacetNormal, SpatialCoordinate, TrialFunction,
                 TestFunction, div, ds, grad, inner,dot, nabla_grad, nabla_div,Identity,dot, dx)
from dolfinx.mesh import CellType, create_box, locate_entities_boundary
from dolfinx.mesh import MeshTags, locate_entities
from dolfinx.fem import (Constant, dirichletbc, Function, LinearProblem, FunctionSpace, VectorFunctionSpace, 
                         locate_dofs_topological,assemble_scalar)

L, B, H = 1,1,1
mesh = dolfinx.mesh.create_box(MPI.COMM_WORLD, [np.array([0,0,0]), np.array([L, B, H])], [1,1,1], cell_type=CellType.hexahedron)

U = VectorElement("CG", mesh.ufl_cell(), 1) # displacement vector element
V = FiniteElement("CG", mesh.ufl_cell(), 1) # voltage finite element
U1, V1 = FunctionSpace(mesh, U), FunctionSpace(mesh, V)

W = FunctionSpace(mesh, MixedElement([U, V]))

#Displacement Dirichlet BC
def clamped_boundary(x):
    return np.isclose(x[0], 0)

fdim = mesh.topology.dim - 1
boundary_facets = locate_entities_boundary(mesh, fdim, clamped_boundary)
u_D = np.array([0,0,1e-3], dtype=ScalarType)
bc1 = dirichletbc(u_D, locate_dofs_topological((W.sub(0)), fdim, boundary_facets), W.sub(0))

# Voltage Dirichlet BC
def Ground(x):
    return np.isclose(x[1], 0)
v_D = Function(V1)
ground_facets = locate_entities_boundary(mesh, fdim, Ground)
with v_D.vector.localForm() as loc:
     loc.set(1)
bc2 = dirichletbc(v_D, locate_dofs_topological((W.sub(1),V1), fdim, ground_facets), W.sub(1))

bcs =[bc1,bc2]
1 Like

Issue submitted at:

As a workaround for now, you can use:

def f(x):
    vals = np.zeros(x.shape)
    vals[2] = 1e-3
    return vals

fdim = mesh.topology.dim - 1
boundary_facets = locate_entities_boundary(mesh, fdim, clamped_boundary)
u_D = Function(U1)
u_D.interpolate(f)
bc1 = dirichletbc(u_D, locate_dofs_topological(
    (W.sub(0), U1), fdim, boundary_facets), W.sub(0))
1 Like

Hello,
Does dirichilet bc syntax has removed FunctionSpace?

dolfinx.fem.dirichiletbc(u_D, locate_dofs_topological(
    (W.sub(0), U1), fdim, boundary_facets))

Because, when I put function space W.sub(0), it is giving error.
Q: Does dirichiletbc doesn’t require Function space in 3rd argument, considering (Function (1st arg) and (boundary_dofs in 2nd arg) ?
Can you share the original working syntax up to dat for dirichiletbc in dolfinx?

Please provide a minimal reproducible example of your error, and information about how you installed dolfinx and what version you are using.