Hi, I was trying to use this code and unfortunately I ran into an error when compiling the K matrix. When it reaches that line, it spits out an error code related to “incompatible function arguments.” I have been looking for something that talks about this error, yet I haven’t encountered anything that solves the issue as relatable ones were seemingly resolved by items which are featured that do exist within the current code (compiling with fem.form, assembly after running the petsc command). Maybe the dolfinx lab I pulled recently causes the code to become outdated (it says it was created six months ago), but I have no idea. Wish I could submit an screenshot as to not clutter too badly but I cannot do so as a new user, so please bear with me.
The lines in question are:
k = ufl.inner(sigma(u), epsilon(v)) * ufl.dx
m = rho * ufl.inner(u, v) * ufl.dx
k_compiled = dolfinx.fem.form(k)
K = dolfinx.fem.petsc.assemble_matrix(k_compiled, bcs=bcs, diag=1)
K.assemble()
specifically, K = dolfinx.fem.petsc.assemlbe_matrix(k_compiled,bcs=bcs,diag=1).
When running the code it throws the error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[8], line 72
69 m = rho * ufl.inner(u, v) * ufl.dx
71 k_compiled = dolfinx.fem.form(k)
---> 72 K = dolfinx.fem.petsc.assemble_matrix(k_compiled, bcs=bcs, diag=1)
73 K.assemble()
75 m_compiled = dolfinx.fem.form(m)
File /usr/lib/python3.12/functools.py:909, in singledispatch.<locals>.wrapper(*args, **kw)
905 if not args:
906 raise TypeError(f'{funcname} requires at least '
907 '1 positional argument')
--> 909 return dispatch(args[0].__class__)(*args, **kw)
File /usr/local/dolfinx-complex/lib/python3.12/dist-packages/dolfinx/fem/petsc.py:400, in assemble_matrix(a, bcs, diag, constants, coeffs, kind)
350 """Assemble a bilinear form into a matrix.
351
352 The following cases are supported:
(...) 397 Matrix representing the bilinear form.
398 """
399 A = create_matrix(a, kind)
--> 400 assemble_matrix(A, a, bcs, diag, constants, coeffs) # type: ignore[arg-type]
401 return A
File /usr/lib/python3.12/functools.py:909, in singledispatch.<locals>.wrapper(*args, **kw)
905 if not args:
906 raise TypeError(f'{funcname} requires at least '
907 '1 positional argument')
--> 909 return dispatch(args[0].__class__)(*args, **kw)
File /usr/local/dolfinx-complex/lib/python3.12/dist-packages/dolfinx/fem/petsc.py:506, in _(A, a, bcs, diag, constants, coeffs)
504 coeffs = pack_coefficients(a) if coeffs is None else coeffs # type: ignore[assignment]
505 _bcs = [bc._cpp_object for bc in bcs] if bcs is not None else []
--> 506 _cpp.fem.petsc.assemble_matrix(A, a._cpp_object, constants, coeffs, _bcs)
507 if a.function_spaces[0] is a.function_spaces[1]:
508 A.assemblyBegin(PETSc.Mat.AssemblyType.FLUSH) # type: ignore[attr-defined]
TypeError: assemble_matrix(): incompatible function arguments. The following argument types are supported:
1. assemble_matrix(A: mat, a: dolfinx.cpp.fem.Form_complex128, constants: ndarray[dtype=complex128, shape=(*), order='C', writable=False], coeffs: collections.abc.Mapping[tuple[dolfinx.cpp.fem._IntegralType, int], ndarray[dtype=complex128, shape=(*, *), order='C', writable=False]], bcs: collections.abc.Sequence[dolfinx.cpp.fem.DirichletBC_complex128], unrolled: bool = False) -> None
2. assemble_matrix(A: mat, a: dolfinx.cpp.fem.Form_complex128, constants: ndarray[dtype=complex128, shape=(*), order='C', writable=False], coeffs: collections.abc.Mapping[tuple[dolfinx.cpp.fem._IntegralType, int], ndarray[dtype=complex128, shape=(*, *), order='C', writable=False]], rows0: ndarray[dtype=int8, shape=(*), order='C', writable=False], rows1: ndarray[dtype=int8, shape=(*), order='C', writable=False], unrolled: bool = False) -> None
Invoked with types: Mat, dolfinx.cpp.fem.Form_complex128, ndarray, dict, list
I’m pretty new to docker/dolfinx, so I understand if this is classifiable as a “skill issue,” or if I am a bit out of my league. For context I am trying to get the bending modes of a plate of arbitrary shape given a fixed edge at y=0, so the code here feels like it would give me some direction.
EDIT: I messed up and posted this in the wrong thread lol. I had meant to put this in a different thread that also had modal analysis code. Nevertheless, running either code returns the same issue and I cannot really see what else breaks past the aforementioned problematic lines.