iMSTK
Interactive Medical Simulation Toolkit
imstkCorotationalFemForceModel.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 "imstkCorotationalFemForceModel.h"
8 
9 #ifdef WIN32
10 #pragma warning( push )
11 #pragma warning( disable : 4458 )
12 #endif
13 #include <corotationalLinearFEM.h>
14 #ifdef WIN32
15 #pragma warning( pop )
16 #endif
17 
18 namespace imstk
19 {
20 CorotationalFemForceModel::CorotationalFemForceModel(std::shared_ptr<vega::VolumetricMesh> mesh, const int warp) : InternalForceModel(), m_warp(warp)
21 {
22  auto tetMesh = std::dynamic_pointer_cast<vega::TetMesh>(mesh);
23  m_corotationalLinearFem = std::make_shared<vega::CorotationalLinearFEM>(tetMesh.get());
24 }
25 
26 void
27 CorotationalFemForceModel::getInternalForce(const Vectord& u, Vectord& internalForce)
28 {
29  double* data = const_cast<double*>(u.data());
30  m_corotationalLinearFem->ComputeEnergyAndForceAndStiffnessMatrix(data, nullptr, internalForce.data(), nullptr, m_warp);
31 }
32 
33 void
34 CorotationalFemForceModel::getTangentStiffnessMatrix(const Vectord& u, SparseMatrixd& tangentStiffnessMatrix)
35 {
36  double* data = const_cast<double*>(u.data());
37  m_corotationalLinearFem->ComputeEnergyAndForceAndStiffnessMatrix(data, nullptr, nullptr, m_vegaTangentStiffnessMatrix.get(), m_warp);
38  InternalForceModel::updateValuesFromMatrix(m_vegaTangentStiffnessMatrix, tangentStiffnessMatrix.valuePtr());
39 }
40 
41 void
42 CorotationalFemForceModel::getTangentStiffnessMatrixTopology(vega::SparseMatrix** tangentStiffnessMatrix)
43 {
44  m_corotationalLinearFem->GetStiffnessMatrixTopology(tangentStiffnessMatrix);
45 }
46 
47 void
48 CorotationalFemForceModel::getForceAndMatrix(const Vectord& u, Vectord& internalForce, SparseMatrixd& tangentStiffnessMatrix)
49 {
50  double* data = const_cast<double*>(u.data());
51  m_corotationalLinearFem->ComputeEnergyAndForceAndStiffnessMatrix(data, nullptr, internalForce.data(), m_vegaTangentStiffnessMatrix.get(), m_warp);
52  InternalForceModel::updateValuesFromMatrix(m_vegaTangentStiffnessMatrix, tangentStiffnessMatrix.valuePtr());
53 }
54 
55 void
57 {
58  m_warp = warp;
59 }
60 
61 void
62 CorotationalFemForceModel::setTangentStiffness(std::shared_ptr<vega::SparseMatrix> K)
63 {
64  m_vegaTangentStiffnessMatrix = K;
65 }
66 } // namespace imstk
void setTangentStiffness(std::shared_ptr< vega::SparseMatrix > K) override
Specify tangent stiffness matrix.
void setWarp(const int warp)
Turn on/off warp.
Compound Geometry.
void getForceAndMatrix(const Vectord &u, Vectord &internalForce, SparseMatrixd &tangentStiffnessMatrix) override
Compute internal force internalForce and stiffness matrix tangentStiffnessMatrix at state ...
void getInternalForce(const Vectord &u, Vectord &internalForce) override
Compute internal force internalForce at state u.
void getTangentStiffnessMatrixTopology(vega::SparseMatrix **tangentStiffnessMatrix) override
Build the sparsity pattern for stiffness matrix.
Base class for internal force model within the following context.
void getTangentStiffnessMatrix(const Vectord &u, SparseMatrixd &tangentStiffnessMatrix) override
Compute stiffness matrix tangentStiffnessMatrix at state .
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...