-
Notifications
You must be signed in to change notification settings - Fork 297
/
TetrahedronHyperelasticityFEMForceField.h
200 lines (152 loc) · 8.77 KB
/
TetrahedronHyperelasticityFEMForceField.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#pragma once
#include <sofa/component/solidmechanics/fem/hyperelastic/config.h>
#include <sofa/component/solidmechanics/fem/hyperelastic/material/HyperelasticMaterial.h>
#include <sofa/core/behavior/ForceField.h>
#include <sofa/type/Mat.h>
#include <sofa/type/MatSym.h>
#include <sofa/core/topology/BaseMeshTopology.h>
#include <sofa/core/topology/TopologyData.h>
namespace sofa::component::solidmechanics::fem::hyperelastic
{
using namespace sofa::type;
using namespace sofa::defaulttype;
using namespace sofa::core::topology;
//***************** Tetrahedron FEM code for several elastic models: TotalLagrangianForceField************************//
/** Compute Finite Element forces based on tetrahedral elements.
*/
template<class DataTypes>
class TetrahedronHyperelasticityFEMForceField : public core::behavior::ForceField<DataTypes>
{
public:
SOFA_CLASS(SOFA_TEMPLATE(TetrahedronHyperelasticityFEMForceField, DataTypes), SOFA_TEMPLATE(core::behavior::ForceField, DataTypes));
typedef core::behavior::ForceField<DataTypes> Inherited;
typedef typename DataTypes::VecCoord VecCoord;
typedef typename DataTypes::VecDeriv VecDeriv;
typedef typename DataTypes::Coord Coord;
typedef typename DataTypes::Deriv Deriv;
typedef typename Coord::value_type Real;
typedef core::objectmodel::Data<VecDeriv> DataVecDeriv;
typedef core::objectmodel::Data<VecCoord> DataVecCoord;
typedef Mat<3,3,Real> Matrix3;
typedef MatSym<3,Real> MatrixSym;
typedef std::pair<MatrixSym,MatrixSym> MatrixPair;
typedef std::pair<Real,MatrixSym> MatrixCoeffPair;
typedef type::vector<Real> SetParameterArray;
typedef type::vector<Coord> SetAnisotropyDirectionArray;
typedef core::topology::BaseMeshTopology::Index Index;
typedef core::topology::BaseMeshTopology::Tetra Element;
typedef core::topology::BaseMeshTopology::SeqTetrahedra VecElement;
typedef sofa::core::topology::Topology::Tetrahedron Tetrahedron;
typedef sofa::core::topology::Topology::TetraID TetraID;
typedef sofa::core::topology::Topology::Tetra Tetra;
typedef sofa::core::topology::Topology::Edge Edge;
typedef sofa::core::topology::BaseMeshTopology::EdgesInTriangle EdgesInTriangle;
typedef sofa::core::topology::BaseMeshTopology::EdgesInTetrahedron EdgesInTetrahedron;
typedef sofa::core::topology::BaseMeshTopology::TrianglesInTetrahedron TrianglesInTetrahedron;
material::MaterialParameters<DataTypes> globalParameters;
/// data structure stored for each tetrahedron
class TetrahedronRestInformation : public material::StrainInformation<DataTypes>
{
public:
/// shape vector at the rest configuration
Coord m_shapeVector[4];
/// fiber direction in rest configuration
Coord m_fiberDirection;
/// rest volume
Real m_restVolume{};
/// current tetrahedron volume
Real m_volScale{};
Real m_volume{};
/// volume/ restVolume
MatrixSym m_SPKTensorGeneral;
/// deformation gradient = gradPhi
Matrix3 m_deformationGradient;
/// right Cauchy-Green deformation tensor C (gradPhi^T gradPhi)
Real m_strainEnergy{};
/// Output stream
inline friend std::ostream& operator<< ( std::ostream& os, const TetrahedronRestInformation& /*eri*/ ) { return os; }
/// Input stream
inline friend std::istream& operator>> ( std::istream& in, TetrahedronRestInformation& /*eri*/ ) { return in; }
TetrahedronRestInformation() = default;
};
/// data structure stored for each edge
class EdgeInformation
{
public:
/// store the stiffness edge matrix
Matrix3 DfDx;
/// Output stream
inline friend std::ostream& operator<< (std::ostream& os, const EdgeInformation& /*eri*/ ) { return os; }
/// Input stream
inline friend std::istream& operator>> (std::istream& in, EdgeInformation& /*eri*/ ) { return in; }
EdgeInformation() = default;
};
protected :
core::topology::BaseMeshTopology* m_topology;
VecCoord m_initialPoints; /// the intial positions of the points
bool m_updateMatrix;
public:
Data<bool> d_stiffnessMatrixRegularizationWeight; ///< Regularization of the Stiffness Matrix (between true or false)
Data<std::string> d_materialName; ///< the name of the material
Data<SetParameterArray> d_parameterSet; ///< The global parameters specifying the material
Data<SetAnisotropyDirectionArray> d_anisotropySet; ///< The global directions of anisotropy of the material
TetrahedronData<sofa::type::vector<TetrahedronRestInformation> > m_tetrahedronInfo; ///< Internal tetrahedron data
EdgeData<sofa::type::vector<EdgeInformation> > m_edgeInfo; ///< Internal edge data
/// Link to be set to the topology container in the component graph.
SingleLink<TetrahedronHyperelasticityFEMForceField<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;
void setMaterialName(std::string materialName);
void setparameter(const SetParameterArray& param);
void setdirection(const SetAnisotropyDirectionArray& direction);
/**
* Method to initialize @sa TetrahedronRestInformation when a new Tetrahedron is created.
* Will be set as creation callback in the TetrahedronData @sa m_tetrahedronInfo
*/
void createTetrahedronRestInformation(Index, TetrahedronRestInformation& t, const Tetrahedron&,
const sofa::type::vector<Index>&, const sofa::type::vector<SReal>&);
protected:
TetrahedronHyperelasticityFEMForceField();
~TetrahedronHyperelasticityFEMForceField() override;
public:
void init() override;
void addForce(const core::MechanicalParams* mparams /* PARAMS FIRST */, DataVecDeriv& d_f, const DataVecCoord& d_x, const DataVecDeriv& d_v) override;
void addDForce(const core::MechanicalParams* mparams /* PARAMS FIRST */, DataVecDeriv& d_df, const DataVecDeriv& d_dx) override;
SReal getPotentialEnergy(const core::MechanicalParams*, const DataVecCoord&) const override;
using Inherit1::addKToMatrix;
void addKToMatrix(sofa::linearalgebra::BaseMatrix *mat, SReal k, unsigned int &offset) override;
void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override;
void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final;
void draw(const core::visual::VisualParams* vparams) override;
void computeBBox(const core::ExecParams* params, bool onlyVisible) override;
Mat<3,3, SReal> getPhi( int tetrahedronIndex);
protected:
/// the array that describes the complete material energy and its derivatives
std::unique_ptr<material::HyperelasticMaterial<DataTypes> > m_myMaterial;
void testDerivatives();
void updateTangentMatrix();
void instantiateMaterial();
};
#if !defined(SOFA_COMPONENT_FORCEFIELD_TETRAHEDRONHYPERELASTICITYFEMFORCEFIELD_CPP)
extern template class SOFA_COMPONENT_SOLIDMECHANICS_FEM_HYPERELASTIC_API TetrahedronHyperelasticityFEMForceField<defaulttype::Vec3Types>;
#endif // !defined(SOFA_COMPONENT_FORCEFIELD_TETRAHEDRONHYPERELASTICITYFEMFORCEFIELD_CPP)
} // namespace sofa::component::solidmechanics::fem::hyperelastic