diff --git a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/BaseMaterial.h b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/BaseMaterial.h index 1bb71b35590..05bb4969585 100644 --- a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/BaseMaterial.h +++ b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/BaseMaterial.h @@ -45,23 +45,58 @@ class SOFA_COMPONENT_SOLIDMECHANICS_FEM_HYPERELASTIC_API BaseMaterial : public v this->core::objectmodel::BaseComponent::init(); } - //virtual VecN computeStress (VecN & strain,int idElement,int id_QP){return stress in the i-th quadrature point} //So here needed the shapefunctionvalue * , quadratureformular* (verifie if shapfunctionvalue compute with the local method) // The same principe for computing the strain given the displacement + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doComputeStress" internally, + * which is the method to override from now on. + * + **/ + virtual void computeStress (type::Vec3 & stress, type::Vec3 & strain, unsigned int & elementIndex) final { + //TODO (SPRINT SED 2025): Component state mechamism + this->doComputeStress(stress, strain, elementIndex); + } + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doComputeDStress" internally, + * which is the method to override from now on. + * + **/ + virtual void computeDStress (type::Vec3 & dstress, type::Vec3 & dstrain) final { + //TODO (SPRINT SED 2025): Component state mechamism + this->doComputeDStress(dstress, dstrain); + } - virtual void computeStress (type::Vec3 & ,type::Vec3 &,unsigned int &) {} - virtual void computeDStress (type::Vec3 & ,type::Vec3 &) {} + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doComputeStress" internally, + * which is the method to override from now on. + * + **/ + virtual void computeStress (unsigned int elementIndex) final { + //TODO (SPRINT SED 2025): Component state mechamism + this->doComputeStress(elementIndex); + }; - virtual void computeStress (unsigned int /*iElement*/)=0;//to be pure virtual - +protected: + virtual void doComputeStress(type::Vec3 & stress, type::Vec3 & strain, unsigned int & idElement) = 0; + virtual void doComputeDStress(type::Vec3 & dstress, type::Vec3 & dstrain) = 0; + virtual void doComputeStress(unsigned int elementIndex) = 0; private: BaseMaterial(const BaseMaterial& n) ; BaseMaterial& operator=(const BaseMaterial& n) ; - }; } // namespace sofa::component::solidmechanics::fem::hyperelastic::material diff --git a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.cpp b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.cpp index e6c5abb96bb..234e3a3eeca 100644 --- a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.cpp +++ b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.cpp @@ -49,7 +49,7 @@ PlasticMaterial::PlasticMaterial() _sigma.push_back(Stress); } -void PlasticMaterial::computeStress(Vec3& Stress, Vec3& Strain, unsigned int& elementIndex) +void PlasticMaterial::doComputeStress(Vec3& Stress, Vec3& Strain, unsigned int& elementIndex) { // Computes the Von Mises strain const SReal vonMisesStrain = computeVonMisesStrain(Strain); @@ -78,7 +78,7 @@ void PlasticMaterial::computeStress(Vec3& Stress, Vec3& Strain, unsigned int& el _previousVonMisesStrain.push_back(vonMisesStrain); } -void PlasticMaterial::computeDStress(Vec3& dStress, Vec3& dStrain) +void PlasticMaterial::doComputeDStress(Vec3& dStress, Vec3& dStrain) { dStress[0] = dStrain[0] + _poissonRatio.getValue() * dStrain[1]; dStress[1] = _poissonRatio.getValue() * dStrain[0] + dStrain[1]; diff --git a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.h b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.h index 6158095ea3d..04dc3886abb 100644 --- a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.h +++ b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.h @@ -59,13 +59,14 @@ class PlasticMaterial : public BaseMaterial VecDouble _previousVonMisesStrain; PlasticMaterial(); - void computeStress (Vec3& stress, Vec3& strain, unsigned int& elementIndex) override; - void computeDStress (Vec3& dstress, Vec3& dstrain) override; SReal computeVonMisesStrain(Vec3 &strain); void computeStressOnSection(Vec3& Stress, Vec3 Strain, int section); // computes the stress on a given section of the piecewise function - void computeStress (unsigned int /*iElement*/) override {} +protected: + void doComputeStress (Vec3& stress, Vec3& strain, unsigned int& elementIndex) override; + void doComputeDStress (Vec3& dstress, Vec3& dstrain) override; + void doComputeStress (unsigned int /*elementIndex*/) override {} };