Back

CompressedRowSparseMatrixConstraint

The `CompressedRowSparseMatrixConstraint` is a specialized sparse matrix implementation in the SOFA Linear Algebra framework, derived from `CompressedRowSparseMatrixGeneric`. This component manages constraints using compressed row storage for efficient memory usage and fast access to non-zero elements. It supports various vector types such as single-, double-, and multi-dimensional floating point vectors. The class provides methods to check if the matrix is empty (`empty`), get iterators for rows and columns (`begin`, `end`, `cbegin`, `cend`, `readLine`, `writeLine`), manage matrix lines (`setLine`, `addLine`), perform operations on matrix elements (e.g., multiplication with vectors in `multTransposeBaseVector`), and print the matrix content to a stream (`prettyPrint`). These methods enable efficient manipulation of constraint matrices, particularly useful for solving linear systems and handling constraints in simulation contexts. Interactions with other SOFA components are primarily through API usage within solvers or algorithms requiring sparse matrix operations. It is typically used as part of larger numerical solutions or constraint projection schemes in simulations involving soft tissue mechanics, rigid-body dynamics, or multiphysics problems.

abstract
The `CompressedRowSparseMatrixConstraint` manages constraints using compressed row storage for efficient memory usage and fast access to non-zero elements, supporting various vector types. It is used in numerical simulations involving large systems with mostly zero elements.
sheet
# CompressedRowSparseMatrixConstraint ## Overview The `CompressedRowSparseMatrixConstraint` is a specialized sparse matrix implementation derived from `CompressedRowSparseMatrixGeneric`. This component efficiently manages constraints using compressed row storage (CRS), which reduces memory usage and improves access efficiency for non-zero values. It supports various vector types such as single-, double-, and multi-dimensional floating point vectors. ## Mathematical Model ### Sparse Matrix Representation - **Compressed Row Storage (CRS):** - The matrix is stored in a compressed format where each row contains non-zero elements and their corresponding column indices. This reduces memory usage and improves access efficiency for non-zero values. - Each row has an index array (`rowIndex`) that points to the start of each row's non-zero entries in the value array (`colsValue`). ### Constraints Representation - **Constraints as Rows:** - Each constraint (or row) in the matrix corresponds to a specific physical or mathematical constraint. For example, it could represent kinematic constraints between rigid bodies or forces acting on soft tissue. - The index of each row represents the identifier for that constraint. ### Column Data Structure - **Columns:** - Each column within a row stores the non-zero elements and their corresponding indices. This structure allows efficient access to individual constraint contributions to specific degrees of freedom (DOFs). - `colsIndex` is an array storing column indices for each entry. - `colsValue` holds the actual values associated with these entries, typically representing the strength or influence of a constraint on a particular DOF. ### Operations and Methods - **Matrix Multiplication:** - The method `multTransposeBaseVector` performs matrix-vector multiplication by iterating over rows and columns to compute the product. This is essential for projecting forces or velocities onto constraints, particularly in implicit integration schemes. \\[ res[colIt.index()] += colIt.val() \times f \\] - Here, `res` accumulates contributions from each non-zero element of the matrix multiplied by a scalar `f` derived from an input vector (`lambda`). This operation is critical for updating constraint forces or enforcing kinematic conditions. - **Addition and Setting Lines:** - The methods `addLine` and `setLine` enable adding new constraints or modifying existing ones. These operations are fundamental in dynamic simulations where constraints can change over time (e.g., contact points between objects). \\[ it.addCol(colIt.index(), colIt.val()) \\] - `addLine` accumulates values, while `setLine` replaces existing constraint entries. ## Dependencies and Connections The `CompressedRowSparseMatrixConstraint` typically interacts with solvers or algorithms requiring sparse matrix operations. It is used as part of larger numerical solutions or constraint projection schemes in simulations involving soft tissue mechanics, rigid-body dynamics, or multiphysics problems.
description
The `CompressedRowSparseMatrixConstraint` is a specialized sparse matrix implementation in the SOFA Linear Algebra framework, derived from `CompressedRowSparseMatrixGeneric`. This component manages constraints using compressed row storage for efficient memory usage and fast access to non-zero elements. It supports various vector types such as single-, double-, and multi-dimensional floating point vectors. The class provides methods to check if the matrix is empty (`empty`), get iterators for rows and columns (`begin`, `end`, `cbegin`, `cend`, `readLine`, `writeLine`), manage matrix lines (`setLine`, `addLine`), perform operations on matrix elements (e.g., multiplication with vectors in `multTransposeBaseVector`), and print the matrix content to a stream (`prettyPrint`). These methods enable efficient manipulation of constraint matrices, particularly useful for solving linear systems and handling constraints in simulation contexts. Interactions with other SOFA components are primarily through API usage within solvers or algorithms requiring sparse matrix operations. It is typically used as part of larger numerical solutions or constraint projection schemes in simulations involving soft tissue mechanics, rigid-body dynamics, or multiphysics problems.
maths
# Mathematical Description of CompressedRowSparseMatrixConstraint ## Overview The `CompressedRowSparseMatrixConstraint` is a specialized sparse matrix implementation used to manage constraints in simulation contexts. Sparse matrices are widely used in numerical simulations and computational physics because they efficiently handle large systems with mostly zero elements, which are common in constraint-based problems. ## Core Concepts ### Sparse Matrix Representation - **Compressed Row Storage (CRS):** - The matrix is stored in a compressed format where each row contains non-zero elements and their corresponding column indices. This reduces memory usage and improves access efficiency for non-zero values. - Each row has an index array (`rowIndex`) that points to the start of each row's non-zero entries in the value array (`colsValue`). ### Constraints Representation - **Constraints as Rows:** - Each constraint (or row) in the matrix corresponds to a specific physical or mathematical constraint. For example, it could represent kinematic constraints between rigid bodies or forces acting on soft tissue. - The index of each row represents the identifier for that constraint. ### Column Data Structure - **Columns:** - Each column within a row stores the non-zero elements and their corresponding indices. This structure allows efficient access to individual constraint contributions to specific degrees of freedom (DOFs). - `colsIndex` is an array storing column indices for each entry. - `colsValue` holds the actual values associated with these entries, typically representing the strength or influence of a constraint on a particular DOF. ### Operations and Methods - **Matrix Multiplication:** - The method `multTransposeBaseVector` performs matrix-vector multiplication by iterating over rows and columns to compute the product. This is essential for projecting forces or velocities onto constraints, particularly in implicit integration schemes. ```cpp res[colIt.index()] += colIt.val() * f; ``` - Here, `res` accumulates contributions from each non-zero element of the matrix multiplied by a scalar `f` derived from an input vector (`lambda`). This operation is critical for updating constraint forces or enforcing kinematic conditions. - **Addition and Setting Lines:** - The methods `addLine` and `setLine` enable adding new constraints or modifying existing ones. These operations are fundamental in dynamic simulations where constraints can change over time (e.g., contact points between objects). ```cpp it.addCol(colIt.index(), colIt.val()); ``` - `addLine` accumulates values, while `setLine` replaces existing constraint entries. ## Physical Interpretation ### Constraint Enforcement - **Constraints in Simulations:** - Constraints are mathematical conditions that must be satisfied by the system. They can represent physical laws (e.g., friction, contact) or user-defined rules (e.g., fixed boundary conditions). - The `CompressedRowSparseMatrixConstraint` manages these constraints efficiently, ensuring they are applied correctly during simulation steps. ### Numerical Solution Techniques - **Linear Solvers:** - Sparse matrices like this one are often used in conjunction with linear solvers to solve large systems of equations arising from discretized physical models. The efficient storage and access provided by CRS make these solvers more computationally feasible. ## Example Use Case Consider a rigid body dynamics simulation where multiple constraints enforce the no-penetration condition between bodies. Each constraint can be represented as a row in the matrix, with non-zero entries indicating which degrees of freedom are affected. The `CompressedRowSparseMatrixConstraint` allows for efficient handling and application of these constraints, ensuring that physical interactions (like collisions) are accurately modeled. ### Summary The `CompressedRowSparseMatrixConstraint` is a powerful tool in numerical simulations, providing an efficient means to manage complex constraint systems. By leveraging sparse matrix techniques, it enables the solution of large-scale problems with significant computational savings.
{
  "name": "CompressedRowSparseMatrixConstraint",
  "main": {
    "name": "CompressedRowSparseMatrixConstraint",
    "namespace": "sofa::linearalgebra",
    "module": "Sofa.framework.LinearAlgebra",
    "include": "sofa/linearalgebra/CompressedRowSparseMatrixConstraint.h",
    "doc": "",
    "inherits": [
      "CompressedRowSparseMatrixGeneric"
    ],
    "templates": [
      "type::Vec1d",
      "type::Vec1f",
      "type::Vec2d",
      "type::Vec2f",
      "type::Vec3d",
      "type::Vec3f",
      "type::Vec6d",
      "type::Vec6f"
    ],
    "data_fields": [],
    "links": [],
    "methods": [
      {
        "name": "empty",
        "return_type": "bool",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "begin",
        "return_type": "RowConstIterator",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "end",
        "return_type": "RowConstIterator",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "cbegin",
        "return_type": "RowConstIterator",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "cend",
        "return_type": "RowConstIterator",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "size",
        "return_type": "int",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "readLine",
        "return_type": "RowConstIterator",
        "params": [
          {
            "name": "lIndex",
            "type": "Index"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "writeLine",
        "return_type": "RowWriteAccessor",
        "params": [
          {
            "name": "lIndex",
            "type": "Index"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "setLine",
        "return_type": "void",
        "params": [
          {
            "name": "lIndex",
            "type": "Index"
          },
          {
            "name": "row",
            "type": "RowType"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "addLine",
        "return_type": "void",
        "params": [
          {
            "name": "lIndex",
            "type": "Index"
          },
          {
            "name": "row",
            "type": "RowType"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "multTransposeBaseVector",
        "return_type": "void",
        "params": [
          {
            "name": "res",
            "type": "VecDeriv &"
          },
          {
            "name": "lambda",
            "type": "const sofa::linearalgebra::BaseVector *"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "prettyPrint",
        "return_type": "void",
        "params": [
          {
            "name": "out",
            "type": "int &"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "Name",
        "return_type": "const char *",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": true,
        "access": "public"
      }
    ]
  },
  "desc": {
    "description": "The `CompressedRowSparseMatrixConstraint` is a specialized sparse matrix implementation in the SOFA Linear Algebra framework, derived from `CompressedRowSparseMatrixGeneric`. This component manages constraints using compressed row storage for efficient memory usage and fast access to non-zero elements. It supports various vector types such as single-, double-, and multi-dimensional floating point vectors.\n\nThe class provides methods to check if the matrix is empty (`empty`), get iterators for rows and columns (`begin`, `end`, `cbegin`, `cend`, `readLine`, `writeLine`), manage matrix lines (`setLine`, `addLine`), perform operations on matrix elements (e.g., multiplication with vectors in `multTransposeBaseVector`), and print the matrix content to a stream (`prettyPrint`). These methods enable efficient manipulation of constraint matrices, particularly useful for solving linear systems and handling constraints in simulation contexts.\n\nInteractions with other SOFA components are primarily through API usage within solvers or algorithms requiring sparse matrix operations. It is typically used as part of larger numerical solutions or constraint projection schemes in simulations involving soft tissue mechanics, rigid-body dynamics, or multiphysics problems."
  },
  "maths": {
    "maths": "# Mathematical Description of CompressedRowSparseMatrixConstraint\n\n## Overview\n\nThe `CompressedRowSparseMatrixConstraint` is a specialized sparse matrix implementation used to manage constraints in simulation contexts. Sparse matrices are widely used in numerical simulations and computational physics because they efficiently handle large systems with mostly zero elements, which are common in constraint-based problems.\n\n## Core Concepts\n\n### Sparse Matrix Representation\n\n- **Compressed Row Storage (CRS):**\n  - The matrix is stored in a compressed format where each row contains non-zero elements and their corresponding column indices. This reduces memory usage and improves access efficiency for non-zero values.\n  - Each row has an index array (`rowIndex`) that points to the start of each row's non-zero entries in the value array (`colsValue`).\n\n### Constraints Representation\n\n- **Constraints as Rows:**\n  - Each constraint (or row) in the matrix corresponds to a specific physical or mathematical constraint. For example, it could represent kinematic constraints between rigid bodies or forces acting on soft tissue.\n  - The index of each row represents the identifier for that constraint.\n\n### Column Data Structure\n\n- **Columns:**\n  - Each column within a row stores the non-zero elements and their corresponding indices. This structure allows efficient access to individual constraint contributions to specific degrees of freedom (DOFs).\n  - `colsIndex` is an array storing column indices for each entry.\n  - `colsValue` holds the actual values associated with these entries, typically representing the strength or influence of a constraint on a particular DOF.\n\n### Operations and Methods\n\n- **Matrix Multiplication:**\n  - The method `multTransposeBaseVector` performs matrix-vector multiplication by iterating over rows and columns to compute the product. This is essential for projecting forces or velocities onto constraints, particularly in implicit integration schemes.\n    ```cpp\n    res[colIt.index()] += colIt.val() * f;\n    ```\n  - Here, `res` accumulates contributions from each non-zero element of the matrix multiplied by a scalar `f` derived from an input vector (`lambda`). This operation is critical for updating constraint forces or enforcing kinematic conditions.\n\n- **Addition and Setting Lines:**\n  - The methods `addLine` and `setLine` enable adding new constraints or modifying existing ones. These operations are fundamental in dynamic simulations where constraints can change over time (e.g., contact points between objects).\n    ```cpp\n    it.addCol(colIt.index(), colIt.val());\n    ```\n  - `addLine` accumulates values, while `setLine` replaces existing constraint entries.\n\n## Physical Interpretation\n\n### Constraint Enforcement\n\n- **Constraints in Simulations:**\n  - Constraints are mathematical conditions that must be satisfied by the system. They can represent physical laws (e.g., friction, contact) or user-defined rules (e.g., fixed boundary conditions).\n  - The `CompressedRowSparseMatrixConstraint` manages these constraints efficiently, ensuring they are applied correctly during simulation steps.\n\n### Numerical Solution Techniques\n\n- **Linear Solvers:**\n  - Sparse matrices like this one are often used in conjunction with linear solvers to solve large systems of equations arising from discretized physical models. The efficient storage and access provided by CRS make these solvers more computationally feasible.\n\n## Example Use Case\n\nConsider a rigid body dynamics simulation where multiple constraints enforce the no-penetration condition between bodies. Each constraint can be represented as a row in the matrix, with non-zero entries indicating which degrees of freedom are affected. The `CompressedRowSparseMatrixConstraint` allows for efficient handling and application of these constraints, ensuring that physical interactions (like collisions) are accurately modeled.\n\n### Summary\n\nThe `CompressedRowSparseMatrixConstraint` is a powerful tool in numerical simulations, providing an efficient means to manage complex constraint systems. By leveraging sparse matrix techniques, it enables the solution of large-scale problems with significant computational savings."
  },
  "summary": {
    "abstract": "The `CompressedRowSparseMatrixConstraint` manages constraints using compressed row storage for efficient memory usage and fast access to non-zero elements, supporting various vector types. It is used in numerical simulations involving large systems with mostly zero elements.",
    "sheet": "# CompressedRowSparseMatrixConstraint\n\n## Overview\n\nThe `CompressedRowSparseMatrixConstraint` is a specialized sparse matrix implementation derived from `CompressedRowSparseMatrixGeneric`. This component efficiently manages constraints using compressed row storage (CRS), which reduces memory usage and improves access efficiency for non-zero values. It supports various vector types such as single-, double-, and multi-dimensional floating point vectors.\n\n## Mathematical Model\n\n### Sparse Matrix Representation\n\n- **Compressed Row Storage (CRS):**\n  - The matrix is stored in a compressed format where each row contains non-zero elements and their corresponding column indices. This reduces memory usage and improves access efficiency for non-zero values.\n  - Each row has an index array (`rowIndex`) that points to the start of each row's non-zero entries in the value array (`colsValue`).\n\n### Constraints Representation\n\n- **Constraints as Rows:**\n  - Each constraint (or row) in the matrix corresponds to a specific physical or mathematical constraint. For example, it could represent kinematic constraints between rigid bodies or forces acting on soft tissue.\n  - The index of each row represents the identifier for that constraint.\n\n### Column Data Structure\n\n- **Columns:**\n  - Each column within a row stores the non-zero elements and their corresponding indices. This structure allows efficient access to individual constraint contributions to specific degrees of freedom (DOFs).\n  - `colsIndex` is an array storing column indices for each entry.\n  - `colsValue` holds the actual values associated with these entries, typically representing the strength or influence of a constraint on a particular DOF.\n\n### Operations and Methods\n\n- **Matrix Multiplication:**\n  - The method `multTransposeBaseVector` performs matrix-vector multiplication by iterating over rows and columns to compute the product. This is essential for projecting forces or velocities onto constraints, particularly in implicit integration schemes.\n    \\\\[ res[colIt.index()] += colIt.val() \\times f \\\\]\n  - Here, `res` accumulates contributions from each non-zero element of the matrix multiplied by a scalar `f` derived from an input vector (`lambda`). This operation is critical for updating constraint forces or enforcing kinematic conditions.\n\n- **Addition and Setting Lines:**\n  - The methods `addLine` and `setLine` enable adding new constraints or modifying existing ones. These operations are fundamental in dynamic simulations where constraints can change over time (e.g., contact points between objects).\n    \\\\[ it.addCol(colIt.index(), colIt.val()) \\\\]\n  - `addLine` accumulates values, while `setLine` replaces existing constraint entries.\n\n## Dependencies and Connections\n\nThe `CompressedRowSparseMatrixConstraint` typically interacts with solvers or algorithms requiring sparse matrix operations. It is used as part of larger numerical solutions or constraint projection schemes in simulations involving soft tissue mechanics, rigid-body dynamics, or multiphysics problems."
  }
}