Back

ConstantSparsityProjectionMethod

sofa::component::linearsystem::ConstantSparsityProjectionMethod
MatrixProjectionMethod
Doc (from source)

Matrix mapping computing the matrix projection taking advantage of the constant sparsity pattern. Matrix projection method computing the matrix projection taking advantage of the constant sparsity pattern

Abstract (AI generated)

The ConstantSparsityProjectionMethod computes matrix projections while optimizing operations on sparse matrices with constant sparsity patterns. It optionally supports parallel computation of matrix products.

Metadata
module
Sofa.Component.LinearSystem
namespace
sofa::component::linearsystem
include
sofa/component/linearsystem/ConstantSparsityProjectionMethod.h
inherits
  • MatrixProjectionMethod
templates
  • sofa::linearalgebra::CompressedRowSparseMatrix<SReal>
description

Mathematical Description of the DistanceMultiMapping Component

Overview

The DistanceMultiMapping component in the SOFA (Simulation Open Framework Architecture) framework is designed to map point positions from multiple mechanical states into scalar distances. This mapping involves calculating the distance between pairs of points, which are defined by edges within a given topology container (BaseMeshTopology). The output represents these distances minus a rest length, enabling non-linear mappings and dynamic interaction analysis.

Mathematical Formulation

Notation

  • Let wzxhzdk:18 be the position vector of point wzxhzdk:19 in one of the input mechanical states.

  • Let wzxhzdk:20 represent pairs of points defined by edges wzxhzdk:21 within the topology container.

  • Let wzxhzdk:22 denote the distance between points wzxhzdk:23 and wzxhzdk:24, i.e., wzxhzdk:25 where wzxhzdk:26 denotes the Euclidean norm.

Calculation of Distances

The component calculates the distances between pairs of points wzxhzdk:4:

$$ JT_K_J = J_0^T K J_1 $$

where wzxhzdk:5, wzxhzdk:6, and wzxhzdk:7 denote the coordinates of point wzxhzdk:8 along the x-, y-, and z-axes respectively.

Rest Lengths

The rest lengths (wzxhzdk:9) are either set to zero if d_computeDistance is true, or initialized using initial distances between points wzxhzdk:10 at simulation start:

$K$

Output Scalar Value

The scalar output value for each pair wzxhzdk:11 is given by the difference between the current distance and the rest length:

$J_0$

This output wzxhzdk:12 represents a non-linear transformation that can be used in subsequent calculations or visualizations.

Physical Interpretation

The DistanceMultiMapping component models physical systems where distances between pairs of points are crucial, such as in the simulation of springs, elastic materials, or constraint-based dynamics. The rest length acts as an equilibrium distance, and deviations from this rest length can be used to model forces that arise due to deformation or displacement.

Example: Elastic Rod Simulation

In a simulation of an elastic rod with points wzxhzdk:13 and wzxhzdk:14, the distance between these points changes over time. The DistanceMultiMapping component calculates klzzwxh:0017, where klzzwxh:0018 is the rest length. This value can be used to compute elastic forces based on Hooke's law:

$J_1$

where wzxhzdk:17 is the spring constant.

Visualization and Display Parameters

The showObjectScale parameter adjusts the scale for visual display, while the showColor parameter specifies a color for displaying object mappings. These parameters are useful for debugging and visualization purposes to ensure that the mapping results are correctly interpreted in the context of the simulation environment.


Data Fields
NameTypeDefaultHelp
d_parallelProduct bool Compute the matrix product in parallel
Methods
void init ()
void reinit ()
void computeProjection (const int KMap, const int )
{
  "name": "ConstantSparsityProjectionMethod",
  "namespace": "sofa::component::linearsystem",
  "module": "Sofa.Component.LinearSystem",
  "include": "sofa/component/linearsystem/ConstantSparsityProjectionMethod.h",
  "doc": "Matrix mapping computing the matrix projection taking advantage of the constant sparsity pattern.\n\nMatrix projection method computing the matrix projection taking advantage of the constant sparsity pattern",
  "inherits": [
    "MatrixProjectionMethod"
  ],
  "templates": [
    "sofa::linearalgebra::CompressedRowSparseMatrix<SReal>"
  ],
  "data_fields": [
    {
      "name": "d_parallelProduct",
      "type": "bool",
      "xmlname": "parallelProduct",
      "help": "Compute the matrix product in parallel"
    }
  ],
  "links": [],
  "methods": [
    {
      "name": "init",
      "return_type": "void",
      "params": [],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "reinit",
      "return_type": "void",
      "params": [],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "computeProjection",
      "return_type": "void",
      "params": [
        {
          "name": "KMap",
          "type": "const int"
        },
        {
          "name": "",
          "type": "const int"
        }
      ],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "protected"
    }
  ],
  "description": "The `ConstantSparsityProjectionMethod` is a component in the SOFA framework under the namespace `sofa::component::linearsystem`, part of the module `Sofa.Component.LinearSystem`. It extends the `MatrixProjectionMethod` to perform matrix projection computations while taking advantage of a constant sparsity pattern, which can enhance performance by optimizing operations on sparse matrices.\n\nThis component inherits from `MatrixProjectionMethod` and is specifically templated for use with `sofa::linearalgebra::CompressedRowSparseMatrix<SReal>`. It provides methods to initialize (`init`) and reinitialize (`reinit`). The core functionality is encapsulated in the protected method `computeProjection`, which computes the projection of matrices taking advantage of constant sparsity.\n\nThe component includes a data field `d_parallelProduct` (boolean), accessible via the XML attribute `parallelProduct`, to control whether matrix products are computed in parallel. If enabled, this feature uses task schedulers from SOFA's simulation module for parallel processing, potentially speeding up computations.",
  "maths": "<maths>\n\n### Mathematical Description\n\nThe `ConstantSparsityProjectionMethod` is designed to compute matrix projections while leveraging the constant sparsity pattern of matrices. This approach aims to optimize performance by minimizing operations on zero-valued elements in sparse matrices.\n\n#### Matrix Projection Computation\n\nGiven a sparse matrix \\(K\\) and two Jacobian matrices \\(J_0\\) and \\(J_1\\), the component computes the projection \\(JT_K_J\\) defined as:\n\n$$\nJT_K_J = J_0^T K J_1\n$$\n\nWhere:\n- \\(K\\): Sparse matrix representing a stiffness or transformation matrix.\n- \\(J_0\\), \\(J_1\\): Jacobian matrices, which may be used to represent constraints or mappings between different spaces.\n- \\(JT_K_J\\): The resulting projection of the matrix product.\n\n#### Constant Sparsity Pattern Optimization\n\nThe constant sparsity pattern refers to the fixed positions of non-zero elements in sparse matrices. By leveraging this pattern, the component avoids unnecessary computations on zero-valued entries, thus improving computational efficiency.\n\n#### Parallel Matrix Product\n\nTo further enhance performance, the component can optionally compute matrix products in parallel using a task scheduler from SOFA's simulation module. This feature is controlled by the boolean data field `d_parallelProduct`:\n- When `d_parallelProduct` is set to `true`, matrix multiplications are computed in parallel.\n- Otherwise, computations are performed sequentially.\n\n### Physical Interpretation\n\nIn the context of physical simulations within SOFA, this component can be used for various tasks such as constraint enforcement or transformation operations between different coordinate systems. The optimization via constant sparsity pattern is particularly useful when dealing with large sparse matrices that arise in complex physical models.\n\n#### Example Usage\n\nConsider a physical system where constraints are imposed on a set of particles. These constraints can be represented by Jacobian matrices \\(J_0\\) and \\(J_1\\), while the stiffness matrix \\(K\\) describes the elastic properties of the system. The projection \\(JT_K_J\\) computed by `ConstantSparsityProjectionMethod` helps in enforcing these constraints efficiently.\n\n#### Summary\n\nThe `ConstantSparsityProjectionMethod` is a specialized component that optimizes sparse matrix operations, particularly useful for large-scale physical simulations. By leveraging constant sparsity patterns and optionally using parallel processing, it enhances computational efficiency while maintaining the accuracy of the underlying physical models.\n</maths>",
  "abstract": "The ConstantSparsityProjectionMethod computes matrix projections while optimizing operations on sparse matrices with constant sparsity patterns. It optionally supports parallel computation of matrix products.",
  "sheet": "<p># ConstantSparsityProjectionMethod</p>\n\n<p><strong>Overview:</strong></p>\n\n<p>The <code>ConstantSparsityProjectionMethod</code> is a specialized component for computing matrix projections in the SOFA framework. It leverages constant sparsity patterns to optimize performance, particularly useful for large-scale physical simulations involving sparse matrices.</p>\n\n<p><strong>Mathematical Model:</strong></p>\n\n<p>The <code>ConstantSparsityProjectionMethod</code> computes the projection of a matrix product while taking advantage of the constant sparsity pattern. Given a sparse matrix <span class=\"math-inline\">\\(K\\)</span>, and two Jacobian matrices <span class=\"math-inline\">\\(J_0\\)</span> and <span class=\"math-inline\">\\(J_1\\)</span>, it computes:</p>\n\n<p><span class=\"math-display\">\\[JT_K_J = J_0^T K J_1\\]</span></p>\n\n<p>This projection leverages the constant sparsity pattern to avoid unnecessary computations on zero-valued entries, thus improving efficiency.</p>\n\n<p><strong>Parameters and Data:</strong></p>\n\n<ul>\n<li><code>d_parallelProduct</code>: A boolean parameter that controls whether matrix products are computed in parallel. When set to <code>true</code>, the component uses task schedulers from SOFA's simulation module for parallel processing.</li>\n</ul>"
}