FELiCS.Solvers.LinearSolver#

Module Contents#

Classes#

LinearSolver

Linear algebra utilities using PETSc and SLEPc.

ResolventOperator

Matrix-free representation of the Resolvent operator multiplied with its conjugate transpose.

Attributes#

FELiCS.Solvers.LinearSolver.logger#
class FELiCS.Solvers.LinearSolver.LinearSolver#

Linear algebra utilities using PETSc and SLEPc.

Provides static methods for solving generalized eigenvalue problems (GEVP), singular value decompositions (SVD), and linear systems efficiently using PETSc and SLEPc.

Initialize the LinearSolver object

Parameters:

None

Notes

Consists of only static methods that don’t need an instance of this class. Call the methods via “LinearSolver.method()”.

Examples

Solving a linear system:

>>> from petsc4py import PETSc
>>> A = PETSc.Mat().create()
>>> b = PETSc.Vec().create()
>>> x = LinearSolver.solveEquationSystem(A, b)

Solving a generalized eigenvalue problem:

>>> eigVals, eigVecs, error = LinearSolver.solveGeneralEigenproblem(
...     A, B, sigma=0.0, nev=5)
static solveGeneralEigenproblem(A, B, sigma, nev, tol=1e-12, max_it=200, adjoint=False, isForEigenProblem=True)#

Solve the generalized eigenvalue problem (GEVP) using SLEPc and PETSc.

Parameters:
  • A (PETSc.Mat) – Matrix defining the eigenvalue problem.

  • B (PETSc.Mat) – Second matrix in the generalized eigenvalue problem.

  • sigma (float) – Initial guess for the eigenvalue.

  • nev (int) – Number of eigenvalues to compute.

  • tol (float, optional) – Tolerance for convergence, by default 1.e-12.

  • max_it (int, optional) – Maximum number of iterations, by default 200.

  • adjoint (bool, optional) – Compute adjoint eigenvalues and eigenvectors if True, by default False.

  • isForEigenProblem (bool, optional) – Flag indicating whether this is for an eigenproblem, by default True.

Returns:

  • eigVals (numpy.ndarray) – Computed eigenvalues.

  • eigVecs (numpy.ndarray) – Computed eigenvectors.

  • error (numpy.ndarray) – Relative residuals for the eigenvalue problem.

static solveSVDOfResolvent(resolventOperator, nev, tol=1e-16, max_it=200)#

Solve the singular value decomposition (SVD) of a resolvent operator.

Parameters:
  • resolventOperator (ResolventOperator) – Resolvent operator object for which the SVD is computed.

  • nev (int) – Number of singular values to compute.

  • tol (float, optional) – Tolerance for convergence, by default 1.e-16.

  • max_it (int, optional) – Maximum number of iterations, by default 200.

Returns:

  • eigVals (numpy.ndarray) – Singular values of the operator.

  • eigVecs (numpy.ndarray) – Singular vectors corresponding to the singular values.

static solveEquationSystem(A, b, destroy=False)#

Solve a linear system of equations Ax = b using PETSc.

Parameters:
  • A (PETSc.Mat) – Matrix representing the linear system.

  • b (PETSc.Vec) – Right-hand side of the equation.

  • destroy (bool, optional) – Whether to destroy the matrix and vector after solving, by default False.

Returns:

x – Solution vector.

Return type:

numpy.ndarray

static solveTransposeEquationSystem(A, b, destroy=False)#

Solve the transpose of a linear system A^T x = b using PETSc.

Parameters:
  • A (PETSc.Mat) – Matrix representing the linear system.

  • b (PETSc.Vec) – Right-hand side of the equation.

  • destroy (bool, optional) – Whether to destroy the matrix and vector after solving, by default False.

Returns:

x – Solution vector.

Return type:

numpy.ndarray

static createEquationSystemSolver(A)#

Create a KSP PETSc solver to solve a linear equation system.

This is useful if several linear equation systems with the same matrix are solved, since it stores the preconditioner and the calculation time is significantly reduced. To solve the equation system use the method “solveEquationSystemWithPredefinedSolver”.

Parameters:

A (PETSc.Mat) – Matrix of the linear system.

Returns:

solver – Preconfigured solver for the given matrix.

Return type:

PETSc.KSP

static solveEquationSystemWithPredefinedSolver(solver, b, destroy=False)#

Solve a linear equation system Ax=b using PETSc and a predefined solver.

Parameters:
  • solver (PETSc.KSP) – Preconfigured solver, can be created with the method “createEquationSystemSolver”.

  • b (PETSc.Vec) – Right-hand side of the equation.

  • destroy (bool, optional) – Whether to destroy the vector after solving, by default False. Can be useful by repetitive computations to avoid memory leaks.

Returns:

x – Solution vector of the linear equation system.

Return type:

numpy.ndarray

class FELiCS.Solvers.LinearSolver.ResolventOperator(ResolventOperator, FEMWeightMatrix_fullSystem, FEMWeightMatrix_forcingNorm, FEMWeightMatrix_responseNorm, RestrictorMatrix_forcing, RestrictorMatrix_response)#

Bases: object

Matrix-free representation of the Resolvent operator multiplied with its conjugate transpose. Used to conduct the singular value decomposition of the system for resolvent analysis. Contains a method called “mult”, which is called by the eigenvalue solver and returns a matrix-vector product of the represented matrix. The resolvent operator requires additional full-size quadratic matrices to calculate the forcing and response norms, as well as (possibly rectangular) restrictor matrices that limit the spatial domain and variable dimensions.

Initialize the ResolventOperator object

Parameters:
  • ResolventOperator (PETSc.Mat) – Matrix representing the linear system.

  • FEMWeightMatrix_fullSystem (PETSc.Mat) – Weight matrix for the full FEM system.

  • FEMWeightMatrix_forcingNorm (PETSc.Mat) – Weight matrix for the forcing norm. Has default size of full system (surplus DOFs will be ignored).

  • FEMWeightMatrix_responseNorm (PETSc.Mat) – Weight matrix for the response norm. Has default size of full system (surplus DOFs will be ignored).

  • RestrictorMatrix_forcing (PETSc.Mat) – Restrictor matrix for forcing. Rectangular matrix of appropriate size without FEM weights. Spatial restrictor values can be between 0 and 1.

  • RestrictorMatrix_response (PETSc.Mat) – Restrictor matrix for response. Rectangular matrix of appropriate size without FEM weights. Spatial restrictor values can be between 0 and 1.

getSize()#

Get the size of the operator.

Returns:

The size of the operator (rows, columns).

Return type:

tuple

getVecs()#

Get PETSc vectors for the operator.

Returns:

A tuple of PETSc.Vec objects used internally by the operator.

Return type:

tuple

mult(mat, X, Y)#

Compute the matrix-vector product Y = mat * X.

Parameters:
  • mat (PETSc.Mat) – The matrix represented by the operator.

  • X (PETSc.Vec) – Input vector.

  • Y (PETSc.Vec) – Output vector.

Returns:

The result of the matrix-vector product.

Return type:

PETSc.Vec

getKSP()#

Get the KSP solver for the operator.

Returns:

KSP solver instance that solves the resolvent equation (without its conjugate transpose). Can be used to get the response to a given forcing.

Return type:

PETSc.KSP

destroySelf()#

Clean up resources to avoid memory leaks.

This method should be called if multiple resolvent SVDs are performed consecutively.