|
25 | 25 | #include <sofa/linearalgebra/BaseMatrix.h> |
26 | 26 | #include <sofa/linearalgebra/CompressedRowSparseMatrix.h> |
27 | 27 | #include <sofa/core/MechanicalParams.h> |
| 28 | +#include <sofa/core/behavior/BaseLocalForceFieldMatrix.h> |
| 29 | + |
28 | 30 |
|
29 | 31 | namespace sofa::component::mechanicalload |
30 | 32 | { |
@@ -118,6 +120,28 @@ void TorsionForceField<DataTypes>::addKToMatrix(linearalgebra::BaseMatrix* matri |
118 | 120 | } |
119 | 121 | } |
120 | 122 |
|
| 123 | +template <typename DataTypes> |
| 124 | +void TorsionForceField<DataTypes>::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) |
| 125 | +{ |
| 126 | + auto dfdx = matrix->getForceDerivativeIn(this->mstate) |
| 127 | + .withRespectToPositionsIn(this->mstate); |
| 128 | + |
| 129 | + const VecId& indices = m_indices.getValue(); |
| 130 | + const Real& tau = m_torque.getValue(); |
| 131 | + |
| 132 | + sofa::type::MatNoInit<3,3, Real> D; |
| 133 | + D(0,0) = 1 - m_u(0)*m_u(0) ; D(0,1) = -m_u(1)*m_u(0) ; D(0,2) = -m_u(2)*m_u(0); |
| 134 | + D(1,0) = -m_u(0)*m_u(1) ; D(1,1) = 1 - m_u(1)*m_u(1) ; D(1,2) = -m_u(2)*m_u(1); |
| 135 | + D(2,0) = -m_u(0)*m_u(2) ; D(2,1) = -m_u(1)*m_u(2) ; D(2,2) = 1 - m_u(3)*m_u(3); |
| 136 | + D *= tau; |
| 137 | + |
| 138 | + for (const auto id : indices) |
| 139 | + { |
| 140 | + const unsigned int c = Deriv::total_size * id; |
| 141 | + dfdx(c, c) += D; |
| 142 | + } |
| 143 | +} |
| 144 | + |
121 | 145 | template <typename DataTypes> |
122 | 146 | void TorsionForceField<DataTypes>::buildDampingMatrix(core::behavior::DampingMatrix*) |
123 | 147 | { |
|
0 commit comments