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]