Skip to content
Snippets Groups Projects
Commit 5048e8a8 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

STYLE: Move force models impl. to ccp files

Move force models implementation to ccp files
parent 73798d0f
No related branches found
No related tags found
No related merge requests found
Showing
with 230 additions and 86 deletions
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
#include "imstkCorotationalFEMForceModel.h"
namespace imstk
{
CorotationalFEMForceModel::CorotationalFEMForceModel(std::shared_ptr<vega::VolumetricMesh> mesh, const int warp) : InternalForceModel(), m_warp(warp)
{
auto tetMesh = std::dynamic_pointer_cast<vega::TetMesh>(mesh);
m_corotationalLinearFEM = std::make_shared<vega::CorotationalLinearFEM>(tetMesh.get());
}
void
CorotationalFEMForceModel::getInternalForce(const Vectord& u, Vectord& internalForce)
{
double *data = const_cast<double*>(u.data());
m_corotationalLinearFEM->ComputeForceAndStiffnessMatrix(data, internalForce.data(), nullptr, m_warp);
}
void
CorotationalFEMForceModel::getTangentStiffnessMatrix(const Vectord& u, SparseMatrixd& tangentStiffnessMatrix)
{
double *data = const_cast<double*>(u.data());
m_corotationalLinearFEM->ComputeForceAndStiffnessMatrix(data, nullptr, m_vegaTangentStiffnessMatrix.get(), m_warp);
InternalForceModel::updateValuesFromMatrix(m_vegaTangentStiffnessMatrix, tangentStiffnessMatrix.valuePtr());
}
void
CorotationalFEMForceModel::getTangentStiffnessMatrixTopology(vega::SparseMatrix** tangentStiffnessMatrix)
{
m_corotationalLinearFEM->GetStiffnessMatrixTopology(tangentStiffnessMatrix);
}
void
CorotationalFEMForceModel::GetForceAndMatrix(const Vectord& u, Vectord& internalForce, SparseMatrixd& tangentStiffnessMatrix)
{
double *data = const_cast<double*>(u.data());
m_corotationalLinearFEM->ComputeForceAndStiffnessMatrix(data, internalForce.data(), m_vegaTangentStiffnessMatrix.get(), m_warp);
InternalForceModel::updateValuesFromMatrix(m_vegaTangentStiffnessMatrix, tangentStiffnessMatrix.valuePtr());
}
void
CorotationalFEMForceModel::SetWarp(const int warp)
{
this->m_warp = warp;
}
void
CorotationalFEMForceModel::setTangentStiffness(std::shared_ptr<vega::SparseMatrix> K)
{
m_vegaTangentStiffnessMatrix = K;
}
}
\ No newline at end of file
......@@ -26,6 +26,7 @@
#include "g3log/g3log.hpp"
//imstk
#include "imstkInternalForceModel.h"
//vega
......@@ -37,51 +38,46 @@ namespace imstk
class CorotationalFEMForceModel : public InternalForceModel
{
public:
CorotationalFEMForceModel(std::shared_ptr<vega::VolumetricMesh> mesh, int warp = 1) : InternalForceModel()
{
auto tetMesh = std::dynamic_pointer_cast<vega::TetMesh>(mesh);
m_corotationalLinearFEM = std::make_shared<vega::CorotationalLinearFEM>(tetMesh.get());
m_warp = warp;
}
///
/// \brief
///
CorotationalFEMForceModel(std::shared_ptr<vega::VolumetricMesh> mesh, const int warp = 1);
CorotationalFEMForceModel() = delete;
virtual ~CorotationalFEMForceModel(){};
void getInternalForce(const Vectord& u, Vectord& internalForce)
{
double *data = const_cast<double*>(u.data());
m_corotationalLinearFEM->ComputeForceAndStiffnessMatrix(data, internalForce.data(), nullptr, m_warp);
}
void getTangentStiffnessMatrix(const Vectord& u, SparseMatrixd& tangentStiffnessMatrix)
{
double *data = const_cast<double*>(u.data());
m_corotationalLinearFEM->ComputeForceAndStiffnessMatrix(data, nullptr, m_vegaTangentStiffnessMatrix.get(), m_warp);
InternalForceModel::updateValuesFromMatrix(m_vegaTangentStiffnessMatrix, tangentStiffnessMatrix.valuePtr());
}
virtual void getTangentStiffnessMatrixTopology(vega::SparseMatrix** tangentStiffnessMatrix)
{
m_corotationalLinearFEM->GetStiffnessMatrixTopology(tangentStiffnessMatrix);
}
void GetForceAndMatrix(const Vectord& u, Vectord& internalForce, SparseMatrixd& tangentStiffnessMatrix)
{
double *data = const_cast<double*>(u.data());
m_corotationalLinearFEM->ComputeForceAndStiffnessMatrix(data, internalForce.data(), m_vegaTangentStiffnessMatrix.get(), m_warp);
InternalForceModel::updateValuesFromMatrix(m_vegaTangentStiffnessMatrix, tangentStiffnessMatrix.valuePtr());
}
void SetWarp(const int warp)
{
this->m_warp = warp;
}
virtual void setTangentStiffness(std::shared_ptr<vega::SparseMatrix> K) override
{
m_vegaTangentStiffnessMatrix = K;
}
///
/// \brief
///
virtual ~CorotationalFEMForceModel() = default;
///
/// \brief
///
void getInternalForce(const Vectord& u, Vectord& internalForce);
///
/// \brief
///
void getTangentStiffnessMatrix(const Vectord& u, SparseMatrixd& tangentStiffnessMatrix);
///
/// \brief
///
virtual void getTangentStiffnessMatrixTopology(vega::SparseMatrix** tangentStiffnessMatrix);
///
/// \brief
///
void GetForceAndMatrix(const Vectord& u, Vectord& internalForce, SparseMatrixd& tangentStiffnessMatrix);
///
/// \brief
///
void SetWarp(const int warp);
///
/// \brief
///
virtual void setTangentStiffness(std::shared_ptr<vega::SparseMatrix> K) override;
protected:
std::shared_ptr<vega::CorotationalLinearFEM> m_corotationalLinearFEM;
......
......@@ -24,6 +24,7 @@
#include "g3log/g3log.hpp"
//imstk
#include "imstkInternalForceModel.h"
#include "imstkMath.h"
......
......@@ -135,7 +135,7 @@ public:
///
/// \brief Destructor
///
~ForceModelConfig(){};
~ForceModelConfig() = default;
///
/// \brief Parse the deformable object config file
......
......@@ -50,7 +50,7 @@ public:
///
/// \brief Destructor
///
~InternalForceModel(){};
virtual ~InternalForceModel() = default;
///
/// \brief Get the internal force given the present state
......
......@@ -24,6 +24,7 @@
#include <g3log/g3log.hpp>
//imstk
#include "imstkInternalForceModel.h"
#include "imstkForceModelConfig.h"
......@@ -35,20 +36,21 @@
namespace imstk
{
class IsotropicHyperelasticFEForceModel : public InternalForceModel
{
public:
IsotropicHyperelasticFEForceModel(HyperElasticMaterialType materialType,
IsotropicHyperelasticFEForceModel(const HyperElasticMaterialType materialType,
std::shared_ptr<vega::VolumetricMesh> mesh,
double inversionThreshold,
bool withGravity = true,
double gravity = 10.0) : InternalForceModel()
const double inversionThreshold,
const bool withGravity = true,
const double gravity = 10.0) : InternalForceModel()
{
auto tetMesh = std::dynamic_pointer_cast<vega::TetMesh>(mesh);
int enableCompressionResistance = 1;
double compressionResistance = 500;
const int enableCompressionResistance = 1;
const double compressionResistance = 500;
switch (materialType)
{
case HyperElasticMaterialType::StVK:
......@@ -86,7 +88,7 @@ public:
IsotropicHyperelasticFEForceModel() = delete;
virtual ~IsotropicHyperelasticFEForceModel(){};
virtual ~IsotropicHyperelasticFEForceModel() = default;
void getInternalForce(const Vectord& u, Vectord& internalForce)
{
......
......@@ -26,6 +26,7 @@
#include "g3log/g3log.hpp"
//imstk
#include "imstkInternalForceModel.h"
//vega
......@@ -38,7 +39,9 @@ namespace imstk
class LinearFEMForceModel : public InternalForceModel
{
public:
LinearFEMForceModel(std::shared_ptr<vega::VolumetricMesh> mesh, bool withGravity = true, double gravity = -9.81) : InternalForceModel()
LinearFEMForceModel(std::shared_ptr<vega::VolumetricMesh> mesh,
const bool withGravity = true,
const double gravity = -9.81) : InternalForceModel()
{
auto tetMesh = std::dynamic_pointer_cast<vega::TetMesh>(mesh);
......@@ -53,7 +56,7 @@ public:
//delete(stVKStiffnessMatrix);
};
virtual ~LinearFEMForceModel(){};
virtual ~LinearFEMForceModel() = default;
void getInternalForce(const Vectord& u, Vectord& internalForce)
{
......
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
#include "imstkMassSpringForceModel.h"
namespace imstk
{
MassSpringForceModel::MassSpringForceModel(std::shared_ptr<vega::MassSpringSystem> massSpringSystem) : InternalForceModel()
{
m_massSpringSystem = massSpringSystem;
}
void
MassSpringForceModel::getInternalForce(const Vectord& u, Vectord& internalForce)
{
double *data = const_cast<double*>(u.data());
m_massSpringSystem->ComputeForce(data, internalForce.data());
}
virtual void
MassSpringForceModel::getTangentStiffnessMatrixTopology(vega::SparseMatrix** tangentStiffnessMatrix)
{
m_massSpringSystem->GetStiffnessMatrixTopology(tangentStiffnessMatrix);
}
void
MassSpringForceModel::getTangentStiffnessMatrix(const Vectord& u, SparseMatrixd& tangentStiffnessMatrix)
{
double *data = const_cast<double*>(u.data());
m_massSpringSystem->ComputeStiffnessMatrix(data, m_vegaTangentStiffnessMatrix.get());
InternalForceModel::updateValuesFromMatrix(m_vegaTangentStiffnessMatrix, tangentStiffnessMatrix.valuePtr());
}
} // imstk
#endif // imstkMassSpringForceModel_h
......@@ -32,33 +32,39 @@
namespace imstk
{
///
/// \class MassSpringForceModel
///
/// \brief Mathematical model for the MassSpring
///
class MassSpringForceModel : public InternalForceModel
{
public:
MassSpringForceModel(std::shared_ptr<vega::MassSpringSystem> massSpringSystem) : InternalForceModel()
{
m_massSpringSystem = massSpringSystem;
}
///
/// \brief
///
MassSpringForceModel(std::shared_ptr<vega::MassSpringSystem> massSpringSystem);
MassSpringForceModel() = delete;
virtual ~MassSpringForceModel(){};
void getInternalForce(const Vectord& u, Vectord& internalForce)
{
double *data = const_cast<double*>(u.data());
m_massSpringSystem->ComputeForce(data, internalForce.data());
}
virtual void getTangentStiffnessMatrixTopology(vega::SparseMatrix** tangentStiffnessMatrix)
{
m_massSpringSystem->GetStiffnessMatrixTopology(tangentStiffnessMatrix);
}
void getTangentStiffnessMatrix(const Vectord& u, SparseMatrixd& tangentStiffnessMatrix)
{
double *data = const_cast<double*>(u.data());
m_massSpringSystem->ComputeStiffnessMatrix(data, m_vegaTangentStiffnessMatrix.get());
InternalForceModel::updateValuesFromMatrix(m_vegaTangentStiffnessMatrix, tangentStiffnessMatrix.valuePtr());
}
///
/// \brief
///
virtual ~MassSpringForceModel() = default;
///
/// \brief
///
void getInternalForce(const Vectord& u, Vectord& internalForce);
///
/// \brief
///
virtual void getTangentStiffnessMatrixTopology(vega::SparseMatrix** tangentStiffnessMatrix);
///
/// \brief
///
void getTangentStiffnessMatrix(const Vectord& u, SparseMatrixd& tangentStiffnessMatrix);
protected:
std::shared_ptr<vega::MassSpringSystem> m_massSpringSystem;// Need to be initialized
......
......@@ -25,6 +25,7 @@
#include <memory>
#include "g3log/g3log.hpp"
//imstk
#include "imstkInternalForceModel.h"
//vega
......@@ -38,16 +39,16 @@ namespace imstk
class StVKForceModel : public InternalForceModel
{
public:
StVKForceModel(std::shared_ptr<vega::VolumetricMesh> mesh, bool withGravity = true, double gravity = 10.0) : InternalForceModel()
StVKForceModel(std::shared_ptr<vega::VolumetricMesh> mesh,
const bool withGravity = true,
const double gravity = 10.0) : InternalForceModel()
{
auto tetMesh = std::dynamic_pointer_cast<vega::TetMesh>(mesh);
m_stVKInternalForces = std::make_shared<vega::StVKInternalForces>(tetMesh.get(), nullptr, withGravity, gravity);
m_vegaStVKStiffnessMatrix = std::make_shared<vega::StVKStiffnessMatrix>(m_stVKInternalForces.get());
}
virtual ~StVKForceModel(){};
virtual ~StVKForceModel() = default;
void getInternalForce(const Vectord& u, Vectord& internalForce)
{
......
......@@ -23,7 +23,8 @@
#include <g3log/g3log.hpp>
namespace imstk {
namespace imstk
{
std::shared_ptr<InteractionPair>
CollisionGraph::addInteractionPair(CollidingObjectPtr A,
......@@ -136,4 +137,5 @@ CollisionGraph::getInteractionPairMap() const
{
return m_interactionPairMap;
}
}
......@@ -435,7 +435,7 @@ DeformableBodyModel::updatePhysicsGeometry()
{
auto volMesh = std::static_pointer_cast<VolumetricMesh>(m_forceModelGeometry);
auto u = m_currentState->getQ();
u.setConstant(1.0);//?
//u.setConstant(1.0);//?
volMesh->setVerticesDisplacements(u);
}
......
......@@ -197,6 +197,9 @@ public:
///
Vectord& getContactForce();
///
/// \brief
///
Vectord& getUnknownVec()
{
return m_qSol;
......
......@@ -69,7 +69,7 @@ SceneManager::runModule()
// Update the nonlinear solvers
for (auto nlSolvers : m_scene->getNonlinearSolvers())
{
//nlSolvers->solveSimple();
nlSolvers->solveSimple();
}
// Apply the geometry maps
......
......@@ -97,13 +97,13 @@ NewtonMethod::solveSimple()
// Compute norms, set tolerances and other temporaries
//double fnorm = this->m_nonLinearSystem->evaluateF(x).norm();
double stopTolerance = 1.0e-6;
const double stopTolerance = 1.0e-6;
this->linearSolver->setTolerance(stopTolerance);
//Vectord dx = x;
for (size_t i = 0; i < this->maxIterations; ++i)
for (size_t i = 0; i < 5; ++i) //this->maxIterations
{
/*if (fnorm < stopTolerance)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment