Hello,
I am solving the coupling equation for displacement(u) and (p).
The current topic is “Cryer’s problem” with such boundary conditions :
- u(r=0) = 0
- p(r=R) = 0
where R is the radius of the sphere.
I could deal with pressure at the boundary, as it is laterally boundary condition.
However, for the center, I am not sure how to implement this ‘boundary condition’, u(r=0)=0
What I have tried is as follows :
# Define function spaces
u_elem = VectorElement('CG', domain.ufl_cell(), 2) # displacement(2D)
p_elem = FiniteElement('CG', domain.ufl_cell(), 1) # pore water pressure(scalar)
V = FunctionSpace(domain, MixedElement([u_elem, p_elem])) #Define vector function space for [u,p]
#Set space for u and p from V
U = FunctionSpace(domain, u_elem)
P = FunctionSpace(domain, p_elem)
def center(x):
return x[0]**2 + x[1]**2 < (0.1*R)**2
cells_center = locate_entities(domain, dim, center)
#Dirichlet BC for u : center
U, _ = V.sub(0).collapse()
u_bc = Function(U)
u_bc.x.set(0)
#center : u = 0
boundary_dofs_u_center = locate_dofs_topological((V.sub(0), U), dim, cells_center)
BC_u_center = dirichletbc(np.full_like(boundary_dofs_u_center, 0, dtype=ScalarType)[0], boundary_dofs_u_center, V.sub(0))
which followed the demo code of ‘’ Defining subdomains for different materials".
The error message is as follows :
TypeError Traceback (most recent call last)
File /usr/local/dolfinx-real/lib/python3.10/dist-packages/dolfinx/fem/bcs.py:125, in DirichletBCMetaClass.__init__(self, value, dofs, V)
124 try:
--> 125 super().__init__(_value, dofs, V) # type: ignore
126 except TypeError:
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
1. dolfinx.cpp.fem.DirichletBC_float64(g: numpy.ndarray[numpy.float64], dofs: numpy.ndarray[numpy.int32], V: dolfinx::fem::FunctionSpace)
2. dolfinx.cpp.fem.DirichletBC_float64(g: dolfinx::fem::Constant<double>, dofs: numpy.ndarray[numpy.int32], V: dolfinx::fem::FunctionSpace)
3. dolfinx.cpp.fem.DirichletBC_float64(g: dolfinx::fem::Function<double>, dofs: numpy.ndarray[numpy.int32])
4. dolfinx.cpp.fem.DirichletBC_float64(g: dolfinx::fem::Function<double>, dofs: List[numpy.ndarray[numpy.int32][2]], V: dolfinx::fem::FunctionSpace)
Invoked with: array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0.]), [array([1796, 1797, 1888, 1889, 1901, 1902, 2041, 2042, 2043, 2044, 2045,
2046, 2133, 2134, 2137, 2138, 2140, 2141], dtype=int32), array([1270, 1271, 1260, 1261, 1268, 1269, 1460, 1461, 1462, 1463, 1456,
1457, 1482, 1483, 1478, 1479, 1480, 1481], dtype=int32)], FunctionSpace(Mesh(VectorElement(Basix element (P, triangle, 1, equispaced, unset, False), 2), 0), VectorElement(FiniteElement('Lagrange', triangle, 2), dim=2))
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
Cell In[17], line 20
16 #center : u = 0
17 #boundary_dofs_u_center = locate_dofs_topological((V.sub(0), U), bdim, boundary_facets_center)
18 #BC_u_center = dirichletbc(u_bc, boundary_dofs_u_center, V.sub(0))
19 boundary_dofs_u_center = locate_dofs_topological((V.sub(0), U), dim, cells_center)
---> 20 BC_u_center = dirichletbc(np.full_like(boundary_dofs_u_center, 0, dtype=ScalarType)[0], boundary_dofs_u_center, V.sub(0))
22 #Dirichlet BC for p : surface
23 P, _ = V.sub(1).collapse()
File /usr/local/dolfinx-real/lib/python3.10/dist-packages/dolfinx/fem/bcs.py:183, in dirichletbc(value, dofs, V)
180 raise AttributeError("Boundary condition value must have a dtype attribute.")
182 formcls = type("DirichletBC", (DirichletBCMetaClass, bctype), {})
--> 183 return formcls(value, dofs, V)
File /usr/local/dolfinx-real/lib/python3.10/dist-packages/dolfinx/fem/bcs.py:127, in DirichletBCMetaClass.__init__(self, value, dofs, V)
125 super().__init__(_value, dofs, V) # type: ignore
126 except TypeError:
--> 127 super().__init__(_value, dofs, V._cpp_object) # type: ignore
128 else:
129 super().__init__(_value, dofs)
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
1. dolfinx.cpp.fem.DirichletBC_float64(g: numpy.ndarray[numpy.float64], dofs: numpy.ndarray[numpy.int32], V: dolfinx::fem::FunctionSpace)
2. dolfinx.cpp.fem.DirichletBC_float64(g: dolfinx::fem::Constant<double>, dofs: numpy.ndarray[numpy.int32], V: dolfinx::fem::FunctionSpace)
3. dolfinx.cpp.fem.DirichletBC_float64(g: dolfinx::fem::Function<double>, dofs: numpy.ndarray[numpy.int32])
4. dolfinx.cpp.fem.DirichletBC_float64(g: dolfinx::fem::Function<double>, dofs: List[numpy.ndarray[numpy.int32][2]], V: dolfinx::fem::FunctionSpace)
Invoked with: array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0.]), [array([1796, 1797, 1888, 1889, 1901, 1902, 2041, 2042, 2043, 2044, 2045,
2046, 2133, 2134, 2137, 2138, 2140, 2141], dtype=int32), array([1270, 1271, 1260, 1261, 1268, 1269, 1460, 1461, 1462, 1463, 1456,
1457, 1482, 1483, 1478, 1479, 1480, 1481], dtype=int32)], <dolfinx.cpp.fem.FunctionSpace object at 0x7f68ce2abdb0>
Could you help me to implement this setting?
ALSO, If you can suggest better function for defining center compared to this code :
def center(x):
return x[0]**2 + x[1]**2 < (0.1*R)**2
Please let me know. It seems that np.isclose might not work depending on mesh cell size.
Thanks.