Class PivotingSolver<M, V, T>
A standard implementation for pivoting solvers.
Inheritance
Inherited Members
Namespace: SpiceSharp.Algebra.Solve
Assembly: SpiceSharp.dll
Syntax
public abstract class PivotingSolver<M, V, T> : ParameterSetCollection, IPivotingSolver<M, V, T>, ISolver<T>, IParameterSetCollection, IParameterSet where M : IMatrix<T> where V : IVector<T>
Type Parameters
Name | Description |
---|---|
M | The matrix type. |
V | The vector type. |
T | The base value type. |
Constructors
PivotingSolver(M, V)
Initializes a new instance of the PivotingSolver<M, V, T> class.
Declaration
protected PivotingSolver(M matrix, V vector)
Parameters
Type | Name | Description |
---|---|---|
M | matrix | |
V | vector |
Properties
Column
Gets the column translation.
Declaration
protected Translation Column { get; }
Property Value
Type | Description |
---|---|
Translation | The column translation. |
Degeneracy
Gets or sets the degeneracy of the matrix. For example, specifying 1 will let the solver know that one equation is expected to be linearly dependent on the others.
Declaration
[GreaterThanOrEquals(0)]
public int Degeneracy { get; set; }
Property Value
Type | Description |
---|---|
int | The degeneracy. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if the value is negative. |
IsFactored
Gets a value indicating whether this solver has been factored. A solver needs to be factored becore it can solve for a solution.
Declaration
public bool IsFactored { get; protected set; }
Property Value
Type | Description |
---|---|
bool |
|
this[MatrixLocation]
Gets or sets the value of the matrix at the specified location.
Declaration
public T this[MatrixLocation location] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
MatrixLocation | location | The location. |
Property Value
Type | Description |
---|---|
T | The value of the matrix element. |
this[int]
Gets or sets the value of the right hand side vector at the specified row.
Declaration
public T this[int row] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | row | The row. |
Property Value
Type | Description |
---|---|
T | The value of the right hand side vector. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if |
this[int, int]
Gets or sets the value of the matrix at the specified row and column.
Declaration
public T this[int row, int column] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | row | The row. |
int | column | The column. |
Property Value
Type | Description |
---|---|
T | The value. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if |
Matrix
Gets the reordered equation matrix.
Declaration
protected M Matrix { get; }
Property Value
Type | Description |
---|---|
M | The reordered equation matrix. |
NeedsReordering
Gets or sets a value indicating whether the solver needs to be reordered all the way from the start.
Declaration
public bool NeedsReordering { get; set; }
Property Value
Type | Description |
---|---|
bool |
|
Remarks
If this flag is false, the solver will still reorder when using OrderAndFactor(), but it will try to stay away from reordering as long as possible. This flag will force the solver to immediately start reordering.
PivotSearchReduction
Gets or sets the pivot search reduction. This makes sure that pivots cannot be chosen from the last N rows. The default, 0, lets the pivot strategy to choose from the whole matrix.
Declaration
[GreaterThanOrEquals(0)]
public int PivotSearchReduction { get; set; }
Property Value
Type | Description |
---|---|
int | The pivot search reduction. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if the value is negative. |
Row
Gets the row translation.
Declaration
protected Translation Row { get; }
Property Value
Type | Description |
---|---|
Translation | The row translation. |
Size
Gets the size of the solver. This is the total number of equations.
Declaration
public int Size { get; }
Property Value
Type | Description |
---|---|
int | The size. |
Vector
Gets the reordered right hand side vector.
Declaration
protected V Vector { get; }
Property Value
Type | Description |
---|---|
V | The reordered right hand side vector. |
Methods
BackwardSubstitute(IVector<T>)
Applies backward substitution on a factored matrix and the intermediate vector.
Declaration
public abstract void BackwardSubstitute(IVector<T> solution)
Parameters
Type | Name | Description |
---|---|---|
IVector<T> | solution | The solution vector. |
BackwardSubstituteTransposed(IVector<T>)
Applies backward substitution on the adjoint matrix and the intermediate vector.
Declaration
public abstract void BackwardSubstituteTransposed(IVector<T> solution)
Parameters
Type | Name | Description |
---|---|---|
IVector<T> | solution | The solution vector. |
Clear()
Clears the solver of any elements. The size of the solver becomes 0.
Declaration
public virtual void Clear()
Remarks
The method is only redefined here to avoid ambiguity issues between IMatrix<T> and IVector<T>.
ComputeDegenerateContribution(int)
Computes a contribution for degenerate solvers (Degeneracy is larger than 0). Used when solving submatrices separately.
Declaration
public abstract T ComputeDegenerateContribution(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index. |
Returns
Type | Description |
---|---|
T | Returns the contribution. |
ComputeDegenerateContributionTransposed(int)
Computes a contribution of the transposed solving for degenerate solvers (Degeneracy is larger than 0). Used when solving submatrices separately.
Declaration
public abstract T ComputeDegenerateContributionTransposed(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index. |
Returns
Type | Description |
---|---|
T | Returns the contribution. |
ExternalToInternal(MatrixLocation)
Maps an external matrix location to an internal one.
Declaration
public MatrixLocation ExternalToInternal(MatrixLocation indices)
Parameters
Type | Name | Description |
---|---|---|
MatrixLocation | indices | The external matrix location. |
Returns
Type | Description |
---|---|
MatrixLocation | The internal matrix location. |
Factor()
Factor the equation matrix and right hand side vector. This method can save time when factoring similar matrices in succession.
Declaration
public abstract bool Factor()
Returns
Type | Description |
---|---|
bool |
|
ForwardSubstitute(IVector<T>)
Applies forward substitution on a factored matrix and right-hand side vector.
Declaration
public abstract void ForwardSubstitute(IVector<T> solution)
Parameters
Type | Name | Description |
---|---|---|
IVector<T> | solution | The solution vector. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
AlgebraException | Thrown if the solver is not factored yet. |
ArgumentException | Thrown if |
ForwardSubstituteTransposed(IVector<T>)
Applies forward substitution on the adjoint matrix and right-hand side vector.
Declaration
public abstract void ForwardSubstituteTransposed(IVector<T> solution)
Parameters
Type | Name | Description |
---|---|---|
IVector<T> | solution | The solution vector. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
AlgebraException | Thrown if the solver is not factored yet. |
ArgumentException | Thrown if |
InternalToExternal(MatrixLocation)
Maps an internal matrix location to an external one.
Declaration
public MatrixLocation InternalToExternal(MatrixLocation indices)
Parameters
Type | Name | Description |
---|---|---|
MatrixLocation | indices | The internal matrix location. |
Returns
Type | Description |
---|---|
MatrixLocation | The external matrix location. |
OrderAndFactor()
Order and factor the equation matrix and right hand side vector. This method will reorder the matrix as it sees fit.
Declaration
public abstract int OrderAndFactor()
Returns
Type | Description |
---|---|
int | The number of rows that were successfully eliminated. |
Precondition(PreconditioningMethod<M, V, T>)
Preconditions the solver matrix and right hand side vector.
Declaration
public abstract void Precondition(PreconditioningMethod<M, V, T> method)
Parameters
Type | Name | Description |
---|---|---|
PreconditioningMethod<M, V, T> | method | The method. |
Reset()
Clears all matrix and vector elements.
Declaration
public virtual void Reset()
Remarks
This method is only redefined here to avoid ambiguity issues between IMatrix<T> and IVector<T>.
SetParameter<P>(string, P)
Declaration
public ISolver<T> SetParameter<P>(string name, P value)
Parameters
Type | Name | Description |
---|---|---|
string | name | |
P | value |
Returns
Type | Description |
---|---|
ISolver<T> |
Type Parameters
Name | Description |
---|---|
P |
SwapColumns(int, int)
Swap two (internal) columns in the system.
Declaration
protected void SwapColumns(int column1, int column2)
Parameters
Type | Name | Description |
---|---|---|
int | column1 | The first column index. |
int | column2 | The second column index. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if |
SwapRows(int, int)
Swap two (internal) rows in the linear system. This method keeps the matrix and vector synchronized.
Declaration
protected void SwapRows(int row1, int row2)
Parameters
Type | Name | Description |
---|---|---|
int | row1 | The first row index. |
int | row2 | The second row index. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if |
ToString()
Returns a string that represents this instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string that represents this instance. |