I converted in this way,

import numpy as np

import ufl

from petsc4py import PETSc

from slepc4py import SLEPc

from mpi4py import MPI

from dolfinx import mesh, fem

import dolfinx

import dolfinx.fem.petsc

# Check for PETSc and SLEPc

if not hasattr(PETSc, ‘Mat’):

print(“PETSc is not available. Exiting.”)

exit()

if not hasattr(SLEPc, ‘EPS’):

print(“SLEPc is not available. Exiting.”)

exit()

# Create mesh

width = 1.0

height = 0.5

mesh = mesh.create_rectangle(MPI.COMM_WORLD, [[0.0, 0.0], [width, height]], [8, 4], mesh.CellType.triangle)

# Define function space

V = fem.FunctionSpace(mesh, (“Nedelec 1st kind H(curl)”, 2))

# Define trial and test functions

u = ufl.TrialFunction(V)

v = ufl.TestFunction(V)

# Define the forms

s = ufl.inner(ufl.curl(v), ufl.curl(u)) * ufl.dx

t = ufl.inner(v, u) * ufl.dx

L = ufl.inner(ufl.as_vector((0.0, 0.0)), v) * ufl.dx

# Define boundary condition

zero = PETSc.ScalarType((0, 0))

bc = fem.dirichletbc(zero, fem.locate_dofs_geometrical(V, lambda x: np.full(x.shape[1], True)), V)

# Assemble the stiffness matrix (S) and mass matrix (T)

A = dolfinx.fem.petsc.assemble_matrix(fem.form(s), bcs=[bc])

A.assemble()

B = dolfinx.fem.petsc.assemble_matrix(fem.form(t), bcs=[bc])

B.assemble()

# Convert assembled matrices to PETSc.Mat

A_petsc = A

B_petsc = B

# Solve the eigensystem using SLEPc

eigensolver = SLEPc.EPS().create()

eigensolver.setOperators(A_petsc, B_petsc)

eigensolver.setProblemType(SLEPc.EPS.ProblemType.GHEP)

eigensolver.setWhichEigenpairs(SLEPc.EPS.Which.SMALLEST_REAL)

eigensolver.solve()

# Process and extract the eigenvalues

nconv = eigensolver.getConverged()

cutoff = None

count = 0

if nconv > 0:

for i in range(nconv):

lr, lc = eigensolver.getEigenvalue(i)

if lr > 1 and lc == 0:

cutoff = np.sqrt(lr)

_, _, rr, _ = eigensolver.getEigenpair(i)

u = fem.Function(V)

u.vector.setArray(rr)

u.vector.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)

print(f"Eigenvalue {i}: {cutoff}")

count += 1

if count > 4:

break

else:

print(“No eigenvalues found.”)

if cutoff is None:

print(“Unable to find dominant mode”)

else:

print(“Cutoff frequency:”, cutoff)

Blockquote

however, I faced with errors, and can you check the code?

ValueError Traceback (most recent call last)

Cell In[33], line 34

32 s = ufl.inner(ufl.curl(v), ufl.curl(u)) * ufl.dx

33 t = ufl.inner(v, u) * ufl.dx

—> 34 L = ufl.inner(ufl.as_vector((0.0, 0.0)), v) * ufl.dx

36 # Define boundary condition

37 zero = PETSc.ScalarType((0, 0))

File /usr/local/lib/python3.10/dist-packages/ufl/measure.py:386, in Measure.**rmul**(self, integrand)

384 domain, = domains

385 elif len(domains) == 0:

→ 386 raise ValueError(“This integral is missing an integration domain.”)

387 else:

388 raise ValueError(“Multiple domains found, making the choice of integration domain ambiguous.”)

ValueError: This integral is missing an integration domain.

Thank you