Skip to content

Commit

Permalink
[all] Fix warnings (#4291)
Browse files Browse the repository at this point in the history
* [all] Fix warnings

* revert change on scenes wrongly committed

* Apply suggestions from code review

Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com>

* [all] Fix warnings

* Fix runtime error due to useless destructor

* take reviews into account: d_nbThreads back to int

---------

Co-authored-by: Alex Bilger <alxbilger@users.noreply.github.com>
  • Loading branch information
hugtalbot and alxbilger committed Dec 1, 2023
1 parent 3e4ec13 commit 4ecb558
Show file tree
Hide file tree
Showing 22 changed files with 163 additions and 156 deletions.
Expand Up @@ -67,7 +67,7 @@ struct FixedPlaneConstraint_test : public BaseSimulationTest

/// Scene initialization
sofa::simulation::Simulation* simulation;
sofa::simulation::setSimulation(simulation = new sofa::simulation::graph::DAGSimulation());
simulation = sofa::simulation::getSimulation();
simulation::Node::SPtr root = simulation->createNewGraph("root");
root->setGravity( type::Vec3(0,0,0) );

Expand Down
Expand Up @@ -45,14 +45,14 @@ using namespace sofa::component::linearsystem;
template<class Matrix, class Vector>
MatrixLinearSolver<Matrix,Vector>::MatrixLinearSolver()
: Inherit()
, d_parallelInverseProduct(initData(&d_parallelInverseProduct, false,
"parallelInverseProduct", "Parallelize the computation of the product J*M^{-1}*J^T "
"where M is the matrix of the linear system and J is any "
"matrix with compatible dimensions"))
, invertData()
, linearSystem()
, currentMFactor(), currentBFactor(), currentKFactor()
, l_linearSystem(initLink("linearSystem", "The linear system to solve"))
, d_parallelInverseProduct(initData(&d_parallelInverseProduct, false,
"parallelInverseProduct", "Parallelize the computation of the product J*M^{-1}*J^T "
"where M is the matrix of the linear system and J is any "
"matrix with compatible dimensions"))
{
this->addUpdateCallback("parallelInverseProduct", {&d_parallelInverseProduct},
[this](const core::DataTracker& tracker) -> sofa::core::objectmodel::ComponentState
Expand Down
Expand Up @@ -52,13 +52,17 @@ class ConstantLocalMatrix : public virtual AssemblingMatrixAccumulator<c>
template <class TMatrix, core::matrixaccumulator::Contribution c>
void ConstantLocalMatrix<TMatrix, c>::add(const core::matrixaccumulator::no_check_policy&, sofa::SignedIndex row, sofa::SignedIndex col, float value)
{
SOFA_UNUSED(row);
SOFA_UNUSED(col);
static_cast<TMatrix*>(this->m_globalMatrix)->colsValue[insertionOrderList[currentId++]]
+= this->m_cachedFactor * value;
}

template <class TMatrix, core::matrixaccumulator::Contribution c>
void ConstantLocalMatrix<TMatrix, c>::add(const core::matrixaccumulator::no_check_policy&, sofa::SignedIndex row, sofa::SignedIndex col, double value)
{
SOFA_UNUSED(row);
SOFA_UNUSED(col);
static_cast<TMatrix*>(this->m_globalMatrix)->colsValue[insertionOrderList[currentId++]]
+= this->m_cachedFactor * value;
}
Expand Down
36 changes: 33 additions & 3 deletions Sofa/Component/LinearSystem/tests/MatrixLinearSystem_test.cpp
Expand Up @@ -250,9 +250,23 @@ template<class DataTypes>
dfdx(10, 20) += 0.;
}

void addForce(const sofa::core::MechanicalParams*, typename Inherit1::DataVecDeriv& f, const typename Inherit1::DataVecCoord& x, const typename Inherit1::DataVecDeriv& v) override {}
void addDForce(const sofa::core::MechanicalParams* mparams, typename Inherit1::DataVecDeriv& df, const typename Inherit1::DataVecDeriv& dx ) override {}
SReal getPotentialEnergy(const sofa::core::MechanicalParams*, const typename Inherit1::DataVecCoord& x) const override { return 0._sreal; }
void addForce(const sofa::core::MechanicalParams*, typename Inherit1::DataVecDeriv& f, const typename Inherit1::DataVecCoord& x, const typename Inherit1::DataVecDeriv& v) override
{
SOFA_UNUSED(f);
SOFA_UNUSED(x);
SOFA_UNUSED(v);
}
void addDForce(const sofa::core::MechanicalParams* mparams, typename Inherit1::DataVecDeriv& df, const typename Inherit1::DataVecDeriv& dx ) override
{
SOFA_UNUSED(mparams);
SOFA_UNUSED(df);
SOFA_UNUSED(dx);
}
SReal getPotentialEnergy(const sofa::core::MechanicalParams*, const typename Inherit1::DataVecCoord& x) const override
{
SOFA_UNUSED(x);
return 0._sreal;
}
};

/// Empty matrix class with the interface of a BaseMatrix
Expand All @@ -273,26 +287,42 @@ class EmptyMatrix : public sofa::linearalgebra::BaseMatrix
}
SReal element(Index i, Index j) const override
{
SOFA_UNUSED(i);
SOFA_UNUSED(j);
return {};
}
void resize(Index nbRow, Index nbCol) override
{
SOFA_UNUSED(nbRow);
SOFA_UNUSED(nbCol);
}
void clear() override
{
}
void set(Index i, Index j, double v) override
{
SOFA_UNUSED(i);
SOFA_UNUSED(j);
SOFA_UNUSED(v);
}
void add(Index row, Index col, double v) override
{
SOFA_UNUSED(row);
SOFA_UNUSED(col);
SOFA_UNUSED(v);
//add method is empty to prevent crashes in tests
}
void add(Index row, Index col, const sofa::type::Mat3x3d& _M) override
{
SOFA_UNUSED(row);
SOFA_UNUSED(col);
SOFA_UNUSED(_M);
}
void add(Index row, Index col, const sofa::type::Mat3x3f& _M) override
{
SOFA_UNUSED(row);
SOFA_UNUSED(col);
SOFA_UNUSED(_M);
}
static const char* Name() { return "EmptyMatrix"; }
};
Expand Down
Expand Up @@ -82,41 +82,27 @@ class EllipsoidForceField : public core::behavior::ForceField<DataTypes>

};

union
{
SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DEPRECATED() Data<sofa::type::vector<Contact> > contacts; ///< Contacts
Data<sofa::type::vector<Contact> > d_contacts; ///< Contacts
};
Data<sofa::type::vector<Contact> > d_contacts; ///< Vector of contacts
SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DISABLED() DeprecatedAndRemoved contacts; ///< Contacts

EllipsoidForceFieldInternalData<DataTypes> data;

public:

union
{
Data<Coord> d_center; ///< ellipsoid center
SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DEPRECATED() Data<Coord> center; ///< ellipsoid center
};
union
{
Data<Coord> d_vradius; ///< ellipsoid radius
SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DEPRECATED() Data<Coord> vradius; ///< ellipsoid radius
};
union
{
Data<Real> d_stiffness; ///< force stiffness (positive to repulse outward, negative inward)
SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DEPRECATED() Data<Real> stiffness; ///< force stiffness (positive to repulse outward, negative inward)
};
union
{
Data<Real> d_damping; ///< force damping
SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DEPRECATED() Data<Real> damping; ///< force damping
};
union
{
Data<sofa::type::RGBAColor> d_color; ///< ellipsoid color. (default=0,0.5,1.0,1.0)
SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DEPRECATED() Data<sofa::type::RGBAColor> color; ///< ellipsoid color. (default=0,0.5,1.0,1.0)
};
Data<Coord> d_center; ///< ellipsoid center
SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DISABLED() DeprecatedAndRemoved center; ///< ellipsoid center

Data<Coord> d_vradius; ///< ellipsoid radius
SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DISABLED() DeprecatedAndRemoved vradius; ///< ellipsoid radius

Data<Real> d_stiffness; ///< force stiffness (positive to repulse outward, negative inward)
SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DISABLED() DeprecatedAndRemoved stiffness; ///< force stiffness (positive to repulse outward, negative inward)

Data<Real> d_damping; ///< force damping
SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DISABLED() DeprecatedAndRemoved damping; ///< force damping

Data<sofa::type::RGBAColor> d_color; ///< ellipsoid color. (default=0,0.5,1.0,1.0)
SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DISABLED() DeprecatedAndRemoved color; ///< ellipsoid color. (default=0,0.5,1.0,1.0)

protected:
EllipsoidForceField();
Expand Down
Expand Up @@ -57,7 +57,7 @@ namespace sofa::component::mechanicalload

template<class DataTypes>
EllipsoidForceField<DataTypes>::EllipsoidForceField()
: d_contacts(initData(&d_contacts,"contacts", "Contacts"))
: d_contacts(initData(&d_contacts,"contacts", "Vector of contacts"))
, d_center(initData(&d_center, "center", "ellipsoid center"))
, d_vradius(initData(&d_vradius, "vradius", "ellipsoid radius"))
, d_stiffness(initData(&d_stiffness, (Real)500, "stiffness", "force stiffness (positive to repulse outward, negative inward)"))
Expand All @@ -69,12 +69,6 @@ EllipsoidForceField<DataTypes>::EllipsoidForceField()
template <class DataTypes>
EllipsoidForceField<DataTypes>::~EllipsoidForceField()
{
d_contacts.~Data();
d_center.~Data();
d_vradius.~Data();
d_stiffness.~Data();
d_damping.~Data();
d_color.~Data();
}

template<class DataTypes>
Expand Down Expand Up @@ -115,7 +109,7 @@ void EllipsoidForceField<DataTypes>::addForce(const sofa::core::MechanicalParams
{
Coord dp = p1[i] - center;
Real norm2 = 0;
for (int j=0; j<N; j++) norm2 += (dp[j]*dp[j])*inv_r2[j];
for (unsigned int j=0; j<N; j++) norm2 += (dp[j]*dp[j])*inv_r2[j];
//Real d = (norm2-1)*s2;
if ((norm2-1)*stiffness<0)
{
Expand Down
Expand Up @@ -32,10 +32,10 @@
#endif

#ifdef SOFA_BUILD_SOFA_COMPONENT_MECHANICALLOAD
#define SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DEPRECATED()
#define SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DISABLED()
#else
#define SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DEPRECATED() \
SOFA_ATTRIBUTE_DEPRECATED( \
#define SOFA_ELLIPSOIDFORCEFIELD_RENAMEDDATA_DISABLED() \
SOFA_ATTRIBUTE_DISABLED( \
"v23.12", "v24.06", "This Data has been renamed to match convention with d_ prefix.")
#endif // SOFA_BUILD_SOFA_COMPONENT_MECHANICALLOAD

Expand Down
Expand Up @@ -658,8 +658,6 @@ template<class DataTypes>
void TriangularFEMForceFieldOptim<DataTypes>::computePrincipalStress()
{
const VecElement& triangles = m_topology->getTriangles();

sofa::helper::ReadAccessor< core::objectmodel::Data< VecTriangleState > > triStates = d_triangleState;
sofa::helper::WriteAccessor< core::objectmodel::Data< VecTriangleInfo > > triInfos = d_triangleInfo;

Real minStress = 0;
Expand Down
Expand Up @@ -263,7 +263,7 @@ public :
/// Returns the range of indices from the column indices corresponding to the id-th row
Range getRowRange(Index id) const
{
if (id + 1 >= rowBegin.size())
if (id + 1 >= static_cast<Index>(rowBegin.size()))
{
return Range(s_invalidIndex, s_invalidIndex);
}
Expand Down
Expand Up @@ -71,6 +71,7 @@ DefaultAnimationLoop::DefaultAnimationLoop(simulation::Node* _m_node)
: Inherit()
, d_parallelODESolving(initData(&d_parallelODESolving, false, "parallelODESolving", "If true, solves all the ODEs in parallel"))
{
SOFA_UNUSED(_m_node);
this->addUpdateCallback("parallelODESolving", {&d_parallelODESolving},
[this](const core::DataTracker& tracker) -> sofa::core::objectmodel::ComponentState
{
Expand Down
Expand Up @@ -58,15 +58,15 @@ void DefaultCollisionGroupManager_test::onSetUp()
+ "/DefaultCollisionGroupManager_singleObject_test.scn";

// Init simulation
sofa::simulation::setSimulation(simulation = new sofa::simulation::graph::DAGSimulation());
root = sofa::simulation::getSimulation()->load(sceneFilename.c_str());
simulation = sofa::simulation::getSimulation();
root = sofa::simulation::node::load(sceneFilename.c_str());
}

void DefaultCollisionGroupManager_test::onTearDown()
{
if (root != nullptr)
{
sofa::simulation::getSimulation()->unload(root);
sofa::simulation::node::unload(root);
}
}

Expand All @@ -75,15 +75,15 @@ bool DefaultCollisionGroupManager_test::combineSingleObject()
EXPECT_TRUE(root != nullptr);
EXPECT_TRUE(sofa::simulation::getSimulation() != nullptr);

sofa::simulation::getSimulation()->init(root.get());
sofa::simulation::node::initRoot(root.get());

// run 200 time steps
// objectives:
// 1) The simulation does not crash
// 2) Collision prevents the cube to fall through the floor
for (unsigned int i = 0; i < 200; ++i)
{
sofa::simulation::getSimulation()->animate(root.get(), 0.01);
sofa::simulation::node::animate(root.get(), 0.01);
}

auto* baseObject = root->getTreeNode("Cube1")->getObject("mechanicalObject");
Expand Down
Expand Up @@ -147,7 +147,7 @@ struct Monitor_test : public BaseSimulationTest
// make a few steps before checkinf if values are correctly updated in
// Monitor
for (int i = 0; i < 10; ++i)
simulation::getSimulation()->animate(root.get(), 1.0);
simulation::node::animate(root.get(), 1.0);

monitor->testModif(mo.get());

Expand Down

0 comments on commit 4ecb558

Please sign in to comment.