Skip to content

Commit

Permalink
Merge pull request #140 from epernod/v22.06
Browse files Browse the repository at this point in the history
Fix headers includes and namespaces to follow changes in SOFA
  • Loading branch information
jnbrunet authored Nov 30, 2022
2 parents 65e31d2 + 45a4b94 commit f96129b
Show file tree
Hide file tree
Showing 64 changed files with 286 additions and 217 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <SofaCaribou/Topology/CaribouTopology.h>

DISABLE_ALL_WARNINGS_BEGIN
#include <sofa/defaulttype/BaseMatrix.h>
#include <SofaCaribou/Algebra/BaseMatrixOperations.h>
DISABLE_ALL_WARNINGS_END

#if (defined(SOFA_VERSION) && SOFA_VERSION < 201200)
Expand Down Expand Up @@ -101,7 +101,7 @@ class HyperelasticForcefieldRecomputeF : public ::SofaCaribou::forcefield::Carib
const sofa::core::objectmodel::Data<VecCoord>& /* 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 & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void HyperelasticForcefieldRecomputeF<Element>::addDForce(

template <typename Element>
void HyperelasticForcefieldRecomputeF<Element>::addKToMatrix(
sofa::defaulttype::BaseMatrix * matrix,
SofaCaribou::Algebra::BaseMatrix * matrix,
SReal kFact, unsigned int & offset)
{
if (not K_is_up_to_date) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <SofaCaribou/config.h>
#include <SofaCaribou/Material/HyperelasticMaterial.h>
#include <SofaCaribou/Forcefield/CaribouForcefield.h>
#include <SofaCaribou/Algebra/BaseMatrixOperations.h>

#include <Caribou/config.h>
#include <Caribou/constants.h>
Expand Down Expand Up @@ -98,7 +99,7 @@ class HyperelasticForcefieldStoreF : public ::SofaCaribou::forcefield::CaribouFo
const sofa::core::objectmodel::Data<VecCoord>& /* 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 & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void HyperelasticForcefieldStoreF<Element>::addDForce(

template <typename Element>
void HyperelasticForcefieldStoreF<Element>::addKToMatrix(
sofa::defaulttype::BaseMatrix * matrix,
SofaCaribou::Algebra::BaseMatrix * matrix,
SReal kFact, unsigned int & offset)
{
if (not K_is_up_to_date) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <SofaCaribou/config.h>
#include <SofaCaribou/Material/HyperelasticMaterial.h>
#include <SofaCaribou/Forcefield/CaribouForcefield.h>
#include <SofaCaribou/Algebra/BaseMatrixOperations.h>

#include <Caribou/config.h>
#include <Caribou/constants.h>
Expand All @@ -17,7 +18,7 @@
#include <SofaCaribou/Topology/CaribouTopology.h>

DISABLE_ALL_WARNINGS_BEGIN
#include <sofa/defaulttype/BaseMatrix.h>
#include <SofaCaribou/Algebra/BaseMatrixOperations.h>
DISABLE_ALL_WARNINGS_END

#if (defined(SOFA_VERSION) && SOFA_VERSION < 201200)
Expand Down Expand Up @@ -105,7 +106,7 @@ class HyperelasticForcefieldStoreFAndS : public ::SofaCaribou::forcefield::Carib
const sofa::core::objectmodel::Data<VecCoord>& /* 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 & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void HyperelasticForcefieldStoreFAndS<Element>::addDForce(

template <typename Element>
void HyperelasticForcefieldStoreFAndS<Element>::addKToMatrix(
sofa::defaulttype::BaseMatrix * matrix,
SofaCaribou::Algebra::BaseMatrix * matrix,
SReal kFact, unsigned int & offset)
{
if (not K_is_up_to_date) {
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions cmake/FindSOFA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
26 changes: 26 additions & 0 deletions src/SofaCaribou/Algebra/BaseMatrixOperations.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <SofaCaribou/config.h>

// Various utilities to perform numerical operations on SOFA's BaseMatrix.
DISABLE_ALL_WARNINGS_BEGIN
#include <sofa/version.h> // for SOFA_VERSION
DISABLE_ALL_WARNINGS_END

#if (defined(SOFA_VERSION) && SOFA_VERSION < 211200)
#include <sofa/defaulttype/BaseMatrix.h>
#else
#include <sofa/linearalgebra/BaseMatrix.h>
#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
23 changes: 14 additions & 9 deletions src/SofaCaribou/Algebra/BaseVectorOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
DISABLE_ALL_WARNINGS_BEGIN
#include <sofa/version.h>
#if (defined(SOFA_VERSION) && SOFA_VERSION < 211299)
#include <sofa/defaulttype/BaseVector.h>
#include <SofaBaseLinearSolver/FullVector.h>
#else
#include <sofa/linearalgebra/BaseVector.h>
#include <sofa/linearalgebra/FullVector.h>
#endif // #if (defined(SOFA_VERSION) && SOFA_VERSION < 211299)
#include <SofaBaseLinearSolver/FullVector.h>
DISABLE_ALL_WARNINGS_END

#if (defined(SOFA_VERSION) && SOFA_VERSION < 201200)
Expand All @@ -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 <typename Real>
auto to_full_vector(const sofa::defaulttype::BaseVector* v) -> const sofa::component::linearsolver::FullVector<Real> * {
return dynamic_cast<const sofa::component::linearsolver::FullVector<Real> *>(v);
auto to_full_vector(const BaseVector* v) -> const FullVector<Real> * {
return dynamic_cast<const FullVector<Real> *>(v);
}

// Dot product between a SOFA full vector and any BaseVector
template <typename ReturnValue, typename Real>
ReturnValue dot(const sofa::component::linearsolver::FullVector<Real> * v1, const sofa::defaulttype::BaseVector * v2) {
ReturnValue dot(const FullVector<Real> * v1, const BaseVector * v2) {
const auto n = static_cast<sofa::Size>(v1->size());
auto value = static_cast<ReturnValue>(0);
for (sofa::Index i = 0; i < n; ++i) {
Expand All @@ -40,7 +45,7 @@ ReturnValue dot(const sofa::component::linearsolver::FullVector<Real> * v1, cons

// Dot product between a two SOFA full vectors
template <typename ReturnValue, typename Real1, typename Real2>
ReturnValue dot(const sofa::component::linearsolver::FullVector<Real1> * v1, const sofa::component::linearsolver::FullVector<Real2> * v2) {
ReturnValue dot(const FullVector<Real1> * v1, const FullVector<Real2> * v2) {
const auto n = static_cast<sofa::Size>(v1->size());
auto value = static_cast<ReturnValue>(0);
for (sofa::Index i = 0; i < n; ++i) {
Expand All @@ -52,7 +57,7 @@ ReturnValue dot(const sofa::component::linearsolver::FullVector<Real1> * 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([email protected]): This function is awful. I'm sure there is a much much cleaner and faster way
Expand Down Expand Up @@ -119,4 +124,4 @@ ReturnValue dot(const sofa::component::linearsolver::FullVector<Real1> * v1, con
return static_cast<double> (value);
}

} // namespace SofaCaribou::Algebra
} // namespace SofaCaribou::Algebra
20 changes: 9 additions & 11 deletions src/SofaCaribou/Algebra/BaseVectorOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sofa/defaulttype/BaseVector.h>
#else
namespace sofa::linearalgebra {
class BaseVector;
}
namespace sofa::defaulttype {
using BaseVector = sofa::linearalgebra::BaseVector;
}
#include <sofa/linearalgebra/BaseVector.h>
#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) *
Expand All @@ -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
} // namespace SofaCaribou::Algebra
10 changes: 5 additions & 5 deletions src/SofaCaribou/Algebra/EigenMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

DISABLE_ALL_WARNINGS_BEGIN
#include <sofa/version.h>
#include <sofa/defaulttype/BaseMatrix.h>
#include <SofaCaribou/Algebra/BaseMatrixOperations.h>
DISABLE_ALL_WARNINGS_END

#if (defined(SOFA_VERSION) && SOFA_VERSION < 201200)
Expand Down Expand Up @@ -68,7 +68,7 @@ namespace SofaCaribou::Algebra {
* \endcode
*/
template <typename Derived, typename Enable = void>
class EigenMatrix : public sofa::defaulttype::BaseMatrix
class EigenMatrix : public BaseMatrix
{
static_assert(
std::is_base_of_v<Eigen::EigenBase<std::decay_t<Derived> >, std::decay_t<Derived> >,
Expand All @@ -77,7 +77,7 @@ class EigenMatrix : public sofa::defaulttype::BaseMatrix

public:
using EigenType = std::remove_cv_t<std::remove_reference_t<Derived>>;
using Base = sofa::defaulttype::BaseMatrix;
using Base = BaseMatrix;
using Index = Base::Index;
using Real = SReal;
using Scalar = typename EigenType::Scalar;
Expand Down Expand Up @@ -168,12 +168,12 @@ class EigenMatrix : public sofa::defaulttype::BaseMatrix
/// SparseMatrix specialization ///
///////////////////////////////////
template <typename Derived>
class EigenMatrix<Derived, CLASS_REQUIRES(std::is_base_of_v<Eigen::SparseMatrixBase<std::decay_t<Derived>>, std::decay_t<Derived>>)> : public sofa::defaulttype::BaseMatrix
class EigenMatrix<Derived, CLASS_REQUIRES(std::is_base_of_v<Eigen::SparseMatrixBase<std::decay_t<Derived>>, std::decay_t<Derived>>)> : public BaseMatrix
{

public:
using EigenType = std::remove_cv_t<std::remove_reference_t<Derived>>;
using Base = sofa::defaulttype::BaseMatrix;
using Base = BaseMatrix;
using Index = Base::Index;
using Real = SReal;
using Scalar = typename EigenType::Scalar;
Expand Down
8 changes: 4 additions & 4 deletions src/SofaCaribou/Algebra/EigenVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <Caribou/traits.h>

DISABLE_ALL_WARNINGS_BEGIN
#include <sofa/defaulttype/BaseMatrix.h>
#include <sofa/defaulttype/BaseVector.h>
#include <SofaCaribou/Algebra/BaseMatrixOperations.h>
#include <SofaCaribou/Algebra/BaseVectorOperations.h>
DISABLE_ALL_WARNINGS_END

#include <Eigen/Dense>
Expand All @@ -23,7 +23,7 @@ namespace SofaCaribou::Algebra {
* @tparam Enable
*/
template <typename Derived, typename Enable = void>
class EigenVector : public sofa::defaulttype::BaseVector
class EigenVector : public BaseVector
{
static_assert(
std::is_base_of_v<Eigen::EigenBase<std::decay_t<Derived> >, std::decay_t<Derived> >,
Expand All @@ -38,7 +38,7 @@ class EigenVector : public sofa::defaulttype::BaseVector

public:
using EigenType = std::remove_cv_t<std::remove_reference_t<Derived>>;
using Base = sofa::defaulttype::BaseVector;
using Base = BaseVector;
using Index = Base::Index;
using Real = typename EigenType::Scalar;

Expand Down
1 change: 1 addition & 0 deletions src/SofaCaribou/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit f96129b

Please sign in to comment.