diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/BTDMatrix.h b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/BTDMatrix.h index 9c8a852618e..35910298f30 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/BTDMatrix.h +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/BTDMatrix.h @@ -185,6 +185,12 @@ class BTDMatrix : public linearalgebra::BaseMatrix void add(Index i, Index j, double v) override; + /** + * Accumulation specialized on contributions of the same size than the blocks. + */ + template 3), int> = 0> + void add(Index row, Index col, const type::Mat& v); + void clear(Index i, Index j) override; void clearRow(Index i) override; @@ -226,6 +232,36 @@ class BTDMatrix : public linearalgebra::BaseMatrix } }; + +template +template 3), int>> +void BTDMatrix::add(Index row, Index col, + const type::Mat& v) +{ + if (row % BSIZE == 0 && col % BSIZE == 0) + { + const Index bi = row / BSIZE; + const Index bj = col / BSIZE; + const Index bindex = bj - bi + 1; + if (bindex >= 3) + { + return; + } + data[bi * 3 + bindex] += v; + } + else + { + for (sofa::Index i = 0; i < BSIZE; ++i) + { + for (sofa::Index j = 0; j < BSIZE; ++j) + { + this->add(row + i, col + j, v(i, j)); + } + } + } +} + + #if !defined(SOFA_LINEARALGEBRA_BTDMATRIX_CPP) extern template class SOFA_LINEARALGEBRA_API linearalgebra::BTDMatrix<6, SReal>; #endif