I am trying to formulate a dirichlet boundary condition for a problem with two unknown variables, and the boundary condition should only be applied to the second unknown variable, but not the first. In the sample code below, it appears that my code functions if I use a boundary condition with
value=default_scalar_type(0)
However, if I set
value= u_D
where u_D is an interpolated function, the code crashes.
How must I formulate u_D to get the boundary condition to work?
Here is the code (I’m sorry, I don’t know how to paste code into a separate window, as everyone else here seems to do…). If you change iflag from 0 to 1 at the bottom of the code, you will have the option of using value=default_scalar_type(0) or value= u_D.
You can see that the code runs with iflag=0 but crashes with iflag=1.
‘’’ python
from dolfinx.fem import (Constant, dirichletbc, Function, functionspace, locate_dofs_geometrical,
locate_dofs_topological)
from mpi4py import MPI
from dolfinx import fem, mesh, default_scalar_type
import numpy as np
import ufl
Define mesh
nx, ny = 50, 50
domain = mesh.create_rectangle(MPI.COMM_WORLD, [np.array([-2, -2]), np.array([2, 2])],
[nx, ny], mesh.CellType.triangle)
VP=fem.functionspace(domain, (“Lagrange”, 1, (2 , )))
Create facet to cell connectivity required to determine boundary facets
tdim = domain.topology.dim
fdim = tdim - 1
domain.topology.create_connectivity(fdim, tdim)
boundary_facets = mesh.exterior_facet_indices(domain.topology)
boundary_dofs_x = locate_dofs_topological(VP.sub(1), domain.topology.dim - 1, boundary_facets)
V=fem.functionspace(domain, (“Lagrange”, 1))
x = ufl.SpatialCoordinate(domain)
u_D=Function(V)
u_D.interpolate(lambda x:x[0])
iflag=1
if iflag==0:
value=default_scalar_type(0)
else:
value=u_D
bcx = dirichletbc(value, boundary_dofs_x, VP.sub(1))
‘’’