Skip to content

Commit

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

* fix warnings in SofaPhysicsSimulation

* clean and fix compilation

* fix compilation

* fix SofaPhysicsSimulation.h

* fix warning in caduceus scene due to missing Sofa.Component.LinearSystem module

* fix SofaPhysicsSimulation.inl

* use narrow_cast in ConstantSparsityPatternSystem
  • Loading branch information
hugtalbot authored Oct 20, 2023
1 parent f6bee9f commit 9653dc2
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ bool LCPConstraintSolver::prepareStates(const core::ConstraintParams * /*cParams
msg_info() <<" propagate DXn performed - collision called" ;

SCOPED_TIMER("resetContactForce");

for (const auto& cc : l_constraintCorrections)
{
cc->resetContactForce();
Expand Down Expand Up @@ -1026,7 +1027,7 @@ int LCPConstraintSolver::lcp_gaussseidel_unbuilt(SReal *dfree, SReal *f, std::ve
{
bool elem1 = false;
bool elem2 = false;
for (const auto cc : l_constraintCorrections)
for (const auto& cc : l_constraintCorrections)
{
if(cc->hasConstraintNumber(c1))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ void ConstantSparsityPatternSystem<TMatrix, TVector>::resizeSystem(sofa::Size n)

if (this->getSystemMatrix())
{
if (n != this->getSystemMatrix()->rowSize() || n != this->getSystemMatrix()->colSize())
Index nIndex = sofa::helper::narrow_cast<Index>(n);
if (nIndex != this->getSystemMatrix()->rowSize() || nIndex != this->getSystemMatrix()->colSize())
{
this->getSystemMatrix()->resize(n, n);
}
Expand Down Expand Up @@ -336,12 +337,6 @@ void ConstantSparsityPatternSystem<TMatrix, TVector>::preAssembleSystem(const co

if (isConstantSparsityPatternUsedYet())
{
// this->getSystemMatrix()->compressed = true;
for (const auto& mat : this->m_localMappedMatrices)
{
// mat.second->compressed = true;
}

reinitLocalMatrices(this->template getLocalMatrixMap<Contribution::STIFFNESS>());
reinitLocalMatrices(this->template getLocalMatrixMap<Contribution::MASS>());
reinitLocalMatrices(this->template getLocalMatrixMap<Contribution::DAMPING>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,14 @@ void EllipsoidForceField<DataTypes>::addForce(const sofa::core::MechanicalParams
const Real stiffabs = helper::rabs(stiffness);
//const Real s2 = (stiff < 0 ? - stiff*stiff : stiff*stiff );
Coord inv_r2;
for (int j=0; j<N; j++) inv_r2[j] = 1/(r[j]*r[j]);
for (unsigned int j=0; j<N; j++)
{
inv_r2[j] = 1 / (r[j] * r[j]);
}
sofa::type::vector<Contact>* contacts = this->d_contacts.beginEdit();
contacts->clear();
f1.resize(p1.size());
for (unsigned int i=0; i<p1.size(); i++)
for (Size i=0; i<p1.size(); i++)
{
Coord dp = p1[i] - center;
Real norm2 = 0;
Expand All @@ -119,7 +122,10 @@ void EllipsoidForceField<DataTypes>::addForce(const sofa::core::MechanicalParams
Real norm = helper::rsqrt(norm2);
Real v = norm-1;
Coord grad;
for (int j=0; j<N; j++) grad[j] = dp[j]*inv_r2[j];
for (unsigned int j=0; j<N; j++)
{
grad[j] = dp[j]*inv_r2[j];
}
Real gnorm2 = grad.norm2();
Real gnorm = helper::rsqrt(gnorm2);
//grad /= gnorm; //.normalize();
Expand All @@ -132,9 +138,9 @@ void EllipsoidForceField<DataTypes>::addForce(const sofa::core::MechanicalParams
Real fact1 = -stiffabs / (norm * gnorm);
Real fact2 = -stiffabs*v / gnorm;
Real fact3 = -stiffabs*v / gnorm2;
for (int ci = 0; ci < N; ++ci)
for (unsigned int ci = 0; ci < N; ++ci)
{
for (int cj = 0; cj < N; ++cj)
for (unsigned int cj = 0; cj < N; ++cj)
c.m[ci][cj] = grad[ci]*grad[cj] * (fact1 + fact3*inv_r2[cj]);
c.m[ci][ci] += fact2*inv_r2[ci];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void addMultTransposeEigen(LhsMatrixDeriv& lhs, const Eigen::SparseMatrix<Real,
// check the next LhsDeriv::total_size rows for potential non zero values
// inside the block [k, bCol, k+LhsDeriv::total_size, bCol+RhsDeriv::total_size]
bool blockEmpty = true;
for (int j = 0; j < LhsDeriv::total_size; ++j)
for (Size j = 0; j < LhsDeriv::total_size; ++j)
{
typename EigenSparseMatrix::InnerIterator it(jacobianT, k+j);
// advance until we are either invalid or inside the block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ public :

if( m.rowIndex.empty() ) return; // if m is null

for( Index xi = 0 ; xi < rowIndex.size() ; ++xi ) // for each non-null transpose block column
for( Size xi = 0 ; xi < rowIndex.size() ; ++xi ) // for each non-null transpose block column
{
unsigned mr = 0; // block row index in m

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ using sofa::helper::logging::MessageDispatcher;
using sofa::helper::logging::LoggingMessageHandler;

SofaPhysicsSimulation::SofaPhysicsSimulation(bool useGUI_, int GUIFramerate_)
: useGUI(useGUI_)
: m_msgIsActivated(false)
, useGUI(useGUI_)
, GUIFramerate(GUIFramerate_)
, m_msgIsActivated(false)
{
sofa::helper::init();
static bool first = true;
Expand Down Expand Up @@ -339,8 +339,7 @@ SofaPhysicsSimulation::SofaPhysicsSimulation(bool useGUI_, int GUIFramerate_)
lastH = 0;
vparams = sofa::core::visual::VisualParams::defaultInstance();

m_Simulation = new sofa::simulation::graph::DAGSimulation();
sofa::simulation::setSimulation(m_Simulation);
assert(sofa::simulation::getSimulation());

sofa::component::init(); // force dependency on Sofa.Component

Expand Down Expand Up @@ -396,12 +395,12 @@ int SofaPhysicsSimulation::load(const char* cfilename)
sofa::helper::BackTrace::autodump();

sofa::helper::system::DataRepository.findFile(filename);
m_RootNode = m_Simulation->load(filename.c_str());
m_RootNode = sofa::simulation::node::load(filename.c_str());
int result = API_SUCCESS;
if (m_RootNode.get())
{
sceneFileName = filename;
m_Simulation->init(m_RootNode.get());
sofa::simulation::node::initRoot(m_RootNode.get());
result = updateOutputMeshes();

if ( useGUI ) {
Expand All @@ -410,7 +409,7 @@ int SofaPhysicsSimulation::load(const char* cfilename)
}
else
{
m_RootNode = m_Simulation->createNewGraph("");
m_RootNode = sofa::simulation::getSimulation()->createNewGraph("");
return API_SCENE_FAILED;
}
initTexturesDone = false;
Expand All @@ -425,7 +424,7 @@ int SofaPhysicsSimulation::unload()
{
if (m_RootNode.get())
{
m_Simulation->unload(m_RootNode);
sofa::simulation::node::unload(m_RootNode);
}
else
{
Expand Down Expand Up @@ -471,7 +470,7 @@ void SofaPhysicsSimulation::createScene()
m_RootNode->setGravity({ 0,-9.8,0 });
this->createScene_impl();

m_Simulation->init(m_RootNode.get());
sofa::simulation::node::initRoot(m_RootNode.get());

updateOutputMeshes();
}
Expand Down Expand Up @@ -604,7 +603,7 @@ void SofaPhysicsSimulation::reset()
{
if (getScene())
{
getSimulation()->reset(getScene());
sofa::simulation::node::reset(getScene());
this->update();
}
}
Expand Down Expand Up @@ -632,8 +631,8 @@ void SofaPhysicsSimulation::step()
sofa::simulation::Node* groot = getScene();
if (!groot) return;
beginStep();
getSimulation()->animate(groot);
getSimulation()->updateVisual(groot);
sofa::simulation::node::animate(groot);
sofa::simulation::node::updateVisual(groot);
if ( useGUI ) {
sofa::gui::common::BaseGUI* gui = sofa::gui::common::GUIManager::getGUI();
gui->stepMainLoop();
Expand Down Expand Up @@ -779,7 +778,7 @@ std::string SofaPhysicsSimulation::getMessage(int messageId, int& msgType)
{
const std::vector<sofa::helper::logging::Message>& msgs = m_msgHandler->getMessages();

if (messageId >= msgs.size()) {
if (messageId >= (int)msgs.size()) {
msgType = -1;
return "Error messageId out of bounds";
}
Expand Down Expand Up @@ -958,7 +957,7 @@ void SofaPhysicsSimulation::drawGL()
if (!initTexturesDone)
{
std::cout << "INIT VISUAL" << std::endl;
getSimulation()->initTextures(groot);
sofa::simulation::node::initTextures(groot);
bool setView = false;
groot->get(currentCamera);
if (!currentCamera)
Expand Down Expand Up @@ -1049,7 +1048,7 @@ void SofaPhysicsSimulation::drawGL()
glMatrixMode(GL_MODELVIEW);
glLoadMatrixd(lastModelviewMatrix);

getSimulation()->draw(vparams,groot);
sofa::simulation::node::draw(vparams,groot);

glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class SOFA_SOFAPHYSICSAPI_API SofaPhysicsSimulation
#endif
protected:

sofa::simulation::Simulation* m_Simulation;
sofa::simulation::Node::SPtr m_RootNode;
std::string sceneFileName;
/// Pointer to the LoggingMessageHandler
Expand Down Expand Up @@ -174,7 +173,7 @@ class SOFA_SOFAPHYSICSAPI_API SofaPhysicsSimulation
}
sofa::simulation::Simulation* getSimulation() const
{
return m_Simulation;
return sofa::simulation::getSimulation();
}
sofa::simulation::Node* getScene() const
{
Expand Down
1 change: 1 addition & 0 deletions examples/Demos/caduceus.scn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [InteractiveCamera VisualStyle] -->
<RequiredPlugin name="Sofa.GL.Component.Rendering3D"/> <!-- Needed to use components [OglModel] -->
<RequiredPlugin name="Sofa.GL.Component.Shader"/> <!-- Needed to use components [LightManager SpotLight] -->
<RequiredPlugin name="Sofa.Component.LinearSystem"/> <!-- Needed to use components [MatrixLinearSystem] -->
</Node>

<VisualStyle displayFlags="showVisual " /> <!--showBehaviorModels showCollisionModels-->
Expand Down

0 comments on commit 9653dc2

Please sign in to comment.