gemseo / algos / linear_solvers

linear_problem module

Linear equations problem.

Classes:

LinearProblem(lhs[, rhs, solution, ...])

Represent the linear equations system lhs.x = rhs.

class gemseo.algos.linear_solvers.linear_problem.LinearProblem(lhs, rhs=None, solution=None, is_symmetric=False, is_positive_def=False, is_converged=None)[source]

Bases: object

Represent the linear equations system lhs.x = rhs.

It also contains the solution, and some properties of the system such as the symmetry or positive definiteness.

rhs

The right hand side of the equation.

Type

ndarray

lhs

The left hand side of the equation. If None, the problem can’t be solved and the user has to set it after init.

Type

ndarray, LinearOperator, sparse

solution

The current solution of the problem.

Type

ndarray

is_converged

If the solution is_converged.

Type

bool

convergence_info

The information provided by the solver if convergence occured or not.

Type

int, str

is_symmetric

Whether the LHS is symmetric.

Type

bool

is_positive_def

Whether the LHS is positive definite.

Type

bool

is_lhs_linear_operator

Whether the LHS is symmetric. XXX

Type

bool

solver_options

The options passed to the solver.

Type

Dict[str, XXX]

solver_name

The solver name.

Type

str

residuals_history

The convergence history of residuals.

Type

List[float]

Parameters
  • lhs (Union[ndarray, spmatrix, LinearOperator]) – The left hand side (matrix or linear operator) of the problem. If None, XXX.

  • rhs (Optional[ndarray]) –

    The right hand side (vector) of the problem. If None, XXX.

    By default it is set to None.

  • solution (Optional[ndarray]) –

    The current solution.

    By default it is set to None.

  • is_symmetric

    Whether to assume that the LHS is symmetric.

    By default it is set to False.

  • is_positive_def

    Whether to assume that the LHS is positive definite.

    By default it is set to False.

  • is_converged

    Whether the solution is converged to the specified tolerance. If False, the algorithm stopped before convergence. If None, no run was performed.

    By default it is set to None.

Return type

None

Methods:

check()

Check the consistency of the dimensions of the LHS and RHS.

compute_residuals([relative_residuals, ...])

Compute the L2 norm of the residuals of the problem.

plot_residuals()

Plot the residuals convergence in log scale.

check()[source]

Check the consistency of the dimensions of the LHS and RHS.

Raises

ValueError – When the shapes are inconsistent.

Return type

None

compute_residuals(relative_residuals=True, store=False, current_x=None)[source]

Compute the L2 norm of the residuals of the problem.

Parameters
  • relative_residuals

    If True, return norm(lhs.solution-rhs)/norm(rhs), else return norm(lhs.solution-rhs).

    By default it is set to True.

  • store

    Whether to store the residuals value in the residuals_history attribute.

    By default it is set to False.

  • current_x

    Compute the residuals associated with current_x, If None, compute then from the solution attribute.

    By default it is set to None.

Returns

The residuals value.

Raises

ValueError – If self.solution is None and current_x is None.

Return type

numpy.ndarray

plot_residuals()[source]

Plot the residuals convergence in log scale.

Returns

The matplotlib figure.

Raises

ValueError – When the residuals history is empty.

Return type

matplotlib.figure.Figure