iMSTK
Interactive Medical Simulation Toolkit
imstkInternalForceModel.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkInternalForceModel.h"
8 
9 namespace imstk
10 {
11 void
12 InternalForceModel::updateValuesFromMatrix(std::shared_ptr<vega::SparseMatrix> vegaMatrix, double* values)
13 {
14  auto rowLengths = vegaMatrix->GetRowLengths();
15  auto nonZeroValues = vegaMatrix->GetEntries();
16 
17  // Flatten the internal non-zeros value array and store it in values.
18  int offset = 0;
19 
20  for (int row = 0, end = vegaMatrix->GetNumRows(); row < end; ++row)
21  {
24  for (int j = 0, end_j = rowLengths[row]; j < end_j; ++j)
25  {
26  values[j + offset] = nonZeroValues[row][j];
27  }
28 
29  offset += rowLengths[row];
30  }
31 }
32 
33 void
34 InternalForceModel::getForceAndMatrix(const Vectord& u, Vectord& internalForce, SparseMatrixd& tangentStiffnessMatrix)
35 {
36  this->getInternalForce(u, internalForce);
37  this->getTangentStiffnessMatrix(u, tangentStiffnessMatrix);
38 }
39 } // namespace imstk
virtual void getForceAndMatrix(const Vectord &u, Vectord &internalForce, SparseMatrixd &tangentStiffnessMatrix)
Compute both internal force internalForce and stiffness matrix tangentStiffnessMatrix at state ...
Compound Geometry.
virtual void getTangentStiffnessMatrix(const Vectord &u, SparseMatrixd &tangentStiffnessMatrix)=0
Compute stiffness matrix tangentStiffnessMatrix at state .
virtual void getInternalForce(const Vectord &u, Vectord &internalForce)=0
Compute internal force internalForce at state u.
static void updateValuesFromMatrix(std::shared_ptr< vega::SparseMatrix > vegaMatrix, double *values)
Update the values of the Eigen sparse matrix given the linearized array of data from the Vega matrix...