sofa-framework / sofa

Real-time multi-physics simulation with an emphasis on medical simulation.
https://www.sofa-framework.org
GNU Lesser General Public License v2.1
871 stars 297 forks source link

[LinearSystem] Refactor matrix assembly #2777

Closed alxbilger closed 1 year ago

alxbilger commented 2 years ago

Complete documentation here: https://notes.inria.fr/sP50g-5eT7-T3aEXXYcf4g (changes are possible)

Random things to have a look:

[ci-depends-on https://github.com/sofa-framework/Regression/pull/44] [ci-depends-on https://github.com/sofa-framework/SofaPython3/pull/343]


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

alxbilger commented 2 years ago

[ci-build][with-all-tests]

alxbilger commented 1 year ago

[ci-build][with-all-tests]

alxbilger commented 1 year ago

[ci-build]

hugtalbot commented 1 year ago

Unit tests added! Performances using the benchmark scenes seem similar to the current ones. To be reviewed @sofa-framework/reviewers

alxbilger commented 1 year ago

[ci-build][with-all-tests]

hugtalbot commented 1 year ago

Using the PR on penalities contact response works!!!

:point_down:

ezgif-5-dce18d02d7

alxbilger commented 1 year ago

Excellent ! Just make sure that you have an assembled matrix in the scene. Thanks for the feedback

fredroy commented 1 year ago

I tried with some scenes with BeamAdapter and there are crashes & stuff 😬

fredroy commented 1 year ago

[ci-build][full-build][with-all-tests]

alxbilger commented 1 year ago

@fredroy Thanks a lot for the tests. I'll investigate

alxbilger commented 1 year ago

@fredroy I think all the problems you found are only due to RestShapeSpringForceField. I am now able to run (properly I think) both scenes SingleBeamDeployment.scn and 3instruments_collis.scn. Could you confirm that?

fredroy commented 1 year ago

@fredroy I think all the problems you found are only due to RestShapeSpringForceField. I am now able to run (properly I think) both scenes SingleBeamDeployment.scn and 3instruments_collis.scn. Could you confirm that?

Good news, it works well ! And a bad news but not directly related to your PR, if parallelCollisionDetectionAndFreeMotion is activated for the animationloop in scenes/3instruments_collis.scn, there is a crash on the message mechanism. Here is the backtrace:

    [Inline Frame] Sofa.Helper.dll!std::_Check_C_return(int _Res) Line 131  C++
    [Inline Frame] Sofa.Helper.dll!std::_Mutex_base::lock() Line 50 C++
    [Inline Frame] Sofa.Helper.dll!std::lock_guard<std::mutex>::{ctor}(std::mutex & _Mtx) Line 427  C++
    Sofa.Helper.dll!sofa::helper::logging::MessageDispatcher::process(sofa::helper::logging::Message & m) Line 151  C++
    Sofa.Helper.dll!sofa::helper::logging::MessageDispatcher::LoggerStream::~LoggerStream() Line 198    C++
    Sofa.GUI.Qt.dll!redirectQtMessages(QtMsgType type, const QMessageLogContext & context, const QString & msg) Line 40 C++
    [External Code] 
    Sofa.GUI.Qt.dll!sofa::gui::qt::setMessageIconFrom(QTreeWidgetItem * item, sofa::core::objectmodel::Base * object) Line 325  C++
    Sofa.GUI.Qt.dll!sofa::gui::qt::ObjectStateListener::notifyEndEdit() Line 350    C++
    Sofa.Core.dll!sofa::core::objectmodel::DDGNode::notifyEndEdit() Line 83 C++
    [Inline Frame] Sofa.Helper.dll!sofa::helper::logging::MessageDispatcherImpl::process(sofa::helper::logging::Message &) Line 119 C++
    Sofa.Helper.dll!sofa::helper::logging::MessageDispatcher::process(sofa::helper::logging::Message & m) Line 152  C++
    Sofa.Helper.dll!sofa::helper::logging::MessageDispatcher::LoggerStream::~LoggerStream() Line 198    C++
>   Sofa.Core.dll!sofa::core::behavior::BaseForceField::buildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix * matrix) Line 62    C++
    Sofa.Component.LinearSolver.Direct.dll!sofa::component::linearsystem::AssemblingMatrixSystem<sofa::linearalgebra::BTDMatrix<6,double>,sofa::linearalgebra::BlockVector<6,double>>::contribute<0>(const sofa::core::MechanicalParams * mparams) Line 85  C++
    Sofa.Component.LinearSolver.Direct.dll!sofa::component::linearsystem::AssemblingMatrixSystem<sofa::linearalgebra::BTDMatrix<6,double>,sofa::linearalgebra::BlockVector<6,double>>::assembleSystem(const sofa::core::MechanicalParams * mparams) Line 123    C++
    Sofa.Core.dll!sofa::core::behavior::BaseMatrixLinearSystem::buildSystemMatrix(const sofa::core::MechanicalParams * mparams) Line 38 C++
    Sofa.Component.LinearSolver.Direct.dll!sofa::component::linearsolver::MatrixLinearSolver<sofa::linearalgebra::BTDMatrix<6,double>,sofa::linearalgebra::BlockVector<6,double>,sofa::component::linearsolver::NoThreadManager>::setSystemMBKMatrix(const sofa::core::MechanicalParams * mparams) Line 241 C++
    Sofa.Simulation.Core.dll!sofa::simulation::common::MechanicalOperations::m_setSystemMBKMatrix(double mFact, double bFact, double kFact) Line 455    C++
    [Inline Frame] Sofa.Component.ODESolver.Backward.dll!sofa::core::behavior::MultiMatrix<sofa::simulation::common::MechanicalOperations>::setSystemMBKMatrix(const sofa::core::behavior::MechanicalMatrix & m) Line 71    C++
    Sofa.Component.ODESolver.Backward.dll!sofa::component::odesolver::backward::EulerImplicitSolver::solve(const sofa::core::ExecParams * params, double dt, sofa::core::TMultiVecId<1,1> xResult, sofa::core::TMultiVecId<2,1> vResult) Line 154   C++
    Sofa.Simulation.Core.dll!sofa::simulation::SolveVisitor::processSolver(sofa::simulation::Node * node, sofa::core::behavior::OdeSolver * s) Line 37  C++
    Sofa.Simulation.Core.dll!sofa::simulation::Visitor::runVisitorTask<sofa::simulation::SolveVisitor,sofa::simulation::Node,sofa::core::behavior::OdeSolver>(sofa::simulation::SolveVisitor * visitor, sofa::simulation::Node * ctx, void(sofa::simulation::SolveVisitor::*)(sofa::simulation::Node *, sofa::core::behavior::OdeSolver *) task, sofa::core::behavior::OdeSolver * ptr, const std::string & typeInfo) Line 247  C++

It crashes when BaseForceField warns about buildStiffnessMatrix not implemented https://github.com/sofa-framework/sofa/blob/c4387feeb9e4a9f303b8cb63359ba31f1fd00493/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.cpp#L57

I think you already suspected that there was a problem with multithreading and the message mechanism somewhere...

alxbilger commented 1 year ago

I think this is this issue: https://github.com/sofa-framework/sofa/issues/3610

fredroy commented 1 year ago

I think this is this issue: #3610

Yep it seems to be the same problem/symptom

damienmarchal commented 1 year ago

Hi all,

It was tested two weeks ago at Defrost, @EulalieCoevoet try our tutorials/tripods and it works like a charm. @TanguyNav found a bug that was reported. To us, it is going in the right direction and we support the merge of this work.

We hope the rest of the community will provide feedback asap.

hugtalbot commented 1 year ago

@alxbilger could you maybe share in the above PR description the link towards the doc page you prepared ?

fredroy commented 1 year ago

[ci-build][full-build][with-all-tests]

fredroy commented 1 year ago

1- small suggestions to remove warnings : https://github.com/alxbilger/sofa/pull/5 2- While solving the warnings, I saw (as usual) lots of warnings about signedness of indices for matrices... should we adjust this inconsistency once and for all (not in this PR but in the broader project of matrices) ?

alxbilger commented 1 year ago

[ci-build][with-all-tests]

sofabot commented 1 year ago

[ci-depends-on] detected during build #93.

To unlock the merge button, you must

sofabot commented 1 year ago

[ci-depends-on] detected during build #94.

To unlock the merge button, you must

sofabot commented 1 year ago

[ci-depends-on] detected during build #95.

To unlock the merge button, you must

sofabot commented 1 year ago

[ci-depends-on] detected during build #96.

To unlock the merge button, you must

sofabot commented 1 year ago

[ci-depends-on] detected during build #97.

To unlock the merge button, you must

sofabot commented 1 year ago

[ci-depends-on] detected during build #98.

To unlock the merge button, you must

sofabot commented 1 year ago

[ci-depends-on] detected during build #99.

To unlock the merge button, you must

sofabot commented 1 year ago

[ci-depends-on] detected during build #100.

To unlock the merge button, you must

sofabot commented 1 year ago

[ci-depends-on] detected during build #101.

To unlock the merge button, you must

bakpaul commented 1 year ago

Ok for a merge on our side !

sofabot commented 1 year ago

[ci-depends-on] detected during build #102.

To unlock the merge button, you must

sofabot commented 1 year ago

[ci-depends-on] detected during build #103.

To unlock the merge button, you must

alxbilger commented 1 year ago

[ci-build][with-all-tests][force-full-build]

alxbilger commented 1 year ago

[ci-build][with-all-tests]

fredroy commented 1 year ago

[ci-build][with-all-tests][force-full-build]

sofabot commented 1 year ago

[ci-depends-on] detected during build #107.

To unlock the merge button, you must

fredroy commented 1 year ago

[ci-build][with-all-tests][force-full-build]

sofabot commented 1 year ago

[ci-depends-on] detected during build #108.

All dependencies are merged/closed and all ExternalProject pointers are up-to-date. Congrats! :+1:

fredroy commented 1 year ago

[ci-build][with-all-tests]

sofabot commented 1 year ago

[ci-depends-on] detected during build #110.

All dependencies are merged/closed and all ExternalProject pointers are up-to-date. Congrats! :+1:

fredroy commented 1 year ago

[ci-build][with-all-tests][force-full-build]

sofabot commented 1 year ago

[ci-depends-on] detected during build #111.

All dependencies are merged/closed and all ExternalProject pointers are up-to-date. Congrats! :+1:

fredroy commented 1 year ago

[ci-build][with-all-tests][force-full-build]

sofabot commented 1 year ago

[ci-depends-on] detected during build #112.

All dependencies are merged/closed and all ExternalProject pointers are up-to-date. Congrats! :+1:

hugtalbot commented 1 year ago

An example of a plugin update further to this PR: https://github.com/SofaDefrost/SoftRobots/pull/213