Skip to content
Merged
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
23 changes: 10 additions & 13 deletions Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@
******************************************************************************/
#pragma once

#include <sofa/component/mass/RigidMassType.h>
#include <sofa/component/mass/VecMassType.h>
#include <sofa/component/mass/config.h>

#include <sofa/type/vector.h>
#include <sofa/type/Vec.h>
#include <sofa/defaulttype/VecTypes.h>
#include <sofa/defaulttype/RigidTypes.h>
#include <sofa/core/behavior/Mass.h>
#include <sofa/core/topology/TopologyData.h>
#include <sofa/core/behavior/TopologyAccessor.h>
#include <sofa/core/objectmodel/DataFileName.h>

#include <sofa/component/mass/VecMassType.h>
#include <sofa/component/mass/RigidMassType.h>
#include <sofa/core/topology/TopologyData.h>
#include <sofa/defaulttype/RigidTypes.h>
#include <sofa/defaulttype/VecTypes.h>
#include <sofa/type/Vec.h>
#include <sofa/type/vector.h>

#include <type_traits>

Expand Down Expand Up @@ -60,10 +59,10 @@ public :
* @tparam GeometricalTypes type of the geometry, i.e type of the state associated with the topology (if the topology and the mass relates to the same state, this will be the same as DataTypes)
*/
template <class DataTypes, class GeometricalTypes = DataTypes>
class DiagonalMass : public core::behavior::Mass<DataTypes>
class DiagonalMass : public core::behavior::Mass<DataTypes>, public virtual sofa::core::behavior::TopologyAccessor
{
public:
SOFA_CLASS(SOFA_TEMPLATE2(DiagonalMass,DataTypes, GeometricalTypes), SOFA_TEMPLATE(core::behavior::Mass,DataTypes));
SOFA_CLASS2(SOFA_TEMPLATE2(DiagonalMass,DataTypes, GeometricalTypes), SOFA_TEMPLATE(core::behavior::Mass,DataTypes), sofa::core::behavior::TopologyAccessor);

using TMassType = typename sofa::component::mass::MassType<DataTypes>::type;

Expand Down Expand Up @@ -113,8 +112,6 @@ class DiagonalMass : public core::behavior::Mass<DataTypes>
/// value defining the initialization process of the mass (0 : totalMass, 1 : massDensity, 2 : vertexMass)
int m_initializationProcess;

/// Link to be set to the topology container in the component graph.
SingleLink<DiagonalMass<DataTypes, GeometricalTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;
/// Link to be set to the MechanicalObject associated with the geometry
SingleLink<DiagonalMass<DataTypes, GeometricalTypes>, sofa::core::behavior::MechanicalState<GeometricalTypes>, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_geometryState;

Expand Down
18 changes: 2 additions & 16 deletions Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ DiagonalMass<DataTypes, GeometricalTypes>::DiagonalMass()
, d_showCenterOfGravity( initData(&d_showCenterOfGravity, false, "showGravityCenter", "Display the center of gravity of the system" ) )
, d_showAxisSize( initData(&d_showAxisSize, 1.0f, "showAxisSizeFactor", "Factor length of the axis displayed (only used for rigids)" ) )
, d_fileMass( initData(&d_fileMass, "filename", "Xsp3.0 file to specify the mass parameters" ) )
, l_topology(initLink("topology", "link to the topology container"))
, l_geometryState(initLink("geometryState", "link to the MechanicalObject associated with the geometry"))
, m_massTopologyType(sofa::geometry::ElementType::UNKNOWN)
{
Expand Down Expand Up @@ -756,22 +755,9 @@ void DiagonalMass<DataTypes, GeometricalTypes>::initTopologyHandlers()
template <class DataTypes, class GeometricalTypes>
bool DiagonalMass<DataTypes, GeometricalTypes>::checkTopology()
{
if (l_topology.empty())
{
msg_info() << "Link \"topology\" to the Topology container should be set to ensure right behavior. First Topology found in current context will be used.";
l_topology.set(this->getContext()->getMeshTopologyLink());
}

if (l_topology.get() == nullptr)
{
msg_error() << "No topology component found at path: " << l_topology.getLinkedPath() << ", nor in current context: " << this->getContext()->name;
sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
this->validateTopology();
if (this->isComponentStateInvalid())
return false;
}
else
{
msg_info() << "Topology path used: '" << l_topology.getLinkedPath() << "'";
}

if (l_geometryState.empty())
{
Expand Down
8 changes: 3 additions & 5 deletions Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

//VERY IMPORTANT FOR GRAPHS
#include <sofa/helper/map.h>
#include <sofa/core/topology/BaseMeshTopology.h>
#include <sofa/core/behavior/TopologyAccessor.h>

#include <type_traits>

Expand All @@ -62,10 +62,10 @@ template <class DataTypes, class TMassType>
* @tparam GeometricalTypes type of the geometry, i.e type of the state associated with the topology (if the topology and the mass relates to the same state, this will be the same as DataTypes)
*/
template <class DataTypes, class GeometricalTypes = DataTypes>
class MeshMatrixMass : public core::behavior::Mass<DataTypes>
class MeshMatrixMass : public core::behavior::Mass<DataTypes>, public virtual core::behavior::TopologyAccessor
{
public:
SOFA_CLASS(SOFA_TEMPLATE2(MeshMatrixMass,DataTypes, GeometricalTypes), SOFA_TEMPLATE(core::behavior::Mass,DataTypes));
SOFA_CLASS2(SOFA_TEMPLATE2(MeshMatrixMass,DataTypes, GeometricalTypes), SOFA_TEMPLATE(core::behavior::Mass,DataTypes), core::behavior::TopologyAccessor);

using TMassType = typename sofa::component::mass::MassType<DataTypes>::type;

Expand Down Expand Up @@ -109,8 +109,6 @@ class MeshMatrixMass : public core::behavior::Mass<DataTypes>
Data< bool > d_printMass; ///< Boolean to print the mass
Data< std::map < std::string, sofa::type::vector<double> > > f_graph; ///< Graph of the controlled potential

/// Link to be set to the topology container in the component graph.
SingleLink<MeshMatrixMass<DataTypes, GeometricalTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;
/// Link to be set to the MechanicalObject associated with the geometry
SingleLink<MeshMatrixMass<DataTypes, GeometricalTypes>, sofa::core::behavior::MechanicalState<GeometricalTypes>, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_geometryState;

Expand Down
20 changes: 3 additions & 17 deletions Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ MeshMatrixMass<DataTypes, GeometricalTypes>::MeshMatrixMass()
, d_lumping( initData(&d_lumping, false, "lumping","If true, the mass matrix is lumped, meaning the mass matrix becomes diagonal (summing all mass values of a line on the diagonal)") )
, d_printMass( initData(&d_printMass, false, "printMass","boolean if you want to check the mass conservation") )
, f_graph( initData(&f_graph,"graph","Graph of the controlled potential") )
, l_topology(initLink("topology", "link to the topology container"))
, l_geometryState(initLink("geometryState", "link to the MechanicalObject associated with the geometry"))
, m_massTopologyType(geometry::ElementType::UNKNOWN)
{
Expand Down Expand Up @@ -1035,22 +1034,9 @@ void MeshMatrixMass<DataTypes, GeometricalTypes>::init()
template <class DataTypes, class GeometricalTypes>
sofa::geometry::ElementType MeshMatrixMass<DataTypes, GeometricalTypes>::checkTopology()
{
if (l_topology.empty())
{
msg_info() << "Link \"topology\" to the Topology container should be set to ensure right behavior. First Topology found in current context will be used.";
l_topology.set(this->getContext()->getMeshTopologyLink());
}

if (l_topology.get() == nullptr)
{
msg_error() << "No topology component found at path: " << l_topology.getLinkedPath() << ", nor in current context: " << this->getContext()->name;
sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
return sofa::geometry::ElementType::POINT;
}
else
{
msg_info() << "Topology path used: '" << l_topology.getLinkedPath() << "'";
}
this->validateTopology();
if (this->isComponentStateInvalid())
return geometry::ElementType::POINT;

if (l_geometryState.empty())
{
Expand Down
18 changes: 6 additions & 12 deletions Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,24 @@
* Contact information: [email protected] *
******************************************************************************/
#pragma once
#include <sofa/component/mass/RigidMassType.h>
#include <sofa/component/mass/VecMassType.h>
#include <sofa/component/mass/config.h>

#include <sofa/defaulttype/VecTypes.h>
#include <sofa/core/behavior/Mass.h>
#include <sofa/core/behavior/MechanicalState.h>
#include <sofa/linearalgebra/BaseVector.h>
#include <sofa/core/behavior/TopologyAccessor.h>
#include <sofa/core/objectmodel/DataFileName.h>
#include <sofa/core/topology/BaseMeshTopology.h>
#include <sofa/core/topology/TopologySubsetIndices.h>

#include <sofa/component/mass/VecMassType.h>
#include <sofa/component/mass/RigidMassType.h>
#include <sofa/defaulttype/VecTypes.h>
#include <sofa/linearalgebra/BaseVector.h>

#include <type_traits>

namespace sofa::component::mass
{

template <class DataTypes>
class UniformMass : public core::behavior::Mass<DataTypes>
class UniformMass : public core::behavior::Mass<DataTypes>, public virtual core::behavior::TopologyAccessor
{
public:
SOFA_CLASS(SOFA_TEMPLATE(UniformMass,DataTypes),
Expand Down Expand Up @@ -90,10 +88,6 @@ class UniformMass : public core::behavior::Mass<DataTypes>
using core::objectmodel::BaseObject::getContext;
////////////////////////////////////////////////////////////////////////////


/// Link to be set to the topology container in the component graph.
SingleLink <UniformMass<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;

protected:
UniformMass();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ UniformMass<DataTypes>::UniformMass()
"are discarded (useful for parallelization using mesh partitioning)" ) )
, d_indices ( initData ( &d_indices, "indices", "optional local DOF indices. Any computation involving only indices outside of this list are discarded" ) )
, d_preserveTotalMass( initData ( &d_preserveTotalMass, false, "preserveTotalMass", "Prevent totalMass from decreasing when removing particles."))
, l_topology(initLink("topology", "link to the topology container"))
{
constructor_message();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#pragma once
#include <sofa/component/solidmechanics/fem/elastic/config.h>
#include <sofa/core/behavior/ForceField.h>
#include <sofa/core/topology/BaseMeshTopology.h>
#include <sofa/core/behavior/TopologyAccessor.h>


namespace sofa::component::solidmechanics::fem::elastic
Expand All @@ -33,21 +33,18 @@ struct _2DMaterials{};
struct _3DMaterials{};

template<class DataTypes>
class BaseLinearElasticityFEMForceField : virtual public core::behavior::ForceField<DataTypes>
class BaseLinearElasticityFEMForceField : virtual public core::behavior::ForceField<DataTypes>, virtual public core::behavior::TopologyAccessor
{
public:
using Coord = typename DataTypes::Coord;
using VecReal = typename DataTypes::VecReal;
using Real = typename DataTypes::Real;

SOFA_CLASS(SOFA_TEMPLATE(BaseLinearElasticityFEMForceField, DataTypes), SOFA_TEMPLATE(core::behavior::ForceField, DataTypes));
SOFA_CLASS2(SOFA_TEMPLATE(BaseLinearElasticityFEMForceField, DataTypes), SOFA_TEMPLATE(core::behavior::ForceField, DataTypes), core::behavior::TopologyAccessor);

Data<VecReal > d_poissonRatio; ///< FEM Poisson Ratio in Hooke's law [0,0.5[
Data<VecReal > d_youngModulus; ///< FEM Young's Modulus in Hooke's law

/// Link to be set to the topology container in the component graph.
SingleLink<BaseLinearElasticityFEMForceField<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH|BaseLink::FLAG_STRONGLINK> l_topology;

BaseLinearElasticityFEMForceField();

void init() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ template <class DataTypes>
BaseLinearElasticityFEMForceField<DataTypes>::BaseLinearElasticityFEMForceField()
: d_poissonRatio(initData(&d_poissonRatio, { defaultPoissonRatioValue }, "poissonRatio", "FEM Poisson Ratio in Hooke's law [0,0.5["))
, d_youngModulus(initData(&d_youngModulus, { defaultYoungModulusValue }, "youngModulus", "FEM Young's Modulus in Hooke's law"))
, l_topology(initLink("topology", "link to the topology container"))
{
d_poissonRatio.setRequired(true);
d_youngModulus.setRequired(true);
Expand Down Expand Up @@ -87,25 +86,13 @@ template <class DataTypes>
void BaseLinearElasticityFEMForceField<DataTypes>::init()
{
core::behavior::ForceField<DataTypes>::init();
this->validateTopology();

if (l_topology.empty())
if (this->isComponentStateInvalid())
{
msg_info() << "link to Topology container should be set to ensure right behavior. First Topology found in current context will be used.";
l_topology.set(this->getContext()->getMeshTopologyLink());
}

if (l_topology == nullptr)
{
msg_error() << "No topology component found at path: " << this->l_topology.getLinkedPath()
<< ", nor in current context: " << this->getContext()->name << ". Object must have a BaseMeshTopology. "
<< "The list of available BaseMeshTopology components is: "
<< core::ObjectFactory::getInstance()->listClassesDerivedFrom<core::topology::BaseMeshTopology>();
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
return;
}

msg_info() << "Topology path used: '" << this->l_topology.getLinkedPath() << "'";

checkYoungModulus();
checkPoissonRatio();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,23 @@
#pragma once

#include <sofa/component/solidmechanics/fem/elastic/config.h>

#include <sofa/core/behavior/ForceField.h>
#include <sofa/core/topology/BaseMeshTopology.h>
#include <sofa/core/behavior/TopologyAccessor.h>
#include <sofa/core/topology/TopologyData.h>
#include <sofa/defaulttype/VecTypes.h>
#include <sofa/helper/map.h>
#include <sofa/type/Mat.h>
#include <sofa/core/topology/TopologyData.h>

#include <map>
#include <sofa/helper/map.h>

namespace sofa::component::solidmechanics::fem::elastic
{

template<class DataTypes>
class QuadBendingFEMForceField : public core::behavior::ForceField<DataTypes>
class QuadBendingFEMForceField : public core::behavior::ForceField<DataTypes>, public virtual core::behavior::TopologyAccessor
{
public:
SOFA_CLASS(SOFA_TEMPLATE(QuadBendingFEMForceField, DataTypes), SOFA_TEMPLATE(core::behavior::ForceField, DataTypes));
SOFA_CLASS2(SOFA_TEMPLATE(QuadBendingFEMForceField, DataTypes), SOFA_TEMPLATE(core::behavior::ForceField, DataTypes), core::behavior::TopologyAccessor);

typedef core::behavior::ForceField<DataTypes> Inherited;
typedef typename DataTypes::VecCoord VecCoord;
Expand Down Expand Up @@ -226,10 +225,6 @@ protected :
Data<type::vector<Real> > d_poisson; ///< Poisson ratio in Hooke's law (vector)
Data<type::vector<Real> > d_young; ///< Young modulus in Hooke's law (vector)
Data<Real> d_thickness; ///< Thickness of the elements

/// Link to be set to the topology container in the component graph.
SingleLink<QuadBendingFEMForceField<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;

};
#if !defined(SOFA_COMPONENT_FORCEFIELD_QUADBENDINGFEMFORCEFIELD_CPP)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ QuadBendingFEMForceField<DataTypes>::QuadBendingFEMForceField()
, d_poisson(initData(&d_poisson, type::vector<Real>(1, static_cast<Real>(0.45)), "poissonRatio", "Poisson ratio in Hooke's law (vector)"))
, d_young(initData(&d_young, type::vector<Real>(1, static_cast<Real>(1000.0)), "youngModulus", "Young modulus in Hooke's law (vector)"))
, d_thickness(initData(&d_thickness, Real(1.), "thickness", "Thickness of the elements"))
, l_topology(initLink("topology", "link to the topology container"))

{
}
Expand All @@ -93,21 +92,13 @@ template <class DataTypes>
void QuadBendingFEMForceField<DataTypes>::init()
{
this->Inherited::init();
if (l_topology.empty())
{
msg_info() << "link to Topology container should be set to ensure right behavior. First Topology found in current context will be used.";
l_topology.set(this->getContext()->getMeshTopologyLink());
}

m_topology = l_topology.get();
msg_info() << "Topology path used: '" << l_topology.getLinkedPath() << "'";
this->validateTopology();

if (m_topology == nullptr)
{
msg_error() << "No topology component found at path: " << l_topology.getLinkedPath() << ", nor in current context: " << this->getContext()->name;
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
if (this->isComponentStateInvalid())
return;
}

m_topology = this->l_topology.get();

if (m_topology->getNbQuads() == 0)
{
msg_warning() << "No quads found in linked Topology.";
Expand Down
2 changes: 2 additions & 0 deletions Sofa/framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ set(HEADER_FILES
${SRC_ROOT}/behavior/SingleStateAccessor.h
${SRC_ROOT}/behavior/SingleStateAccessor.inl
${SRC_ROOT}/behavior/StateAccessor.h
${SRC_ROOT}/behavior/TopologyAccessor.h
${SRC_ROOT}/behavior/fwd.h
${SRC_ROOT}/collision/BroadPhaseDetection.h
${SRC_ROOT}/collision/CollisionAlgorithm.h
Expand Down Expand Up @@ -285,6 +286,7 @@ set(SOURCE_FILES
${SRC_ROOT}/behavior/ProjectiveConstraintSet.cpp
${SRC_ROOT}/behavior/SingleMatrixAccessor.cpp
${SRC_ROOT}/behavior/SingleStateAccessor.cpp
${SRC_ROOT}/behavior/TopologyAccessor.cpp
${SRC_ROOT}/behavior/fwd.cpp
${SRC_ROOT}/collision/BroadPhaseDetection.cpp
${SRC_ROOT}/collision/Contact.cpp
Expand Down
Loading
Loading