I am working on a mode extraction problem. I think I am successful when working on a single material but run into problems when trying to assign different materials (subdomains.).

The subdomains are defined in gmesh, and i retrieve them via

```
mesh, cell_tags, facet_tags = gmshio.read_from_msh(p, MPI.COMM_SELF, 0, gdim=3)
cell_tags.find(1)
```

.

The following (one-material/domain) code seems to work (does not create errors, the mode extraction and problem solution is omitted here):

```
from dolfinx.fem import functionspace, Function
from dolfinx.mesh import create_box
import ufl
from mpi4py import MPI
import numpy as np
from ufl import grad
import dolfinx
ll = np.array([0,0,0]) #lower left corner [m]
ur = np.array([1.5,1,0.8]) #upper right corner [m]
dims = ur - ll
meshSizeMin = 0.1
numCellsPerDim = np.ceil(dims / meshSizeMin).astype(np.int64)
numCellsPerDim
mesh = create_box(MPI.COMM_SELF, [list(ll),list(ur)],list(numCellsPerDim))
V = functionspace(mesh, ("Lagrange", 1, (mesh.geometry.dim,)))
# V = functionspace(mesh, ("DG", 0, (mesh.geometry.dim,)))
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
μ = 0.5
λ = 0.5
def ϵ(v): #Strain Function (Dehnung)
return ufl.sym(grad(v))
def σ(v): #Stress (Spannung)
return 2.0*μ*ϵ(v) + λ*ufl.nabla_div(v)*ufl.Identity(len(v))
print(σ(u))
```

My aim is to make `λ`

and `μ`

functions, following the tutorial (Defining subdomains for different materials — FEniCSx tutorial). Here I only do this for `λ`

to keep the example minimal:

```
λ = Function(V)
cabCells = [1,2,3]
λ_cab = 0.7
λ.x.array[cabCells] = np.full_like(cabCells, λ_cab, dtype=dolfinx.default_scalar_type)
print(σ(u))
```

I get the following error:

```
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[41], line 1
----> 1 print(σ(u))
Cell In[38], line 29, in σ(v)
28 def σ(v): #Stress (Spannung)
---> 29 return 2.0*μ*ϵ(v) + λ*ufl.nabla_div(v)*ufl.Identity(len(v))
File ~/miniconda3/envs/fem/lib/python3.10/site-packages/ufl/exproperators.py:183, in _mul(self, o)
181 return NotImplemented
182 o = as_ufl(o)
--> 183 return _mult(self, o)
File ~/miniconda3/envs/fem/lib/python3.10/site-packages/ufl/exproperators.py:156, in _mult(a, b)
153 ti = ai + bi
155 else:
--> 156 raise ValueError(f"Invalid ranks {r1} and {r2} in product.")
158 # TODO: I think applying as_tensor after index sums results in
159 # cleaner expression graphs.
160 # Wrap as tensor again
161 if ti:
ValueError: Invalid ranks 1 and 2 in product.
```

I have started to work around this, using the dot product etc, but essentially I am not fully understanding whats happening here. I assume I might have to integrate `λ`

and `μ`

?

Thanks for any help!

`DOLFINx version: 0.7.3 based on GIT commit: b488a495d3d74a048e5866f437f2df20b075d907 of https://github.com/FEniCS/dolfinx/`

`print(PETSc.ScalarType)`

`<class 'numpy.complex128'>`