Skip to content

Commit

Permalink
Add getter to BeamSection and mechanical param into RodSectionMaterial
Browse files Browse the repository at this point in the history
  • Loading branch information
epernod committed Jul 31, 2023
1 parent 3de0bbd commit 2307cb6
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 16 deletions.
8 changes: 8 additions & 0 deletions src/BeamAdapter/component/engine/WireRestShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ class WireRestShape : public core::objectmodel::BaseObject
/// This function gives the mass density and the BeamSection data depending on the beam position
void getInterpolationParam(const Real& x_curv, Real &_rho, Real &_A, Real &_Iy , Real &_Iz, Real &_Asy, Real &_Asz, Real &_J) const;


/// Returns the Young modulus, Poisson's and massDensity coefficient of this section
void getMechanicalParamAtX(const Real& x_curv, Real& youngModulus, Real& cPoisson, Real& massDensity) const;

/// Returns the BeamSection @sa m_beamSection corresponding to this RodSection
[[nodiscard]] const BeamSection& getBeamSectionAtX(const Real& x_curv) const;


/**
* This function provides a type::vector with the curviliar abscissa of the noticeable point(s)
* and the minimum density (number of points) between them. (Nb. nbP_density.size() == xP_noticeable.size() - 1)
Expand Down
39 changes: 39 additions & 0 deletions src/BeamAdapter/component/engine/WireRestShape.inl
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,45 @@ void WireRestShape<DataTypes>::getInterpolationParam(const Real& x_curv, Real &_
}


template <class DataTypes>
void WireRestShape<DataTypes>::getMechanicalParamAtX(const Real& x_curv, Real& youngModulus, Real& cPoisson, Real& massDensity) const
{
const Real x_used = x_curv - Real(EPSILON);
const type::vector<Real>& keyPts = d_keyPoints.getValue();

// Check in which section x_used belongs to and get access to this section material
for (auto i = 1; i < keyPts.size(); ++i)
{
if (x_used <= keyPts[i])
{
return l_sectionMaterials.get(i - 1)->getMechanicalParamAtX(youngModulus, cPoisson, massDensity);
}
}

msg_error() << " problem in getMechanicalParamAtX : x_curv " << x_curv << " is not between keyPoints" << keyPts;
}


template <class DataTypes>
const BeamSection& WireRestShape<DataTypes>::getBeamSectionAtX(const Real& x_curv) const
{
const Real x_used = x_curv - Real(EPSILON);
const type::vector<Real>& keyPts = d_keyPoints.getValue();

// Check in which section x_used belongs to and get access to this section material
for (auto i = 1; i < keyPts.size(); ++i)
{
if (x_used <= keyPts[i])
{
return l_sectionMaterials.get(i - 1)->getBeamSectionAtX();
}
}

msg_error() << " problem in getBeamSectionAtX : x_curv " << x_curv << " is not between keyPoints" << keyPts;
return BeamSection();
}


template <class DataTypes>
typename WireRestShape<DataTypes>::Real WireRestShape<DataTypes>::getLength()
{
Expand Down
8 changes: 7 additions & 1 deletion src/BeamAdapter/component/model/BaseRodSectionMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ class BaseRodSectionMaterial : public core::objectmodel::BaseObject
void getInterpolationParam(Real& _rho, Real& _A, Real& _Iy, Real& _Iz, Real& _Asy, Real& _Asz, Real& _J) const;


/// Returns the Young modulus, Poisson's and massDensity coefficient of this section
void getMechanicalParamAtX(Real& youngModulus, Real& cPoisson, Real& massDensity) const;

/// Returns the BeamSection @sa m_beamSection corresponding to this RodSection
[[nodiscard]] const BeamSection& getBeamSectionAtX() const { return m_beamSection; }


/// This function is called to get the rest position of the beam depending on the current curved abscisse given in parameter
virtual void getRestTransformOnX(Transform& global_H_local, const Real& x_used, const Real& x_start)
Expand Down Expand Up @@ -114,7 +120,7 @@ class BaseRodSectionMaterial : public core::objectmodel::BaseObject

private:
/// Internal structure to store physical parameter of the a beam section
BeamSection beamSection;
BeamSection m_beamSection;
};

} // namespace sofa::beamadapter
41 changes: 26 additions & 15 deletions src/BeamAdapter/component/model/BaseRodSectionMaterial.inl
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ void BaseRodSectionMaterial<DataTypes>::init()
// Prepare beam sections
double r = this->d_radius.getValue();
double rInner = this->d_innerRadius.getValue();
this->beamSection._r = r;
this->beamSection._rInner = rInner;
this->beamSection._Iz = M_PI * (r * r * r * r - rInner * rInner * rInner * rInner) / 4.0;
this->beamSection._Iy = this->beamSection._Iz;
this->beamSection._J = this->beamSection._Iz + this->beamSection._Iy;
this->beamSection._A = M_PI * (r * r - rInner * rInner);
this->beamSection._Asy = 0.0;
this->beamSection._Asz = 0.0;
this->m_beamSection._r = r;
this->m_beamSection._rInner = rInner;
this->m_beamSection._Iz = M_PI * (r * r * r * r - rInner * rInner * rInner * rInner) / 4.0;
this->m_beamSection._Iy = this->m_beamSection._Iz;
this->m_beamSection._J = this->m_beamSection._Iz + this->m_beamSection._Iy;
this->m_beamSection._A = M_PI * (r * r - rInner * rInner);
this->m_beamSection._Asy = 0.0;
this->m_beamSection._Asz = 0.0;

// call delegate method to init the section
bool res = initSection();
Expand All @@ -79,18 +79,29 @@ void BaseRodSectionMaterial<DataTypes>::getYoungModulusAtX(Real& youngModulus, R
template <class DataTypes>
void BaseRodSectionMaterial<DataTypes>::getInterpolationParam(Real& _rho, Real& _A, Real& _Iy, Real& _Iz, Real& _Asy, Real& _Asz, Real& _J) const
{
if (d_massDensity.isSet())
if (d_massDensity.isSet()) {
_rho = d_massDensity.getValue();
std::cout << "_rho: " << _rho << std::endl;
}

if (d_radius.isSet())
{
_A = beamSection._A;
_Iy = beamSection._Iy;
_Iz = beamSection._Iz;
_Asy = beamSection._Asy;
_Asz = beamSection._Asz;
_J = beamSection._J;
_A = m_beamSection._A;
_Iy = m_beamSection._Iy;
_Iz = m_beamSection._Iz;
_Asy = m_beamSection._Asy;
_Asz = m_beamSection._Asz;
_J = m_beamSection._J;
}
}


template <class DataTypes>
void BaseRodSectionMaterial<DataTypes>::getMechanicalParamAtX(Real& youngModulus, Real& cPoisson, Real& massDensity) const
{
youngModulus = this->d_youngModulus.getValue();
cPoisson = this->d_poissonRatio.getValue();
massDensity = this->d_massDensity.getValue();
}

} // namespace sofa::beamadapter

0 comments on commit 2307cb6

Please sign in to comment.