Skip to content

Commit

Permalink
[src] Update RodSection, WireRestShape and All BeamInterpolation to c…
Browse files Browse the repository at this point in the history
…orrectly redirect the getters to the Data for: getBeamSection, getInterpolationParameters and getMechanicalParameters. Remove the now useless pointer to the RestShape inside the FEM. Go only through the Interpolation component.
  • Loading branch information
epernod committed Jul 19, 2024
1 parent 847928e commit 56548b8
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 197 deletions.
13 changes: 8 additions & 5 deletions src/BeamAdapter/component/BaseBeamInterpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,22 @@ class BaseBeamInterpolation : public virtual sofa::core::objectmodel::BaseObject
void addCollisionOnBeam(unsigned int b);
void clearCollisionOnBeam();

virtual void getYoungModulusAtX(int beamId, Real& x_curv, Real& youngModulus, Real& cPoisson) = 0;
virtual void getSamplingParameters(type::vector<Real>& xP_noticeable,
type::vector<int>& nbP_density) = 0;
virtual void getNumberOfCollisionSegment(Real& dx, unsigned int& numLines) = 0;


virtual void getCurvAbsAtBeam(const unsigned int& edgeInList_input, const Real& baryCoord_input, Real& x_output) = 0;
virtual void getSplineRestTransform(unsigned int edgeInList, Transform& local_H_local0_rest, Transform& local_H_local1_rest) = 0;
virtual void getInterpolationParam(unsigned int edgeInList, Real& _L, Real& _A, Real& _Iy, Real& _Iz,
Real& _Asy, Real& _Asz, Real& J) = 0;
virtual void getMechanicalParam(int beamId, Real& youngModulus, Real& cPoisson, Real& massDensity) = 0;

/// Returns the BeamSection @sa m_beamSection corresponding to the given beam
virtual const BeamSection& getBeamSection(sofa::Index beamId) = 0;
/// Returns the BeamSection data depending on the beam position at the given beam, similar to @getBeamSection
virtual void getInterpolationParameters(sofa::Index beamId, Real& _L, Real& _A, Real& _Iy, Real& _Iz, Real& _Asy, Real& _Asz, Real& J) = 0;
/// Returns the Young modulus, Poisson's ratio and massDensity coefficient of the section at the given curvilinear abscissa
virtual void getMechanicalParameters(sofa::Index beamId, Real& youngModulus, Real& cPoisson, Real& massDensity) = 0;


virtual const BeamSection& getBeamSection(int edgeIndex) = 0;
virtual void getBeamAtCurvAbs(const Real& x_input, unsigned int& edgeInList_output, Real& baryCoord_output, unsigned int start = 0);

int computeTransform(const EdgeID edgeInList, Transform& global_H_local0, Transform& global_H_local1, const VecCoord& x);
Expand Down
12 changes: 7 additions & 5 deletions src/BeamAdapter/component/BeamInterpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,21 @@ class BeamInterpolation : public BaseBeamInterpolation<DataTypes>
bool verifyTopology();
void computeCrossSectionInertiaMatrix();

void getInterpolationParam(unsigned int edgeInList, Real &_L, Real &_A, Real &_Iy , Real &_Iz,
const BeamSection& getBeamSection(sofa::Index beamId) override {
SOFA_UNUSED(beamId);
return this->m_constantSection;
}
void getInterpolationParameters(sofa::Index beamId, Real &_L, Real &_A, Real &_Iy , Real &_Iz,
Real &_Asy, Real &_Asz, Real &J) override;

void getMechanicalParameters(sofa::Index beamId, Real& youngModulus, Real& cPoisson, Real& massDensity) override;

void getTangentUsingSplinePoints(unsigned int edgeInList, const Real& baryCoord, const ConstVecCoordId &vecXId, Vec3& t );


/// computeActualLength => given the 4 control points of the spline, it provides an estimate of the length (using gauss points integration)


const BeamSection &getBeamSection(int /*edgeIndex*/ ) override {return this->m_constantSection;}


virtual void getCurvAbsAtBeam(const unsigned int& edgeInList_input, const Real& baryCoord_input, Real& x_output) {}
virtual void getBeamAtCurvAbs(const Real& x_input, unsigned int& edgeInList_output, Real& baryCoord_output, unsigned int start = 0) {}
Expand Down Expand Up @@ -188,8 +192,6 @@ class BeamInterpolation : public BaseBeamInterpolation<DataTypes>
Real getRestTotalLength() override;
void getCollisionSampling(Real &dx, const Real& x_localcurv_abs) override;
void getNumberOfCollisionSegment(Real &dx, unsigned int &numLines) override;
void getYoungModulusAtX(int beamId,Real& x_curv, Real& youngModulus, Real& cPoisson) override;
void getMechanicalParam(int beamId, Real& youngModulus, Real& cPoisson, Real& massDensity) override;

void setTransformBetweenDofAndNode(int beam, const Transform &DOF_H_Node, unsigned int zeroORone );
void getSplineRestTransform(unsigned int edgeInList, Transform &local_H_local0_rest, Transform &local_H_local1_rest) override;
Expand Down
61 changes: 26 additions & 35 deletions src/BeamAdapter/component/BeamInterpolation.inl
Original file line number Diff line number Diff line change
Expand Up @@ -395,32 +395,44 @@ void BeamInterpolation<DataTypes>::getNumberOfCollisionSegment(Real &dx, unsigne
dx = getRestTotalLength()/numLines;
}

template <class DataTypes>
void BeamInterpolation<DataTypes>::getYoungModulusAtX(int beamId, Real& /*x_curv*/, Real& youngModulus, Real& cPoisson)

template<class DataTypes>
void BeamInterpolation<DataTypes>::getInterpolationParameters(sofa::Index beamId, Real& _L, Real& _A, Real& _Iy,
Real& _Iz, Real& _Asy, Real& _Asz, Real& _J)
{
/// get the length of the beam:
_L = this->d_lengthList.getValue()[beamId];
_A = m_constantSection._A;
_Iy = m_constantSection._Iy;
_Iz = m_constantSection._Iz;
_Asy = m_constantSection._Asy;
_Asz = m_constantSection._Asz;
_J = m_constantSection._J;
}


template<class DataTypes>
void BeamInterpolation<DataTypes>::getMechanicalParameters(sofa::Index beamId, Real& youngModulus, Real& cPoisson, Real& massDensity)
{
const auto& defaultYoungModuli = d_defaultYoungModulus.getValue();
if (beamId < int(defaultYoungModuli.size())) {

youngModulus = defaultYoungModuli[beamId];
} else {
}
else {
youngModulus = m_defaultYoungModulus;
}

const auto& poissonRatios = d_poissonRatio.getValue();
if (beamId < int(poissonRatios.size())) {

cPoisson = poissonRatios[beamId];
} else {
cPoisson = m_defaultPoissonRatio;
cPoisson = poissonRatios[beamId];
}
else {
cPoisson = m_defaultPoissonRatio;
}
}


template<class DataTypes>
void BeamInterpolation<DataTypes>::getMechanicalParam(int beamId, Real& youngModulus, Real& cPoisson, Real& massDensity)
{
Real xcurv;
return getYoungModulusAtX(beamId, xcurv, youngModulus, cPoisson);
//TODO: massDensity??
}


Expand Down Expand Up @@ -494,27 +506,6 @@ void BeamInterpolation<DataTypes>::getSplineRestTransform(unsigned int edgeInLis
}


template<class DataTypes>
void BeamInterpolation<DataTypes>::getInterpolationParam(unsigned int edgeInList, Real &_L, Real &_A, Real &_Iy ,
Real &_Iz, Real &_Asy, Real &_Asz, Real &_J)
{
/// get the length of the beam:
_L = this->d_lengthList.getValue()[edgeInList];

BeamSection bS = getBeamSection(edgeInList);
_A=bS._A;
_Iy=bS._Iy;
_Iz=bS._Iz;
_Asy=bS._Asy;
_Asz=bS._Asz;
_J=bS._J;
}






template<class DataTypes>
void BeamInterpolation<DataTypes>::getTangentUsingSplinePoints(unsigned int edgeInList, const Real& baryCoord,
const ConstVecCoordId &vecXId, Vec3& t )
Expand Down
22 changes: 5 additions & 17 deletions src/BeamAdapter/component/WireBeamInterpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,15 @@ class WireBeamInterpolation : public BaseBeamInterpolation<DataTypes>
}


void getYoungModulusAtX(int beamId,Real& x_curv, Real& youngModulus, Real& cPoisson) override
{
this->getAbsCurvXFromBeam(beamId, x_curv);
this->m_restShape->getYoungModulusAtX(x_curv, youngModulus, cPoisson);
}


void getMechanicalParam(int beamId, Real& youngModulus, Real& cPoisson, Real& massDensity) override
{
Real x_curv = 0;
this->getAbsCurvXFromBeam(beamId, x_curv);
this->m_restShape->getMechanicalParamAtX(x_curv, youngModulus, cPoisson, massDensity);
}

virtual void getRestTransform(unsigned int edgeInList, Transform &local0_H_local1_rest);

void getCurvAbsAtBeam(const unsigned int& edgeInList_input, const Real& baryCoord_input, Real& x_output) override;
void getSplineRestTransform(unsigned int edgeInList, Transform &local_H_local0_rest, Transform &local_H_local1_rest) override;
void getInterpolationParam(unsigned int edgeInList, Real& _L, Real& _A, Real& _Iy, Real& _Iz,
Real& _Asy, Real& _Asz, Real& _J) override;
const BeamSection& getBeamSection(int edgeIndex) override;

const BeamSection& getBeamSection(sofa::Index beamId) override;
void getInterpolationParameters(sofa::Index beamId, Real& _L, Real& _A, Real& _Iy, Real& _Iz, Real& _Asy, Real& _Asz, Real& _J) override;
void getMechanicalParameters(sofa::Index, Real& youngModulus, Real& cPoisson, Real& massDensity) override;

bool getApproximateCurvAbs(const Vec3& x_input, const VecCoord& x, Real& x_output); // Project a point on the segments, return false if cant project


Expand Down
28 changes: 19 additions & 9 deletions src/BeamAdapter/component/WireBeamInterpolation.inl
Original file line number Diff line number Diff line change
Expand Up @@ -163,29 +163,39 @@ void WireBeamInterpolation<DataTypes>::getCurvAbsAtBeam(const unsigned int &edge


template<class DataTypes>
void WireBeamInterpolation<DataTypes>::getInterpolationParam(unsigned int edgeInList, Real& _L, Real& _A, Real& _Iy, Real& _Iz,
Real& _Asy, Real& _Asz, Real& _J)
const BeamSection& WireBeamInterpolation<DataTypes>::getBeamSection(sofa::Index beamId)
{
_L = this->d_lengthList.getValue()[edgeInList];
Real _rho;
Real x_curv = 0;
this->getAbsCurvXFromBeam(edgeInList, x_curv);
this->getAbsCurvXFromBeam(beamId, x_curv);

auto restShape = this->m_restShape.get();
restShape->getInterpolationParam(x_curv, _rho, _A, _Iy, _Iz, _Asy, _Asz, _J);
return restShape->getBeamSectionAtX(x_curv);
}


template<class DataTypes>
const BeamSection& WireBeamInterpolation<DataTypes>::getBeamSection(int edgeIndex)
void WireBeamInterpolation<DataTypes>::getInterpolationParameters(sofa::Index beamId, Real& _L, Real& _A, Real& _Iy, Real& _Iz,
Real& _Asy, Real& _Asz, Real& _J)
{
_L = this->d_lengthList.getValue()[beamId];
Real _rho;
Real x_curv = 0;
this->getAbsCurvXFromBeam(edgeIndex, x_curv);
this->getAbsCurvXFromBeam(beamId, x_curv);

auto restShape = this->m_restShape.get();
return restShape->getBeamSectionAtX(x_curv);
restShape->getInterpolationParametersAtX(x_curv, _A, _Iy, _Iz, _Asy, _Asz, _J);
}


template<class DataTypes>
void WireBeamInterpolation<DataTypes>::getMechanicalParameters(sofa::Index beamId, Real& youngModulus, Real& cPoisson, Real& massDensity)
{
Real x_curv = 0;
this->getAbsCurvXFromBeam(beamId, x_curv);
this->m_restShape->getMechanicalParametersAtX(x_curv, youngModulus, cPoisson, massDensity);
}


template<class DataTypes>
bool WireBeamInterpolation<DataTypes>::getApproximateCurvAbs(const Vec3& x_input, const VecCoord& x, Real& x_output)
{
Expand Down
16 changes: 6 additions & 10 deletions src/BeamAdapter/component/engine/WireRestShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,14 @@ class WireRestShape : public core::objectmodel::BaseObject
/// This function is called by the force field to evaluate the rest position of each beam
void getRestTransformOnX(Transform &global_H_local, const Real &x);

/// This function gives the Young modulus and Poisson's coefficient of the beam depending on the beam position
void getYoungModulusAtX(const Real& x_curv, Real& youngModulus, Real& cPoisson) const;

/// 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 BeamSection @sa m_beamSection corresponding to the given curvilinear abscissa, will call @sa BaseRodSectionMaterial::getBeamSection
[[nodiscard]] const BeamSection& getBeamSectionAtX(const Real& x_curv) const;

/// Returns the Young modulus, Poisson's and massDensity coefficient of the section at the given curvilinear abscissa
void getMechanicalParamAtX(const Real& x_curv, Real& youngModulus, Real& cPoisson, Real& massDensity) const;
/// Returns the BeamSection data depending on the beam position at the given curvilinear abscissa, will call @sa BaseRodSectionMaterial::getInterpolationParameters
void getInterpolationParametersAtX(const Real& x_curv, Real &_A, Real &_Iy , Real &_Iz, Real &_Asy, Real &_Asz, Real &_J) const;

/// Returns the BeamSection @sa m_beamSection corresponding to the given curvilinear abscissa
[[nodiscard]] const BeamSection& getBeamSectionAtX(const Real& x_curv) const;
/// Returns the Young modulus, Poisson's ratio and massDensity coefficient of the section at the given curvilinear abscissa, will call @sa BaseRodSectionMaterial::getMechanicalParameters
void getMechanicalParametersAtX(const Real& x_curv, Real& youngModulus, Real& cPoisson, Real& massDensity) const;


/**
Expand Down
40 changes: 10 additions & 30 deletions src/BeamAdapter/component/engine/WireRestShape.inl
Original file line number Diff line number Diff line change
Expand Up @@ -258,26 +258,7 @@ void WireRestShape<DataTypes>::getRestTransformOnX(Transform &global_H_local, co


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

// Depending on the position of the beam, determine the corresponding section material and returning its Young modulus
for (sofa::Size i = 1; i < keyPts.size(); ++i)
{
if (x_used <= keyPts[i])
{
return l_sectionMaterials.get(i - 1)->getYoungModulusAtX(youngModulus, cPoisson);
}
}

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


template <class DataTypes>
void WireRestShape<DataTypes>::getInterpolationParam(const Real& x_curv, Real &_rho, Real &_A, Real &_Iy , Real &_Iz, Real &_Asy, Real &_Asz, Real &_J) const
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();
Expand All @@ -287,17 +268,18 @@ void WireRestShape<DataTypes>::getInterpolationParam(const Real& x_curv, Real &_
{
if (x_used <= keyPts[i])
{
return l_sectionMaterials.get(i - 1)->getInterpolationParam(_rho, _A, _Iy, _Iz, _Asy, _Asz, _J);
return l_sectionMaterials.get(i - 1)->getBeamSection();
}
}

msg_error() << " problem in getInterpolationParam : x_curv " << x_curv << " is not between keyPoints" << keyPts;
msg_error() << " problem in getBeamSection : x_curv " << x_curv << " is not between keyPoints" << keyPts;
static const BeamSection emptySection{};
return emptySection;
}



template <class DataTypes>
const BeamSection& WireRestShape<DataTypes>::getBeamSectionAtX(const Real& x_curv) const
void WireRestShape<DataTypes>::getInterpolationParametersAtX(const Real& x_curv, Real &_A, Real &_Iy , Real &_Iz, Real &_Asy, Real &_Asz, Real &_J) const
{
const Real x_used = x_curv - Real(EPSILON);
const type::vector<Real>& keyPts = d_keyPoints.getValue();
Expand All @@ -307,18 +289,16 @@ const BeamSection& WireRestShape<DataTypes>::getBeamSectionAtX(const Real& x_cur
{
if (x_used <= keyPts[i])
{
return l_sectionMaterials.get(i - 1)->getBeamSection();
return l_sectionMaterials.get(i - 1)->getInterpolationParameters(_A, _Iy, _Iz, _Asy, _Asz, _J);
}
}

msg_error() << " problem in getBeamSection : x_curv " << x_curv << " is not between keyPoints" << keyPts;
static const BeamSection emptySection{};
return emptySection;
msg_error() << " problem in getInterpolationParam : x_curv " << x_curv << " is not between keyPoints" << keyPts;
}


template <class DataTypes>
void WireRestShape<DataTypes>::getMechanicalParamAtX(const Real& x_curv, Real& youngModulus, Real& cPoisson, Real& massDensity) const
void WireRestShape<DataTypes>::getMechanicalParametersAtX(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();
Expand All @@ -328,7 +308,7 @@ void WireRestShape<DataTypes>::getMechanicalParamAtX(const Real& x_curv, Real& y
{
if (x_used <= keyPts[i])
{
return l_sectionMaterials.get(i - 1)->getMechanicalParamAtX(youngModulus, cPoisson, massDensity);
return l_sectionMaterials.get(i - 1)->getMechanicalParameters(youngModulus, cPoisson, massDensity);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class AdaptiveBeamForceFieldAndMass : public core::behavior::Mass<DataTypes>

Real _A, _L, _Iy, _Iz, _Asy, _Asz, _J; ///< Interpolation & geometrical parameters
Real _rho;
Real _youngM;
Real _cPoisson;
};

public:
Expand Down Expand Up @@ -198,7 +200,6 @@ class AdaptiveBeamForceFieldAndMass : public core::behavior::Mass<DataTypes>

protected :
SingleLink<AdaptiveBeamForceFieldAndMass<DataTypes>, BInterpolation, BaseLink::FLAG_STOREPATH|BaseLink::FLAG_STRONGLINK> l_interpolation;
SingleLink<AdaptiveBeamForceFieldAndMass<DataTypes>, WireRestShape, BaseLink::FLAG_STOREPATH|BaseLink::FLAG_STRONGLINK> l_instrumentParameters;

void applyMassLarge( VecDeriv& df, int bIndex, Index nd0Id, Index nd1Id, SReal factor);
void applyStiffnessLarge( VecDeriv& df, const VecDeriv& dx, int beam, Index nd0Id, Index nd1Id, SReal factor );
Expand Down
Loading

0 comments on commit 56548b8

Please sign in to comment.