Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#pragma once

#include <sofa/component/solidmechanics/fem/hyperelastic/config.h>
#include <sofa/component/solidmechanics/fem/elastic/CauchyStressEvaluator.h>
#include <sofa/type/FullySymmetric4Tensor.h>
#include <sofa/component/solidmechanics/fem/hyperelastic/impl/MajorSymmetric4Tensor.h>
#include <sofa/component/solidmechanics/fem/hyperelastic/impl/Strain.h>
#include <sofa/core/objectmodel/BaseObject.h>

#if !defined(SOFA_COMPONENT_SOLIDMECHANICS_FEM_HYPERELASTIC_HYPERELASTIC_MATERIAL_CPP)
#include <sofa/defaulttype/VecTypes.h>
Expand All @@ -35,10 +35,10 @@ namespace sofa::component::solidmechanics::fem::hyperelastic
{

template<class TDataTypes>
class HyperelasticMaterial : public virtual sofa::core::objectmodel::BaseObject
class HyperelasticMaterial : public elastic::CauchyStressEvaluator<TDataTypes>
{
public:
SOFA_ABSTRACT_CLASS(HyperelasticMaterial<TDataTypes>, sofa::core::objectmodel::BaseObject);
SOFA_ABSTRACT_CLASS(HyperelasticMaterial<TDataTypes>, elastic::CauchyStressEvaluator<TDataTypes>);
using DataTypes = TDataTypes;

protected:
Expand All @@ -49,6 +49,7 @@ class HyperelasticMaterial : public virtual sofa::core::objectmodel::BaseObject
using DeformationGradient = sofa::type::Mat<spatial_dimensions, spatial_dimensions, Real>;
using RightCauchyGreenTensor = sofa::type::Mat<spatial_dimensions, spatial_dimensions, Real>;
using StressTensor = sofa::type::Mat<spatial_dimensions, spatial_dimensions, Real>;
using StressVoigtVector = typename elastic::CauchyStressEvaluator<DataTypes>::StressVoigtVector;
using ElasticityTensor = sofa::type::FullySymmetric4Tensor<spatial_dimensions, Real>;
using TangentModulus = MajorSymmetric4Tensor<DataTypes>;

Expand All @@ -71,6 +72,8 @@ class HyperelasticMaterial : public virtual sofa::core::objectmodel::BaseObject
*/
virtual TangentModulus materialTangentModulus(Strain<DataTypes>& strain) = 0;

StressVoigtVector computeStress(const DeformationGradient& F, sofa::Size elementId) override;

};

#if !defined(SOFA_COMPONENT_SOLIDMECHANICS_FEM_HYPERELASTIC_HYPERELASTIC_MATERIAL_CPP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,25 @@ void HyperelasticMaterial<DataTypes>::init()
}
}

template <class TDataTypes>
auto HyperelasticMaterial<TDataTypes>::computeStress(const DeformationGradient& F, sofa::Size elementId) -> StressVoigtVector
{
SOFA_UNUSED(elementId);

Strain<DataTypes> strain(deformationGradient, F);
const auto P = this->firstPiolaKirchhoffStress(strain);
const auto J = strain.getDeterminantDeformationGradient();
assert(std::abs(J) > std::numeric_limits<Real>::epsilon());
const auto sigma = (static_cast<Real>(1)/J) * P * F.transposed();

StressVoigtVector stressVoigt;
for (sofa::Size i = 0; i < type::NumberOfIndependentElements<spatial_dimensions>; ++i)
{
const auto [p, q] = type::toTensorIndices<spatial_dimensions>(i);
stressVoigt[i] = (p == q) ? sigma(p, q) : static_cast<Real>(0.5) * (sigma(p, q) + sigma(q, p));
}

return stressVoigt;
}

} // namespace elasticity
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
<StVenantKirchhoffMaterial name="material" youngModulus="2e6" poissonRatio="0.45"/>
<HyperelasticityFEMForceField name="FEM" template="Vec3,Hexahedron" topology="@grid"
computeForceStrategy="parallel" computeForceDerivStrategy="parallel"/>
<VonMisesStress template="Vec3,Hexahedron" name="stress" topology="@grid" stressEvaluator="@material"
colorMap="green yellow orange red purple #221C35"/>
</Node>
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
<StVenantKirchhoffMaterial name="material" youngModulus="2e6" poissonRatio="0.45"/>
<HyperelasticityFEMForceField name="FEM" template="Vec3,Hexahedron" topology="@grid"
computeForceStrategy="parallel" computeForceDerivStrategy="parallel"/>
<VonMisesStress template="Vec3,Hexahedron" name="stress" topology="@grid" stressEvaluator="@material"
colorMap="green yellow orange red purple #221C35"/>

</Node>
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
<StVenantKirchhoffMaterial name="material" youngModulus="2e6" poissonRatio="0.45"/>
<HyperelasticityFEMForceField name="FEM" template="Vec3,Hexahedron" topology="@grid"
computeForceStrategy="sequenced" computeForceDerivStrategy="sequenced"/>
<VonMisesStress template="Vec3,Hexahedron" name="stress" topology="@grid" stressEvaluator="@material"
colorMap="green yellow orange red purple #221C35"/>

</Node>
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
<StVenantKirchhoffMaterial name="material" youngModulus="2e6" poissonRatio="0.45"/>
<HyperelasticityFEMForceField name="FEM" template="Vec3,Hexahedron" topology="@grid"
computeForceStrategy="sequenced" computeForceDerivStrategy="sequenced"/>
<VonMisesStress template="Vec3,Hexahedron" name="stress" topology="@grid" stressEvaluator="@material"
colorMap="green yellow orange red purple #221C35"/>

</Node>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<StVenantKirchhoffMaterial name="material" youngModulus="2e6" poissonRatio="0.45"/>
<HyperelasticityFEMForceField name="FEM" template="Vec3,Tetrahedron" topology="@Tetra_topo"
computeForceStrategy="parallel" computeForceDerivStrategy="parallel"/>
<VonMisesStress template="Vec3,Tetrahedron" name="stress" topology="@Tetra_topo" stressEvaluator="@material"
colorMap="green yellow orange red purple #221C35"/>
</Node>

</Node>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<StVenantKirchhoffMaterial name="material" youngModulus="2e6" poissonRatio="0.45"/>
<HyperelasticityFEMForceField name="FEM" template="Vec3,Tetrahedron" topology="@Tetra_topo"
computeForceStrategy="parallel" computeForceDerivStrategy="parallel"/>
<VonMisesStress template="Vec3,Tetrahedron" name="stress" topology="@Tetra_topo" stressEvaluator="@material"
colorMap="green yellow orange red purple #221C35"/>
</Node>

</Node>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<StVenantKirchhoffMaterial name="material" youngModulus="2e6" poissonRatio="0.45"/>
<HyperelasticityFEMForceField name="FEM" template="Vec3,Tetrahedron" topology="@Tetra_topo"
computeForceStrategy="sequenced" computeForceDerivStrategy="sequenced"/>
<VonMisesStress template="Vec3,Tetrahedron" name="stress" topology="@Tetra_topo" stressEvaluator="@material"
colorMap="green yellow orange red purple #221C35"/>
</Node>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<StVenantKirchhoffMaterial name="material" youngModulus="2e6" poissonRatio="0.45"/>
<HyperelasticityFEMForceField name="FEM" template="Vec3,Tetrahedron" topology="@Tetra_topo"
computeForceStrategy="sequenced" computeForceDerivStrategy="sequenced"/>
<VonMisesStress template="Vec3,Tetrahedron" name="stress" topology="@Tetra_topo" stressEvaluator="@material"
colorMap="green yellow orange red purple #221C35"/>
</Node>

</Node>
Loading