Skip to content

Commit

Permalink
Add RodSectionMaterial classes to be used in WireRestShape (#114)
Browse files Browse the repository at this point in the history
* Add WireSectionMaterial component to store the material property of a wire section and delegate the interpolation param to this class

* [src] Move numEdges and numEdgesCollision into WireSectionMaterial

* Add float/double methods.

* Update src/BeamAdapter/component/model/WireSectionMaterial.cpp

Co-authored-by: Frederick Roy <[email protected]>

* Turn severals methods into const

* [WireSection] Update WireSectionMaterial to be templated

* Fix compilation

* backup work on moving loader to material

* backup work on new RodSection classes architecture

* Add RodSpire and RodStraight sections implementation

* Add RodMeshSection implementation

* Clean and doc Rod section classes and WireRestShape

* Remove BaseRodSectionMaterial.cpp

* Forgot to update cudaInstantiations

* fix compilation

* Fix Cuda instanciations

---------

Co-authored-by: Frederick Roy <[email protected]>
Co-authored-by: Frederick Roy <[email protected]>
  • Loading branch information
3 people authored Oct 20, 2023
1 parent bc63e7a commit fc6a7df
Show file tree
Hide file tree
Showing 16 changed files with 1,121 additions and 6 deletions.
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ set(HEADER_FILES
${BEAMADAPTER_SRC}/component/mapping/MultiAdaptiveBeamMapping.h
${BEAMADAPTER_SRC}/component/mapping/MultiAdaptiveBeamMapping.inl

${BEAMADAPTER_SRC}/component/model/BaseRodSectionMaterial.h
${BEAMADAPTER_SRC}/component/model/BaseRodSectionMaterial.inl
${BEAMADAPTER_SRC}/component/model/RodMeshSection.h
${BEAMADAPTER_SRC}/component/model/RodMeshSection.inl
${BEAMADAPTER_SRC}/component/model/RodSpireSection.h
${BEAMADAPTER_SRC}/component/model/RodSpireSection.inl
${BEAMADAPTER_SRC}/component/model/RodStraightSection.h
${BEAMADAPTER_SRC}/component/model/RodStraightSection.inl

${BEAMADAPTER_SRC}/utils/BeamSection.h
${BEAMADAPTER_SRC}/utils/BeamActions.h
${BEAMADAPTER_SRC}/utils/deprecatedcomponent.h
)
)

set(SOURCE_FILES
${BEAMADAPTER_SRC}/initBeamAdapter.cpp
Expand All @@ -86,7 +95,12 @@ set(SOURCE_FILES
${BEAMADAPTER_SRC}/component/mapping/AdaptiveBeamMapping.cpp
${BEAMADAPTER_SRC}/component/mapping/BeamLengthMapping.cpp
${BEAMADAPTER_SRC}/component/mapping/MultiAdaptiveBeamMapping.cpp
)

${BEAMADAPTER_SRC}/component/model/BaseRodSectionMaterial.cpp
${BEAMADAPTER_SRC}/component/model/RodMeshSection.cpp
${BEAMADAPTER_SRC}/component/model/RodSpireSection.cpp
${BEAMADAPTER_SRC}/component/model/RodStraightSection.cpp
)

if(SofaImplicitField_FOUND)
set(HEADER_FILES ${HEADER_FILES}
Expand Down
4 changes: 2 additions & 2 deletions src/BeamAdapter/component/engine/WireRestShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ class WireRestShape : public core::objectmodel::BaseObject
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);
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);
void getInterpolationParam(const Real& x_curv, Real &_rho, Real &_A, Real &_Iy , Real &_Iz, Real &_Asy, Real &_Asz, Real &_J) const;

/**
* This function provides a type::vector with the curviliar abscissa of the noticeable point(s)
Expand Down
4 changes: 2 additions & 2 deletions src/BeamAdapter/component/engine/WireRestShape.inl
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,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)
void WireRestShape<DataTypes>::getYoungModulusAtX(const Real& x_curv, Real& youngModulus, Real& cPoisson) const
{
//Initialization
Real _E1, _E2;
Expand Down Expand Up @@ -462,7 +462,7 @@ void WireRestShape<DataTypes>::getYoungModulusAtX(const Real& x_curv, Real& youn


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)
void WireRestShape<DataTypes>::getInterpolationParam(const Real& x_curv, Real &_rho, Real &_A, Real &_Iy , Real &_Iz, Real &_Asy, Real &_Asz, Real &_J) const
{
if(x_curv <= this->d_straightLength.getValue())
{
Expand Down
34 changes: 34 additions & 0 deletions src/BeamAdapter/component/model/BaseRodSectionMaterial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/******************************************************************************
* BeamAdapter plugin *
* (c) 2006 Inria, University of Lille, CNRS *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: see Authors.md *
* *
* Contact information: [email protected] *
******************************************************************************/
#define SOFA_PLUGIN_BEAMADAPTER_BASERODSECTIONMATERIAL_CPP

#include <BeamAdapter/component/model/BaseRodSectionMaterial.inl>
#include <sofa/defaulttype/RigidTypes.h>

namespace sofa::beamadapter
{

using namespace sofa::defaulttype;

template class SOFA_BEAMADAPTER_API BaseRodSectionMaterial<Rigid3Types>;

}// namespace sofa::beamadapter
122 changes: 122 additions & 0 deletions src/BeamAdapter/component/model/BaseRodSectionMaterial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/******************************************************************************
* BeamAdapter plugin *
* (c) 2006 Inria, University of Lille, CNRS *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: see Authors.md *
* *
* Contact information: [email protected] *
******************************************************************************/
#pragma once

#include <BeamAdapter/config.h>
#include <BeamAdapter/utils/BeamSection.h>
#include <sofa/defaulttype/SolidTypes.h>
#include <sofa/core/objectmodel/BaseObject.h>
#include <sofa/component/topology/container/dynamic/EdgeSetTopologyModifier.h>
#include <sofa/core/loader/MeshLoader.h>

namespace sofa::beamadapter
{

using sofa::core::loader::MeshLoader;

/**
* \class BaseRodSectionMaterial
* \brief Base class describing a Rod section which will define a set of beam elements.
*
* This class provide an api to define a rod/wire section using physical and geometry parameters.
* The section will then be modellized by a set of beam elements. Inheriting class should provide the geometry structure:
* @sa RodMeshSection to define a rod using a mesh file, @sa RodSpireSection or @sa RodStraightSection to define procedural shapes.
* Method @sa initSection and @sa getRestTransformOnX should be overriden to provide the correct creation and interpolation.
*
* The rod section is described by:
* - Topology parameters: vertices and edges @sa d_nbEdgesVisu and @sa d_nbEdgesCollis
* - Geometry parameters: radius @sa d_radius, @sa d_innerRadius and length @sa d_length
* - Mechanical parameters: @sa d_poissonRatio and @sa d_youngModulus
*/
template <class DataTypes>
class BaseRodSectionMaterial : public core::objectmodel::BaseObject
{
public:
SOFA_CLASS(SOFA_TEMPLATE(BaseRodSectionMaterial, DataTypes), core::objectmodel::BaseObject);

using Coord = typename DataTypes::Coord;
using Real = typename Coord::value_type;
using Transform = typename sofa::defaulttype::SolidTypes<Real>::Transform;
using Vec3 = sofa::type::Vec<3, Real>;
using Quat = sofa::type::Quat<Real>;
using Size = sofa::Size;

/////////////////////////// Inherited from BaseObject //////////////////////////////////////////

/// Default Constructor
BaseRodSectionMaterial();

/// init method from BaseObject API. Will call internal @see initSection to be overriden by children
void init() override;


/////////////////////////// Geometry and physics Getter //////////////////////////////////////////

/// Returns the number of visual edges of this section. To be set or computed by child.
[[nodiscard]] int getNbVisualEdges() const { return d_nbEdgesVisu.getValue(); }

/// Returns the number of collision edges of this section. To be set or computed by child.
[[nodiscard]] int getNbCollisionEdges() const { return d_nbEdgesCollis.getValue(); }

/// Returns the total length of this section. To be set or computed by child.
[[nodiscard]] Real getLength() const { return d_length.getValue(); }

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

/// Returns the mass density and the BeamSection of this section
void getInterpolationParam(Real& _rho, Real& _A, Real& _Iy, Real& _Iz, Real& _Asy, Real& _Asz, Real& _J) const;

/// 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)
{
SOFA_UNUSED(global_H_local);
SOFA_UNUSED(x_used);
SOFA_UNUSED(x_start);
}

protected:
/// Internal method to init the section. to be overidden by child.
virtual bool initSection() { return false; }

public:
Data<Real> d_poissonRatio; ///< Data defining the mehcanical Poisson ratio of this section
Data<Real> d_youngModulus; ///< Data defining the mehcanical Young Modulus of this section
Data<Real> d_massDensity; ///< Data defining the mehcanical mass density of this section

Data<Real> d_radius; ///< Data defining the geometry radius of this section
Data<Real> d_innerRadius; ///< Data defining the geometry internal radius of this section is hollow
Data<Real> d_length; ///< Data defining the geometry length of this section

Data<Size> d_nbEdgesVisu; ///< Data defining the number of visual edges composing this section
Data<Size> d_nbEdgesCollis; ///< Data defining the number of collision edges composing this section

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

#if !defined(SOFA_PLUGIN_BEAMADAPTER_BASERODSECTIONMATERIAL_CPP)
extern template class SOFA_BEAMADAPTER_API BaseRodSectionMaterial<sofa::defaulttype::Rigid3Types>;
#endif

} // namespace sofa::beamadapter
96 changes: 96 additions & 0 deletions src/BeamAdapter/component/model/BaseRodSectionMaterial.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/******************************************************************************
* BeamAdapter plugin *
* (c) 2006 Inria, University of Lille, CNRS *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: see Authors.md *
* *
* Contact information: [email protected] *
******************************************************************************/
#pragma once

#include <BeamAdapter/component/model/BaseRodSectionMaterial.h>

namespace sofa::beamadapter
{

template <class DataTypes>
BaseRodSectionMaterial<DataTypes>::BaseRodSectionMaterial()
: d_poissonRatio(initData(&d_poissonRatio, (Real)0.49, "poissonRatio", "Poisson Ratio of this section"))
, d_youngModulus(initData(&d_youngModulus, (Real)5000, "youngModulus", "Young Modulus of this section"))
, d_massDensity(initData(&d_massDensity, (Real)1.0, "massDensity", "Density of the mass (usually in kg/m^3)"))
, d_radius(initData(&d_radius, (Real)1.0, "radius", "Full radius of this section"))
, d_innerRadius(initData(&d_innerRadius, (Real)0.0, "innerRadius", "Inner radius of this section if hollow"))
, d_length(initData(&d_length, (Real)1.0, "length", "Total length of this section"))
, d_nbEdgesVisu(initData(&d_nbEdgesVisu, (Size)10, "nbEdgesVisu", "number of Edges for the visual model"))
, d_nbEdgesCollis(initData(&d_nbEdgesCollis, (Size)20, "nbEdgesCollis", "number of Edges for the collision model"))
{

}


template <class DataTypes>
void BaseRodSectionMaterial<DataTypes>::init()
{
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Loading);

// 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;

// call delegate method to init the section
bool res = initSection();

if (res)
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid);
else
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
}


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


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())
_rho = d_massDensity.getValue();

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

} // namespace sofa::beamadapter
39 changes: 39 additions & 0 deletions src/BeamAdapter/component/model/RodMeshSection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/******************************************************************************
* BeamAdapter plugin *
* (c) 2006 Inria, University of Lille, CNRS *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: see Authors.md *
* *
* Contact information: [email protected] *
******************************************************************************/
#define SOFA_PLUGIN_BEAMADAPTER_RODMESHSECTION_CPP

#include <BeamAdapter/component/model/RodMeshSection.inl>
#include <BeamAdapter/component/model/BaseRodSectionMaterial.inl>
#include <sofa/core/ObjectFactory.h>
#include <sofa/defaulttype/RigidTypes.h>

namespace sofa::beamadapter
{

using namespace sofa::defaulttype;

const int RodMeshSectionClass = core::RegisterObject("Class defining a Rod Section using a MeshLoader and material parameters.")
.add< RodMeshSection<Rigid3Types> >(true);

template class SOFA_BEAMADAPTER_API RodMeshSection<Rigid3Types>;

}// namespace sofa::beamadapter
Loading

0 comments on commit fc6a7df

Please sign in to comment.