pygeon.numerics.linear_system module
Module for the LinearSystem class.
- class pygeon.numerics.linear_system.LinearSystem(A, b=None)[source]
Bases:
objectClass for storing a linear system consisting of the matrix and its right-hand side. The class keeps track of essential boundary conditions and reduces the system appropriately before solving.
- __init__(A, b=None)[source]
Initialize a LinearSystem object.
- Parameters:
A (sps.csc_array) – The coefficient matrix of the linear system.
b (np.ndarray, optional) – The right-hand side vector of the linear system. Defaults to None.
- Returns:
None
- reset_bc()[source]
Reset the boundary conditions.
This method sets the degrees of freedom (is_dof) to True for all elements in the b vector, and sets the essential values (ess_vals) to zero for all elements in the b vector.
- flag_ess_bc(is_ess_dof, ess_vals)[source]
Flags the essential boundary conditions for the degrees of freedom specified by is_ess_dof.
- Parameters:
is_ess_dof (np.ndarray) – Boolean array indicating the degrees of freedom to flag as essential.
ess_vals (np.ndarray) – Array of essential values corresponding to the flagged degrees of freedom.
- Returns:
None
- reduce_system()[source]
Reduces the linear system by applying a restriction operator and returning the reduced system.
- Returns:
A tuple containing the reduced matrix A, the reduced vector b, and the restriction operator R.
- solve(solver=<function spsolve>)[source]
Solve the linear system of equations.
- Parameters:
solver (Callable) – The solver function to use. Defaults to sps.linalg.spsolve.
- Returns:
The solution to the linear system of equations.
- Return type:
np.ndarray
- repeat_ess_vals()[source]
Repeat the essential values of the linear system.
If the input vector b has dimension 1, the method returns the essential values as is. Otherwise, it repeats the essential values for each column of b.
- Returns:
The repeated essential values.
- Return type:
- pygeon.numerics.linear_system.create_restriction(keep_dof)[source]
Helper function to create the restriction mapping
- Parameters:
keep_dof (np.ndarray) – Boolean array indicating which degrees of freedom (dofs) to keep. True for the dofs of the system, False for the overwritten values.
- Returns:
The restriction mapping matrix.
- Return type:
sps.csc_array