Skip to content

Commit a79c82a

Browse files
alxbilgerbakpaulfredroy
authored
[FEM] Refactor templates in latest FEM classes (#6124)
* [FEM] Refactor templates in latest FEM classes * Refactor also the mass * rename ElementCorotationalFEMForceField to CorotationalFEMForceField * rename ElementLinearSmallStrainFEMForceField to LinearSmallStrainFEMForceField * rename ElementFEMMass to FEMMass * [FEM] Refactor templates in latest FEM classes * Refactor also the mass * rename ElementCorotationalFEMForceField to CorotationalFEMForceField * rename ElementLinearSmallStrainFEMForceField to LinearSmallStrainFEMForceField * rename ElementFEMMass to FEMMass * adapt to CUDA * forgot some scenes * apply refactoring to Hexa2PrismTopologicalMapping.scn --------- Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Co-authored-by: Frederick Roy <froy@lnrobo.com> Co-authored-by: Frederick Roy <fredroy@users.noreply.github.com>
1 parent f34d9b5 commit a79c82a

63 files changed

Lines changed: 491 additions & 569 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Sofa/Component/Mass/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ project(Sofa.Component.Mass LANGUAGES CXX)
44
set(SOFACOMPONENTMASS_SOURCE_DIR "src/sofa/component/mass")
55

66
set(HEADER_FILES
7-
${SOFACOMPONENTMASS_SOURCE_DIR}/config.h.in
8-
${SOFACOMPONENTMASS_SOURCE_DIR}/init.h
97
${SOFACOMPONENTMASS_SOURCE_DIR}/AddMToMatrixFunctor.h
108
${SOFACOMPONENTMASS_SOURCE_DIR}/DiagonalMass.h
119
${SOFACOMPONENTMASS_SOURCE_DIR}/DiagonalMass.inl
12-
${SOFACOMPONENTMASS_SOURCE_DIR}/ElementFEMMass.h
13-
${SOFACOMPONENTMASS_SOURCE_DIR}/ElementFEMMass.inl
10+
${SOFACOMPONENTMASS_SOURCE_DIR}/FEMMass.h
11+
${SOFACOMPONENTMASS_SOURCE_DIR}/FEMMass.inl
1412
${SOFACOMPONENTMASS_SOURCE_DIR}/MassType.h
1513
${SOFACOMPONENTMASS_SOURCE_DIR}/MeshMatrixMass.h
1614
${SOFACOMPONENTMASS_SOURCE_DIR}/MeshMatrixMass.inl
@@ -19,12 +17,14 @@ set(HEADER_FILES
1917
${SOFACOMPONENTMASS_SOURCE_DIR}/UniformMass.h
2018
${SOFACOMPONENTMASS_SOURCE_DIR}/UniformMass.inl
2119
${SOFACOMPONENTMASS_SOURCE_DIR}/VecMassType.h
20+
${SOFACOMPONENTMASS_SOURCE_DIR}/config.h.in
21+
${SOFACOMPONENTMASS_SOURCE_DIR}/init.h
2222
)
2323

2424
set(SOURCE_FILES
2525
${SOFACOMPONENTMASS_SOURCE_DIR}/init.cpp
2626
${SOFACOMPONENTMASS_SOURCE_DIR}/DiagonalMass.cpp
27-
${SOFACOMPONENTMASS_SOURCE_DIR}/ElementFEMMass.cpp
27+
${SOFACOMPONENTMASS_SOURCE_DIR}/FEMMass.cpp
2828
${SOFACOMPONENTMASS_SOURCE_DIR}/MeshMatrixMass.cpp
2929
${SOFACOMPONENTMASS_SOURCE_DIR}/NodalMassDensity.cpp
3030
${SOFACOMPONENTMASS_SOURCE_DIR}/UniformMass.cpp

Sofa/Component/Mass/src/sofa/component/mass/ElementFEMMass.cpp

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/******************************************************************************
2+
* SOFA, Simulation Open-Framework Architecture *
3+
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Authors: The SOFA Team and external contributors (see Authors.txt) *
19+
* *
20+
* Contact information: contact@sofa-framework.org *
21+
******************************************************************************/
22+
#define SOFA_COMPONENT_MASS_FEMMASS_CPP
23+
#include <sofa/component/mass/FEMMass.inl>
24+
#include <sofa/core/ObjectFactory.h>
25+
#include <sofa/defaulttype/VecTypes.h>
26+
#include <sofa/fem/FiniteElement[all].h>
27+
28+
namespace sofa::component::mass
29+
{
30+
31+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec1Types, sofa::geometry::Edge>;
32+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec2Types, sofa::geometry::Edge>;
33+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Edge>;
34+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec2Types, sofa::geometry::Triangle>;
35+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Triangle>;
36+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec2Types, sofa::geometry::Quad>;
37+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Quad>;
38+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Tetrahedron>;
39+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Hexahedron>;
40+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Prism>;
41+
42+
void registerFEMMass(sofa::core::ObjectFactory* factory)
43+
{
44+
factory->registerObjects(sofa::core::ObjectRegistrationData("Finite-element mass (inertia and body force)")
45+
.add< FEMMass<sofa::defaulttype::Vec1Types, sofa::geometry::Edge> >()
46+
.add< FEMMass<sofa::defaulttype::Vec2Types, sofa::geometry::Edge> >()
47+
.add< FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Edge> >()
48+
.add< FEMMass<sofa::defaulttype::Vec2Types, sofa::geometry::Triangle> >()
49+
.add< FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Triangle> >()
50+
.add< FEMMass<sofa::defaulttype::Vec2Types, sofa::geometry::Quad> >()
51+
.add< FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Quad> >()
52+
.add< FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Tetrahedron> >()
53+
.add< FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Hexahedron> >()
54+
.add< FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Prism> >()
55+
);
56+
}
57+
58+
}

Sofa/Component/Mass/src/sofa/component/mass/ElementFEMMass.h renamed to Sofa/Component/Mass/src/sofa/component/mass/FEMMass.h

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace sofa::component::mass
3636
{
3737

3838
/**
39-
* @class ElementFEMMass
39+
* @class FEMMass
4040
* @brief Computes and stores the mass matrix for a finite element model.
4141
*
4242
* This class calculates the mass matrix for a given set of finite elements based on a nodal mass density field.
@@ -54,14 +54,14 @@ namespace sofa::component::mass
5454
* @tparam TElementType The type of finite element (e.g., sofa::geometry::Tetrahedron).
5555
*/
5656
template<class TDataTypes, class TElementType>
57-
class ElementFEMMass :
57+
class FEMMass :
5858
public core::behavior::Mass<TDataTypes>,
5959
public virtual sofa::core::behavior::TopologyAccessor
6060
{
6161
public:
6262
using DataTypes = TDataTypes;
6363
using ElementType = TElementType;
64-
SOFA_CLASS2(SOFA_TEMPLATE2(ElementFEMMass, DataTypes, ElementType),
64+
SOFA_CLASS2(SOFA_TEMPLATE2(FEMMass, DataTypes, ElementType),
6565
core::behavior::Mass<TDataTypes>,
6666
sofa::core::behavior::TopologyAccessor);
6767

@@ -80,31 +80,13 @@ class ElementFEMMass :
8080

8181
public:
8282

83-
/**
84-
* @brief Gets the class name according to the provided template parameters.
85-
*
86-
* For example, `ElementFEMMass<Vec3Types, sofa::geometry::Edge>` will return "EdgeFEMMass".
87-
*
88-
* @return A string representing the class name.
89-
*/
90-
static const std::string GetCustomClassName()
91-
{
92-
return std::string(sofa::geometry::elementTypeToString(ElementType::Element_type)) + "FEMMass";
93-
}
94-
95-
/**
96-
* @brief Gets the template name based on the data types.
97-
* @return A string representing the template name (e.g., "Vec3d").
98-
*/
99-
static const std::string GetCustomTemplateName() { return DataTypes::Name(); }
100-
10183
/**
10284
* @brief Link to the nodal mass density component.
10385
*
10486
* This component provides the mass density at each node of the mesh.
10587
* It must be present in the context for the mass to be calculated correctly.
10688
*/
107-
sofa::SingleLink<ElementFEMMass, NodalMassDensity,
89+
sofa::SingleLink<FEMMass, NodalMassDensity,
10890
sofa::BaseLink::FLAG_STOREPATH | sofa::BaseLink::FLAG_STRONGLINK> l_nodalMassDensity;
10991

11092
/**
@@ -211,7 +193,7 @@ class ElementFEMMass :
211193
/**
212194
* @brief Default constructor.
213195
*/
214-
ElementFEMMass();
196+
FEMMass();
215197

216198
/**
217199
* @brief Performs the internal calculation and assembly of the mass matrix.
@@ -267,17 +249,17 @@ class ElementFEMMass :
267249
GlobalMassMatrixType m_globalMassMatrix;
268250
};
269251

270-
#if !defined(SOFA_COMPONENT_MASS_ELEMENTFEMMASS_CPP)
271-
template class SOFA_COMPONENT_MASS_API ElementFEMMass<sofa::defaulttype::Vec1Types, sofa::geometry::Edge>;
272-
template class SOFA_COMPONENT_MASS_API ElementFEMMass<sofa::defaulttype::Vec2Types, sofa::geometry::Edge>;
273-
template class SOFA_COMPONENT_MASS_API ElementFEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Edge>;
274-
template class SOFA_COMPONENT_MASS_API ElementFEMMass<sofa::defaulttype::Vec2Types, sofa::geometry::Triangle>;
275-
template class SOFA_COMPONENT_MASS_API ElementFEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Triangle>;
276-
template class SOFA_COMPONENT_MASS_API ElementFEMMass<sofa::defaulttype::Vec2Types, sofa::geometry::Quad>;
277-
template class SOFA_COMPONENT_MASS_API ElementFEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Quad>;
278-
template class SOFA_COMPONENT_MASS_API ElementFEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Tetrahedron>;
279-
template class SOFA_COMPONENT_MASS_API ElementFEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Hexahedron>;
280-
template class SOFA_COMPONENT_MASS_API ElementFEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Prism>;
252+
#if !defined(SOFA_COMPONENT_MASS_FEMMASS_CPP)
253+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec1Types, sofa::geometry::Edge>;
254+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec2Types, sofa::geometry::Edge>;
255+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Edge>;
256+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec2Types, sofa::geometry::Triangle>;
257+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Triangle>;
258+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec2Types, sofa::geometry::Quad>;
259+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Quad>;
260+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Tetrahedron>;
261+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Hexahedron>;
262+
template class SOFA_COMPONENT_MASS_API FEMMass<sofa::defaulttype::Vec3Types, sofa::geometry::Prism>;
281263
#endif
282264

283265
} // namespace sofa::component::mass

Sofa/Component/Mass/src/sofa/component/mass/ElementFEMMass.inl renamed to Sofa/Component/Mass/src/sofa/component/mass/FEMMass.inl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Contact information: contact@sofa-framework.org *
2121
******************************************************************************/
2222
#pragma once
23-
#include <sofa/component/mass/ElementFEMMass.h>
23+
#include <sofa/component/mass/FEMMass.h>
2424
#include <sofa/core/behavior/BaseLocalMassMatrix.h>
2525
#include <sofa/helper/IotaView.h>
2626
#include <sofa/helper/ScopedAdvancedTimer.h>
@@ -29,14 +29,14 @@ namespace sofa::component::mass
2929
{
3030

3131
template <class TDataTypes, class TElementType>
32-
ElementFEMMass<TDataTypes, TElementType>::ElementFEMMass()
32+
FEMMass<TDataTypes, TElementType>::FEMMass()
3333
: l_nodalMassDensity(initLink("nodalMassDensity", "Link to nodal mass density"))
3434
{
3535
}
3636

3737

3838
template <class TDataTypes, class TElementType>
39-
void ElementFEMMass<TDataTypes, TElementType>::init()
39+
void FEMMass<TDataTypes, TElementType>::init()
4040
{
4141
TopologyAccessor::init();
4242

@@ -57,7 +57,7 @@ void ElementFEMMass<TDataTypes, TElementType>::init()
5757
}
5858

5959
template <class TDataTypes, class TElementType>
60-
void ElementFEMMass<TDataTypes, TElementType>::validateNodalMassDensity()
60+
void FEMMass<TDataTypes, TElementType>::validateNodalMassDensity()
6161
{
6262
if (l_nodalMassDensity.empty())
6363
{
@@ -76,7 +76,7 @@ void ElementFEMMass<TDataTypes, TElementType>::validateNodalMassDensity()
7676

7777

7878
template <class TDataTypes, class TElementType>
79-
void ElementFEMMass<TDataTypes, TElementType>::elementFEMMass_init()
79+
void FEMMass<TDataTypes, TElementType>::elementFEMMass_init()
8080
{
8181
const auto& elements = FiniteElement::getElementSequence(*this->l_topology);
8282
sofa::type::vector<ElementMassMatrix> elementMassMatrices;
@@ -89,7 +89,7 @@ void ElementFEMMass<TDataTypes, TElementType>::elementFEMMass_init()
8989
}
9090

9191
template <class TDataTypes, class TElementType>
92-
void ElementFEMMass<TDataTypes, TElementType>::calculateElementMassMatrix(
92+
void FEMMass<TDataTypes, TElementType>::calculateElementMassMatrix(
9393
const auto& elements, sofa::type::vector<ElementMassMatrix> &elementMassMatrices)
9494
{
9595
const auto nbElements = elements.size();
@@ -149,7 +149,7 @@ void ElementFEMMass<TDataTypes, TElementType>::calculateElementMassMatrix(
149149
}
150150

151151
template <class TDataTypes, class TElementType>
152-
void ElementFEMMass<TDataTypes, TElementType>::initializeGlobalMassMatrix(
152+
void FEMMass<TDataTypes, TElementType>::initializeGlobalMassMatrix(
153153
const auto& elements, const sofa::type::vector<ElementMassMatrix>& elementMassMatrices)
154154
{
155155
SCOPED_TIMER("elementMassMatrix");
@@ -183,7 +183,7 @@ void ElementFEMMass<TDataTypes, TElementType>::initializeGlobalMassMatrix(
183183
}
184184

185185
template <class TDataTypes, class TElementType>
186-
void ElementFEMMass<TDataTypes, TElementType>::addForce(const core::MechanicalParams* mparams,
186+
void FEMMass<TDataTypes, TElementType>::addForce(const core::MechanicalParams* mparams,
187187
sofa::DataVecDeriv_t<DataTypes>& f,
188188
const sofa::DataVecCoord_t<DataTypes>& x,
189189
const sofa::DataVecDeriv_t<DataTypes>& v)
@@ -213,7 +213,7 @@ void ElementFEMMass<TDataTypes, TElementType>::addForce(const core::MechanicalPa
213213
}
214214

215215
template <class TDataTypes, class TElementType>
216-
void ElementFEMMass<TDataTypes, TElementType>::buildMassMatrix(
216+
void FEMMass<TDataTypes, TElementType>::buildMassMatrix(
217217
sofa::core::behavior::MassMatrixAccumulator* matrices)
218218
{
219219
for (std::size_t xi = 0; xi < m_globalMassMatrix.rowIndex.size(); ++xi)
@@ -234,7 +234,7 @@ void ElementFEMMass<TDataTypes, TElementType>::buildMassMatrix(
234234
}
235235

236236
template <class TDataTypes, class TElementType>
237-
void ElementFEMMass<TDataTypes, TElementType>::addMDx(const core::MechanicalParams* mparams,
237+
void FEMMass<TDataTypes, TElementType>::addMDx(const core::MechanicalParams* mparams,
238238
DataVecDeriv_t<DataTypes>& f,
239239
const DataVecDeriv_t<DataTypes>& dx,
240240
SReal factor)
@@ -259,7 +259,7 @@ void ElementFEMMass<TDataTypes, TElementType>::addMDx(const core::MechanicalPara
259259
}
260260

261261
template <class TDataTypes, class TElementType>
262-
void ElementFEMMass<TDataTypes, TElementType>::accFromF(const core::MechanicalParams* mparams,
262+
void FEMMass<TDataTypes, TElementType>::accFromF(const core::MechanicalParams* mparams,
263263
DataVecDeriv_t<DataTypes>& a,
264264
const DataVecDeriv_t<DataTypes>& f)
265265
{
@@ -271,7 +271,7 @@ void ElementFEMMass<TDataTypes, TElementType>::accFromF(const core::MechanicalPa
271271
}
272272

273273
template <class TDataTypes, class TElementType>
274-
SReal ElementFEMMass<TDataTypes, TElementType>::getKineticEnergy(
274+
SReal FEMMass<TDataTypes, TElementType>::getKineticEnergy(
275275
const core::MechanicalParams* mparams,
276276
const DataVecDeriv_t<DataTypes>& v) const
277277
{
@@ -297,7 +297,7 @@ SReal ElementFEMMass<TDataTypes, TElementType>::getKineticEnergy(
297297
}
298298

299299
template <class TDataTypes, class TElementType>
300-
SReal ElementFEMMass<TDataTypes, TElementType>::getPotentialEnergy(
300+
SReal FEMMass<TDataTypes, TElementType>::getPotentialEnergy(
301301
const core::MechanicalParams* mparams,
302302
const DataVecCoord_t<DataTypes>& x) const
303303
{

0 commit comments

Comments
 (0)