iMSTK
Interactive Medical Simulation Toolkit
imstkIsotropicHyperelasticFeForceModel.h
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 #pragma once
8 
9 #include "imstkInternalForceModel.h"
10 
11 #ifdef WIN32
12 #pragma warning( push )
13 #pragma warning( disable : 4458 )
14 #endif
15 #include <isotropicHyperelasticFEM.h>
16 #ifdef WIN32
17 #pragma warning( pop )
18 #endif
19 
20 namespace imstk
21 {
28 {
29 public:
31  std::shared_ptr<vega::VolumetricMesh> mesh,
32  const double inversionThreshold,
33  const bool withGravity = true,
34  const double gravity = 10.0);
36  ~IsotropicHyperelasticFeForceModel() override = default;
37 
41  inline void getInternalForce(const Vectord& u, Vectord& internalForce) override
42  {
43  double* data = const_cast<double*>(u.data());
44  m_isotropicHyperelasticFem->ComputeForces(data, internalForce.data());
45  }
46 
50  inline void getTangentStiffnessMatrix(const Vectord& u, SparseMatrixd& tangentStiffnessMatrix) override
51  {
52  double* data = const_cast<double*>(u.data());
53  m_isotropicHyperelasticFem->GetTangentStiffnessMatrix(data, m_vegaTangentStiffnessMatrix.get());
54  InternalForceModel::updateValuesFromMatrix(m_vegaTangentStiffnessMatrix, tangentStiffnessMatrix.valuePtr());
55  }
56 
60  inline void getTangentStiffnessMatrixTopology(vega::SparseMatrix** tangentStiffnessMatrix) override
61  {
62  m_isotropicHyperelasticFem->GetStiffnessMatrixTopology(tangentStiffnessMatrix);
63  }
64 
68  inline void getForceAndMatrix(const Vectord& u, Vectord& internalForce, SparseMatrixd& tangentStiffnessMatrix) override
69  {
70  double* data = const_cast<double*>(u.data());
71  m_isotropicHyperelasticFem->GetForceAndTangentStiffnessMatrix(data, internalForce.data(), m_vegaTangentStiffnessMatrix.get());
72  InternalForceModel::updateValuesFromMatrix(m_vegaTangentStiffnessMatrix, tangentStiffnessMatrix.valuePtr());
73  }
74 
78  inline void setTangentStiffness(std::shared_ptr<vega::SparseMatrix> K) override
79  {
80  m_vegaTangentStiffnessMatrix = K;
81  }
82 
83 protected:
84  std::shared_ptr<vega::IsotropicHyperelasticFEM> m_isotropicHyperelasticFem;
85  std::shared_ptr<vega::IsotropicMaterial> m_isotropicMaterial;
86  std::shared_ptr<vega::SparseMatrix> m_vegaTangentStiffnessMatrix;
87 };
88 } // namespace imstk
Compound Geometry.
void getTangentStiffnessMatrix(const Vectord &u, SparseMatrixd &tangentStiffnessMatrix) override
Get the tangent stiffness matrix.
Force model for the isotropic hyperelastic material.
void getTangentStiffnessMatrixTopology(vega::SparseMatrix **tangentStiffnessMatrix) override
Get the tangent stiffness matrix topology.
Base class for internal force model within the following context.
void getForceAndMatrix(const Vectord &u, Vectord &internalForce, SparseMatrixd &tangentStiffnessMatrix) override
Get the tangent stiffness matrix and internal force.
void getInternalForce(const Vectord &u, Vectord &internalForce) override
Get the internal force.
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...
void setTangentStiffness(std::shared_ptr< vega::SparseMatrix > K) override
Set the tangent stiffness matrix.