CompressedRowSparseMatrixMechanical
The `CompressedRowSparseMatrixMechanical` implements the Compressed Row Storage (CRS) format tailored for mechanical systems in SOFA, supporting various block sizes and symmetric operations. It efficiently manages sparse matrices representing stiffness or mass properties.
- module
- Sofa.framework.LinearAlgebra
- namespace
- sofa::linearalgebra
- include
- sofa/linearalgebra/CompressedRowSparseMatrixMechanical.h
- inherits
-
- BaseMatrix
- CompressedRowSparseMatrixGeneric
- templates
-
- Mat1x1d
- Mat1x1f
- Mat2x2d
- Mat2x2f
- Mat3x3d
- Mat3x3f
- Mat4x4d
- Mat4x4f
- Mat<6, 6, double>
- Mat<6, 6, float>
- Mat<8, 8, double>
- Mat<8, 8, float>
- double
- float
- description
Mathematical Description
The CompressedRowSparseMatrixMechanical class in the SOFA framework is a specialized variant of the Compressed Row Storage (CRS) format, designed to optimize operations for mechanical systems. This matrix structure is particularly suited to sparse matrices where most elements are zero, which commonly occurs in finite element analysis and other physical simulation contexts.
Key Properties
- Sparse Matrix Representation: The CRS format stores only the non-zero elements of a matrix along with additional metadata that allows efficient reconstruction of the full matrix when needed.
- Mechanical Systems: This class is tailored for mechanical systems, where matrices often represent stiffness or mass properties. These properties are sparse due to local interactions between nodes or elements.
- Block Sizes: The matrix can store blocks (submatrices) instead of individual elements, which can be useful when representing tensors in multi-dimensional problems like 2D or 3D mechanics.
- Symmetry Handling: It includes optimizations for symmetric matrices, common in mechanical systems where physical properties are often reciprocal.
- Template Specializations: The class supports various block sizes (e.g.,
Mat1x1,Mat2x2,Mat3x3,Mat4x4, and higher-dimensional tensors) to handle different types of data efficiently. - Memory Management: Efficient memory management is crucial for large-scale simulations, where the sparse nature of matrices can drastically reduce storage requirements compared to dense matrix representations.
Matrix Operations
- Matrix Addition: The
addmethod allows adding a submatrix (block) at specified row and column indices. If the block indices align with predefined sizes, it updates existing blocks; otherwise, it performs element-wise addition using the base matrix methods. - Block Manipulations: Specialized versions of the
addfunction handle different types of block matrices (type::Mat3x3f,type::Mat3x3d) and their respective scalar types (float, double).
Example Usage in Mechanical Systems
Consider a mechanical system where nodes are connected via springs or other elastic elements. The stiffness matrix representing the system is sparse because each node only interacts with its neighbors.
For example, if we have four nodes with pairwise interactions leading to a 4x4 stiffness matrix:
$$ K = \begin{pmatrix} k_1 & -k_{12} & 0 & 0 \\ -k_{12} & k_2 & -k_{23} & 0 \\ 0 & -k_{23} & k_3 & -k_{34} \\ 0 & 0 & -k_{34} & k_4 \end{pmatrix} $$where $k_i$ and $-k_{ij}$ are the stiffness coefficients. This matrix is sparse, and using a CompressedRowSparseMatrixMechanical can efficiently store and manipulate such structures.
Symmetric Operations
In mechanical systems, matrices like the mass or stiffness matrix often exhibit symmetry:
$$ K = K^T $$The class includes optimizations for symmetric operations, such as adding symmetric blocks or performing symmetric vector multiplications. These operations are essential in solving linear systems and eigenvalue problems that arise from the discretization of mechanical equations.
Summary
The CompressedRowSparseMatrixMechanical is a powerful tool for managing sparse matrices with block structures in mechanical simulations. Its design allows efficient memory usage and optimized mathematical operations, making it suitable for large-scale physical modeling tasks.
Methods
void
split_row_index
(Index & index, Index & modulo)
void
split_col_index
(Index & index, Index & modulo)
void
compress
()
virtual
void
swap
(Matrix & m)
bool
nonzeros
(Index , Index , Block & val, const Real )
bool
nonsmall
(Index , Index , Block & val, const Real ref)
bool
upper
(Index i, Index j, Block & val, const Real )
bool
lower
(Index i, Index j, Block & val, const Real )
bool
upper_nonzeros
(Index i, Index j, Block & val, const Real ref)
bool
lower_nonzeros
(Index i, Index j, Block & val, const Real ref)
bool
upper_nonsmall
(Index i, Index j, Block & val, const Real ref)
bool
lower_nonsmall
(Index i, Index j, Block & val, const Real ref)
void
filterValues
(TMatrix & srcMatrix, int * filter, const Real ref, bool keepEmptyRows)
void
copyNonZeros
(TMatrix & M, bool keepEmptyRows)
void
copyNonSmall
(TMatrix & M, const Real ref, bool keepEmptyRows)
void
copyUpper
(Matrix & M, bool keepEmptyRows)
void
copyLower
(Matrix & M, bool keepEmptyRows)
void
copyUpperNonZeros
(TMatrix & M, bool keepEmptyRows)
void
copyLowerNonZeros
(TMatrix & M, bool keepEmptyRows)
void
copyUpperNonSmall
(Matrix & M, const Real ref, bool keepEmptyRows)
void
copyLowerNonSmall
(Matrix & M, const Real ref, bool keepEmptyRows)
void
bAccessorDelete
(const InternalBlockAccessor * )
virtual
void
bAccessorCopy
(InternalBlockAccessor * )
virtual
SReal
bAccessorElement
(const InternalBlockAccessor * b, Index i, Index j)
virtual
void
bAccessorSet
(InternalBlockAccessor * b, Index i, Index j, double v)
virtual
void
bAccessorAdd
(InternalBlockAccessor * b, Index i, Index j, double v)
virtual
const T *
bAccessorElementsCSRImpl
(const InternalBlockAccessor * b, T * buffer)
const float *
bAccessorElements
(const InternalBlockAccessor * b, float * buffer)
virtual
const double *
bAccessorElements
(const InternalBlockAccessor * b, double * buffer)
virtual
const int *
bAccessorElements
(const InternalBlockAccessor * b, int * buffer)
virtual
void
bAccessorSetCSRImpl
(InternalBlockAccessor * b, const T * buffer)
void
bAccessorSet
(InternalBlockAccessor * b, const float * buffer)
virtual
void
bAccessorSet
(InternalBlockAccessor * b, const double * buffer)
virtual
void
bAccessorSet
(InternalBlockAccessor * b, const int * buffer)
virtual
void
bAccessorAddCSRImpl
(InternalBlockAccessor * b, const T * buffer)
void
bAccessorAdd
(InternalBlockAccessor * b, const float * buffer)
virtual
void
bAccessorAdd
(InternalBlockAccessor * b, const double * buffer)
virtual
void
bAccessorAdd
(InternalBlockAccessor * b, const int * buffer)
virtual
BlockConstAccessor
blockGet
(Index i, Index j)
virtual
BlockAccessor
blockGetW
(Index i, Index j)
virtual
BlockAccessor
blockCreate
(Index i, Index j)
virtual
void
itCopyColBlock
(InternalColBlockIterator * )
virtual
void
itDeleteColBlock
(const InternalColBlockIterator * )
virtual
void
itAccessColBlock
(InternalColBlockIterator * it, BlockConstAccessor * b)
virtual
void
itIncColBlock
(InternalColBlockIterator * it)
virtual
void
itDecColBlock
(InternalColBlockIterator * it)
virtual
bool
itEqColBlock
(const InternalColBlockIterator * it, const InternalColBlockIterator * it2)
virtual
bool
itLessColBlock
(const InternalColBlockIterator * it, const InternalColBlockIterator * it2)
virtual
ColBlockConstIterator
bRowBegin
(Index ib)
virtual
ColBlockConstIterator
bRowEnd
(Index ib)
virtual
int
bRowRange
(Index ib)
void
itCopyRowBlock
(InternalRowBlockIterator * )
virtual
void
itDeleteRowBlock
(const InternalRowBlockIterator * )
virtual
Index
itAccessRowBlock
(InternalRowBlockIterator * it)
virtual
ColBlockConstIterator
itBeginRowBlock
(InternalRowBlockIterator * it)
virtual
ColBlockConstIterator
itEndRowBlock
(InternalRowBlockIterator * it)
virtual
int
itRangeRowBlock
(InternalRowBlockIterator * it)
void
itIncRowBlock
(InternalRowBlockIterator * it)
virtual
void
itDecRowBlock
(InternalRowBlockIterator * it)
virtual
bool
itEqRowBlock
(const InternalRowBlockIterator * it, const InternalRowBlockIterator * it2)
virtual
bool
itLessRowBlock
(const InternalRowBlockIterator * it, const InternalRowBlockIterator * it2)
virtual
RowBlockConstIterator
bRowsBegin
()
virtual
RowBlockConstIterator
bRowsEnd
()
virtual
int
bRowsRange
()
Real
vget
(const Vec & vec, Index i, Index j, Index k)
Real
vget
(const int & vec, Index i, Index , Index k)
Real
vget
(const BaseVector & vec, Index i)
Real2
vget
(const FullVector<Real2> & vec, Index i)
void
vset
(Vec & vec, Index i, Index j, Index k, Real v)
void
vset
(int & vec, Index i, Index , Index k, Real v)
void
vset
(BaseVector & vec, Index i, Real v)
void
vset
(FullVector<Real2> & vec, Index i, Real2 v)
void
vadd
(Vec & vec, Index i, Index j, Index k, Real v)
void
vadd
(int & vec, Index i, Index , Index k, Real v)
void
vadd
(BaseVector & vec, Index i, Real v)
void
vadd
(FullVector<Real2> & vec, Index i, Real2 v)
void
vresize
(Vec & vec, Index , Index totalSize)
void
vresize
(int & vec, Index blockSize, Index )
void
tmul
(V1 & res, const V2 & vec)
void
taddMul
(V1 & res, const V2 & vec)
void
taddMul_by_line
(V1 & res, const V2 & vec)
void
taddMulTranspose
(V1 & res, const V2 & vec)
CompressedRowSparseMatrixMechanical<TBlock, TPolicy>
operator+
(const CompressedRowSparseMatrixMechanical<TBlock, TPolicy> & m)
void
mul
(V2 & result, const V1 & v)
void
addMultTranspose
(V1 & result, const V2 & v)
Vec
operator*
(const Vec & v)
void
addMul_by_line
(V & res, const type::Vec<<recovery-expr>(), Real2> & v)
void
addMul_by_line
(V & res, const V2 & v)
void
addMul
(V1 & res, const V2 & v)
bool
hasRef
(const M2 * m)
int
expr
()
bool
valid
()
void
addTo
(Dest * dest)
void
equal
(const M & m, bool add)
void
addEqual
(const M & m)
void
operator=
(const CompressedRowSparseMatrixMechanical<TBlock2, TPolicy2> & m)
void
operator+=
(const CompressedRowSparseMatrixMechanical<TBlock2, TPolicy2> & m)
void
operator-=
(const CompressedRowSparseMatrixMechanical<TBlock2, TPolicy2> & m)
void
operator=
(const MatrixExpr<Expr2> & m)
void
operator+=
(const MatrixExpr<Expr2> & m)
void
operator-=
(const MatrixExpr<Expr2> & m)
MatrixExpr<MatrixTranspose<Matrix>>
t
()
MatrixExpr<MatrixNegative<Matrix>>
operator-
()
MatrixExpr<MatrixScale<Matrix, double>>
operator*
(const double & r)
const char *
Name
()
{
"name": "CompressedRowSparseMatrixMechanical",
"namespace": "sofa::linearalgebra",
"module": "Sofa.framework.LinearAlgebra",
"include": "sofa/linearalgebra/CompressedRowSparseMatrixMechanical.h",
"doc": "",
"inherits": [
"BaseMatrix",
"CompressedRowSparseMatrixGeneric"
],
"templates": [
"Mat1x1d",
"Mat1x1f",
"Mat2x2d",
"Mat2x2f",
"Mat3x3d",
"Mat3x3f",
"Mat4x4d",
"Mat4x4f",
"Mat<6, 6, double>",
"Mat<6, 6, float>",
"Mat<8, 8, double>",
"Mat<8, 8, float>",
"double",
"float"
],
"data_fields": [],
"links": [],
"methods": [
{
"name": "split_row_index",
"return_type": "void",
"params": [
{
"name": "index",
"type": "Index &"
},
{
"name": "modulo",
"type": "Index &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "public"
},
{
"name": "split_col_index",
"return_type": "void",
"params": [
{
"name": "index",
"type": "Index &"
},
{
"name": "modulo",
"type": "Index &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "public"
},
{
"name": "compress",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "swap",
"return_type": "void",
"params": [
{
"name": "m",
"type": "Matrix &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "nonzeros",
"return_type": "bool",
"params": [
{
"name": "",
"type": "Index"
},
{
"name": "",
"type": "Index"
},
{
"name": "val",
"type": "Block &"
},
{
"name": "",
"type": "const Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "public"
},
{
"name": "nonsmall",
"return_type": "bool",
"params": [
{
"name": "",
"type": "Index"
},
{
"name": "",
"type": "Index"
},
{
"name": "val",
"type": "Block &"
},
{
"name": "ref",
"type": "const Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "public"
},
{
"name": "upper",
"return_type": "bool",
"params": [
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
},
{
"name": "val",
"type": "Block &"
},
{
"name": "",
"type": "const Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "public"
},
{
"name": "lower",
"return_type": "bool",
"params": [
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
},
{
"name": "val",
"type": "Block &"
},
{
"name": "",
"type": "const Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "public"
},
{
"name": "upper_nonzeros",
"return_type": "bool",
"params": [
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
},
{
"name": "val",
"type": "Block &"
},
{
"name": "ref",
"type": "const Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "public"
},
{
"name": "lower_nonzeros",
"return_type": "bool",
"params": [
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
},
{
"name": "val",
"type": "Block &"
},
{
"name": "ref",
"type": "const Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "public"
},
{
"name": "upper_nonsmall",
"return_type": "bool",
"params": [
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
},
{
"name": "val",
"type": "Block &"
},
{
"name": "ref",
"type": "const Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "public"
},
{
"name": "lower_nonsmall",
"return_type": "bool",
"params": [
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
},
{
"name": "val",
"type": "Block &"
},
{
"name": "ref",
"type": "const Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "public"
},
{
"name": "filterValues",
"return_type": "void",
"params": [
{
"name": "srcMatrix",
"type": "TMatrix &"
},
{
"name": "filter",
"type": "int *"
},
{
"name": "ref",
"type": "const Real"
},
{
"name": "keepEmptyRows",
"type": "bool"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "copyNonZeros",
"return_type": "void",
"params": [
{
"name": "M",
"type": "TMatrix &"
},
{
"name": "keepEmptyRows",
"type": "bool"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "copyNonSmall",
"return_type": "void",
"params": [
{
"name": "M",
"type": "TMatrix &"
},
{
"name": "ref",
"type": "const Real"
},
{
"name": "keepEmptyRows",
"type": "bool"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "copyUpper",
"return_type": "void",
"params": [
{
"name": "M",
"type": "Matrix &"
},
{
"name": "keepEmptyRows",
"type": "bool"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "copyLower",
"return_type": "void",
"params": [
{
"name": "M",
"type": "Matrix &"
},
{
"name": "keepEmptyRows",
"type": "bool"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "copyUpperNonZeros",
"return_type": "void",
"params": [
{
"name": "M",
"type": "TMatrix &"
},
{
"name": "keepEmptyRows",
"type": "bool"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "copyLowerNonZeros",
"return_type": "void",
"params": [
{
"name": "M",
"type": "TMatrix &"
},
{
"name": "keepEmptyRows",
"type": "bool"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "copyUpperNonSmall",
"return_type": "void",
"params": [
{
"name": "M",
"type": "Matrix &"
},
{
"name": "ref",
"type": "const Real"
},
{
"name": "keepEmptyRows",
"type": "bool"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "copyLowerNonSmall",
"return_type": "void",
"params": [
{
"name": "M",
"type": "Matrix &"
},
{
"name": "ref",
"type": "const Real"
},
{
"name": "keepEmptyRows",
"type": "bool"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "bAccessorDelete",
"return_type": "void",
"params": [
{
"name": "",
"type": "const InternalBlockAccessor *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorCopy",
"return_type": "void",
"params": [
{
"name": "",
"type": "InternalBlockAccessor *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorElement",
"return_type": "SReal",
"params": [
{
"name": "b",
"type": "const InternalBlockAccessor *"
},
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorSet",
"return_type": "void",
"params": [
{
"name": "b",
"type": "InternalBlockAccessor *"
},
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
},
{
"name": "v",
"type": "double"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorAdd",
"return_type": "void",
"params": [
{
"name": "b",
"type": "InternalBlockAccessor *"
},
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
},
{
"name": "v",
"type": "double"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorElementsCSRImpl",
"return_type": "const T *",
"params": [
{
"name": "b",
"type": "const InternalBlockAccessor *"
},
{
"name": "buffer",
"type": "T *"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorElements",
"return_type": "const float *",
"params": [
{
"name": "b",
"type": "const InternalBlockAccessor *"
},
{
"name": "buffer",
"type": "float *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorElements",
"return_type": "const double *",
"params": [
{
"name": "b",
"type": "const InternalBlockAccessor *"
},
{
"name": "buffer",
"type": "double *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorElements",
"return_type": "const int *",
"params": [
{
"name": "b",
"type": "const InternalBlockAccessor *"
},
{
"name": "buffer",
"type": "int *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorSetCSRImpl",
"return_type": "void",
"params": [
{
"name": "b",
"type": "InternalBlockAccessor *"
},
{
"name": "buffer",
"type": "const T *"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorSet",
"return_type": "void",
"params": [
{
"name": "b",
"type": "InternalBlockAccessor *"
},
{
"name": "buffer",
"type": "const float *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorSet",
"return_type": "void",
"params": [
{
"name": "b",
"type": "InternalBlockAccessor *"
},
{
"name": "buffer",
"type": "const double *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorSet",
"return_type": "void",
"params": [
{
"name": "b",
"type": "InternalBlockAccessor *"
},
{
"name": "buffer",
"type": "const int *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorAddCSRImpl",
"return_type": "void",
"params": [
{
"name": "b",
"type": "InternalBlockAccessor *"
},
{
"name": "buffer",
"type": "const T *"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorAdd",
"return_type": "void",
"params": [
{
"name": "b",
"type": "InternalBlockAccessor *"
},
{
"name": "buffer",
"type": "const float *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorAdd",
"return_type": "void",
"params": [
{
"name": "b",
"type": "InternalBlockAccessor *"
},
{
"name": "buffer",
"type": "const double *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bAccessorAdd",
"return_type": "void",
"params": [
{
"name": "b",
"type": "InternalBlockAccessor *"
},
{
"name": "buffer",
"type": "const int *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "blockGet",
"return_type": "BlockConstAccessor",
"params": [
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "blockGetW",
"return_type": "BlockAccessor",
"params": [
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "blockCreate",
"return_type": "BlockAccessor",
"params": [
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "itCopyColBlock",
"return_type": "void",
"params": [
{
"name": "",
"type": "InternalColBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itDeleteColBlock",
"return_type": "void",
"params": [
{
"name": "",
"type": "const InternalColBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itAccessColBlock",
"return_type": "void",
"params": [
{
"name": "it",
"type": "InternalColBlockIterator *"
},
{
"name": "b",
"type": "BlockConstAccessor *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itIncColBlock",
"return_type": "void",
"params": [
{
"name": "it",
"type": "InternalColBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itDecColBlock",
"return_type": "void",
"params": [
{
"name": "it",
"type": "InternalColBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itEqColBlock",
"return_type": "bool",
"params": [
{
"name": "it",
"type": "const InternalColBlockIterator *"
},
{
"name": "it2",
"type": "const InternalColBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itLessColBlock",
"return_type": "bool",
"params": [
{
"name": "it",
"type": "const InternalColBlockIterator *"
},
{
"name": "it2",
"type": "const InternalColBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bRowBegin",
"return_type": "ColBlockConstIterator",
"params": [
{
"name": "ib",
"type": "Index"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "bRowEnd",
"return_type": "ColBlockConstIterator",
"params": [
{
"name": "ib",
"type": "Index"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "bRowRange",
"return_type": "int",
"params": [
{
"name": "ib",
"type": "Index"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "itCopyRowBlock",
"return_type": "void",
"params": [
{
"name": "",
"type": "InternalRowBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itDeleteRowBlock",
"return_type": "void",
"params": [
{
"name": "",
"type": "const InternalRowBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itAccessRowBlock",
"return_type": "Index",
"params": [
{
"name": "it",
"type": "InternalRowBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itBeginRowBlock",
"return_type": "ColBlockConstIterator",
"params": [
{
"name": "it",
"type": "InternalRowBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itEndRowBlock",
"return_type": "ColBlockConstIterator",
"params": [
{
"name": "it",
"type": "InternalRowBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itRangeRowBlock",
"return_type": "int",
"params": [
{
"name": "it",
"type": "InternalRowBlockIterator *"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itIncRowBlock",
"return_type": "void",
"params": [
{
"name": "it",
"type": "InternalRowBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itDecRowBlock",
"return_type": "void",
"params": [
{
"name": "it",
"type": "InternalRowBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itEqRowBlock",
"return_type": "bool",
"params": [
{
"name": "it",
"type": "const InternalRowBlockIterator *"
},
{
"name": "it2",
"type": "const InternalRowBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "itLessRowBlock",
"return_type": "bool",
"params": [
{
"name": "it",
"type": "const InternalRowBlockIterator *"
},
{
"name": "it2",
"type": "const InternalRowBlockIterator *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "bRowsBegin",
"return_type": "RowBlockConstIterator",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "bRowsEnd",
"return_type": "RowBlockConstIterator",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "bRowsRange",
"return_type": "int",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "vget",
"return_type": "Real",
"params": [
{
"name": "vec",
"type": "const Vec &"
},
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
},
{
"name": "k",
"type": "Index"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "vget",
"return_type": "Real",
"params": [
{
"name": "vec",
"type": "const int &"
},
{
"name": "i",
"type": "Index"
},
{
"name": "",
"type": "Index"
},
{
"name": "k",
"type": "Index"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "vget",
"return_type": "Real",
"params": [
{
"name": "vec",
"type": "const BaseVector &"
},
{
"name": "i",
"type": "Index"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "vget",
"return_type": "Real2",
"params": [
{
"name": "vec",
"type": "const FullVector<Real2> &"
},
{
"name": "i",
"type": "Index"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "vset",
"return_type": "void",
"params": [
{
"name": "vec",
"type": "Vec &"
},
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
},
{
"name": "k",
"type": "Index"
},
{
"name": "v",
"type": "Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "vset",
"return_type": "void",
"params": [
{
"name": "vec",
"type": "int &"
},
{
"name": "i",
"type": "Index"
},
{
"name": "",
"type": "Index"
},
{
"name": "k",
"type": "Index"
},
{
"name": "v",
"type": "Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "vset",
"return_type": "void",
"params": [
{
"name": "vec",
"type": "BaseVector &"
},
{
"name": "i",
"type": "Index"
},
{
"name": "v",
"type": "Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "vset",
"return_type": "void",
"params": [
{
"name": "vec",
"type": "FullVector<Real2> &"
},
{
"name": "i",
"type": "Index"
},
{
"name": "v",
"type": "Real2"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "vadd",
"return_type": "void",
"params": [
{
"name": "vec",
"type": "Vec &"
},
{
"name": "i",
"type": "Index"
},
{
"name": "j",
"type": "Index"
},
{
"name": "k",
"type": "Index"
},
{
"name": "v",
"type": "Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "vadd",
"return_type": "void",
"params": [
{
"name": "vec",
"type": "int &"
},
{
"name": "i",
"type": "Index"
},
{
"name": "",
"type": "Index"
},
{
"name": "k",
"type": "Index"
},
{
"name": "v",
"type": "Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "vadd",
"return_type": "void",
"params": [
{
"name": "vec",
"type": "BaseVector &"
},
{
"name": "i",
"type": "Index"
},
{
"name": "v",
"type": "Real"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "vadd",
"return_type": "void",
"params": [
{
"name": "vec",
"type": "FullVector<Real2> &"
},
{
"name": "i",
"type": "Index"
},
{
"name": "v",
"type": "Real2"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "vresize",
"return_type": "void",
"params": [
{
"name": "vec",
"type": "Vec &"
},
{
"name": "",
"type": "Index"
},
{
"name": "totalSize",
"type": "Index"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "vresize",
"return_type": "void",
"params": [
{
"name": "vec",
"type": "int &"
},
{
"name": "blockSize",
"type": "Index"
},
{
"name": "",
"type": "Index"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "protected"
},
{
"name": "tmul",
"return_type": "void",
"params": [
{
"name": "res",
"type": "V1 &"
},
{
"name": "vec",
"type": "const V2 &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "taddMul",
"return_type": "void",
"params": [
{
"name": "res",
"type": "V1 &"
},
{
"name": "vec",
"type": "const V2 &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "taddMul_by_line",
"return_type": "void",
"params": [
{
"name": "res",
"type": "V1 &"
},
{
"name": "vec",
"type": "const V2 &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "taddMulTranspose",
"return_type": "void",
"params": [
{
"name": "res",
"type": "V1 &"
},
{
"name": "vec",
"type": "const V2 &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "operator+",
"return_type": "CompressedRowSparseMatrixMechanical<TBlock, TPolicy>",
"params": [
{
"name": "m",
"type": "const CompressedRowSparseMatrixMechanical<TBlock, TPolicy> &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "mul",
"return_type": "void",
"params": [
{
"name": "result",
"type": "V2 &"
},
{
"name": "v",
"type": "const V1 &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "addMultTranspose",
"return_type": "void",
"params": [
{
"name": "result",
"type": "V1 &"
},
{
"name": "v",
"type": "const V2 &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "operator*",
"return_type": "Vec",
"params": [
{
"name": "v",
"type": "const Vec &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "addMul_by_line",
"return_type": "void",
"params": [
{
"name": "res",
"type": "V &"
},
{
"name": "v",
"type": "const type::Vec<<recovery-expr>(), Real2> &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "addMul_by_line",
"return_type": "void",
"params": [
{
"name": "res",
"type": "V &"
},
{
"name": "v",
"type": "const V2 &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "addMul",
"return_type": "void",
"params": [
{
"name": "res",
"type": "V1 &"
},
{
"name": "v",
"type": "const V2 &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "hasRef",
"return_type": "bool",
"params": [
{
"name": "m",
"type": "const M2 *"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "expr",
"return_type": "int",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "valid",
"return_type": "bool",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "addTo",
"return_type": "void",
"params": [
{
"name": "dest",
"type": "Dest *"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "equal",
"return_type": "void",
"params": [
{
"name": "m",
"type": "const M &"
},
{
"name": "add",
"type": "bool"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "addEqual",
"return_type": "void",
"params": [
{
"name": "m",
"type": "const M &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "operator=",
"return_type": "void",
"params": [
{
"name": "m",
"type": "const CompressedRowSparseMatrixMechanical<TBlock2, TPolicy2> &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "operator+=",
"return_type": "void",
"params": [
{
"name": "m",
"type": "const CompressedRowSparseMatrixMechanical<TBlock2, TPolicy2> &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "operator-=",
"return_type": "void",
"params": [
{
"name": "m",
"type": "const CompressedRowSparseMatrixMechanical<TBlock2, TPolicy2> &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "operator=",
"return_type": "void",
"params": [
{
"name": "m",
"type": "const MatrixExpr<Expr2> &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "operator+=",
"return_type": "void",
"params": [
{
"name": "m",
"type": "const MatrixExpr<Expr2> &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "operator-=",
"return_type": "void",
"params": [
{
"name": "m",
"type": "const MatrixExpr<Expr2> &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "t",
"return_type": "MatrixExpr<MatrixTranspose<Matrix>>",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "operator-",
"return_type": "MatrixExpr<MatrixNegative<Matrix>>",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "operator*",
"return_type": "MatrixExpr<MatrixScale<Matrix, double>>",
"params": [
{
"name": "r",
"type": "const double &"
}
],
"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"
}
],
"description": "This class is a specific implementation of the Compressed Row Sparse (CRS) matrix format tailored for mechanical systems in the SOFA framework. It extends functionality to support various block sizes and symmetric operations, which are common in physical simulation scenarios.",
"parameters": [
{
"name": "Block Size",
"description": "Determines the size of each block within the sparse matrix. Common values include 1 (for scalar entries), 3 (for 3D vectors) or 6 (for combined 3D vector + rotation)."
},
{
"name": "Symmetry Flag",
"description": "Indicates whether the matrix should be symmetric. This can lead to more efficient memory usage and faster operations for matrices that have a symmetric structure."
}
],
"functions": [
{
"name": "add()",
"description": "Adds a value or block to specific row and column indices of the matrix, adjusting for symmetry if applicable.",
"parameters": [
{
"name": "row",
"type": "Index"
},
{
"name": "col",
"type": "Index"
},
{
"name": "_M",
"type": "value/block"
}
]
},
{
"name": "setIdentity()",
"description": "Sets the matrix to be an identity matrix, with ones along its diagonal and zeros elsewhere.",
"parameters": []
},
{
"name": "getNbBlocks()",
"description": "Returns the number of blocks in either rows or columns.",
"parameters": [
{
"name": "isRow",
"type": "bool"
}
]
},
{
"name": "wblock()",
"description": "Provides write access to a specific block within the matrix, creating it if necessary.",
"parameters": [
{
"name": "rowIdx",
"type": "Index"
},
{
"name": "colIdx",
"type": "Index"
},
{
"name": "create",
"type": "bool"
}
]
},
{
"name": "rblock()",
"description": "Provides read access to a specific block within the matrix.",
"parameters": [
{
"name": "rowIdx",
"type": "Index"
},
{
"name": "colIdx",
"type": "Index"
}
]
}
],
"example_usage": "This component is typically used in SOFA simulation scenes where large sparse matrices are required to represent mechanical properties like stiffness or mass. The block size and symmetry options allow for efficient storage and manipulation of these matrices during the simulation process.",
"notes": "The CompressedRowSparseMatrixMechanical class supports both float and double precision, as well as different sized blocks (1x1, 2x2, 3x3, etc.). It is particularly useful in scenarios where mechanical properties are represented by dense submatrices within a larger sparse matrix structure.",
"maths": "## Mathematical Description\n\nThe `CompressedRowSparseMatrixMechanical` class in the SOFA framework is a specialized variant of the Compressed Row Storage (CRS) format, designed to optimize operations for mechanical systems. This matrix structure is particularly suited to sparse matrices where most elements are zero, which commonly occurs in finite element analysis and other physical simulation contexts.\n\n### Key Properties\n1. **Sparse Matrix Representation**: The CRS format stores only the non-zero elements of a matrix along with additional metadata that allows efficient reconstruction of the full matrix when needed.\n2. **Mechanical Systems**: This class is tailored for mechanical systems, where matrices often represent stiffness or mass properties. These properties are sparse due to local interactions between nodes or elements.\n3. **Block Sizes**: The matrix can store blocks (submatrices) instead of individual elements, which can be useful when representing tensors in multi-dimensional problems like 2D or 3D mechanics.\n4. **Symmetry Handling**: It includes optimizations for symmetric matrices, common in mechanical systems where physical properties are often reciprocal.\n5. **Template Specializations**: The class supports various block sizes (e.g., `Mat1x1`, `Mat2x2`, `Mat3x3`, `Mat4x4`, and higher-dimensional tensors) to handle different types of data efficiently.\n6. **Memory Management**: Efficient memory management is crucial for large-scale simulations, where the sparse nature of matrices can drastically reduce storage requirements compared to dense matrix representations.\n\n### Matrix Operations\n1. **Matrix Addition**: The `add` method allows adding a submatrix (block) at specified row and column indices. If the block indices align with predefined sizes, it updates existing blocks; otherwise, it performs element-wise addition using the base matrix methods.\n2. **Block Manipulations**: Specialized versions of the `add` function handle different types of block matrices (`type::Mat3x3f`, `type::Mat3x3d`) and their respective scalar types (float, double).\n\n### Example Usage in Mechanical Systems\nConsider a mechanical system where nodes are connected via springs or other elastic elements. The stiffness matrix representing the system is sparse because each node only interacts with its neighbors.\n\nFor example, if we have four nodes with pairwise interactions leading to a 4x4 stiffness matrix:\n\\[\nK = \\begin{pmatrix}\n k_1 & -k_{12} & 0 & 0 \\\\\n -k_{12} & k_2 & -k_{23} & 0 \\\\\n 0 & -k_{23} & k_3 & -k_{34} \\\\\n 0 & 0 & -k_{34} & k_4\n\\end{pmatrix}\n\\]\nwhere \\(k_i\\) and \\(-k_{ij}\\) are the stiffness coefficients. This matrix is sparse, and using a `CompressedRowSparseMatrixMechanical` can efficiently store and manipulate such structures.\n\n### Symmetric Operations\nIn mechanical systems, matrices like the mass or stiffness matrix often exhibit symmetry:\n\\[\nK = K^T\n\\]\nThe class includes optimizations for symmetric operations, such as adding symmetric blocks or performing symmetric vector multiplications. These operations are essential in solving linear systems and eigenvalue problems that arise from the discretization of mechanical equations.\n\n### Summary\nThe `CompressedRowSparseMatrixMechanical` is a powerful tool for managing sparse matrices with block structures in mechanical simulations. Its design allows efficient memory usage and optimized mathematical operations, making it suitable for large-scale physical modeling tasks.",
"abstract": "The `CompressedRowSparseMatrixMechanical` implements the Compressed Row Storage (CRS) format tailored for mechanical systems in SOFA, supporting various block sizes and symmetric operations. It efficiently manages sparse matrices representing stiffness or mass properties.",
"sheet": "# CompressedRowSparseMatrixMechanical\n\n## Overview\nThe `CompressedRowSparseMatrixMechanical` is a specialized matrix class designed to handle sparse matrices in the context of mechanical systems within the SOFA framework. This component extends the functionality of the Compressed Row Storage (CRS) format, supporting various block sizes and symmetric operations typical in physical simulations.\n\n## Mathematical Model\nThe `CompressedRowSparseMatrixMechanical` implements the Compressed Row Storage (CRS) format for sparse matrices. In this format, only non-zero elements are stored along with additional metadata to reconstruct the full matrix efficiently. The key properties include:\n\n1. **Sparse Matrix Representation**: Only non-zero elements are stored.\n2. **Block Sizes**: Supports various block sizes such as `Mat1x1`, `Mat2x2`, `Mat3x3`, and higher-dimensional tensors, which can represent tensors in multi-dimensional problems like 2D or 3D mechanics.\n3. **Symmetry Handling**: Optimizations for symmetric matrices are included, common in mechanical systems where physical properties are often reciprocal.\n\n### Matrix Operations\n1. **Matrix Addition**: The `add` method allows adding a submatrix (block) at specified row and column indices. If the block indices align with predefined sizes, it updates existing blocks; otherwise, it performs element-wise addition using base matrix methods.\n2. **Block Manipulations**: Specialized versions of the `add` function handle different types of block matrices (`type::Mat3x3f`, `type::Mat3x3d`) and their respective scalar types (float, double).\n\n### Example Usage in Mechanical Systems\nConsider a mechanical system where nodes are connected via springs or other elastic elements. The stiffness matrix representing the system is sparse because each node only interacts with its neighbors.\n\nFor example, if we have four nodes with pairwise interactions leading to a 4x4 stiffness matrix:\n\\[\nK = \\begin{pmatrix}\n k_1 & -k_{12} & 0 & 0 \\\\\n -k_{12} & k_2 & -k_{23} & 0 \\\\\n 0 & -k_{23} & k_3 & -k_{34} \\\\\n 0 & 0 & -k_{34} & k_4\n\\end{pmatrix}\n\\]\nwhere \\(k_i\\) and \\(-k_{ij}\\) are the stiffness coefficients. This matrix is sparse, and using a `CompressedRowSparseMatrixMechanical` can efficiently store and manipulate such structures.\n\n### Symmetric Operations\nIn mechanical systems, matrices like the mass or stiffness matrix often exhibit symmetry:\n\\[\nK = K^T\n\\]\nThe class includes optimizations for symmetric operations, such as adding symmetric blocks or performing symmetric vector multiplications. These operations are essential in solving linear systems and eigenvalue problems that arise from the discretization of mechanical equations."
}