Hi there,
I have been trying to move my fenics code to dolfinx, but have run into an issue with my Dirichlet boundary conditions. Looking at the documentation, the arguments and process have changed, but I’m not sure how to overcome this argument error. Here is a MWE made to illustrate my problem:
import numpy as np
from mpi4py import MPI
from dolfinx import fem, mesh
crystal_mesh = mesh.create_unit_cube(MPI.COMM_WORLD, 10, 10, 10)
V = fem.functionspace(crystal_mesh, ("CG", 2))
def bound(x):
return np.isclose(x[0], 0)
facets = mesh.locate_entities_boundary(crystal_mesh, dim=2, marker=bound)
const_value = fem.Constant(crystal_mesh, np.array([100], dtype=np.float32))
sur_dof = fem.locate_dofs_topological(V, entity_dim = 2, entities=facets)
dbc = fem.dirichletbc(const_value, dofs = sur_dof, V = V)
```
This results in:
```
Traceback (most recent call last):
File "MWE.py", line 230, in dirichletbc
bc = bctype(_value, dofs, V)
TypeError: __init__(): incompatible function arguments. The following argument types are supported:
1. __init__(self, g: ndarray[dtype=float32, writable=False, order='C'], dofs: ndarray[dtype=int32, writable=False, shape=(*), order='C'], V: dolfinx.cpp.fem.FunctionSpace_float32) -> None
2. __init__(self, g: dolfinx.cpp.fem.Constant_float32, dofs: ndarray[dtype=int32, writable=False, shape=(*), order='C'], V: dolfinx.cpp.fem.FunctionSpace_float32) -> None
3. __init__(self, g: dolfinx.cpp.fem.Function_float32, dofs: ndarray[dtype=int32, writable=False, shape=(*), order='C']) -> None
4. __init__(self, g: dolfinx.cpp.fem.Function_float32, dofs: collections.abc.Sequence[ndarray[dtype=int32, writable=False, shape=(*), order='C']], V: dolfinx.cpp.fem.FunctionSpace_float32) -> None
Invoked with types: dolfinx.cpp.fem.DirichletBC_float32, dolfinx.cpp.fem.Constant_float32, ndarray, dolfinx.fem.function.FunctionSpace
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "MWE.py", line 15, in <module>
dbc = fem.dirichletbc(const_value, dofs = sur_dof, V = V)
File "/home/leroux/.conda/envs/leroux_fenicsx/lib/python3.13/site-packages/dolfinx/fem/bcs.py", line 232, in dirichletbc
bc = bctype(_value, dofs, V._cpp_object)
TypeError: __init__(): incompatible function arguments. The following argument types are supported:
1. __init__(self, g: ndarray[dtype=float32, writable=False, order='C'], dofs: ndarray[dtype=int32, writable=False, shape=(*), order='C'], V: dolfinx.cpp.fem.FunctionSpace_float32) -> None
2. __init__(self, g: dolfinx.cpp.fem.Constant_float32, dofs: ndarray[dtype=int32, writable=False, shape=(*), order='C'], V: dolfinx.cpp.fem.FunctionSpace_float32) -> None
3. __init__(self, g: dolfinx.cpp.fem.Function_float32, dofs: ndarray[dtype=int32, writable=False, shape=(*), order='C']) -> None
4. __init__(self, g: dolfinx.cpp.fem.Function_float32, dofs: collections.abc.Sequence[ndarray[dtype=int32, writable=False, shape=(*), order='C']], V: dolfinx.cpp.fem.FunctionSpace_float32) -> None
Invoked with types: dolfinx.cpp.fem.DirichletBC_float32, dolfinx.cpp.fem.Constant_float32, ndarray, dolfinx.cpp.fem.FunctionSpace_float64
```
My -very limited- understanding tells me that I need a way to create a float32 functionspace (which I only see documentation for a deprecated functionspace_float32()) in order to fulfill argument type 2 listed in the error.
I assume this is a trivial mistake on my part where I misunderstand some data shape/type/structure but I have bene stumped on this one for a little bit.
Thanks in advance :)