-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathHyperReducedTetrahedronFEMForceField.h
More file actions
165 lines (120 loc) · 7.74 KB
/
HyperReducedTetrahedronFEMForceField.h
File metadata and controls
165 lines (120 loc) · 7.74 KB
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
/******************************************************************************
* Model Order Reduction plugin for SOFA *
* version 1.0 *
* Copyright © Inria *
* All rights reserved *
* 2018 *
* *
* This software is under the GNU General Public License v2 (GPLv2) *
* https://www.gnu.org/licenses/licenses.en.html *
* *
* *
* *
* Authors: Olivier Goury, Felix Vanneste *
* *
* Contact information: https://project.inria.fr/modelorderreduction/contact *
******************************************************************************/
#pragma once
#include <ModelOrderReduction/config.h>
#include <ModelOrderReduction/component/forcefield/HyperReducedHelper.h>
#include <sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.h>
#define SIMPLEFEM_COLORMAP
#define SOFAHYPERREDUCEDTETRAHEDRONFEMFORCEFIELD_COLORMAP
#include <sofa/helper/ColorMap.h>
namespace sofa::component::forcefield
{
namespace {
using sofa::component::solidmechanics::fem::elastic::TetrahedronFEMForceField;
}
/** This forceField is the HyperReduced version of TetrahedronFEMForceField.
* At the moment, it is only implemented for the "large" method (i.e not for small, polar or svd).
*/
template<class DataTypes>
class HyperReducedTetrahedronFEMForceField : public virtual TetrahedronFEMForceField<DataTypes>, public modelorderreduction::HyperReducedHelper
{
public:
SOFA_CLASS2(SOFA_TEMPLATE(HyperReducedTetrahedronFEMForceField, DataTypes), SOFA_TEMPLATE(TetrahedronFEMForceField, DataTypes), HyperReducedHelper);
typedef typename core::behavior::ForceField<DataTypes> InheritForceField;
typedef typename DataTypes::VecCoord VecCoord;
typedef typename DataTypes::VecDeriv VecDeriv;
typedef typename DataTypes::VecReal VecReal;
typedef VecCoord Vector;
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 sofa::Index Index;
typedef core::topology::BaseMeshTopology::Tetra Element;
typedef core::topology::BaseMeshTopology::SeqTetrahedra VecElement;
typedef core::topology::BaseMeshTopology::Tetrahedron Tetrahedron;
using index_type = sofa::Index;
enum { SMALL = 0, ///< Symbol of small displacements tetrahedron solver
LARGE = 1, ///< Symbol of corotational large displacements tetrahedron solver based on a QR decomposition -> Nesme et al 2005 "Efficient, Physically Plausible Finite Elements"
POLAR = 2, ///< Symbol of corotational large displacements tetrahedron solver based on a polar decomposition -> Muller et al 2004 "Interactive Virtual Materials"
SVD = 3 ///< Symbol of corotational large displacements tetrahedron solver based on a SVD decomposition -> inspired from Irving et al 2004 "Invertible Finite Element for Robust Simulation of Large Deformation"
};
protected:
/// @name Per element (tetrahedron) data
/// @{
/// Displacement vector (deformation of the 4 corners of a tetrahedron
typedef type::VecNoInit<12, Real> Displacement;
/// Material stiffness matrix of a tetrahedron
typedef type::Mat<6, 6, Real> MaterialStiffness;
/// Strain-displacement matrix
typedef type::Mat<12, 6, Real> StrainDisplacement;
type::MatNoInit<3, 3, Real> R0;
/// Rigid transformation (rotation) matrix
typedef type::MatNoInit<3, 3, Real> Transformation;
/// Stiffness matrix ( = RJKJtRt with K the Material stiffness matrix, J the strain-displacement matrix, and R the transformation matrix if any )
typedef type::Mat<12, 12, Real> StiffnessMatrix;
/// Symmetrical tensor written as a vector following the Voigt notation
typedef type::VecNoInit<6,Real> VoigtTensor;
/// @}
/// Vector of material stiffness of each tetrahedron
typedef type::vector<MaterialStiffness> VecMaterialStiffness;
typedef type::vector<StrainDisplacement> VecStrainDisplacement; ///< a vector of strain-displacement matrices
/// structures used to compute vonMises stress
typedef type::Mat<4, 4, Real> Mat44;
typedef type::Mat<3, 3, Real> Mat33;
typedef type::Mat<4, 3, Real> Mat43;
/// Vector of material stiffness matrices of each tetrahedron
using TetrahedronFEMForceField<DataTypes>::materialsStiffnesses;
using TetrahedronFEMForceField<DataTypes>::strainDisplacements; ///< the strain-displacement matrices vector
using TetrahedronFEMForceField<DataTypes>::rotations;
using TetrahedronFEMForceField<DataTypes>::_plasticStrains; ///< one plastic strain per element
using TetrahedronFEMForceField<DataTypes>::d_showVonMisesStressPerElement;
/// @name Full system matrix assembly support
/// @{
typedef std::pair<index_type,Real> Col_Value;
typedef type::vector< Col_Value > CompressedValue;
typedef type::vector< CompressedValue > CompressedMatrix;
/// @}
public:
virtual void init() override;
virtual void addForce(const core::MechanicalParams* mparams, DataVecDeriv& d_f, const DataVecCoord& d_x, const DataVecDeriv& d_v) override;
virtual void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& d_df, const DataVecDeriv& d_dx) override;
// Make other overloaded version of getPotentialEnergy() to show up in subclass.
using TetrahedronFEMForceField<DataTypes>::getPotentialEnergy;
virtual void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override;
void draw(const core::visual::VisualParams* vparams) override;
protected:
////////////// small displacements method
void accumulateForceSmall( Vector& f, const Vector & p, typename VecElement::const_iterator elementIt, Index elementIndex );
void applyStiffnessSmall( Vector& f, const Vector& x, int i=0, Index a=0,Index b=1,Index c=2,Index d=3, SReal fact=1.0 );
////////////// large displacements method
using TetrahedronFEMForceField<DataTypes>::_rotatedInitialElements; ///< The initials positions in its frame
using TetrahedronFEMForceField<DataTypes>::_initialRotations;
void accumulateForceLarge( Vector& f, const Vector & p, typename VecElement::const_iterator elementIt, Index elementIndex );
////////////// polar decomposition method
using TetrahedronFEMForceField<DataTypes>::_rotationIdx;
void accumulateForcePolar( Vector& f, const Vector & p, typename VecElement::const_iterator elementIt, Index elementIndex );
////////////// svd decomposition method
using TetrahedronFEMForceField<DataTypes>::_initialTransformation;
void accumulateForceSVD( Vector& f, const Vector & p, typename VecElement::const_iterator elementIt, Index elementIndex );
void applyStiffnessCorotational( Vector& f, const Vector& x, int i=0, Index a=0,Index b=1,Index c=2,Index d=3, SReal fact=1.0 );
};
#if !defined(SOFA_COMPONENT_FORCEFIELD_HYPERREDUCEDTETRAHEDRONFEMFORCEFIELD_CPP)
extern template class SOFA_MODELORDERREDUCTION_API HyperReducedTetrahedronFEMForceField<defaulttype::Vec3Types>;
#endif
} // namespace sofa::component::forcefield