I know that PETSc can be set to obtain the eigenvectors of the matrix, but I want to add the process of solving the eigenvectors as UFL form in the variational formula. Is there a solution or approximate solution?
I’m not sure if I entirely follow your question. Are you trying to get an eigenfunction back into a PDE?
That’s quite straightforward, simply move the PETSc eigenvector to the u.x.array
But it sounds to me like you would like to write a variational statement that can be solved to obtain what would be an eigensolution? That’s probably more tricky, and I’ve never tried it but maybe something like this works:
A generalized eigenvalue problem
\underline{K} \, \underline{u} =\lambda \underline{M}\,\underline{u}\,\,\,\,\,\, \lambda\in\mathbb{C},
Corresponds to the weak form:
-M(\lambda u,v) + B(u,v) = 0 \,\,\, \forall v\in V
Which clearly has the trivial solution u=0 (assuming homogeneous BCs of some sort, which is the case for eigensolutions). But eigensolution are then pairs (\lambda,u)\in\mathbb{C}\times V for which the weak statement is also satisfied.
How is this possible? For linear coercive problems, solutions should be unique? Yes, but:
- By introduction of \lambda as a variable, this has become a nonlinear problem through the term \lambda u
- For the particular \lambda that just-so-happens to equal an eigenvalue, I suppose the linearlized formulation is not Coercive permitting multiple solutions (the trivial u=0 and the non-trivial eigensolution).
So what to do?
- Are you dealing with non-symmatric systems? Then you probably have to move to complex mode as your eigenvalues and functions can be complex.
- Add \lambda as an additional unknown scalar to your weak formulation (see Scientific Computing Tools for Finite Element Methods — scifem ). For non-symmetric problems this would have to be a complex-valued unknown. Not sure if that is immediately possible in sci-fem. You may have to introduce \lambda_r and \lambda_i as the real and imaginary parts. If your system is symmetric you only need \lambda_r as a real number.
- Work out the above weak form as a nonlinear form.
- Initialize the nonlinear form somehow to avoid obtaining the trivial u=0. That’s probably quite annoying to avoid.
- Solve, and report whether this actually works, I’m curious

Thank you. Your reply is very valuable.
Furthermore, my aim is to use UFL to complete the spectral decomposition of a 2 * 2 tensor (The type is dolfinx.fem.Function and it needs to be solved in the equation) and obtain it’s eigenvector for my variational equation.
My problem is Nonlinear and the tensor is symmetrical. The solution is completed using interleaved iterations by two variational control equation. One requires the eigenvector, and another is not.
Oh.. But for a 2x2 tensor you can simply work out the explicit expressions for the eigenvectors by hand right? And use ufl tensor syntax:
# 's' is the 2x2 ufl tensor
T = s[0,0] + s[1,1] # Trace
D = s[0,0]*s[1,1] - s[1,0]*s[0,1]
lambda1 = T/2 + ufl.sqrt( T**2/4 - D )
lambda2 = T/2 - ufl.sqrt( T**2/4 - D )
v1 = ufl.as_vector( (lambda1-s[1,1], s[1,0] ) )
v2 = ufl.as_vector( (lambda2-s[1,1], s[1,0] ) )
Taken from: 2x2 matrices
Note this assumes s[1,0] is nonzero. There is an alternative expression for s[1,0] is zero and s[0,1] is not.