diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 059febc1..c8040e7f 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -145,11 +145,17 @@ jobs: run: | if [ "$SOFA_VERSION" = "master" ]; then curl --output sofa.zip -L "https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries/CI_BRANCH=master,CI_SCOPE=standard/lastSuccessfulBuild/artifact/MacOS/*zip*/MacOS.zip" + unzip sofa.zip -d temp + mv temp/MacOS/`ls temp/MacOS` sofa.zip + rm -rf temp + unzip sofa.zip -d temp + mv temp/`ls temp` $SOFA_ROOT else curl --output sofa.zip -L "https://github.com/sofa-framework/sofa/releases/download/$SOFA_VERSION/SOFA_"$SOFA_VERSION"_MacOS.zip" + unzip sofa.zip -d temp + sudo mv temp/`ls temp` $SOFA_ROOT fi - unzip sofa.zip -d temp - sudo mv temp/`ls temp` $SOFA_ROOT + # CCACHE diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 5c1d7116..978c7fef 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -22,22 +22,27 @@ jobs: SOFA_VERSION_I: 999999 CONTAINER: jnbrunet/caribou-ubuntu-2004-builder:latest PYTHON_VERSION: 3.8 + PYBIND11_VERSION: 2.6 - sofa_version: v21.12.00 SOFA_VERSION_I: 211200 CONTAINER: jnbrunet/caribou-ubuntu-2004-builder:latest PYTHON_VERSION: 3.8 + PYBIND11_VERSION: 2.4 - sofa_version: v21.06.03 SOFA_VERSION_I: 210603 CONTAINER: jnbrunet/caribou-ubuntu-1804-builder:latest PYTHON_VERSION: 3.7 + PYBIND11_VERSION: 2.4 - sofa_version: v20.12.03 SOFA_VERSION_I: 201203 CONTAINER: jnbrunet/caribou-ubuntu-1804-builder:latest PYTHON_VERSION: 3.7 + PYBIND11_VERSION: 2.4 - sofa_version: v20.06.01 SOFA_VERSION_I: 200601 CONTAINER: jnbrunet/caribou-ubuntu-1804-builder:latest PYTHON_VERSION: 3.7 + PYBIND11_VERSION: 2.4 env: SOFA_VERSION: ${{ matrix.sofa_version }} SOFA_ROOT: /opt/sofa @@ -54,6 +59,14 @@ jobs: git fetch origin git rebase origin/master + - name: Install pybind11 + if: ${{ matrix.PYBIND11_VERSION != '2.4' }} + run: | + git clone --depth 1 -b v${{ matrix.PYBIND11_VERSION }} https://github.com/pybind/pybind11.git /tmp/pybind11 + cmake -GNinja -S/tmp/pybind11 -B/tmp/pybind11/build -DPYBIND11_TEST=OFF -DCMAKE_BUILD_TYPE=Release + cmake --install /tmp/pybind11/build + rm -rf /tmp/pybind11 + - name: Download SOFA Release run: | if [ "$SOFA_VERSION" = "master" ]; then @@ -217,6 +230,8 @@ jobs: if: ${{ always() }} run: | [ "$SOFA_VERSION" = "v20.06.01" ] && export LD_LIBRARY_PATH="$SOFA_ROOT/lib:$LD_LIBRARY_PATH" + export LD_LIBRARY_PATH="$SOFA_ROOT/collections/SofaBaseMechanics/lib:$LD_LIBRARY_PATH" + export LD_LIBRARY_PATH="$SOFA_ROOT/collections/SofaBaseUtils/lib:$LD_LIBRARY_PATH" $CARIBOU_ROOT/bin/Caribou.unittests.SofaCaribou - name: SofaCaribou.PyTest diff --git a/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldRecomputeF.h b/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldRecomputeF.h index dd59b6ea..cb43a13f 100644 --- a/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldRecomputeF.h +++ b/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldRecomputeF.h @@ -17,7 +17,7 @@ #include DISABLE_ALL_WARNINGS_BEGIN -#include +#include DISABLE_ALL_WARNINGS_END #if (defined(SOFA_VERSION) && SOFA_VERSION < 201200) @@ -101,7 +101,7 @@ class HyperelasticForcefieldRecomputeF : public ::SofaCaribou::forcefield::Carib const sofa::core::objectmodel::Data& /* d_x */) const override; - void addKToMatrix(sofa::defaulttype::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) override; + void addKToMatrix(SofaCaribou::Algebra::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) override; /** Get the set of Gauss integration nodes of an element */ inline auto gauss_nodes_of(std::size_t element_id) const -> const auto & { diff --git a/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldRecomputeF.inl b/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldRecomputeF.inl index 9c2e0ec5..3a1f30b7 100644 --- a/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldRecomputeF.inl +++ b/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldRecomputeF.inl @@ -214,7 +214,7 @@ void HyperelasticForcefieldRecomputeF::addDForce( template void HyperelasticForcefieldRecomputeF::addKToMatrix( - sofa::defaulttype::BaseMatrix * matrix, + SofaCaribou::Algebra::BaseMatrix * matrix, SReal kFact, unsigned int & offset) { if (not K_is_up_to_date) { diff --git a/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreF.h b/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreF.h index d8b4b21e..6717b0ba 100644 --- a/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreF.h +++ b/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreF.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -98,7 +99,7 @@ class HyperelasticForcefieldStoreF : public ::SofaCaribou::forcefield::CaribouFo const sofa::core::objectmodel::Data& /* d_x */) const override; - void addKToMatrix(sofa::defaulttype::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) override; + void addKToMatrix(SofaCaribou::Algebra::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) override; /** Get the set of Gauss integration nodes of an element */ auto gauss_nodes_of(std::size_t element_id) const -> const auto & { diff --git a/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreF.inl b/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreF.inl index 6bfd5cae..a72a8839 100644 --- a/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreF.inl +++ b/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreF.inl @@ -215,7 +215,7 @@ void HyperelasticForcefieldStoreF::addDForce( template void HyperelasticForcefieldStoreF::addKToMatrix( - sofa::defaulttype::BaseMatrix * matrix, + SofaCaribou::Algebra::BaseMatrix * matrix, SReal kFact, unsigned int & offset) { if (not K_is_up_to_date) { diff --git a/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreFAndS.h b/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreFAndS.h index 7a03d7ea..6f153ab4 100644 --- a/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreFAndS.h +++ b/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreFAndS.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -17,7 +18,7 @@ #include DISABLE_ALL_WARNINGS_BEGIN -#include +#include DISABLE_ALL_WARNINGS_END #if (defined(SOFA_VERSION) && SOFA_VERSION < 201200) @@ -105,7 +106,7 @@ class HyperelasticForcefieldStoreFAndS : public ::SofaCaribou::forcefield::Carib const sofa::core::objectmodel::Data& /* d_x */) const override; - void addKToMatrix(sofa::defaulttype::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) override; + void addKToMatrix(SofaCaribou::Algebra::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) override; /** Get the set of Gauss integration nodes of an element */ auto gauss_nodes_of(std::size_t element_id) const -> const auto & { diff --git a/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreFAndS.inl b/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreFAndS.inl index 3dcbe0ed..b7c08728 100644 --- a/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreFAndS.inl +++ b/Benchmark/SofaCaribou/Forcefield/RecomputeOrStore/HyperelasticForcefieldStoreFAndS.inl @@ -214,7 +214,7 @@ void HyperelasticForcefieldStoreFAndS::addDForce( template void HyperelasticForcefieldStoreFAndS::addKToMatrix( - sofa::defaulttype::BaseMatrix * matrix, + SofaCaribou::Algebra::BaseMatrix * matrix, SReal kFact, unsigned int & offset) { if (not K_is_up_to_date) { diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fbf9f06..9eb2b5d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,7 +94,9 @@ else() endif() # Python 3 option -find_package(SofaPython3 QUIET) +if (CARIBOU_WITH_SOFA) + sofa_find_package(SofaPython3 QUIET) +endif() set(CMAKE_CXX_STANDARD 17) set(PYBIND11_FINDPYTHON ON) set(PYBIND11_PYTHON_VERSION 3) diff --git a/cmake/FindSOFA.cmake b/cmake/FindSOFA.cmake index 510e6200..1f0db7b0 100644 --- a/cmake/FindSOFA.cmake +++ b/cmake/FindSOFA.cmake @@ -65,6 +65,9 @@ endif() # Compatibility layer set(SOFA_VERSION ${SofaFramework_VERSION}) foreach(component ${SOFA_FIND_COMPONENTS}) + if (SOFA_VERSION VERSION_LESS "22.06.99") + string(REGEX REPLACE "Sofa.Simulation.*" "SofaSimulation" component ${component}) + endif() if (SOFA_VERSION VERSION_LESS "20.12.99") string(REGEX REPLACE "SofaSimpleFem|SofaRigid|SofaDeformable|SofaObjectInteraction|SofaMeshCollision|SofaEngine|SofaExplicitOdeSolver|SofaImplicitOdeSolver|SofaLoader" "SofaCommon" component ${component}) diff --git a/src/SofaCaribou/Algebra/BaseMatrixOperations.h b/src/SofaCaribou/Algebra/BaseMatrixOperations.h new file mode 100644 index 00000000..9283f772 --- /dev/null +++ b/src/SofaCaribou/Algebra/BaseMatrixOperations.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +// Various utilities to perform numerical operations on SOFA's BaseMatrix. +DISABLE_ALL_WARNINGS_BEGIN +#include // for SOFA_VERSION +DISABLE_ALL_WARNINGS_END + +#if (defined(SOFA_VERSION) && SOFA_VERSION < 211200) +#include +#else +#include +#endif // (defined(SOFA_VERSION) && SOFA_VERSION < 211299) + +namespace SofaCaribou::Algebra +{ + +#if (defined(SOFA_VERSION) && SOFA_VERSION < 211200) +using BaseMatrix = sofa::defaulttype::BaseMatrix; +#else +using BaseMatrix = sofa::linearalgebra::BaseMatrix; +#endif // (defined(SOFA_VERSION) && SOFA_VERSION < 211299) + + +} // namespace SofaCaribou::Algebra diff --git a/src/SofaCaribou/Algebra/BaseVectorOperations.cpp b/src/SofaCaribou/Algebra/BaseVectorOperations.cpp index 438776a1..3c9d6d63 100644 --- a/src/SofaCaribou/Algebra/BaseVectorOperations.cpp +++ b/src/SofaCaribou/Algebra/BaseVectorOperations.cpp @@ -4,11 +4,10 @@ DISABLE_ALL_WARNINGS_BEGIN #include #if (defined(SOFA_VERSION) && SOFA_VERSION < 211299) -#include +#include #else -#include +#include #endif // #if (defined(SOFA_VERSION) && SOFA_VERSION < 211299) -#include DISABLE_ALL_WARNINGS_END #if (defined(SOFA_VERSION) && SOFA_VERSION < 201200) @@ -21,14 +20,20 @@ using Index = sofa::defaulttype::BaseVector::Index; namespace SofaCaribou::Algebra { namespace { // Anonymous +#if (defined(SOFA_VERSION) && SOFA_VERSION < 211299) +using namespace sofa::component::linearsolver; +#else +using namespace sofa::linearalgebra; +#endif + template -auto to_full_vector(const sofa::defaulttype::BaseVector* v) -> const sofa::component::linearsolver::FullVector * { - return dynamic_cast *>(v); +auto to_full_vector(const BaseVector* v) -> const FullVector * { + return dynamic_cast *>(v); } // Dot product between a SOFA full vector and any BaseVector template -ReturnValue dot(const sofa::component::linearsolver::FullVector * v1, const sofa::defaulttype::BaseVector * v2) { +ReturnValue dot(const FullVector * v1, const BaseVector * v2) { const auto n = static_cast(v1->size()); auto value = static_cast(0); for (sofa::Index i = 0; i < n; ++i) { @@ -40,7 +45,7 @@ ReturnValue dot(const sofa::component::linearsolver::FullVector * v1, cons // Dot product between a two SOFA full vectors template -ReturnValue dot(const sofa::component::linearsolver::FullVector * v1, const sofa::component::linearsolver::FullVector * v2) { +ReturnValue dot(const FullVector * v1, const FullVector * v2) { const auto n = static_cast(v1->size()); auto value = static_cast(0); for (sofa::Index i = 0; i < n; ++i) { @@ -52,7 +57,7 @@ ReturnValue dot(const sofa::component::linearsolver::FullVector * v1, con } /** Compute the dot product between two BaseVector, i.e. scalar = v1.dot(v2) */ - double dot(const sofa::defaulttype::BaseVector * v1, const sofa::defaulttype::BaseVector * v2) { + double dot(const BaseVector * v1, const BaseVector * v2) { caribou_assert(v1->size() == v2->size()); // todo(jnbrunet2000@gmail.com): This function is awful. I'm sure there is a much much cleaner and faster way @@ -119,4 +124,4 @@ ReturnValue dot(const sofa::component::linearsolver::FullVector * v1, con return static_cast (value); } -} // namespace SofaCaribou::Algebra \ No newline at end of file +} // namespace SofaCaribou::Algebra diff --git a/src/SofaCaribou/Algebra/BaseVectorOperations.h b/src/SofaCaribou/Algebra/BaseVectorOperations.h index f1fb048d..593ce5a3 100644 --- a/src/SofaCaribou/Algebra/BaseVectorOperations.h +++ b/src/SofaCaribou/Algebra/BaseVectorOperations.h @@ -10,20 +10,18 @@ DISABLE_ALL_WARNINGS_BEGIN DISABLE_ALL_WARNINGS_END #if (defined(SOFA_VERSION) && SOFA_VERSION < 211200) -namespace sofa::defaulttype { - class BaseVector; -} +#include #else -namespace sofa::linearalgebra { - class BaseVector; -} -namespace sofa::defaulttype { - using BaseVector = sofa::linearalgebra::BaseVector; -} +#include #endif // (defined(SOFA_VERSION) && SOFA_VERSION < 211299) namespace SofaCaribou::Algebra { +#if (defined(SOFA_VERSION) && SOFA_VERSION < 211200) +using BaseVector = sofa::defaulttype::BaseVector; +#else +using BaseVector = sofa::linearalgebra::BaseVector; +#endif /** * Compute the dot product between two BaseVector, i.e. scalar = v1.dot(v2) * @@ -33,6 +31,6 @@ namespace SofaCaribou::Algebra { * simply reuse this callback. Hence we avoid the need to do multiple virtual checks * each time this function is called */ - double dot(const sofa::defaulttype::BaseVector * v1, const sofa::defaulttype::BaseVector * v2); + double dot(const BaseVector * v1, const BaseVector * v2); -} // namespace SofaCaribou::Algebra \ No newline at end of file +} // namespace SofaCaribou::Algebra diff --git a/src/SofaCaribou/Algebra/EigenMatrix.h b/src/SofaCaribou/Algebra/EigenMatrix.h index 171ec806..9e7a18dd 100644 --- a/src/SofaCaribou/Algebra/EigenMatrix.h +++ b/src/SofaCaribou/Algebra/EigenMatrix.h @@ -5,7 +5,7 @@ DISABLE_ALL_WARNINGS_BEGIN #include -#include +#include DISABLE_ALL_WARNINGS_END #if (defined(SOFA_VERSION) && SOFA_VERSION < 201200) @@ -68,7 +68,7 @@ namespace SofaCaribou::Algebra { * \endcode */ template -class EigenMatrix : public sofa::defaulttype::BaseMatrix +class EigenMatrix : public BaseMatrix { static_assert( std::is_base_of_v >, std::decay_t >, @@ -77,7 +77,7 @@ class EigenMatrix : public sofa::defaulttype::BaseMatrix public: using EigenType = std::remove_cv_t>; - using Base = sofa::defaulttype::BaseMatrix; + using Base = BaseMatrix; using Index = Base::Index; using Real = SReal; using Scalar = typename EigenType::Scalar; @@ -168,12 +168,12 @@ class EigenMatrix : public sofa::defaulttype::BaseMatrix /// SparseMatrix specialization /// /////////////////////////////////// template -class EigenMatrix>, std::decay_t>)> : public sofa::defaulttype::BaseMatrix +class EigenMatrix>, std::decay_t>)> : public BaseMatrix { public: using EigenType = std::remove_cv_t>; - using Base = sofa::defaulttype::BaseMatrix; + using Base = BaseMatrix; using Index = Base::Index; using Real = SReal; using Scalar = typename EigenType::Scalar; diff --git a/src/SofaCaribou/Algebra/EigenVector.h b/src/SofaCaribou/Algebra/EigenVector.h index eec18671..cb2779ee 100644 --- a/src/SofaCaribou/Algebra/EigenVector.h +++ b/src/SofaCaribou/Algebra/EigenVector.h @@ -5,8 +5,8 @@ #include DISABLE_ALL_WARNINGS_BEGIN -#include -#include +#include +#include DISABLE_ALL_WARNINGS_END #include @@ -23,7 +23,7 @@ namespace SofaCaribou::Algebra { * @tparam Enable */ template -class EigenVector : public sofa::defaulttype::BaseVector +class EigenVector : public BaseVector { static_assert( std::is_base_of_v >, std::decay_t >, @@ -38,7 +38,7 @@ class EigenVector : public sofa::defaulttype::BaseVector public: using EigenType = std::remove_cv_t>; - using Base = sofa::defaulttype::BaseVector; + using Base = BaseVector; using Index = Base::Index; using Real = typename EigenType::Scalar; diff --git a/src/SofaCaribou/CMakeLists.txt b/src/SofaCaribou/CMakeLists.txt index db549418..7b22406c 100644 --- a/src/SofaCaribou/CMakeLists.txt +++ b/src/SofaCaribou/CMakeLists.txt @@ -4,6 +4,7 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) set(HEADER_FILES config.h.in + Algebra/BaseMatrixOperations.h Algebra/BaseVectorOperations.h Algebra/EigenMatrix.h Algebra/EigenVector.h diff --git a/src/SofaCaribou/Forcefield/CaribouForcefield.h b/src/SofaCaribou/Forcefield/CaribouForcefield.h index 5d548dd5..aeb546ea 100644 --- a/src/SofaCaribou/Forcefield/CaribouForcefield.h +++ b/src/SofaCaribou/Forcefield/CaribouForcefield.h @@ -69,9 +69,9 @@ class CaribouForcefield : public sofa::core::behavior::ForceField bool; - [[nodiscard]] auto - getTemplateName() const -> std::string override { - return templateName(this); + static auto + GetCustomTemplateName() -> std::string { + return templateName(); } static auto templateName(const CaribouForcefield* = nullptr) -> std::string; diff --git a/src/SofaCaribou/Forcefield/HexahedronElasticForce.cpp b/src/SofaCaribou/Forcefield/HexahedronElasticForce.cpp index f41780cb..ce1186ca 100644 --- a/src/SofaCaribou/Forcefield/HexahedronElasticForce.cpp +++ b/src/SofaCaribou/Forcefield/HexahedronElasticForce.cpp @@ -344,7 +344,7 @@ void HexahedronElasticForce::addDForce( sofa::helper::AdvancedTimer::stepEnd("HexahedronElasticForce::addDForce"); } -void HexahedronElasticForce::addKToMatrix(sofa::defaulttype::BaseMatrix * matrix, SReal kFact, unsigned int & offset) +void HexahedronElasticForce::addKToMatrix(SofaCaribou::Algebra::BaseMatrix * matrix, SReal kFact, unsigned int & offset) { auto * topology = d_topology_container.get(); diff --git a/src/SofaCaribou/Forcefield/HexahedronElasticForce.h b/src/SofaCaribou/Forcefield/HexahedronElasticForce.h index cc91a6d9..98b66d31 100644 --- a/src/SofaCaribou/Forcefield/HexahedronElasticForce.h +++ b/src/SofaCaribou/Forcefield/HexahedronElasticForce.h @@ -4,7 +4,10 @@ DISABLE_ALL_WARNINGS_BEGIN #include -#include + +#include + + #include #include #include @@ -88,29 +91,29 @@ class HexahedronElasticForce : public ForceField // Public methods - + HexahedronElasticForce(); - + void init() override; - + void reinit() override; - + void addForce( const MechanicalParams* mparams, Data& d_f, const Data& d_x, const Data& d_v) override; - + void addDForce( const MechanicalParams* /*mparams*/, Data& /*d_df*/, const Data& /*d_dx*/) override; - + void draw(const sofa::core::visual::VisualParams* vparams) override; SReal getPotentialEnergy( @@ -118,10 +121,10 @@ class HexahedronElasticForce : public ForceField const Data& /* d_x */) const override {return 0;} - - void addKToMatrix(sofa::defaulttype::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) override; - + void addKToMatrix(SofaCaribou::Algebra::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) override; + + void computeBBox(const sofa::core::ExecParams* params, bool onlyVisible) override; template @@ -173,15 +176,15 @@ class HexahedronElasticForce : public ForceField } /** Get the complete tangent stiffness matrix */ - + const Eigen::SparseMatrix & K(); /** Get the eigen values of the tangent stiffness matrix */ - + const Vector & eigenvalues(); /** Get the condition number of the tangent stiffness matrix */ - + Real cond(); private: diff --git a/src/SofaCaribou/Forcefield/HyperelasticForcefield.h b/src/SofaCaribou/Forcefield/HyperelasticForcefield.h index 7aec1b20..8f3480d8 100644 --- a/src/SofaCaribou/Forcefield/HyperelasticForcefield.h +++ b/src/SofaCaribou/Forcefield/HyperelasticForcefield.h @@ -17,7 +17,7 @@ #include DISABLE_ALL_WARNINGS_BEGIN -#include +#include DISABLE_ALL_WARNINGS_END #if (defined(SOFA_VERSION) && SOFA_VERSION < 201200) @@ -73,35 +73,35 @@ class HyperelasticForcefield : public CaribouForcefield { // Public methods - + HyperelasticForcefield(); - + void init() override; - + void addForce(const sofa::core::MechanicalParams* mparams, sofa::core::MultiVecDerivId fId ) override; - + void addForce( const sofa::core::MechanicalParams* mparams, sofa::core::objectmodel::Data& d_f, const sofa::core::objectmodel::Data& d_x, const sofa::core::objectmodel::Data& d_v) override; - + void addDForce( const sofa::core::MechanicalParams* /*mparams*/, sofa::core::objectmodel::Data& /*d_df*/, const sofa::core::objectmodel::Data& /*d_dx*/) override; - + SReal getPotentialEnergy( const sofa::core::MechanicalParams* /* mparams */, const sofa::core::objectmodel::Data& /* d_x */) const override; - - void addKToMatrix(sofa::defaulttype::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) override; + + void addKToMatrix(SofaCaribou::Algebra::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) override; /** Get the set of Gauss integration nodes of an element */ inline auto gauss_nodes_of(std::size_t element_id) const -> const auto & { @@ -152,11 +152,11 @@ class HyperelasticForcefield : public CaribouForcefield { } /** Get the eigen values of the tangent stiffness matrix */ - + auto eigenvalues() -> const Vector &; /** Get the condition number of the tangent stiffness matrix */ - + auto cond() -> Real; /** diff --git a/src/SofaCaribou/Forcefield/HyperelasticForcefield.inl b/src/SofaCaribou/Forcefield/HyperelasticForcefield.inl index 70e53676..83147a27 100644 --- a/src/SofaCaribou/Forcefield/HyperelasticForcefield.inl +++ b/src/SofaCaribou/Forcefield/HyperelasticForcefield.inl @@ -6,7 +6,7 @@ #include DISABLE_ALL_WARNINGS_BEGIN -#include +#include #include #include DISABLE_ALL_WARNINGS_END @@ -215,7 +215,7 @@ void HyperelasticForcefield::addDForce( template void HyperelasticForcefield::addKToMatrix( - sofa::defaulttype::BaseMatrix * matrix, + SofaCaribou::Algebra::BaseMatrix * matrix, SReal kFact, unsigned int & offset) { if (not K_is_up_to_date) { diff --git a/src/SofaCaribou/Forcefield/TetrahedronElasticForce.cpp b/src/SofaCaribou/Forcefield/TetrahedronElasticForce.cpp index bdbaa83f..ecbf587d 100644 --- a/src/SofaCaribou/Forcefield/TetrahedronElasticForce.cpp +++ b/src/SofaCaribou/Forcefield/TetrahedronElasticForce.cpp @@ -282,7 +282,7 @@ void TetrahedronElasticForce::addDForce( } void TetrahedronElasticForce::addKToMatrix( - sofa::defaulttype::BaseMatrix * matrix, + SofaCaribou::Algebra::BaseMatrix * matrix, SReal kFact, unsigned int & offset) { diff --git a/src/SofaCaribou/Forcefield/TetrahedronElasticForce.h b/src/SofaCaribou/Forcefield/TetrahedronElasticForce.h index 0d238b3e..0b1de65d 100644 --- a/src/SofaCaribou/Forcefield/TetrahedronElasticForce.h +++ b/src/SofaCaribou/Forcefield/TetrahedronElasticForce.h @@ -4,7 +4,7 @@ DISABLE_ALL_WARNINGS_BEGIN #include -#include +#include #include #include #include @@ -93,7 +93,7 @@ class TetrahedronElasticForce : public ForceField { const Data& /*d_dx*/) override; void addKToMatrix( - sofa::defaulttype::BaseMatrix * /*matrix*/, + SofaCaribou::Algebra::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) override; diff --git a/src/SofaCaribou/Forcefield/TractionForcefield.h b/src/SofaCaribou/Forcefield/TractionForcefield.h index 28ccf64f..73478801 100644 --- a/src/SofaCaribou/Forcefield/TractionForcefield.h +++ b/src/SofaCaribou/Forcefield/TractionForcefield.h @@ -6,7 +6,7 @@ #include DISABLE_ALL_WARNINGS_BEGIN -#include +#include #include DISABLE_ALL_WARNINGS_END @@ -73,25 +73,25 @@ class TractionForcefield : public CaribouForcefield // Public methods - + TractionForcefield(); - + void init() override; - + void reset() override; - + void addForce(const sofa::core::MechanicalParams* mparams, Data& d_f, const Data& d_x, const Data& d_v) override; - + void addDForce(const sofa::core::MechanicalParams* /*mparams*/, Data& /*d_df*/, const Data& /*d_dx*/) override {} - - void addKToMatrix(sofa::defaulttype::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) override {} - + void addKToMatrix(SofaCaribou::Algebra::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) override {} + + void handleEvent(sofa::core::objectmodel::Event* event) override; SReal getPotentialEnergy(const sofa::core::MechanicalParams* /*mparams*/, const Data& /* x */) const override diff --git a/src/SofaCaribou/Mapping/CaribouBarycentricMapping.h b/src/SofaCaribou/Mapping/CaribouBarycentricMapping.h index dd8aa306..6783a929 100644 --- a/src/SofaCaribou/Mapping/CaribouBarycentricMapping.h +++ b/src/SofaCaribou/Mapping/CaribouBarycentricMapping.h @@ -57,9 +57,9 @@ class CaribouBarycentricMapping void applyJT (const sofa::core::ConstraintParams* cparams, DataMapMapSparseMatrix & output_jacobian, const MappedDataMapMapSparseMatrix & input_jacobian) override; void draw (const sofa::core::visual::VisualParams* vparams) override; - [[nodiscard]] auto - getTemplateName() const -> std::string override { - return templateName(this); + static auto + GetCustomTemplateName() -> std::string { + return templateName(); } static auto templateName(const CaribouBarycentricMapping* = nullptr) -> std::string { diff --git a/src/SofaCaribou/Mass/CaribouMass.h b/src/SofaCaribou/Mass/CaribouMass.h index 124b8064..ac4e27dd 100644 --- a/src/SofaCaribou/Mass/CaribouMass.h +++ b/src/SofaCaribou/Mass/CaribouMass.h @@ -7,7 +7,7 @@ DISABLE_ALL_WARNINGS_BEGIN #include #include #include -#include +#include #include DISABLE_ALL_WARNINGS_END @@ -101,14 +101,14 @@ class CaribouMass : public sofa::core::behavior::Mass::type; // Public methods - + CaribouMass(); - + void init() override; template - + static auto canCreate(Derived * o, sofa::core::objectmodel::BaseContext* context, sofa::core::objectmodel::BaseObjectDescription* arg) -> bool; template @@ -155,24 +155,24 @@ class CaribouMass : public sofa::core::behavior::Mass & x0); /** @@ -223,11 +223,11 @@ class CaribouMass : public sofa::core::behavior::Mass - + void assemble_mass_matrix(const Eigen::MatrixBase & x0); /** Get the set of Gauss integration nodes of an element */ - + inline auto gauss_nodes_of(std::size_t element_id) const -> const auto & { return p_elements_quadrature_nodes[element_id]; } diff --git a/src/SofaCaribou/Mass/CaribouMass.inl b/src/SofaCaribou/Mass/CaribouMass.inl index 6833a4d2..7236cfad 100644 --- a/src/SofaCaribou/Mass/CaribouMass.inl +++ b/src/SofaCaribou/Mass/CaribouMass.inl @@ -415,7 +415,7 @@ void CaribouMass::addForce(const sofa::core::MechanicalParams * /*mpara } template -void CaribouMass::addMToMatrix(sofa::defaulttype::BaseMatrix * matrix, SReal mFact, unsigned int & offset) { +void CaribouMass::addMToMatrix(SofaCaribou::Algebra::BaseMatrix * matrix, SReal mFact, unsigned int & offset) { // Start the timer sofa::helper::ScopedAdvancedTimer _t_ ("CaribouMass::addMToMatrix"); diff --git a/src/SofaCaribou/Ode/BackwardEulerODESolver.cpp b/src/SofaCaribou/Ode/BackwardEulerODESolver.cpp index 75433a13..58d134d2 100644 --- a/src/SofaCaribou/Ode/BackwardEulerODESolver.cpp +++ b/src/SofaCaribou/Ode/BackwardEulerODESolver.cpp @@ -36,8 +36,6 @@ using sofa::core::MechanicalParams; using sofa::core::MultiVecCoordId; using sofa::core::MultiVecDerivId; using sofa::component::linearsolver::DefaultMultiMatrixAccessor; -using sofa::defaulttype::BaseMatrix; -using sofa::defaulttype::BaseVector; using Timer = sofa::helper::AdvancedTimer; // Constructor @@ -81,7 +79,7 @@ void BackwardEulerODESolver::solve(const sofa::core::ExecParams *params, SReal d void BackwardEulerODESolver::assemble_rhs_vector(const MechanicalParams & mechanical_parameters, const MultiMatrixAccessor & matrix_accessor, MultiVecDerivId & f_id, - BaseVector * f) + SofaCaribou::Algebra::BaseVector * f) { const auto h = mechanical_parameters.dt(); @@ -160,7 +158,7 @@ void BackwardEulerODESolver::assemble_rhs_vector(const MechanicalParams & mec // A = (1 + h*r_m) M + h C + [h * (h + r_k)] K void BackwardEulerODESolver::assemble_system_matrix(const MechanicalParams & mechanical_parameters, DefaultMultiMatrixAccessor & matrix_accessor, - BaseMatrix * A) + SofaCaribou::Algebra::BaseMatrix * A) { const auto h = mechanical_parameters.dt(); @@ -202,7 +200,7 @@ void BackwardEulerODESolver::assemble_system_matrix(const MechanicalParams & mec // Propagate dv that was previously solved in A [dv] = F void BackwardEulerODESolver::propagate_solution_increment(const MechanicalParams & mechanical_parameters, const MultiMatrixAccessor & matrix_accessor, - const BaseVector * dx, + const SofaCaribou::Algebra::BaseVector * dx, MultiVecCoordId & x_id, MultiVecDerivId & v_id, MultiVecDerivId & dx_id) { // 1. Prepare everything need to solve constraints later on @@ -242,4 +240,4 @@ void BackwardEulerODESolver::propagate_solution_increment(const MechanicalParams } -} // namespace SofaCaribou::ode \ No newline at end of file +} // namespace SofaCaribou::ode diff --git a/src/SofaCaribou/Ode/BackwardEulerODESolver.h b/src/SofaCaribou/Ode/BackwardEulerODESolver.h index 20020373..c722133f 100644 --- a/src/SofaCaribou/Ode/BackwardEulerODESolver.h +++ b/src/SofaCaribou/Ode/BackwardEulerODESolver.h @@ -101,31 +101,31 @@ class BackwardEulerODESolver : public NewtonRaphsonSolver { template using Data = sofa::core::objectmodel::Data; - + BackwardEulerODESolver(); - + void solve (const sofa::core::ExecParams* params, SReal dt, sofa::core::MultiVecCoordId x_id, sofa::core::MultiVecDerivId v_id) override; private: /** @see NewtonRaphsonSolver::assemble_rhs_vector */ - + void assemble_rhs_vector(const sofa::core::MechanicalParams & mechanical_parameters, const sofa::core::behavior::MultiMatrixAccessor & matrix_accessor, sofa::core::MultiVecDerivId & f_id, - sofa::defaulttype::BaseVector * f) final; + SofaCaribou::Algebra::BaseVector * f) final; /** @see NewtonRaphsonSolver::assemble_system_matrix */ - + void assemble_system_matrix(const sofa::core::MechanicalParams & mechanical_parameters, sofa::component::linearsolver::DefaultMultiMatrixAccessor & matrix_accessor, - sofa::defaulttype::BaseMatrix * A) final; + SofaCaribou::Algebra::BaseMatrix * A) final; /** @see NewtonRaphsonSolver::propagate_position_increment */ - + void propagate_solution_increment(const sofa::core::MechanicalParams & mechanical_parameters, const sofa::core::behavior::MultiMatrixAccessor & matrix_accessor, - const sofa::defaulttype::BaseVector * dx, + const SofaCaribou::Algebra::BaseVector * dx, sofa::core::MultiVecCoordId & x_id, sofa::core::MultiVecDerivId & v_id, sofa::core::MultiVecDerivId & dx_id) final; diff --git a/src/SofaCaribou/Ode/NewtonRaphsonSolver.h b/src/SofaCaribou/Ode/NewtonRaphsonSolver.h index 91c92a87..680a3daa 100644 --- a/src/SofaCaribou/Ode/NewtonRaphsonSolver.h +++ b/src/SofaCaribou/Ode/NewtonRaphsonSolver.h @@ -6,8 +6,8 @@ DISABLE_ALL_WARNINGS_BEGIN #include #include #include -#include -#include +#include +#include #include #include #include @@ -63,16 +63,16 @@ class NewtonRaphsonSolver : public sofa::core::behavior::OdeSolver { ALWAYS }; - + NewtonRaphsonSolver(); - + void init() override; - + void reset() override; - + void solve (const sofa::core::ExecParams* params, SReal dt, sofa::core::MultiVecCoordId x_id, sofa::core::MultiVecDerivId v_id) override; /** List of times (in nanoseconds) that each Newton-Raphson iteration took to compute in the last call to Solve(). */ @@ -85,11 +85,11 @@ class NewtonRaphsonSolver : public sofa::core::behavior::OdeSolver { auto squared_initial_residual() const -> const FLOATING_POINT_TYPE & { return p_squared_initial_residual; } /** Get the current strategy that determine when the pattern of the system matrix should be analyzed. */ - + auto pattern_analysis_strategy() const -> PatternAnalysisStrategy; /** Set the current strategy that determine when the pattern of the system matrix should be analyzed. */ - + void set_pattern_analysis_strategy(const PatternAnalysisStrategy & strategy); private: @@ -114,7 +114,7 @@ class NewtonRaphsonSolver : public sofa::core::behavior::OdeSolver { virtual void assemble_rhs_vector(const sofa::core::MechanicalParams & mechanical_parameters, const sofa::core::behavior::MultiMatrixAccessor & matrix_accessor, sofa::core::MultiVecDerivId & f_id, - sofa::defaulttype::BaseVector * f) = 0; + SofaCaribou::Algebra::BaseVector * f) = 0; /** * Assemble the left-hand side (LHS) system matrix of the equation to be solved. This will be done at the beginning @@ -137,7 +137,7 @@ class NewtonRaphsonSolver : public sofa::core::behavior::OdeSolver { */ virtual void assemble_system_matrix(const sofa::core::MechanicalParams & mechanical_parameters, sofa::component::linearsolver::DefaultMultiMatrixAccessor & matrix_accessor, - sofa::defaulttype::BaseMatrix * A) = 0; + SofaCaribou::Algebra::BaseMatrix * A) = 0; /** * Propagate the newly solved increment vector. @@ -159,14 +159,14 @@ class NewtonRaphsonSolver : public sofa::core::behavior::OdeSolver { */ virtual void propagate_solution_increment(const sofa::core::MechanicalParams & mechanical_parameters, const sofa::core::behavior::MultiMatrixAccessor & matrix_accessor, - const sofa::defaulttype::BaseVector * dx, + const SofaCaribou::Algebra::BaseVector * dx, sofa::core::MultiVecCoordId & x_id, sofa::core::MultiVecDerivId & v_id, sofa::core::MultiVecDerivId & dx_id) = 0; protected: /** Check that the linked linear solver is not null and that it implements the SofaCaribou::solver::LinearSolver interface */ - + bool has_valid_linear_solver () const; /// INPUTS @@ -185,13 +185,13 @@ class NewtonRaphsonSolver : public sofa::core::behavior::OdeSolver { /// Private members /// Global system matrix A = mM + bB + kK - std::unique_ptr p_A; + std::unique_ptr p_A; /// Global system LHS vector (the solution) - std::unique_ptr p_DX; + std::unique_ptr p_DX; /// Global system RHS vector (the forces) - std::unique_ptr p_F; + std::unique_ptr p_F; /// Total displacement since the beginning of the step sofa::core::MultiVecDerivId p_U_id; diff --git a/src/SofaCaribou/Ode/StaticODESolver.cpp b/src/SofaCaribou/Ode/StaticODESolver.cpp index 18f8906a..644a42a3 100644 --- a/src/SofaCaribou/Ode/StaticODESolver.cpp +++ b/src/SofaCaribou/Ode/StaticODESolver.cpp @@ -35,7 +35,7 @@ using Timer = sofa::helper::AdvancedTimer; void StaticODESolver::assemble_rhs_vector(const sofa::core::MechanicalParams &mechanical_parameters, const sofa::core::behavior::MultiMatrixAccessor & matrix_accessor, sofa::core::MultiVecDerivId & f_id, - sofa::defaulttype::BaseVector *f) { + SofaCaribou::Algebra::BaseVector *f) { // 1. Clear the force vector (F := 0) MechanicalResetForceVisitor(&mechanical_parameters, f_id, false /* onlyMapped */) @@ -61,7 +61,7 @@ void StaticODESolver::assemble_rhs_vector(const sofa::core::MechanicalParams &me // Assemble A in A [dx] = F void StaticODESolver::assemble_system_matrix(const sofa::core::MechanicalParams &mechanical_parameters, sofa::component::linearsolver::DefaultMultiMatrixAccessor & matrix_accessor, - sofa::defaulttype::BaseMatrix *A) { + SofaCaribou::Algebra::BaseMatrix *A) { // Step 1. Building stage: // Here we go down on the current context sub-graph and call : // 1. ff->addMBKToMatrix(&K) for every force field "ff" found. @@ -99,7 +99,7 @@ void StaticODESolver::assemble_system_matrix(const sofa::core::MechanicalParams // Propagate Dx that was previously solved in A [dx] = F void StaticODESolver::propagate_solution_increment(const sofa::core::MechanicalParams &mechanical_parameters, const sofa::core::behavior::MultiMatrixAccessor & matrix_accessor, - const sofa::defaulttype::BaseVector * dx, + const SofaCaribou::Algebra::BaseVector * dx, sofa::core::MultiVecCoordId & x_id, sofa::core::MultiVecDerivId & /* v_id */, sofa::core::MultiVecDerivId & dx_id) { @@ -124,4 +124,4 @@ void StaticODESolver::propagate_solution_increment(const sofa::core::MechanicalP // This will call the methods apply and applyJ on every mechanical mappings. MechanicalPropagateOnlyPositionAndVelocityVisitor(&mechanical_parameters).execute(this->getContext()); } -} // namespace SofaCaribou::ode \ No newline at end of file +} // namespace SofaCaribou::ode diff --git a/src/SofaCaribou/Ode/StaticODESolver.h b/src/SofaCaribou/Ode/StaticODESolver.h index 642d66d1..47d990e2 100644 --- a/src/SofaCaribou/Ode/StaticODESolver.h +++ b/src/SofaCaribou/Ode/StaticODESolver.h @@ -50,20 +50,20 @@ class StaticODESolver : public NewtonRaphsonSolver { void assemble_rhs_vector(const sofa::core::MechanicalParams & mechanical_parameters, const sofa::core::behavior::MultiMatrixAccessor & matrix_accessor, sofa::core::MultiVecDerivId & f_id, - sofa::defaulttype::BaseVector * f) final; + SofaCaribou::Algebra::BaseVector * f) final; /** @see NewtonRaphsonSolver::assemble_system_matrix */ void assemble_system_matrix(const sofa::core::MechanicalParams & mechanical_parameters, sofa::component::linearsolver::DefaultMultiMatrixAccessor & matrix_accessor, - sofa::defaulttype::BaseMatrix * A) final; + SofaCaribou::Algebra::BaseMatrix * A) final; /** @see NewtonRaphsonSolver::propagate_solution_increment */ void propagate_solution_increment(const sofa::core::MechanicalParams & mechanical_parameters, const sofa::core::behavior::MultiMatrixAccessor & matrix_accessor, - const sofa::defaulttype::BaseVector * dx, + const SofaCaribou::Algebra::BaseVector * dx, sofa::core::MultiVecCoordId & x_id, sofa::core::MultiVecDerivId & v_id, sofa::core::MultiVecDerivId & dx_id) final; }; -} // namespace SofaCaribou::ode \ No newline at end of file +} // namespace SofaCaribou::ode diff --git a/src/SofaCaribou/Solver/ConjugateGradientSolver.h b/src/SofaCaribou/Solver/ConjugateGradientSolver.h index 01490403..c13dc868 100644 --- a/src/SofaCaribou/Solver/ConjugateGradientSolver.h +++ b/src/SofaCaribou/Solver/ConjugateGradientSolver.h @@ -160,7 +160,7 @@ class ConjugateGradientSolver : public EigenSolver { /** @see SofaCaribou::solver::LinearSolver::solve */ - bool solve(const sofa::defaulttype::BaseVector * F, sofa::defaulttype::BaseVector * X) override; + bool solve(const SofaCaribou::Algebra::BaseVector * F, SofaCaribou::Algebra::BaseVector * X) override; /** * Solve the linear system Ax = b using a preconditioner. diff --git a/src/SofaCaribou/Solver/ConjugateGradientSolver.inl b/src/SofaCaribou/Solver/ConjugateGradientSolver.inl index f8ca4214..edcafdee 100644 --- a/src/SofaCaribou/Solver/ConjugateGradientSolver.inl +++ b/src/SofaCaribou/Solver/ConjugateGradientSolver.inl @@ -463,7 +463,7 @@ bool ConjugateGradientSolver::factorize() { } template -bool ConjugateGradientSolver::solve(const sofa::defaulttype::BaseVector * F_, sofa::defaulttype::BaseVector *X_) { +bool ConjugateGradientSolver::solve(const SofaCaribou::Algebra::BaseVector * F_, SofaCaribou::Algebra::BaseVector *X_) { const auto & F = dynamic_cast *>(F_)->vector(); auto & X = dynamic_cast *>(X_)->vector(); const PreconditioningMethod preconditioning_method = get_preconditioning_method_from_string(d_preconditioning_method.getValue().getSelectedItem()); diff --git a/src/SofaCaribou/Solver/EigenSolver.h b/src/SofaCaribou/Solver/EigenSolver.h index 84e8cfd7..ec5e7e7c 100644 --- a/src/SofaCaribou/Solver/EigenSolver.h +++ b/src/SofaCaribou/Solver/EigenSolver.h @@ -143,14 +143,14 @@ class EigenSolver : public sofa::core::behavior::LinearSolver, public SofaCaribo static auto canCreate(Derived* o, sofa::core::objectmodel::BaseContext* context, sofa::core::objectmodel::BaseObjectDescription* arg) -> bool; protected: - void set_system_matrix(const sofa::defaulttype::BaseMatrix * A) override { + void set_system_matrix(const SofaCaribou::Algebra::BaseMatrix * A) override { p_A_ptr = dynamic_cast *>(A); } private: /** * @see SofaCaribou::solver::LinearSolver::create_new_matrix */ - sofa::defaulttype::BaseMatrix * create_new_matrix(sofa::Size rows, sofa::Size cols) const override { + SofaCaribou::Algebra::BaseMatrix * create_new_matrix(sofa::Size rows, sofa::Size cols) const override { auto * matrix = new SofaCaribou::Algebra::EigenMatrix (static_cast(rows), static_cast(cols)); if (symmetric()) { matrix->set_symmetric(symmetric()); @@ -161,7 +161,7 @@ class EigenSolver : public sofa::core::behavior::LinearSolver, public SofaCaribo /** * @see SofaCaribou::solver::LinearSolver::create_new_vector */ - sofa::defaulttype::BaseVector * create_new_vector(sofa::Size n) const override { + SofaCaribou::Algebra::BaseVector * create_new_vector(sofa::Size n) const override { return new SofaCaribou::Algebra::EigenVector(n); } diff --git a/src/SofaCaribou/Solver/EigenSolver.inl b/src/SofaCaribou/Solver/EigenSolver.inl index 6632435f..dcd6b646 100644 --- a/src/SofaCaribou/Solver/EigenSolver.inl +++ b/src/SofaCaribou/Solver/EigenSolver.inl @@ -9,7 +9,7 @@ DISABLE_ALL_WARNINGS_BEGIN #include #include #include -#include +//#include DISABLE_ALL_WARNINGS_END #ifndef _WIN32 @@ -252,4 +252,4 @@ auto EigenSolver::canCreate(Derived*, sofa::core::objectmodel::Ba return true; } -} // namespace SofaCaribou::solver \ No newline at end of file +} // namespace SofaCaribou::solver diff --git a/src/SofaCaribou/Solver/LDLTSolver.h b/src/SofaCaribou/Solver/LDLTSolver.h index d3a488f4..e8dcdedf 100644 --- a/src/SofaCaribou/Solver/LDLTSolver.h +++ b/src/SofaCaribou/Solver/LDLTSolver.h @@ -47,7 +47,7 @@ class LDLTSolver : public EigenSolver { * @see SofaCaribou::solver::LinearSolver::solve */ - bool solve(const sofa::defaulttype::BaseVector * F, sofa::defaulttype::BaseVector * X) override; + bool solve(const SofaCaribou::Algebra::BaseVector * F, SofaCaribou::Algebra::BaseVector * X) override; // Get the backend name of the class derived from the EigenSolver template parameter diff --git a/src/SofaCaribou/Solver/LDLTSolver.inl b/src/SofaCaribou/Solver/LDLTSolver.inl index 646b76a9..7fc008a8 100644 --- a/src/SofaCaribou/Solver/LDLTSolver.inl +++ b/src/SofaCaribou/Solver/LDLTSolver.inl @@ -64,8 +64,8 @@ bool LDLTSolver::factorize() { } template -bool LDLTSolver::solve(const sofa::defaulttype::BaseVector * F, - sofa::defaulttype::BaseVector *X) { +bool LDLTSolver::solve(const SofaCaribou::Algebra::BaseVector * F, + SofaCaribou::Algebra::BaseVector *X) { auto F_ = dynamic_cast *>(F); auto X_ = dynamic_cast *>(X); diff --git a/src/SofaCaribou/Solver/LLTSolver.h b/src/SofaCaribou/Solver/LLTSolver.h index 6adecf84..fd48c981 100644 --- a/src/SofaCaribou/Solver/LLTSolver.h +++ b/src/SofaCaribou/Solver/LLTSolver.h @@ -47,7 +47,7 @@ class LLTSolver : public EigenSolver { * @see SofaCaribou::solver::LinearSolver::solve */ - bool solve(const sofa::defaulttype::BaseVector * F, sofa::defaulttype::BaseVector * X) override; + bool solve(const SofaCaribou::Algebra::BaseVector * F, SofaCaribou::Algebra::BaseVector * X) override; /// Get the backend name of the class derived from the EigenSolver_t template parameter diff --git a/src/SofaCaribou/Solver/LLTSolver.inl b/src/SofaCaribou/Solver/LLTSolver.inl index 3b9a518e..2cf9da0b 100644 --- a/src/SofaCaribou/Solver/LLTSolver.inl +++ b/src/SofaCaribou/Solver/LLTSolver.inl @@ -63,8 +63,8 @@ bool LLTSolver::factorize() { } template -bool LLTSolver::solve(const sofa::defaulttype::BaseVector * F, - sofa::defaulttype::BaseVector *X) { +bool LLTSolver::solve(const SofaCaribou::Algebra::BaseVector * F, + SofaCaribou::Algebra::BaseVector *X) { auto F_ = dynamic_cast *>(F); auto X_ = dynamic_cast *>(X); diff --git a/src/SofaCaribou/Solver/LUSolver.h b/src/SofaCaribou/Solver/LUSolver.h index da2fc136..746ed0fa 100644 --- a/src/SofaCaribou/Solver/LUSolver.h +++ b/src/SofaCaribou/Solver/LUSolver.h @@ -36,7 +36,7 @@ class LUSolver : public EigenSolver { * @see SofaCaribou::solver::LinearSolver::solve */ - bool solve(const sofa::defaulttype::BaseVector * F, sofa::defaulttype::BaseVector * X) override; + bool solve(const SofaCaribou::Algebra::BaseVector * F, SofaCaribou::Algebra::BaseVector * X) override; /** * States if the system matrix is symmetric. Note that this value isn't set automatically, the user must diff --git a/src/SofaCaribou/Solver/LUSolver.inl b/src/SofaCaribou/Solver/LUSolver.inl index 77bb85da..db309de1 100644 --- a/src/SofaCaribou/Solver/LUSolver.inl +++ b/src/SofaCaribou/Solver/LUSolver.inl @@ -70,8 +70,8 @@ bool LUSolver::factorize() { } template -bool LUSolver::solve(const sofa::defaulttype::BaseVector * F, - sofa::defaulttype::BaseVector *X) { +bool LUSolver::solve(const SofaCaribou::Algebra::BaseVector * F, + SofaCaribou::Algebra::BaseVector *X) { auto F_ = dynamic_cast *>(F); auto X_ = dynamic_cast *>(X); diff --git a/src/SofaCaribou/Solver/LinearSolver.h b/src/SofaCaribou/Solver/LinearSolver.h index a5d969aa..ed32190e 100644 --- a/src/SofaCaribou/Solver/LinearSolver.h +++ b/src/SofaCaribou/Solver/LinearSolver.h @@ -12,10 +12,6 @@ namespace sofa::linearalgebra { class BaseVector; class BaseMatrix; } -namespace sofa::defaulttype { - using BaseVector = sofa::linearalgebra::BaseVector; - using BaseMatrix = sofa::linearalgebra::BaseMatrix; -} #endif // (defined(SOFA_VERSION) && SOFA_VERSION < 211299) namespace SofaCaribou::solver { @@ -26,6 +22,13 @@ namespace SofaCaribou::solver { */ class LinearSolver { public: +#if (defined(SOFA_VERSION) && SOFA_VERSION < 211200) + using BaseMatrix = sofa::defaulttype::BaseMatrix; + using BaseVector = sofa::defaulttype::BaseVector; +#else + using BaseMatrix = sofa::linearalgebra::BaseMatrix; + using BaseVector = sofa::linearalgebra::BaseVector; +#endif /** * Creates a new BaseMatrix of size rows x cols. * @@ -41,7 +44,7 @@ class LinearSolver { * memory of this newly created matrix. */ [[nodiscard]] - virtual sofa::defaulttype::BaseMatrix * create_new_matrix(unsigned int rows, unsigned int cols) const = 0; + virtual BaseMatrix * create_new_matrix(unsigned int rows, unsigned int cols) const = 0; /** * Creates a new BaseVector of size n. @@ -58,7 +61,7 @@ class LinearSolver { * memory of this newly created vector. */ [[nodiscard]] - virtual sofa::defaulttype::BaseVector * create_new_vector(unsigned int n) const = 0; + virtual BaseVector * create_new_vector(unsigned int n) const = 0; /** * Solve the linear system A [X] = F @@ -71,8 +74,8 @@ class LinearSolver { * @note The vectors must be of the virtual type SofaCaribou::Algebra::EigenVector * @note LinearSolver::factorize must have been called before this method. */ - virtual bool solve(const sofa::defaulttype::BaseVector * F, - sofa::defaulttype::BaseVector * X) = 0; + virtual bool solve(const BaseVector * F, + BaseVector * X) = 0; /** * Analyze the pattern of the given matrix. @@ -101,7 +104,7 @@ class LinearSolver { * later on using the analyse_patern(), factorize(), and solve() methods. * @param A A pointer to the fully assembled system matrix. */ - virtual void set_system_matrix(const sofa::defaulttype::BaseMatrix * A) = 0; + virtual void set_system_matrix(const BaseMatrix * A) = 0; /** * Returns true if this solver is an iterative one, false otherwise. In case of iterative solvers, diff --git a/src/SofaCaribou/Topology/CaribouTopology.h b/src/SofaCaribou/Topology/CaribouTopology.h index 9d48c308..2551a8c3 100644 --- a/src/SofaCaribou/Topology/CaribouTopology.h +++ b/src/SofaCaribou/Topology/CaribouTopology.h @@ -80,12 +80,12 @@ class CaribouTopology : public sofa::core::objectmodel::BaseObject { CaribouTopology(); void init() override; - [[nodiscard]] auto - getTemplateName() const -> std::string override { - return templateName(this); + static auto GetCustomTemplateName() -> std::string { + return "Unknown"; } + static auto templateName(const CaribouTopology* = nullptr) -> std::string { - return "Unknown"; + return GetCustomTemplateName(); } /** diff --git a/src/SofaCaribou/Topology/CaribouTopology[Hexahedron20].cpp b/src/SofaCaribou/Topology/CaribouTopology[Hexahedron20].cpp index 3288d0c9..6b49a22a 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Hexahedron20].cpp +++ b/src/SofaCaribou/Topology/CaribouTopology[Hexahedron20].cpp @@ -19,7 +19,7 @@ namespace SofaCaribou::topology { // Hexahedron Quadratic specialization template<> auto -CaribouTopology::templateName(const CaribouTopology *) -> std::string { +CaribouTopology::GetCustomTemplateName() -> std::string { return "Hexahedron20"; } diff --git a/src/SofaCaribou/Topology/CaribouTopology[Hexahedron20].h b/src/SofaCaribou/Topology/CaribouTopology[Hexahedron20].h index 7886a693..114a98e5 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Hexahedron20].h +++ b/src/SofaCaribou/Topology/CaribouTopology[Hexahedron20].h @@ -7,8 +7,7 @@ namespace SofaCaribou::topology { // Hexahedron quadratic specialization template<> -auto CaribouTopology::templateName( - const CaribouTopology *) -> std::string; +auto CaribouTopology::GetCustomTemplateName() -> std::string; template <> auto CaribouTopology::mesh_is_compatible( const sofa::core::topology::BaseMeshTopology * topology) -> bool; diff --git a/src/SofaCaribou/Topology/CaribouTopology[Hexahedron].cpp b/src/SofaCaribou/Topology/CaribouTopology[Hexahedron].cpp index 7add6d8c..b3b4dd54 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Hexahedron].cpp +++ b/src/SofaCaribou/Topology/CaribouTopology[Hexahedron].cpp @@ -18,7 +18,8 @@ namespace SofaCaribou::topology { // Hexahedron linear specialization template<> -auto CaribouTopology::templateName(const CaribouTopology *) -> std::string { +auto +CaribouTopology::GetCustomTemplateName() -> std::string { return "Hexahedron"; } diff --git a/src/SofaCaribou/Topology/CaribouTopology[Hexahedron].h b/src/SofaCaribou/Topology/CaribouTopology[Hexahedron].h index 19866853..e6d7b29a 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Hexahedron].h +++ b/src/SofaCaribou/Topology/CaribouTopology[Hexahedron].h @@ -7,8 +7,7 @@ namespace SofaCaribou::topology { // Hexahedron linear specialization template<> -auto CaribouTopology::templateName( - const CaribouTopology *) -> std::string; +auto CaribouTopology::GetCustomTemplateName() -> std::string; template <> auto CaribouTopology::mesh_is_compatible( const sofa::core::topology::BaseMeshTopology * topology) -> bool; diff --git a/src/SofaCaribou/Topology/CaribouTopology[Quad8].cpp b/src/SofaCaribou/Topology/CaribouTopology[Quad8].cpp index 96b28647..66eef25d 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Quad8].cpp +++ b/src/SofaCaribou/Topology/CaribouTopology[Quad8].cpp @@ -17,7 +17,7 @@ namespace SofaCaribou::topology { // Quad 2D quadratic specialization template<> -auto CaribouTopology>::templateName(const CaribouTopology> *) -> std::string { +auto CaribouTopology>::GetCustomTemplateName() -> std::string { return "Quad8_2D"; } @@ -30,7 +30,7 @@ auto CaribouTopology>::mesh_is_compatible(const BaseMeshTopology *) - // Quad 3D quadratic specialization template<> auto -CaribouTopology>::templateName(const CaribouTopology> *) -> std::string { +CaribouTopology>::GetCustomTemplateName() -> std::string { return "Quad8"; } diff --git a/src/SofaCaribou/Topology/CaribouTopology[Quad8].h b/src/SofaCaribou/Topology/CaribouTopology[Quad8].h index d499599f..2f429630 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Quad8].h +++ b/src/SofaCaribou/Topology/CaribouTopology[Quad8].h @@ -7,8 +7,7 @@ namespace SofaCaribou::topology { // Quad 2D quadratic specialization template<> -auto CaribouTopology>::templateName( - const CaribouTopology> *) -> std::string; +auto CaribouTopology>::GetCustomTemplateName() -> std::string; template <> auto CaribouTopology>::mesh_is_compatible( const sofa::core::topology::BaseMeshTopology * topology) -> bool; @@ -18,8 +17,7 @@ class CaribouTopology>; // Quad 3D quadratic specialization template<> -auto CaribouTopology>::templateName( - const CaribouTopology> *) -> std::string; +auto CaribouTopology>::GetCustomTemplateName() -> std::string; template <> auto CaribouTopology>::mesh_is_compatible( const sofa::core::topology::BaseMeshTopology * topology) -> bool; diff --git a/src/SofaCaribou/Topology/CaribouTopology[Quad].cpp b/src/SofaCaribou/Topology/CaribouTopology[Quad].cpp index cd76ecf6..b9c1fb84 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Quad].cpp +++ b/src/SofaCaribou/Topology/CaribouTopology[Quad].cpp @@ -17,7 +17,7 @@ namespace SofaCaribou::topology { // Quad 2D linear specialization template<> -auto CaribouTopology>::templateName(const CaribouTopology> *) -> std::string { +auto CaribouTopology>::GetCustomTemplateName() -> std::string { return "Quad_2D"; } @@ -36,7 +36,7 @@ auto CaribouTopology>::get_indices_data_from(const BaseMeshTopology * // Quad 3D linear specialization template<> auto -CaribouTopology>::templateName(const CaribouTopology> *) -> std::string { +CaribouTopology>::GetCustomTemplateName() -> std::string { return "Quad"; } diff --git a/src/SofaCaribou/Topology/CaribouTopology[Quad].h b/src/SofaCaribou/Topology/CaribouTopology[Quad].h index ea6aea06..1aafa436 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Quad].h +++ b/src/SofaCaribou/Topology/CaribouTopology[Quad].h @@ -7,8 +7,7 @@ namespace SofaCaribou::topology { // Quad 2D linear specialization template<> -auto CaribouTopology>::templateName( - const CaribouTopology> *) -> std::string; +auto CaribouTopology>::GetCustomTemplateName() -> std::string; template <> auto CaribouTopology>::mesh_is_compatible( const sofa::core::topology::BaseMeshTopology * topology) -> bool; @@ -21,8 +20,7 @@ class CaribouTopology>; // Quad 3D linear specialization template<> -auto CaribouTopology>::templateName( - const CaribouTopology> *) -> std::string; +auto CaribouTopology>::GetCustomTemplateName() -> std::string; template <> auto CaribouTopology>::mesh_is_compatible( const sofa::core::topology::BaseMeshTopology * topology) -> bool; diff --git a/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron10].cpp b/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron10].cpp index a1c8f851..58a69cad 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron10].cpp +++ b/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron10].cpp @@ -18,7 +18,7 @@ namespace SofaCaribou::topology { // Tetrahedron Quadratic specialization template<> auto -CaribouTopology::templateName(const CaribouTopology *) -> std::string { +CaribouTopology::GetCustomTemplateName() -> std::string { return "Tetrahedron10"; } diff --git a/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron10].h b/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron10].h index 2c29ec8e..00b3a0d4 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron10].h +++ b/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron10].h @@ -7,8 +7,7 @@ namespace SofaCaribou::topology { // Tetrahedron quadratic specialization template<> -auto CaribouTopology::templateName( - const CaribouTopology *) -> std::string; +auto CaribouTopology::GetCustomTemplateName() -> std::string; template <> auto CaribouTopology::mesh_is_compatible( const sofa::core::topology::BaseMeshTopology * topology) -> bool; diff --git a/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron].cpp b/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron].cpp index 90142697..a6fe735b 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron].cpp +++ b/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron].cpp @@ -17,7 +17,7 @@ namespace SofaCaribou::topology { // Tetrahedron linear specialization template<> -auto CaribouTopology::templateName(const CaribouTopology *) -> std::string { +auto CaribouTopology::GetCustomTemplateName() -> std::string { return "Tetrahedron"; } diff --git a/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron].h b/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron].h index a8fc11bc..799c4dff 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron].h +++ b/src/SofaCaribou/Topology/CaribouTopology[Tetrahedron].h @@ -7,8 +7,7 @@ namespace SofaCaribou::topology { // Tetrahedron linear specialization template<> -auto CaribouTopology::templateName( - const CaribouTopology *) -> std::string; +auto CaribouTopology::GetCustomTemplateName() -> std::string; template <> auto CaribouTopology::mesh_is_compatible( const sofa::core::topology::BaseMeshTopology * topology) -> bool; diff --git a/src/SofaCaribou/Topology/CaribouTopology[Triangle6].cpp b/src/SofaCaribou/Topology/CaribouTopology[Triangle6].cpp index 024d450a..189688da 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Triangle6].cpp +++ b/src/SofaCaribou/Topology/CaribouTopology[Triangle6].cpp @@ -17,7 +17,7 @@ namespace SofaCaribou::topology { // Triangle 2D quadratic specialization template<> -auto CaribouTopology>::templateName(const CaribouTopology> *) -> std::string { +auto CaribouTopology>::GetCustomTemplateName() -> std::string { return "Triangle6_2D"; } @@ -30,7 +30,7 @@ auto CaribouTopology>::mesh_is_compatible(const BaseMeshTopology // Triangle 3D quadratic specialization template<> auto -CaribouTopology>::templateName(const CaribouTopology> *) -> std::string { +CaribouTopology>::GetCustomTemplateName() -> std::string { return "Triangle6"; } diff --git a/src/SofaCaribou/Topology/CaribouTopology[Triangle6].h b/src/SofaCaribou/Topology/CaribouTopology[Triangle6].h index 12c3577d..756b1afe 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Triangle6].h +++ b/src/SofaCaribou/Topology/CaribouTopology[Triangle6].h @@ -6,8 +6,7 @@ namespace SofaCaribou::topology { // Triangle 2D quadratic specialization -template<> auto CaribouTopology>::templateName( - const CaribouTopology> *) -> std::string; +template<> auto CaribouTopology>::GetCustomTemplateName() -> std::string; template <> auto CaribouTopology>::mesh_is_compatible( const sofa::core::topology::BaseMeshTopology * topology) -> bool; @@ -16,8 +15,7 @@ extern template class CaribouTopology>; // Triangle 3D quadratic specialization -template<> auto CaribouTopology>::templateName( - const CaribouTopology> *) -> std::string; +template<> auto CaribouTopology>::GetCustomTemplateName() -> std::string; template <> auto CaribouTopology>::mesh_is_compatible( const sofa::core::topology::BaseMeshTopology * topology) -> bool; diff --git a/src/SofaCaribou/Topology/CaribouTopology[Triangle].cpp b/src/SofaCaribou/Topology/CaribouTopology[Triangle].cpp index 51017906..5809c7c7 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Triangle].cpp +++ b/src/SofaCaribou/Topology/CaribouTopology[Triangle].cpp @@ -17,7 +17,7 @@ namespace SofaCaribou::topology { // Triangle 2D linear specialization template<> -auto CaribouTopology>::templateName(const CaribouTopology> *) -> std::string { +auto CaribouTopology>::GetCustomTemplateName() -> std::string { return "Triangle_2D"; } @@ -36,7 +36,7 @@ auto CaribouTopology>::get_indices_data_from(const BaseMeshTopolog // Triangle 3D linear specialization template<> auto -CaribouTopology>::templateName(const CaribouTopology> *) -> std::string { +CaribouTopology>::GetCustomTemplateName() -> std::string { return "Triangle"; } diff --git a/src/SofaCaribou/Topology/CaribouTopology[Triangle].h b/src/SofaCaribou/Topology/CaribouTopology[Triangle].h index 2c243f66..24c5043f 100644 --- a/src/SofaCaribou/Topology/CaribouTopology[Triangle].h +++ b/src/SofaCaribou/Topology/CaribouTopology[Triangle].h @@ -7,8 +7,7 @@ namespace SofaCaribou::topology { // Triangle 2D linear specialization template<> -auto CaribouTopology>::templateName( - const CaribouTopology> *) -> std::string; +auto CaribouTopology>::GetCustomTemplateName() -> std::string; template <> auto CaribouTopology>::mesh_is_compatible( const sofa::core::topology::BaseMeshTopology * topology) -> bool; @@ -21,8 +20,7 @@ class CaribouTopology>; // Triangle 3D linear specialization template<> -auto CaribouTopology>::templateName( - const CaribouTopology> *) -> std::string; +auto CaribouTopology>::GetCustomTemplateName() -> std::string; template <> auto CaribouTopology>::mesh_is_compatible( const sofa::core::topology::BaseMeshTopology * topology) -> bool; diff --git a/src/SofaCaribou/Topology/FictitiousGrid.h b/src/SofaCaribou/Topology/FictitiousGrid.h index 8634d864..bb65dcb5 100644 --- a/src/SofaCaribou/Topology/FictitiousGrid.h +++ b/src/SofaCaribou/Topology/FictitiousGrid.h @@ -277,8 +277,8 @@ class FictitiousGrid : public virtual BaseObject } } - std::string getTemplateName() const override { - return templateName(this); + static std::string GetCustomTemplateName() { + return templateName(); } static std::string templateName(const FictitiousGrid* = nullptr) { diff --git a/unittest/SofaCaribou/Algebra/test_base_vector_operations.cpp b/unittest/SofaCaribou/Algebra/test_base_vector_operations.cpp index 242a36c9..95e2fde2 100644 --- a/unittest/SofaCaribou/Algebra/test_base_vector_operations.cpp +++ b/unittest/SofaCaribou/Algebra/test_base_vector_operations.cpp @@ -4,8 +4,17 @@ DISABLE_ALL_WARNINGS_BEGIN #include -#include #include + +#if (defined(SOFA_VERSION) && SOFA_VERSION < 211299) +#include +using namespace sofa::component::linearsolver; +#else +#include +using namespace sofa::linearalgebra; +#endif // (defined(SOFA_VERSION) && SOFA_VERSION < 211299) + + DISABLE_ALL_WARNINGS_END #include @@ -19,8 +28,8 @@ TEST(Algebra, SofaFullDFullDDotProduct) { const Eigen::VectorXd v1 = Eigen::VectorXd::Random(n); const Eigen::VectorXd v2 = Eigen::VectorXd::Random(n); - sofa::component::linearsolver::FullVector sofa_v1 (n); - sofa::component::linearsolver::FullVector sofa_v2 (n); + FullVector sofa_v1 (n); + FullVector sofa_v2 (n); for (sofa::Index i = 0; i < n; ++i) { sofa_v1[i] = v1[static_cast(i)]; @@ -35,8 +44,8 @@ TEST(Algebra, SofaFullDFullFDotProduct) { const Eigen::VectorXd v1 = Eigen::VectorXd::Random(n); const Eigen::VectorXf v2 = Eigen::VectorXf::Random(n); - sofa::component::linearsolver::FullVector sofa_v1 (n); - sofa::component::linearsolver::FullVector sofa_v2 (n); + FullVector sofa_v1 (n); + FullVector sofa_v2 (n); for (sofa::Index i = 0; i < n; ++i) { sofa_v1[i] = v1[static_cast(i)]; @@ -51,8 +60,8 @@ TEST(Algebra, SofaFullFFullDDotProduct) { const Eigen::VectorXf v1 = Eigen::VectorXf::Random(n); const Eigen::VectorXd v2 = Eigen::VectorXd::Random(n); - sofa::component::linearsolver::FullVector sofa_v1 (n); - sofa::component::linearsolver::FullVector sofa_v2 (n); + FullVector sofa_v1 (n); + FullVector sofa_v2 (n); for (sofa::Index i = 0; i < n; ++i) { sofa_v1[i] = v1[static_cast(i)]; @@ -60,4 +69,4 @@ TEST(Algebra, SofaFullFFullDDotProduct) { } EXPECT_NEAR(SofaCaribou::Algebra::dot(&sofa_v1, &sofa_v2), v1.cast().dot(v2), 1e-10); -} \ No newline at end of file +} diff --git a/unittest/SofaCaribou/CMakeLists.txt b/unittest/SofaCaribou/CMakeLists.txt index 8b4480db..2d53df4e 100644 --- a/unittest/SofaCaribou/CMakeLists.txt +++ b/unittest/SofaCaribou/CMakeLists.txt @@ -15,7 +15,7 @@ set(SOURCE_FILES enable_testing() -find_package(SOFA COMPONENTS SofaFramework SofaSimulationGraph SofaBaseMechanics SofaBaseUtils SofaBaseLinearSolver SofaMiscForceField QUIET REQUIRED) +find_package(SOFA COMPONENTS SofaFramework Sofa.Simulation.Graph SofaBaseMechanics SofaBaseUtils SofaBaseLinearSolver SofaMiscForceField QUIET REQUIRED) find_package(Caribou COMPONENTS Topology REQUIRED) find_package(Threads REQUIRED) @@ -31,10 +31,15 @@ endif() target_link_libraries(${PROJECT_NAME} PUBLIC gtest) target_link_libraries(${PROJECT_NAME} PUBLIC SofaCaribou) -target_link_libraries(${PROJECT_NAME} PUBLIC SofaHelper SofaSimulationGraph SofaBaseMechanics SofaBaseUtils SofaSimulationCommon SofaBaseLinearSolver SofaMiscForceField) +target_link_libraries(${PROJECT_NAME} PUBLIC SofaHelper SofaBaseMechanics SofaBaseUtils SofaBaseLinearSolver SofaMiscForceField) target_link_libraries(${PROJECT_NAME} PUBLIC $<$,$,8.0>>:stdc++fs> $<$,$,9.0>>:c++fs>) +if (${SofaFramework_VERSION} VERSION_LESS "22.06.99") + target_link_libraries(${PROJECT_NAME} PUBLIC SofaSimulationGraph) +else() + target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Simulation.Graph) +endif() target_compile_definitions(${PROJECT_NAME} PUBLIC $<$,$,8.0>>:LEGACY_CXX> $<$,$,9.0>>:LEGACY_CXX>) diff --git a/unittest/SofaCaribou/main.cpp b/unittest/SofaCaribou/main.cpp index 7dc9c4e3..7feff4d3 100644 --- a/unittest/SofaCaribou/main.cpp +++ b/unittest/SofaCaribou/main.cpp @@ -12,7 +12,11 @@ namespace fs = ::std::filesystem; DISABLE_ALL_WARNINGS_BEGIN #include +#if (defined(SOFA_VERSION) && SOFA_VERSION >= 220600) +#include +#else #include +#endif #if (defined(SOFA_VERSION) && SOFA_VERSION >= 201200) #include #include