129. fe.eigen
— eigen.py: Solving large eigenproblems.¶
This module contains some functions that can be used to compute the eigenpairs (eigenvalues and eigenvectors) of generalized eigenproblem problems with large positive definite matrices.
The standard eigenproblem consists in finding the solutions (x, e) satisfying the equation A.x = e.x, where A is an (n, n) matrix, x is an (n) vector and e is a scalar. There are n solutions.
In structural mechanics often a generalized eigenproblem is encountered, with the following form: A.x = e.B.x, where B is also a positive definite matrix of size (n, n). Moreover, due to the discretization process (e.g. finite elements), the value of n can be very high. Therefore specialized solution methods are required, and only a small number of solutions can practaically be computed.
This module contains some Python function to solve such large eigenproblems for the lowest p eigenvalues. Most of the alogrithms were based on the book “Finite Element Procedures in Engineering Analysis” by K-J Bathe (Prentice-Hall 1982).
(C) 2016 Benedict Verhegghe (benedict.verhegghe@feops.com) This code is distributed under the GNU-GPL v 1.3 or later.
The only non-standard Python module used is numpy (http://www.numpy.org/).
Available functions for solving eigenproblems: - tjacobi: for small standard symmetric problems - gjacobi: for small generalized symmetric positive definite problems - inverse: for medium size generalized problems (discouraged) - subspace: for large generalized problems - lanczos: for large generalized problems
129.1. Functions defined in module fe.eigen¶
- fe.eigen.lu_decomp(A, ptol=1e-20)[source]¶
Perform an LU decomposition of A.
The LU decomposition of a matrix A is a set of two matrices L and U, where L is a lower triangular matrix with unit diagonal elements, and U is an upper triangular matrix, such that L * U = A.
Unlike scipy’s lu_factor function, this function does not perform any pivoting. Instead, as soon as a zero diagonal element is encountered, the function aborts.
- fe.eigen.count_neg_diag(a)[source]¶
Compute the number of negative diagonal elements in LDLt decomposition
Constructs the LDLt (or LU) decomposition of k and returns the number of negative diagonal elements.
- fe.eigen.sturm_check(k, m, e, bound='lu', group=True, tol=0.01, verbose=False)[source]¶
Performs a Sturm sequence check on the eigenvalues e.
When applying a shift s: ks = k - s * m, the number of negative diagonal elements in the LDLt decomposition (or the LU decomposition) is equal to the number of eigenvalues lower than s. This function uses that property to check the obtained eigenvalues.
- Parameters:
e – The eigenvalues found for the eigenproblem (k, m) bound: either ‘l’, ‘u’ or ‘lu’: specifies if a shift at the lower bound, the upper bound, or both is to be performed.
group – If True, a check around all eigenvalues as a group is done. If False, a check around each individual eigenvalue is performed.
tol – accuracy used to compute bounds around an eigenvalue. This value should be larger than the accuracy of the obtained eigenvalues.
verbose – If True, prints report.
- Returns:
bool – True if all checks pass, else False.
.. note:: The function currently does not check for clustered eigenvalues, – and therefore might be slighlty off the correct values if values are clustered.
- fe.eigen.flip(x)[source]¶
Flip vectors in x to make largest component positive.
x: a set of column vectors (n, p)
Returns the set x (n, p) with possibly some vector(s) flipped.
- fe.eigen.orthonormalize(x, m=None, i=0)[source]¶
Orthonormalize the vectors of x with respect to m.
- Parameters:
x – a set of p column vectors (n, p), p <= n
m – mass matrix (n, n). Defaults to an identity matrix.
i – the first vector to be orthonormalized, i <= p. This can be used to speed up the operations in case the first i-1 vectors are already orthonormal. The operations will only be performed for vectors i..p.
- Returns:
vectors (array(n, p-i)) – The p-i orthonormalized vectors.
lengths (array(p-i)) – The length factors of the p-i vectors.
- fe.eigen.compare(x, y)[source]¶
Compare the column vectors of x and y.
Returns the maximum 2-norm of the difference between columns vectors in the matrices x and y.
- fe.eigen.initial_vectors(k, m, p, randx=False)[source]¶
Compute initial values for p eigenvectors of k, m.
The first vector contains the diagonal of the mass matrix. The following vectors are unit vectors corresponding with the smallest kii/mii values (which would produce the smallest eigenvalues if all DOFs were uncoupled).
As an option, a random vector may be used as the last one, to enforce all DOFs being sollicited.
- fe.eigen.tjacobi(k, tol=1e-06, maxsweeps=20, verbose=False)[source]¶
Compute eigenvalues of a symmetric matrix using threshold jacobi method.
Solves the standard eigenproblem k.x = e.x, where k is a symmetric matrix.
The jacobi method consists in zeroing the off-diagonal elements by subsequent rotations. In this variant only elements larger than a given threshold are zeroed.
- Returns:
e (array(ndof)) – The eigenvalues of k in order of increasing eigenvalue.
x (array(ndof, ndof)) – The eigenvectors (columnwise) corresponding with the eigenvalues e.
- fe.eigen.gjacobi(k, m, tol=1e-06, maxsweeps=20, verbose=False)[source]¶
Compute eigenvalues of (k, m) using generalized jacobi method.
Solves for all eigenpairs of the generalized eigenproblem k.x = e.m.x
Parameters: k: stiffness matrix (n, n), positive definite m: mass matrix (n, n), positive definite
The method consists in zeroing the off-diagonal elements of k and m by subsequent rotations. Only elements larger than the given threshold are zeroed.
The method is very efficient for small systems, as it converges quadratically, and can be used as part of the subspace iteration method.
Returns e, x: the eigenvalues e(n) and eigenvectors x(, n, ) in order of increasing eigenvalue.
- fe.eigen.inverse(k, m, p=None, x=None, tol=0.001, maxit=20, verbose=True)[source]¶
Find the eigenvectors and eigenvalues of k, m by inverse iteration
Solves for the p smallest eigenvalues (and corresponding eigenvectors) of the generalized eigenproblem k.x = e.m.x using simultaneous inverse iteration.
- Parameters:
k (float array(n, n)) – The stiffness matrix.
m (float array(n, n)) – The mass matrix (n, n)
p – number of eigenvalues to compute. Can be omitted if x is specified.
x (the p smallest eigenvalues e(p) and corresponding) – initial guesses for the first p eigenvectors (n, p). If not specified, proper initial values are constructed automatically.
tol (float) – required accuracy on the eigenvalues
maxit (int) – maximum number of subspace iterations. Avoids runaway on badly converging problems
verbose (bool) – If True, the convergence trace is printed
e (Returns) –
x –
x(n (eigenvectors) –
eigenvalue. (p) in order of increasing absolute) –
- fe.eigen.subspace(k, m, p, q=None, x=None, tol=1e-06, maxit=20, verbose=False, check=True)[source]¶
Find some eigenvectors and eigenvalues of k, m by subspace iteration.
Solves for the p smallest eigenvalues (and corresponding eigenvectors) of the generalized eigenproblem k.x = e.m.x using subspace iteration.
- Parameters:
k – stiffness matrix (n, n)
m – mass matrix (n, n)
p – number of eigenpairs to compute (p <= n)
q – size of the subspace (p <= q <= n). If not specified and neither is x, it is set to min(2p, p+8, n), else to the number of columns in x.
x (the p smallest eigenvalues e(p) and corresponding) – initial guesses for the first q eigenvectors (n, q). If not specified, proper initial values are constructed automatically.
tol – required accuracy on the eigenvalues
maxit – maximum number of subspace iterations. Avoids runaway on badly converging problems
verbose (bool) – If True, the convergence trace is printed.
e (Returns) –
x –
x(n (eigenvectors) –
eigenvalue. (p) in order of increasing absolute) –
- fe.eigen.lanczos(k, m, p, q=None, randx=False, check=True, verbosity=0)[source]¶
Solves a generalized eigenproblem using lanczos vectors.
Solves for the p smallest eigenvalues (and corresponding eigenvectors) of the generalized eigenproblem k.x = e.m.x using lanczos vectors.
- Parameters:
k – stiffness matrix (n, n)
m – mass matrix (n, n)
p – number of eigenpairs to compute (p <= n)
q – number of lanczos vectors to be used. Default q == p. Since each following eigenvalue is obtained with smaller accuracy, this should be set larger than p (e.g. 2*p) if p accurate values are required.
randx – use a random starting vector instead of all ones.
e (Returns) –
x (the p smallest eigenvalues e(p) and corresponding) –
x(n (eigenvectors) –
eigenvalue. (p) in order of increasing absolute) –