dolfinx.la
Linear algebra functionality.
Functions
|
Check that list of vectors are orthonormal. |
|
Create a distributed sparse matrix. |
|
Compute a norm of the vector. |
|
Orthogonalise set of vectors in-place. |
|
Create a distributed vector. |
Classes
|
|
|
Distributed compressed sparse row matrix. |
|
|
|
Distributed vector object. |
- class dolfinx.la.MatrixCSR(A: MatrixCSR_float32 | MatrixCSR_float64 | MatrixCSR_complex64 | MatrixCSR_complex128)[source]
Bases:
objectDistributed compressed sparse row matrix.
Create a distributed compressed sparse row matrix.
Note
Objects of this type should be created using
matrix_csr()and not created using this initialiser.- Parameters:
A – The C++/nanobind matrix object.
- add(x: ndarray[tuple[Any, ...], dtype[floating]], rows: ndarray[tuple[Any, ...], dtype[int32]], cols: ndarray[tuple[Any, ...], dtype[int32]], bs: int = 1) None[source]
Add a block of values in the matrix.
- index_map(i: int) IndexMap[source]
Index map for row/column.
- Parameters:
i – 0 for row map, 1 for column map.
- mult(x: Vector, y: Vector) None[source]
Compute
y += Ax.- Parameters:
x – Input Vector
y – Output Vector
- set(x: ndarray[tuple[Any, ...], dtype[floating]], rows: ndarray[tuple[Any, ...], dtype[int32]], cols: ndarray[tuple[Any, ...], dtype[int32]], bs: int = 1) None[source]
Set a block of values in the matrix.
- set_value(x: floating) None[source]
Set all non-zero entries to a value.
- Parameters:
x – The value to set all non-zero entries to.
- squared_norm() floating[source]
Compute the squared Frobenius norm.
Note
This operation is collective and requires communication.
- to_dense() ndarray[tuple[Any, ...], dtype[floating]][source]
Copy to a dense 2D array.
Note
Typically used for debugging.
- to_scipy(ghosted: bool = False)[source]
Convert to a SciPy CSR/BSR matrix. Data is shared.
Note
SciPy must be available.
- Parameters:
ghosted – If
Truerows that are ghosted in parallel are included in the returned SciPy matrix, otherwise ghost rows are not included.- Returns:
SciPy compressed sparse row (both block sizes equal to one) or a SciPy block compressed sparse row matrix.
- class dolfinx.la.Vector(x: Vector_float32 | Vector_float64 | Vector_complex64 | Vector_complex128 | Vector_int8 | Vector_int32 | Vector_int64)[source]
Bases:
objectDistributed vector object.
Create a distributed vector.
- Parameters:
x – C++ Vector object.
Note
This initialiser is intended for internal library use only. User code should call
vector()to create a vector object.- property block_size: int
Block size for the vector.
- property petsc_vec
PETSc vector holding the entries of the vector.
Upon first call, this function creates a PETSc
Vecobject that wraps the degree-of-freedom data. TheVecobject is cached and the cachedVecis returned upon subsequent calls.Note
When the object is destroyed it will destroy the underlying petsc4py vector automatically.
- scatter_reverse(mode: InsertMode) None[source]
Scatter ghost entries to owner.
- Parameters:
mode – Control how scattered values are set/accumulated by owner.
- dolfinx.la.is_orthonormal(basis: list[Vector], eps: float = 1e-12) bool[source]
Check that list of vectors are orthonormal.
- dolfinx.la.matrix_csr(sp: SparsityPattern, block_mode=BlockMode.compact, dtype: DTypeLike = <class 'numpy.float64'>) MatrixCSR[source]
Create a distributed sparse matrix.
The matrix uses compressed sparse row storage.
- Parameters:
sp – The sparsity pattern that defines the nonzero structure of the matrix the parallel distribution of the matrix.
block_mode – Block mode to use.
dtype – Scalar type.
- Returns:
A sparse matrix.