CompressedRowSparseMatrixGeneric
The `CompressedRowSparseMatrixGeneric` is a generic compressed row sparse matrix (CRS) implementation used in the SOFA framework's Linear Algebra module. It provides efficient storage and operations for large, sparse matrices, typically representing linear systems in finite element simulations or other numerical methods. ### Role and Purpose - **Storage Efficiency**: This component optimizes memory usage by storing only non-zero elements of a matrix, which is crucial for the performance of large-scale simulations where dense representations would be impractical. - **Flexibility**: It supports different data types (e.g., double, float, Mat1x1d) through template specialization, allowing it to work with various block sizes and matrix types. ### Interactions with Other Components - The `CompressedRowSparseMatrixGeneric` is a core component within the SOFA Linear Algebra framework. It serves as a foundational data structure for other components such as solvers (e.g., iterative Krylov methods, direct sparse factorizations) that require efficient storage and manipulation of large matrices. - It interacts with these solvers through matrix operations like multiplication (`mul`), transposition (`transposeFullRows`), and addition (`addBlock`). ### Practical Usage Guidance - **Initialization**: The component can be instantiated with predefined sizes, which are managed internally to store row indices, column indices, and block values efficiently. - **Matrix Operations**: Methods like `getWBlock`, `setBlock`, and `addBlock` allow for efficient access and modification of matrix elements. Additionally, the `mul` method is used to perform matrix multiplications, while `compress` methods ensure that the internal structure remains optimized. - **Policy Customization**: The behavior can be customized using policies (e.g., `CRSDefaultPolicy`) which control aspects such as automatic compression and resizing, symmetry enforcement, and zero block removal.
- abstract
- The `CompressedRowSparseMatrixGeneric` implements a compressed row sparse (CSR) matrix for efficient storage and manipulation of large sparse matrices in SOFA simulations. It supports various data types through template specialization and provides methods for essential linear algebra operations.
- sheet
- # CompressedRowSparseMatrixGeneric ## Overview The `CompressedRowSparseMatrixGeneric` is a generic implementation of the compressed row sparse (CSR) matrix format, used to efficiently store and manipulate large sparse matrices in SOFA simulations. It supports different data types through template specialization and provides methods for essential linear algebra operations such as multiplication and transposition. ## Mathematical Model In the CSR format, each row of the matrix is stored using three arrays: - **Row Pointers (`rowBegin`)**: An array storing the starting index of each row in the `colsIndex` and `colValues` arrays. It has a length of `m + 1`, where `m` is the number of rows, with the last element pointing to one past the end of `colsIndex`. - **Column Indices (`colsIndex`)**: An array storing the column indices of non-zero elements in row-major order. - **Values (`colValues`)**: An array storing the values of the non-zero elements corresponding to their positions in `colsIndex`. The internal representation consists of three main data structures: - `rowBegin`: Array of integers representing row pointers for the CSR format. - `colsIndex`: Array of integers representing column indices of non-zero elements. - `colValues`: Array of generic block values (e.g., doubles, floats, or matrices) storing the actual non-zero matrix entries. #### Matrix Operations 1. **Matrix Multiplication (`mul`)**: Performs sparse matrix multiplication between two sparse matrices $A$ and $B$, resulting in matrix $C$. This operation is critical for solving systems of linear equations, where $Ax = b$. 2. **Matrix Transposition (`transposeFullRows`)**: Computes the transpose of the sparse matrix by interchanging row and column indices while preserving non-zero values. 3. **Addition (`addBlock`)**: Allows adding or modifying elements in the sparse matrix at specified positions, ensuring only non-zero values are stored efficiently.
- description
- The `CompressedRowSparseMatrixGeneric` is a generic compressed row sparse matrix (CRS) implementation used in the SOFA framework's Linear Algebra module. It provides efficient storage and operations for large, sparse matrices, typically representing linear systems in finite element simulations or other numerical methods. ### Role and Purpose - **Storage Efficiency**: This component optimizes memory usage by storing only non-zero elements of a matrix, which is crucial for the performance of large-scale simulations where dense representations would be impractical. - **Flexibility**: It supports different data types (e.g., double, float, Mat1x1d) through template specialization, allowing it to work with various block sizes and matrix types. ### Interactions with Other Components - The `CompressedRowSparseMatrixGeneric` is a core component within the SOFA Linear Algebra framework. It serves as a foundational data structure for other components such as solvers (e.g., iterative Krylov methods, direct sparse factorizations) that require efficient storage and manipulation of large matrices. - It interacts with these solvers through matrix operations like multiplication (`mul`), transposition (`transposeFullRows`), and addition (`addBlock`). ### Practical Usage Guidance - **Initialization**: The component can be instantiated with predefined sizes, which are managed internally to store row indices, column indices, and block values efficiently. - **Matrix Operations**: Methods like `getWBlock`, `setBlock`, and `addBlock` allow for efficient access and modification of matrix elements. Additionally, the `mul` method is used to perform matrix multiplications, while `compress` methods ensure that the internal structure remains optimized. - **Policy Customization**: The behavior can be customized using policies (e.g., `CRSDefaultPolicy`) which control aspects such as automatic compression and resizing, symmetry enforcement, and zero block removal.
- maths
- ## Mathematical Description The `CompressedRowSparseMatrixGeneric` is a generic implementation of the Compressed Sparse Row (CSR) format for storing sparse matrices. In linear algebra, a sparse matrix is one in which most elements are zero. Efficient storage and operations on such matrices are crucial in numerical simulations where memory usage and computational efficiency are critical. ### CSR Format Overview In the CSR format, each row of the matrix is stored as three arrays: - **Row Pointers (`rowBegin`)**: This array stores the starting index of each row in the `colsIndex` and `colValues` arrays. It has a length of `m + 1`, where `m` is the number of rows, with the last element pointing to one past the end of `colsIndex`. - **Column Indices (`colsIndex`)**: This array stores the column indices of non-zero elements in row-major order. - **Values (`colValues`)**: This array stores the values of the non-zero elements corresponding to their positions in `colsIndex`. ### Internal Representation and Methods The `CompressedRowSparseMatrixGeneric` class maintains three main data structures: - `rowBegin`: An array of integers representing row pointers for the CSR format. - `colsIndex`: An array of integers representing column indices of non-zero elements. - `colValues`: An array of generic block values (e.g., doubles, floats, or matrices) storing the actual non-zero matrix entries. #### Matrix Operations 1. **Matrix Multiplication (`mul`)**: The `mul` method performs sparse matrix multiplication between two sparse matrices. Given a matrix $A$ and another matrix $B$, the result is stored in matrix $C$. This operation is critical for solving systems of linear equations, where $Ax = b$. 2. **Matrix Transposition (`transposeFullRows`)**: The `transposeFullRows` method computes the transpose of the sparse matrix, which swaps rows and columns. For a matrix $A$, its transpose $A^T$ is obtained by interchanging the row and column indices while preserving the non-zero values. 3. **Addition (`addBlock`)**: This operation allows adding or modifying elements in the sparse matrix at specified positions. It ensures that only non-zero values are stored efficiently, avoiding storage of zeros which would otherwise increase memory usage significantly. ### Customization and Policies The behavior of `CompressedRowSparseMatrixGeneric` can be customized through policies (e.g., `CRSDefaultPolicy`). These policies control various aspects such as: - **Automatic Compression**: Ensuring that the internal structure remains optimized after operations by removing redundant zeros and reallocating memory efficiently. - **Symmetry Enforcement**: Ensuring the matrix is symmetric, which is important for certain linear solvers that exploit symmetry properties to reduce computational complexity. ### Use Cases in Numerical Simulations In numerical simulations (e.g., finite element methods), large sparse matrices often represent stiffness or mass matrices. Efficient storage and operations on these matrices are crucial for the performance of iterative solvers and direct factorization algorithms used in solving linear systems arising from discretized partial differential equations. The `CompressedRowSparseMatrixGeneric` plays a vital role in providing an efficient and flexible data structure to support such simulations, ensuring that memory usage is minimized while maintaining high computational efficiency.
{
"name": "CompressedRowSparseMatrixGeneric",
"main": {
"name": "CompressedRowSparseMatrixGeneric",
"namespace": "sofa::linearalgebra",
"module": "Sofa.framework.LinearAlgebra",
"include": "sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h",
"doc": "",
"inherits": [],
"templates": [
"double",
"float",
"type::Mat1x1d",
"type::Mat1x1f",
"type::Mat3x3d",
"type::Mat3x3f"
],
"data_fields": [],
"links": [],
"methods": [
{
"name": "sortedFind",
"return_type": "bool",
"params": [
{
"name": "v",
"type": "const VecIndex &"
},
{
"name": "in",
"type": "Range"
},
{
"name": "val",
"type": "Index"
},
{
"name": "result",
"type": "Index &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "public"
},
{
"name": "sortedFind",
"return_type": "bool",
"params": [
{
"name": "v",
"type": "const VecIndex &"
},
{
"name": "val",
"type": "Index"
},
{
"name": "result",
"type": "Index &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "public"
},
{
"name": "rowBSize",
"return_type": "Index",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "colBSize",
"return_type": "Index",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getRowIndex",
"return_type": "const VecIndex &",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getRowBegin",
"return_type": "const VecIndex &",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getRowRange",
"return_type": "Range",
"params": [
{
"name": "id",
"type": "Index"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getColsIndex",
"return_type": "const VecIndex &",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getColsValue",
"return_type": "const VecBlock &",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "resizeBlock",
"return_type": "void",
"params": [
{
"name": "nbBRow",
"type": "Index"
},
{
"name": "nbBCol",
"type": "Index"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "registerNewCol",
"return_type": "bool",
"params": [
{
"name": "colId",
"type": "Index &"
},
{
"name": "bvalue",
"type": "TBlock &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "registerBtempLine",
"return_type": "int",
"params": [
{
"name": "itbtemp",
"type": "int &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "fullyCompressBtemp",
"return_type": "void",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "insertBtemp",
"return_type": "Block *",
"params": [
{
"name": "i",
"type": "const Index"
},
{
"name": "j",
"type": "const Index"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
}
]
},
"desc": {
"description": "The `CompressedRowSparseMatrixGeneric` is a generic compressed row sparse matrix (CRS) implementation used in the SOFA framework's Linear Algebra module. It provides efficient storage and operations for large, sparse matrices, typically representing linear systems in finite element simulations or other numerical methods.\n\n### Role and Purpose\n- **Storage Efficiency**: This component optimizes memory usage by storing only non-zero elements of a matrix, which is crucial for the performance of large-scale simulations where dense representations would be impractical.\n- **Flexibility**: It supports different data types (e.g., double, float, Mat1x1d) through template specialization, allowing it to work with various block sizes and matrix types.\n\n### Interactions with Other Components\n- The `CompressedRowSparseMatrixGeneric` is a core component within the SOFA Linear Algebra framework. It serves as a foundational data structure for other components such as solvers (e.g., iterative Krylov methods, direct sparse factorizations) that require efficient storage and manipulation of large matrices.\n- It interacts with these solvers through matrix operations like multiplication (`mul`), transposition (`transposeFullRows`), and addition (`addBlock`).\n\n### Practical Usage Guidance\n- **Initialization**: The component can be instantiated with predefined sizes, which are managed internally to store row indices, column indices, and block values efficiently.\n- **Matrix Operations**: Methods like `getWBlock`, `setBlock`, and `addBlock` allow for efficient access and modification of matrix elements. Additionally, the `mul` method is used to perform matrix multiplications, while `compress` methods ensure that the internal structure remains optimized.\n- **Policy Customization**: The behavior can be customized using policies (e.g., `CRSDefaultPolicy`) which control aspects such as automatic compression and resizing, symmetry enforcement, and zero block removal."
},
"maths": {
"maths": "## Mathematical Description\n\nThe `CompressedRowSparseMatrixGeneric` is a generic implementation of the Compressed Sparse Row (CSR) format for storing sparse matrices. In linear algebra, a sparse matrix is one in which most elements are zero. Efficient storage and operations on such matrices are crucial in numerical simulations where memory usage and computational efficiency are critical.\n\n### CSR Format Overview\n\nIn the CSR format, each row of the matrix is stored as three arrays:\n- **Row Pointers (`rowBegin`)**: This array stores the starting index of each row in the `colsIndex` and `colValues` arrays. It has a length of `m + 1`, where `m` is the number of rows, with the last element pointing to one past the end of `colsIndex`.\n- **Column Indices (`colsIndex`)**: This array stores the column indices of non-zero elements in row-major order.\n- **Values (`colValues`)**: This array stores the values of the non-zero elements corresponding to their positions in `colsIndex`.\n\n### Internal Representation and Methods\n\nThe `CompressedRowSparseMatrixGeneric` class maintains three main data structures:\n- `rowBegin`: An array of integers representing row pointers for the CSR format.\n- `colsIndex`: An array of integers representing column indices of non-zero elements.\n- `colValues`: An array of generic block values (e.g., doubles, floats, or matrices) storing the actual non-zero matrix entries.\n\n#### Matrix Operations\n\n1. **Matrix Multiplication (`mul`)**: The `mul` method performs sparse matrix multiplication between two sparse matrices. Given a matrix $A$ and another matrix $B$, the result is stored in matrix $C$. This operation is critical for solving systems of linear equations, where $Ax = b$.\n\n2. **Matrix Transposition (`transposeFullRows`)**: The `transposeFullRows` method computes the transpose of the sparse matrix, which swaps rows and columns. For a matrix $A$, its transpose $A^T$ is obtained by interchanging the row and column indices while preserving the non-zero values.\n\n3. **Addition (`addBlock`)**: This operation allows adding or modifying elements in the sparse matrix at specified positions. It ensures that only non-zero values are stored efficiently, avoiding storage of zeros which would otherwise increase memory usage significantly.\n\n### Customization and Policies\n\nThe behavior of `CompressedRowSparseMatrixGeneric` can be customized through policies (e.g., `CRSDefaultPolicy`). These policies control various aspects such as:\n- **Automatic Compression**: Ensuring that the internal structure remains optimized after operations by removing redundant zeros and reallocating memory efficiently.\n- **Symmetry Enforcement**: Ensuring the matrix is symmetric, which is important for certain linear solvers that exploit symmetry properties to reduce computational complexity.\n\n### Use Cases in Numerical Simulations\n\nIn numerical simulations (e.g., finite element methods), large sparse matrices often represent stiffness or mass matrices. Efficient storage and operations on these matrices are crucial for the performance of iterative solvers and direct factorization algorithms used in solving linear systems arising from discretized partial differential equations.\n\nThe `CompressedRowSparseMatrixGeneric` plays a vital role in providing an efficient and flexible data structure to support such simulations, ensuring that memory usage is minimized while maintaining high computational efficiency."
},
"summary": {
"abstract": "The `CompressedRowSparseMatrixGeneric` implements a compressed row sparse (CSR) matrix for efficient storage and manipulation of large sparse matrices in SOFA simulations. It supports various data types through template specialization and provides methods for essential linear algebra operations.",
"sheet": "# CompressedRowSparseMatrixGeneric\n\n## Overview\nThe `CompressedRowSparseMatrixGeneric` is a generic implementation of the compressed row sparse (CSR) matrix format, used to efficiently store and manipulate large sparse matrices in SOFA simulations. It supports different data types through template specialization and provides methods for essential linear algebra operations such as multiplication and transposition.\n\n## Mathematical Model\nIn the CSR format, each row of the matrix is stored using three arrays:\n- **Row Pointers (`rowBegin`)**: An array storing the starting index of each row in the `colsIndex` and `colValues` arrays. It has a length of `m + 1`, where `m` is the number of rows, with the last element pointing to one past the end of `colsIndex`.\n- **Column Indices (`colsIndex`)**: An array storing the column indices of non-zero elements in row-major order.\n- **Values (`colValues`)**: An array storing the values of the non-zero elements corresponding to their positions in `colsIndex`.\n\nThe internal representation consists of three main data structures:\n- `rowBegin`: Array of integers representing row pointers for the CSR format.\n- `colsIndex`: Array of integers representing column indices of non-zero elements.\n- `colValues`: Array of generic block values (e.g., doubles, floats, or matrices) storing the actual non-zero matrix entries.\n\n#### Matrix Operations\n1. **Matrix Multiplication (`mul`)**: Performs sparse matrix multiplication between two sparse matrices $A$ and $B$, resulting in matrix $C$. This operation is critical for solving systems of linear equations, where $Ax = b$.\n2. **Matrix Transposition (`transposeFullRows`)**: Computes the transpose of the sparse matrix by interchanging row and column indices while preserving non-zero values.\n3. **Addition (`addBlock`)**: Allows adding or modifying elements in the sparse matrix at specified positions, ensuring only non-zero values are stored efficiently."
}
}