iMSTK
Interactive Medical Simulation Toolkit
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
imstkLinearFemForceModel.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 "imstkLinearFemForceModel.h"
8 
9 #include "imstkMacros.h"
10 
11 DISABLE_WARNING_PUSH
12  DISABLE_WARNING_HIDES_CLASS_MEMBER
13 
14 #include <StVKElementABCDLoader.h>
15 #include <StVKStiffnessMatrix.h>
16 #include <tetMesh.h>
17 
18 DISABLE_WARNING_POP
19 
20 namespace imstk
21 {
22 LinearFemForceModel::LinearFemForceModel(std::shared_ptr<vega::VolumetricMesh> mesh,
23  const bool withGravity, const double gravity) : InternalForceModel()
24 {
25  auto tetMesh = std::dynamic_pointer_cast<vega::TetMesh>(mesh);
26 
27  vega::StVKElementABCD* precomputedIntegrals = vega::StVKElementABCDLoader::load(tetMesh.get());
28  m_stVKInternalForces = std::make_shared<vega::StVKInternalForces>(tetMesh.get(), precomputedIntegrals, withGravity, gravity);
29 
30  auto stVKStiffnessMatrix = std::make_shared<vega::StVKStiffnessMatrix>(m_stVKInternalForces.get());
31 
32  stVKStiffnessMatrix->GetStiffnessMatrixTopology(&m_stiffnessMatrixRawPtr);
33  std::shared_ptr<vega::SparseMatrix> m_stiffnessMatrix2(m_stiffnessMatrixRawPtr);
34  m_stiffnessMatrix = m_stiffnessMatrix2;
35 
36  auto K = m_stiffnessMatrix.get();
37  stVKStiffnessMatrix->GetStiffnessMatrixTopology(&K);
38  double* zero = (double*)calloc(m_stiffnessMatrix->GetNumRows(), sizeof(double));
39  stVKStiffnessMatrix->ComputeStiffnessMatrix(zero, m_stiffnessMatrix.get());
40  free(zero);
41 };
42 
43 LinearFemForceModel::~LinearFemForceModel()
44 {
45  if (m_stiffnessMatrixRawPtr)
46  {
47  delete m_stiffnessMatrixRawPtr;
48  }
49 }
50 } // namespace imstk
Compound Geometry.