Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/BTDMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <std::size_t M = N, std::enable_if_t<(M > 3), int> = 0>
void add(Index row, Index col, const type::Mat<BSIZE, BSIZE, Real>& v);

void clear(Index i, Index j) override;

void clearRow(Index i) override;
Expand Down Expand Up @@ -226,6 +232,36 @@ class BTDMatrix : public linearalgebra::BaseMatrix
}
};


template <std::size_t N, typename T>
template <std::size_t M, std::enable_if_t<(M > 3), int>>
void BTDMatrix<N, T>::add(Index row, Index col,
const type::Mat<BSIZE, BSIZE, Real>& 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
Expand Down