Skip to content

Commit 295b51e

Browse files
authored
Merge pull request #20 from EulalieCoevoet/pr_changeforcefieldinheritence
[forcefield] TriangularShellForceField: changes inheritance
2 parents 9c679fd + 7d0e943 commit 295b51e

3 files changed

Lines changed: 22 additions & 20 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ sofa_find_package(Sofa.Component.Controller REQUIRED)
77
sofa_find_package(Sofa.Component.Topology.Container.Dynamic REQUIRED)
88
sofa_find_package(Sofa.Component.StateContainer REQUIRED)
99
sofa_find_package(Sofa.Component.Mapping.Linear REQUIRED)
10+
sofa_find_package(Sofa.Component.SolidMechanics.FEM.Elastic REQUIRED)
1011
sofa_find_package(Sofa.GL REQUIRED)
1112

1213
set(README_FILE README.md)
@@ -77,6 +78,7 @@ target_link_libraries(${PROJECT_NAME}
7778
Sofa.Component.Topology.Container.Dynamic
7879
Sofa.Component.StateContainer
7980
Sofa.Component.Mapping.Linear
81+
Sofa.Component.SolidMechanics.FEM.Elastic
8082
Sofa.GL
8183
)
8284

src/Shell/forcefield/TriangularShellForceField.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#endif
3131

3232

33-
#include <sofa/core/behavior/ForceField.h>
33+
#include <sofa/component/solidmechanics/fem/elastic/BaseLinearElasticityFEMForceField.h>
3434
#include <sofa/core/behavior/MechanicalState.h>
3535
#include <sofa/core/objectmodel/Data.h>
3636
#include <sofa/helper/OptionsGroup.h>
@@ -57,7 +57,7 @@ namespace forcefield
5757
using namespace sofa::type;
5858
using sofa::type::vector;
5959
using namespace sofa::core::topology;
60-
using namespace sofa::core::behavior;
60+
using namespace sofa::component::solidmechanics::fem::elastic;
6161

6262
/// This class can be overridden if needed for additional storage within template specializations.
6363
template<class DataTypes>
@@ -68,14 +68,14 @@ class TriangularShellForceFieldInternalData
6868

6969

7070
template<class DataTypes>
71-
class TriangularShellForceField : public core::behavior::ForceField<DataTypes>
71+
class TriangularShellForceField : public BaseLinearElasticityFEMForceField<DataTypes>
7272
{
7373
public:
74-
SOFA_CLASS(SOFA_TEMPLATE(TriangularShellForceField,DataTypes), SOFA_TEMPLATE(core::behavior::ForceField,DataTypes));
74+
SOFA_CLASS(SOFA_TEMPLATE(TriangularShellForceField,DataTypes), SOFA_TEMPLATE(BaseLinearElasticityFEMForceField,DataTypes));
7575

76-
typedef core::behavior::ForceField<DataTypes> Inherited;
77-
typedef typename DataTypes::VecCoord VecCoord;
78-
typedef typename DataTypes::VecDeriv VecDeriv;
76+
typedef BaseLinearElasticityFEMForceField<DataTypes> Inherited;
77+
typedef typename DataTypes::VecCoord VecCoord;
78+
typedef typename DataTypes::VecDeriv VecDeriv;
7979
//typedef typename DataTypes::VecReal VecReal;
8080

8181
typedef typename DataTypes::Coord Coord;
@@ -206,8 +206,9 @@ class TriangularShellForceField : public core::behavior::ForceField<DataTypes>
206206

207207
sofa::core::topology::BaseMeshTopology* getTopology() {return _topology;}
208208

209-
Data<Real> d_poisson;
210-
Data<Real> d_young;
209+
using BaseLinearElasticityFEMForceField<DataTypes>::getYoungModulusInElement;
210+
using BaseLinearElasticityFEMForceField<DataTypes>::getPoissonRatioInElement;
211+
211212
Data <Real> d_thickness;
212213
Data <sofa::helper::OptionsGroup> d_membraneElement;
213214
Data <sofa::helper::OptionsGroup> d_bendingElement;

src/Shell/forcefield/TriangularShellForceField.inl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ void TriangularShellForceField<DataTypes>::TRQSTriangleHandler::applyCreateFunct
7373
// --------------------------------------------------------------------------------------
7474
template <class DataTypes>
7575
TriangularShellForceField<DataTypes>::TriangularShellForceField()
76-
: d_poisson(initData(&d_poisson,(Real)0.45,"poissonRatio","Poisson ratio in Hooke's law"))
77-
, d_young(initData(&d_young,(Real)3000.,"youngModulus","Young modulus in Hooke's law"))
78-
, d_thickness(initData(&d_thickness,(Real)0.1,"thickness","Thickness of the plates"))
76+
: d_thickness(initData(&d_thickness,(Real)0.1,"thickness","Thickness of the plates"))
7977
, d_membraneElement(initData(&d_membraneElement, "membraneElement", "The membrane element to use"))
8078
, d_bendingElement(initData(&d_bendingElement, "bendingElement", "The bending plate element to use"))
8179
, d_corotated(initData(&d_corotated, true, "corotated", "Compute forces in corotational frame"))
@@ -543,8 +541,8 @@ void TriangularShellForceField<DataTypes>::computeRotation(Transformation& R, co
543541
template <class DataTypes>
544542
void TriangularShellForceField<DataTypes>::computeMaterialStiffness()
545543
{
546-
Real E = d_young.getValue(),
547-
nu = d_poisson.getValue(),
544+
Real E = getYoungModulusInElement(0),
545+
nu = getPoissonRatioInElement(0),
548546
t = d_thickness.getValue();
549547

550548
materialMatrix[0][0] = 1.0;
@@ -1131,34 +1129,35 @@ void TriangularShellForceField<DataTypes>::andesTemplate(StiffnessMatrix &K, con
11311129
template <class DataTypes>
11321130
void TriangularShellForceField<DataTypes>::computeStiffnessMatrixAll3I(StiffnessMatrix &K, TriangleInformation &tinfo)
11331131
{
1134-
return andesTemplate(K, tinfo, 1.0, AndesBeta(4.0/9.0, 1.0/12.0, 5.0/12.0, 1.0/2.0, 0.0, 1.0/3.0, -1.0/3.0, -1.0/12.0, -1.0/2.0, -5.0/12.0));
1132+
return andesTemplate(K, tinfo, 1.0, AndesBeta{4.0/9.0, 1.0/12.0, 5.0/12.0, 1.0/2.0, 0.0, 1.0/3.0, -1.0/3.0, -1.0/12.0, -1.0/2.0, -5.0/12.0});
11351133
}
11361134

11371135
template <class DataTypes>
11381136
void TriangularShellForceField<DataTypes>::computeStiffnessMatrixAll3M(StiffnessMatrix &K, TriangleInformation &tinfo)
11391137
{
1140-
return andesTemplate(K, tinfo, 1.0, AndesBeta(4.0/9.0, 1.0/4.0, 5.0/4.0, 3.0/2.0, 0.0, 1.0, -1.0, -1.0/4.0, -3.0/2.0, -5.0/4.0));
1138+
return andesTemplate(K, tinfo, 1.0, AndesBeta{4.0/9.0, 1.0/4.0, 5.0/4.0, 3.0/2.0, 0.0, 1.0, -1.0, -1.0/4.0, -3.0/2.0, -5.0/4.0});
11411139
}
11421140

11431141
template <class DataTypes>
11441142
void TriangularShellForceField<DataTypes>::computeStiffnessMatrixAllLS(StiffnessMatrix &K, TriangleInformation &tinfo)
11451143
{
1146-
return andesTemplate(K, tinfo, 1.0, AndesBeta(4.0/9.0, 3.0/20.0, 3.0/4.0, 9.0/10.0, 0.0, 3.0/5.0, -3.0/5.0, -3.0/20.0, -9.0/10.0, -3.0/4.0));
1144+
return andesTemplate(K, tinfo, 1.0, AndesBeta{4.0/9.0, 3.0/20.0, 3.0/4.0, 9.0/10.0, 0.0, 3.0/5.0, -3.0/5.0, -3.0/20.0, -9.0/10.0, -3.0/4.0});
11471145
}
11481146

11491147
template <class DataTypes>
11501148
void TriangularShellForceField<DataTypes>::computeStiffnessMatrixLSTRet(StiffnessMatrix &K, TriangleInformation &tinfo)
11511149
{
1152-
return andesTemplate(K, tinfo, 4.0/3.0, AndesBeta(1.0/2.0, 2.0/3.0, -2.0/3.0, 0.0, 0.0, -4.0/3.0, 4.0/3.0, -2.0/3.0, 0.0, 2.0/3.0));
1150+
return andesTemplate(K, tinfo, 4.0/3.0, AndesBeta{1.0/2.0, 2.0/3.0, -2.0/3.0, 0.0, 0.0, -4.0/3.0, 4.0/3.0, -2.0/3.0, 0.0, 2.0/3.0});
11531151
}
11541152

11551153
// Optimal ANDES membrane element
11561154
// See: C. A. Felippa, A study of optimal membrane triangles with drilling freedoms, 2003
11571155
template <class DataTypes>
11581156
void TriangularShellForceField<DataTypes>::computeStiffnessMatrixAndesOpt(StiffnessMatrix &K, TriangleInformation &tinfo)
11591157
{
1160-
Real beta0 = helper::rmax(0.5 - 2.0*d_poisson.getValue()*d_poisson.getValue(), 0.01);
1161-
return andesTemplate(K, tinfo, 3.0/2.0, AndesBeta(beta0, 1.0, 2.0, 1.0, 0.0, 1.0, -1.0, -1.0, -1.0, -2.0));
1158+
Real poissonRatio = getPoissonRatioInElement(0);
1159+
Real beta0 = helper::rmax(0.5 - 2.0 * poissonRatio * poissonRatio, 0.01);
1160+
return andesTemplate(K, tinfo, 3.0/2.0, AndesBeta{beta0, 1.0, 2.0, 1.0, 0.0, 1.0, -1.0, -1.0, -1.0, -2.0});
11621161
}
11631162

11641163
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

0 commit comments

Comments
 (0)