Skip to content

Commit c1b6cba

Browse files
committed
Squashed merge of PR #5439
commit 370b6c4 Merge: 8d4aacd 912335e Author: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Fri Apr 10 09:25:36 2026 +0200 Merge branch 'master' into 2025_sedsprint_BaseMaterial commit 8d4aacd Merge: a099baa fb6ac6c Author: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Tue Jan 6 11:42:09 2026 +0100 Merge branch 'master' into 2025_sedsprint_BaseMaterial commit a099baa Author: Théo BL <theo.biasutto-lervat@inria.fr> Date: Mon May 12 15:22:49 2025 +0200 refacto: ensure naming consistency commit e20ce58 Author: Théo BL <theo.biasutto-lervat@inria.fr> Date: Mon May 12 15:17:53 2025 +0200 feat(sed_sprint): apply template method to BaseMaterial
1 parent 754ced7 commit c1b6cba

3 files changed

Lines changed: 47 additions & 11 deletions

File tree

Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/BaseMaterial.h

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,58 @@ class SOFA_COMPONENT_SOLIDMECHANICS_FEM_HYPERELASTIC_API BaseMaterial : public v
4545
this->core::objectmodel::BaseComponent::init();
4646
}
4747

48-
4948
//virtual VecN computeStress (VecN & strain,int idElement,int id_QP){return stress in the i-th quadrature point}
5049
//So here needed the shapefunctionvalue * , quadratureformular* (verifie if shapfunctionvalue compute with the local method)
5150
// The same principe for computing the strain given the displacement
5251

52+
/**
53+
* !!! WARNING since v25.12 !!!
54+
*
55+
* The template method pattern has been applied to this part of the API.
56+
* This method calls the newly introduced method "doComputeStress" internally,
57+
* which is the method to override from now on.
58+
*
59+
**/
60+
virtual void computeStress (type::Vec3 & stress, type::Vec3 & strain, unsigned int & elementIndex) final {
61+
//TODO (SPRINT SED 2025): Component state mechamism
62+
this->doComputeStress(stress, strain, elementIndex);
63+
}
64+
65+
/**
66+
* !!! WARNING since v25.12 !!!
67+
*
68+
* The template method pattern has been applied to this part of the API.
69+
* This method calls the newly introduced method "doComputeDStress" internally,
70+
* which is the method to override from now on.
71+
*
72+
**/
73+
virtual void computeDStress (type::Vec3 & dstress, type::Vec3 & dstrain) final {
74+
//TODO (SPRINT SED 2025): Component state mechamism
75+
this->doComputeDStress(dstress, dstrain);
76+
}
5377

54-
virtual void computeStress (type::Vec3 & ,type::Vec3 &,unsigned int &) {}
55-
virtual void computeDStress (type::Vec3 & ,type::Vec3 &) {}
78+
/**
79+
* !!! WARNING since v25.12 !!!
80+
*
81+
* The template method pattern has been applied to this part of the API.
82+
* This method calls the newly introduced method "doComputeStress" internally,
83+
* which is the method to override from now on.
84+
*
85+
**/
86+
virtual void computeStress (unsigned int elementIndex) final {
87+
//TODO (SPRINT SED 2025): Component state mechamism
88+
this->doComputeStress(elementIndex);
89+
};
5690

57-
virtual void computeStress (unsigned int /*iElement*/)=0;//to be pure virtual
58-
91+
protected:
92+
virtual void doComputeStress(type::Vec3 & stress, type::Vec3 & strain, unsigned int & idElement) = 0;
93+
virtual void doComputeDStress(type::Vec3 & dstress, type::Vec3 & dstrain) = 0;
94+
virtual void doComputeStress(unsigned int elementIndex) = 0;
5995

6096
private:
6197
BaseMaterial(const BaseMaterial& n) ;
6298
BaseMaterial& operator=(const BaseMaterial& n) ;
6399

64-
65100
};
66101

67102
} // namespace sofa::component::solidmechanics::fem::hyperelastic::material

Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ PlasticMaterial::PlasticMaterial()
4949
_sigma.push_back(Stress);
5050
}
5151

52-
void PlasticMaterial::computeStress(Vec3& Stress, Vec3& Strain, unsigned int& elementIndex)
52+
void PlasticMaterial::doComputeStress(Vec3& Stress, Vec3& Strain, unsigned int& elementIndex)
5353
{
5454
// Computes the Von Mises strain
5555
const SReal vonMisesStrain = computeVonMisesStrain(Strain);
@@ -78,7 +78,7 @@ void PlasticMaterial::computeStress(Vec3& Stress, Vec3& Strain, unsigned int& el
7878
_previousVonMisesStrain.push_back(vonMisesStrain);
7979
}
8080

81-
void PlasticMaterial::computeDStress(Vec3& dStress, Vec3& dStrain)
81+
void PlasticMaterial::doComputeDStress(Vec3& dStress, Vec3& dStrain)
8282
{
8383
dStress[0] = dStrain[0] + _poissonRatio.getValue() * dStrain[1];
8484
dStress[1] = _poissonRatio.getValue() * dStrain[0] + dStrain[1];

Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ class PlasticMaterial : public BaseMaterial
5959
VecDouble _previousVonMisesStrain;
6060

6161
PlasticMaterial();
62-
void computeStress (Vec3& stress, Vec3& strain, unsigned int& elementIndex) override;
63-
void computeDStress (Vec3& dstress, Vec3& dstrain) override;
6462

6563
SReal computeVonMisesStrain(Vec3 &strain);
6664
void computeStressOnSection(Vec3& Stress, Vec3 Strain, int section); // computes the stress on a given section of the piecewise function
6765

68-
void computeStress (unsigned int /*iElement*/) override {}
66+
protected:
67+
void doComputeStress (Vec3& stress, Vec3& strain, unsigned int& elementIndex) override;
68+
void doComputeDStress (Vec3& dstress, Vec3& dstrain) override;
69+
void doComputeStress (unsigned int /*elementIndex*/) override {}
6970

7071
};
7172

0 commit comments

Comments
 (0)