diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 1ff9c1eb..6e017830 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -195,7 +195,7 @@ jobs: && ccache -s - name: Archive production - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4.4.0 with: name: caribou_macos_${{ matrix.sofa_version }} path: SofaCaribou.tar.gz diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index fca4b794..720aa823 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -10,209 +10,119 @@ on: jobs: build: - name: Building with ${{ matrix.sofa_version }} - runs-on: ubuntu-20.04 - container: ${{ matrix.CONTAINER }} + name: Run on ${{ matrix.os }} with SOFA ${{ matrix.sofa_branch }} + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - sofa_version: [ master ] - include: - - sofa_version: master - SOFA_VERSION_I: 999999 - CONTAINER: jnbrunet/caribou-ubuntu-2004-builder:latest - PYTHON_VERSION: 3.8 - PYBIND11_VERSION: 2.6 - env: - SOFA_VERSION: ${{ matrix.sofa_version }} - SOFA_ROOT: /opt/sofa - PYTHON_VERSION: ${{ matrix.PYTHON_VERSION }} + os: [ubuntu-22.04] + sofa_branch: [master] steps: - - uses: actions/checkout@v2 + - name: Setup SOFA and environment + id: sofa + uses: sofa-framework/sofa-setup-action@v5 with: - fetch-depth: 0 - - - run: | - git config --global user.email "caribou@github.com" - git config --global user.name "Caribou Github" - 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 - curl --output sofa.zip -L "https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries/lastStableBuild/CI_BRANCH=master,CI_SCOPE=standard/artifact/Linux/*zip*/Linux.zip" - unzip sofa.zip -d temp - mv temp/Linux/`ls temp/Linux` 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"_Linux.zip" - unzip sofa.zip -d temp - mv temp/`ls temp` $SOFA_ROOT - fi - - - name: Get Time - id: time - uses: nanzm/get-time-action@v1.0 + sofa_root: ${{ github.workspace }}/sofa + sofa_version: ${{ matrix.sofa_branch }} + sofa_scope: 'standard' + - name: Checkout source code + uses: actions/checkout@v2 with: - timeZone: 8 - format: 'YYYY-MM-DD-HH-mm-ss' - - - name: ccache cache files - uses: actions/cache@v2 - if: ${{ always() }} - with: - path: .ccache - key: ubuntu-ccache-${{ steps.time.outputs.time }} - restore-keys: | - ubuntu-ccache- + path: ${{ env.WORKSPACE_SRC_PATH }} - name: Build caribou - env: - CCACHE_COMPRESS: true - CCACHE_COMPRESSLEVEL: 6 - CCACHE_MAXSIZE: "500M" - PYTHONEXE: ${{ format('/usr/bin/python{0}', matrix.PYTHON_VERSION) }} - run: - export CCACHE_BASEDIR=$GITHUB_WORKSPACE && - export CCACHE_DIR=$GITHUB_WORKSPACE/.ccache && - ccache -z && - cmake - -GNinja - -DPYTHON_EXECUTABLE=$PYTHONEXE - -DCMAKE_C_COMPILER_LAUNCHER=ccache - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - -DCARIBOU_BUILD_TESTS=ON - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_INSTALL_PREFIX=SofaCaribou - . - && cmake --build . && cmake --install . - && tar czvf SofaCaribou.tar.gz SofaCaribou - && echo ${CCACHE_BASEDIR} - && ccache -s - - - name: Archive production - uses: actions/upload-artifact@v2 - with: - name: caribou_${{ matrix.sofa_version }} - path: SofaCaribou.tar.gz - - test: - name: Testing with ${{ matrix.sofa_version }} - needs: [build] - runs-on: ubuntu-20.04 - container: ubuntu:20.04 - strategy: - fail-fast: false - matrix: - sofa_version: [ master ] - include: - - sofa_version: master - PYTHON_VERSION: 3.8 - sofa_version_int: 211200 - env: - SOFA_VERSION: ${{ matrix.sofa_version }} - SOFA_ROOT: /opt/sofa - CARIBOU_ROOT: /opt/sofa/plugins/SofaCaribou - - steps: - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.PYTHON_VERSION }} - - - name: Install dependencies run: | - apt-get update - apt-get -qq --no-install-recommends install \ - libgl1-mesa-glx libglib2.0-0 libglx0 libopengl0 libharfbuzz0b libgomp1 curl ca-certificates unzip - python -m pip install numpy meshio scipy - - - name: Install SOFA + sudo apt install libeigen3-dev + cd "$WORKSPACE_BUILD_PATH" + cmake \ + -GNinja \ + -DCARIBOU_BUILD_TESTS=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="$WORKSPACE_INSTALL_PATH" \ + -DCMAKE_PREFIX_PATH=$SOFA_ROOT/lib/cmake \ + ../src + cmake --build . && cmake --install . + + - name: Sanitize artifact name + id: sanitize + # This step removes special characters from the artifact name to ensure compatibility with upload-artifact + # Characters removed: " : < > | * ? \r \n \ / + # Spaces are replaced with underscores + # This sanitization prevents errors in artifact creation and retrieval + shell: pwsh run: | - if [ "$SOFA_VERSION" = "master" ]; then - curl --output sofa.zip -L "https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries/lastStableBuild/CI_BRANCH=master,CI_SCOPE=standard/artifact/Linux/*zip*/Linux.zip" - unzip sofa.zip -d temp - mv temp/Linux/`ls temp/Linux` 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"_Linux.zip" - unzip sofa.zip -d temp - mv temp/`ls temp` $SOFA_ROOT - fi + $originalName = "Caribou_${{ steps.sofa.outputs.run_branch }}_for-SOFA-${{ steps.sofa.outputs.sofa_version }}_${{ runner.os }}" + $artifact_name = $originalName -replace '[":;<>|*?\r\n\\/]', '' -replace ' ', '_' + echo "artifact_name=$artifact_name" >> $env:GITHUB_OUTPUT + + - name: Create artifact + uses: actions/upload-artifact@v4.4.0 + with: + name: ${{ steps.sanitize.outputs.artifact_name }} + path: ${{ env.WORKSPACE_INSTALL_PATH }} - - name: Download caribou + - name: Install artifact uses: actions/download-artifact@v4.1.7 with: - name: caribou_${{ matrix.sofa_version }} - path: /tmp + name: ${{ steps.sanitize.outputs.artifact_name }} + path: ${{ env.WORKSPACE_ARTIFACT_PATH }} - - name: Unpack caribou - run: tar xzf /tmp/SofaCaribou.tar.gz -C /opt/sofa/plugins + - name: Set env vars for tests + shell: bash + run: | + echo "LD_LIBRARY_PATH=$WORKSPACE_ARTIFACT_PATH/lib:$SOFA_ROOT/lib:$SOFA_ROOT/plugins/SofaPython3/lib:$LD_LIBRARY_PATH" | tee -a $GITHUB_ENV + # export PYTHONPATH=$PYTHONPATH:$CARIBOU_ROOT/lib/python3/site-packages - name: Caribou.unittests.Geometry if: ${{ always() }} run: | - export LD_LIBRARY_PATH="$SOFA_ROOT/lib:$LD_LIBRARY_PATH" - $CARIBOU_ROOT/bin/Caribou.unittests.Geometry + cd $WORKSPACE_BUILD_PATH + ./bin/Caribou.unittests.Geometry - name: Caribou.Geometry.PyTest if: ${{ always() }} run: | - export PYTHONPATH=$PYTHONPATH:$CARIBOU_ROOT/lib/python3/site-packages - python $CARIBOU_ROOT/bin/pytest/Caribou_Geometry_Test.py - + export PYTHONPATH=$PYTHONPATH:$WORKSPACE_INSTALL_PATH/lib/python3/site-packages:$WORKSPACE_INSTALL_PATH/plugins/SofaPython3/lib/python3/site-packages + cd "$WORKSPACE_BUILD_PATH"/../src + python3 src/Caribou/Python/Geometry/pytest/Caribou_Geometry_Test.py - name: Caribou.unittests.Topology if: ${{ always() }} run: | - [ "$SOFA_VERSION" = "v20.06.01" ] && export LD_LIBRARY_PATH="$SOFA_ROOT/lib:$LD_LIBRARY_PATH" - $CARIBOU_ROOT/bin/Caribou.unittests.Topology + cd $WORKSPACE_BUILD_PATH + ./bin/Caribou.unittests.Topology - name: Caribou.Topology.PyTest if: ${{ always() }} run: | - export PYTHONPATH=$PYTHONPATH:$CARIBOU_ROOT/lib/python3/site-packages - python $CARIBOU_ROOT/bin/pytest/Caribou_Topology_Test.py + cd $${{ env.WORKSPACE_SRC_PATH }} + python3 src/Caribou/Python/Topology/pytest/Caribou_Topology_Test.py - name: Caribou.unittests.Mechanics if: ${{ always() }} run: | - export LD_LIBRARY_PATH="$SOFA_ROOT/lib:$LD_LIBRARY_PATH" - $CARIBOU_ROOT/bin/Caribou.unittests.Mechanics + cd $WORKSPACE_BUILD_PATH + ./bin/Caribou.unittests.Mechanics - name: Caribou.unittests.SofaCaribou 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 + cd $WORKSPACE_BUILD_PATH + ./bin/Caribou.unittests.SofaCaribou - name: SofaCaribou.PyTest - if: ${{ matrix.sofa_version_int >= '201200' }} + if: ${{ always() }} run: | + cd $WORKSPACE_BUILD_PATH export PYTHONPATH=$PYTHONPATH:$CARIBOU_ROOT/lib/python3/site-packages:$SOFA_ROOT/plugins/SofaPython3/lib/python3/site-packages - python $CARIBOU_ROOT/bin/pytest/SofaCaribou_Forcefield_HyperelasticForcefield.py + python3 src/SofaCaribou/Python/pytest/SofaCaribou_Forcefield_HyperelasticForcefield.py deploy: name: Deploy ${{ matrix.sofa_version }} - needs: [test] + needs: [build] runs-on: ubuntu-20.04 if: github.event_name == 'schedule' strategy: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 00000000..909f0373 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,252 @@ +name: Windows + +on: + pull_request: + branches: + - master + schedule: + # Runs every day at 23:15 + - cron: '15 23 * * *' + +jobs: + build: + name: Building with ${{ matrix.sofa_version }} + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + sofa_version: [ master ] + include: + - sofa_version: master + PYTHON_VERSION: 3.8 + EIGEN_VERSION: 3.4 + PYBIND11_VERSION: 2.4.3 +# - sofa_version: v21.12.00 +# PYTHON_VERSION: 3.7 +# EIGEN_VERSION: 3.3.7 +# PYBIND11_VERSION: 2.4.3 + env: + SOFA_VERSION: ${{ matrix.sofa_version }} + SOFA_ROOT: ${{ format('{0}/sofa', github.workspace) }} + PYBIND11_ROOT: ${{ format('{0}/pybind11', github.workspace) }} + PYBIND11_VERSION: ${{ matrix.PYBIND11_VERSION }} + QT_ROOT: ${{ format('{0}/qt', github.workspace) }} + PYTHON_VERSION: ${{ matrix.PYTHON_VERSION }} + BOOST_ROOT: ${{ format('{0}/boost', github.workspace) }} + EIGEN_ROOT: ${{ format('{0}/eigen', github.workspace) }} + EIGEN_VERSION: ${{ matrix.EIGEN_VERSION }} + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - run: | + git config --global user.email "caribou@github.com" + git config --global user.name "Caribou Github" + git fetch origin + git merge origin/master + +# Python + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.PYTHON_VERSION }} + +# Eigen3 + - name: cache eigen + uses: actions/cache@v2 + id: cache-eigen + with: + path: ${{ github.workspace }}/eigen + key: eigen-${{ matrix.EIGEN_VERSION }}-windows + - name: Install Eigen + if: steps.cache-eigen.outputs.cache-hit != 'true' + shell: bash + run: | + git clone --depth 1 -b $EIGEN_VERSION https://gitlab.com/libeigen/eigen.git eigen_src + cmake -S eigen_src -B eigen_src/build -DCMAKE_BUILD_TYPE=Release -DEIGEN_BUILD_DOC=OFF -DCMAKE_INSTALL_PREFIX="$EIGEN_ROOT" + cmake --build eigen_src/build --target install + +# PYBIND11 + - name: Install pybind11 + shell: bash + run: | + git clone --depth 1 -b v$PYBIND11_VERSION https://github.com/pybind/pybind11.git pybind11_src + cmake -S pybind11_src -B pybind11_src/build -DPYBIND11_TEST=OFF -DCMAKE_BUILD_TYPE=Release -DPYBIND11_FINDPYTHON=ON + cmake --install pybind11_src/build --prefix $PYBIND11_ROOT + rm -rf pybind11_src + +# BOOST + - name: Cache Boost + id: cache-Boost + uses: actions/cache@v1 + with: + path: ${{ format('{0}/boost', github.workspace) }} + key: boost-1.69.0-windows + + - name: Install Boost + if: steps.cache-Boost.outputs.cache-hit != 'true' + run: | + $BOOST_MAJOR = 1 + $BOOST_MINOR = 69 + $BOOST_PATCH = 0 + Invoke-WebRequest "https://boost.teeks99.com/bin/$($BOOST_MAJOR).$($BOOST_MINOR).$($BOOST_PATCH)/boost_$($BOOST_MAJOR)_$($BOOST_MINOR)_$($BOOST_PATCH)-msvc-14.1-64.exe" -OutFile boostinstaller.exe + ./boostinstaller.exe /NORESTART /VERYSILENT /DIR="$($BOOST_ROOT)" | Out-Null + rm -Force boostinstaller.exe + +# SOFA + - name: Download SOFA Release + shell: bash + 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/Windows/*zip*/Windows.zip" + unzip sofa.zip -d temp + mv temp/Windows/`ls temp/Windows` sofa.zip + rm -rf temp + unzip sofa.zip -d temp + mv temp/`ls temp` $SOFA_ROOT + rm -rf temp + else + curl --output sofa.zip -L "https://github.com/sofa-framework/sofa/releases/download/$SOFA_VERSION/SOFA_"$SOFA_VERSION"_Win64.zip" + unzip sofa.zip -d temp + mv temp/`ls temp` $SOFA_ROOT + fi + + # Patch SP3 absolute path + sed -i 's/C:\/pybind11\/[0-9].[0-9].[0-9]\/install\/include;//' $SOFA_ROOT/plugins/SofaPython3/lib/cmake/SofaPython3/PluginTargets.cmake + +# SOFA DEPENDENCY PACK + - name: Download SOFA Dependency pack + shell: bash + run: | + curl --output sofa_dependency.zip -L "https://www.sofa-framework.org/download/WinDepPack/VS-2017/latest" + unzip sofa_dependency.zip -d temp + mv temp/`ls temp` $SOFA_ROOT/windows_dependency + rm -rf temp + +# QT + - name: Cache Qt + id: cache-qt + uses: actions/cache@v1 + with: + path: ${{ format('{0}/qt', github.workspace) }} + key: qt-5.12.6-windows + + - name: Install Qt + uses: jurplel/install-qt-action@v2 + with: + version: '5.12.6' + dir: ${{ format('{0}/qt', github.workspace) }} + cached: ${{ steps.cache-qt.outputs.cache-hit }} + modules: 'qtcharts qtwebengine' + +# CARIBOU + - name: Build caribou + shell: bash + run: + cmake -DCMAKE_BUILD_TYPE=Release + -Dpybind11_DIR=$PYBIND11_ROOT + -DEigen3_ROOT=$EIGEN_ROOT + -DCMAKE_INCLUDE_PATH=$SOFA_ROOT/windows_dependency/include + -DCMAKE_LIBRARY_PATH=$SOFA_ROOT/windows_dependency/lib/win64 + -DQt5_ROOT=$QT_ROOT\5.12.5\msvc2017_64 + -DCMAKE_INSTALL_PREFIX=$SOFA_ROOT/plugins/SofaCaribou + -DCMAKE_PREFIX_PATH=$SOFA_ROOT/lib/cmake + -DCARIBOU_WITH_PYTHON_3=OFF + . + && cmake --build . --config Release + && cmake --install . + +# ZIP + - name: Zip production + run: Compress-Archive -LiteralPath "$($env:SOFA_ROOT)/plugins/SofaCaribou" -DestinationPath SofaCaribou.zip + +# ARCHIVE + - name: Archive production + uses: actions/upload-artifact@v4.4.0 + with: + name: caribou_win64_${{ matrix.sofa_version }} + path: SofaCaribou.zip + + test: + name: Testing with ${{ matrix.sofa_version }} + needs: [build] + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + sofa_version: [ master ] + include: + - sofa_version: master + PYTHON_VERSION: 3.8.10 +# - sofa_version: v21.12.00 +# PYTHON_VERSION: 3.7 + env: + SOFA_VERSION: ${{ matrix.sofa_version }} + SOFA_ROOT: ${{ format('{0}\sofa', github.workspace) }} + CARIBOU_ROOT: ${{ format('{0}\sofa\plugins\SofaCaribou', github.workspace) }} + + steps: +# Python + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.PYTHON_VERSION }} + +# PATH + - run: echo "${$env:SOFA_ROOT}/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + +# SOFA + - name: Download SOFA Release + shell: bash + 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/Windows/*zip*/Windows.zip" + unzip sofa.zip -d temp + mv temp/Windows/`ls temp/Windows` sofa.zip + rm -rf temp + unzip sofa.zip -d temp + mv temp/`ls temp` $SOFA_ROOT + rm -rf temp + else + curl --output sofa.zip -L "https://github.com/sofa-framework/sofa/releases/download/$SOFA_VERSION/SOFA_"$SOFA_VERSION"_Win64.zip" + unzip sofa.zip -d temp + mv temp/`ls temp` $SOFA_ROOT + fi + +# CARIBOU + - name: Download caribou + uses: actions/download-artifact@v4.1.7 + with: + name: caribou_win64_${{ matrix.sofa_version }} + - name: Install caribou + run: Expand-Archive -Path SofaCaribou.zip -DestinationPath "${$env:SOFA_ROOT}\plugins" + + - name: Caribou.unittests.Geometry + if: ${{ always() }} + shell: bash + run: | + export PATH="$SOFA_ROOT/bin:$PATH" + $CARIBOU_ROOT/bin/Caribou.unittests.Geometry.exe + + - name: Caribou.unittests.Topology + if: ${{ always() }} + shell: bash + run: | + export PATH="$SOFA_ROOT/bin:$PATH" + $CARIBOU_ROOT/bin/Caribou.unittests.Topology.exe + + - name: Caribou.unittests.Mechanics + if: ${{ always() }} + shell: bash + run: | + export PATH="$SOFA_ROOT/bin:$PATH" + $CARIBOU_ROOT/bin/Caribou.unittests.Mechanics.exe + + - name: Caribou.unittests.SofaCaribou + if: ${{ always() }} + shell: bash + run: | + export PATH="$SOFA_ROOT/bin:$PATH" + $CARIBOU_ROOT/bin/Caribou.unittests.SofaCaribou.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index 9eb2b5d2..58400fdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,16 +50,19 @@ CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) # OPTIONS option(CARIBOU_USE_FLOAT "Use float precision for floating point values." OFF) +option(CARIBOU_WITH_PYTHON_3 "Compile the plugin with python 3 support" OFF) CMAKE_DEPENDENT_OPTION(CARIBOU_OPTIMIZE_FOR_NATIVE "Build with -march=native to allow msse support" ON "COMPILER_SUPPORTS_MARCH_NATIVE" OFF) # SOFA option find_package(Threads QUIET) -find_package(SOFA COMPONENTS SofaFramework QUIET) -CMAKE_DEPENDENT_OPTION(CARIBOU_WITH_SOFA "Compile the SofaCaribou library" ON "SOFA_FOUND" OFF) +find_package(SOFA COMPONENTS Sofa.Config QUIET) +CMAKE_DEPENDENT_OPTION(CARIBOU_WITH_SOFA "Compile the SofaCaribou library" ON "Sofa.Config_FOUND" OFF) if (CARIBOU_WITH_SOFA) list(APPEND CMAKE_PREFIX_PATH ${SOFA_MODULE_DIR}) list(REMOVE_DUPLICATES CMAKE_PREFIX_PATH) - find_package(SofaPython3 QUIET) # We need to do this first to setup the exact python version required + if (CARIBOU_WITH_PYTHON_3) + find_package(SofaPython3 QUIET) # We need to do this first to setup the exact python version required + endif() endif() # Tests @@ -94,21 +97,27 @@ else() endif() # Python 3 option -if (CARIBOU_WITH_SOFA) +if (CARIBOU_WITH_SOFA AND CARIBOU_WITH_PYTHON_3) sofa_find_package(SofaPython3 QUIET) endif() set(CMAKE_CXX_STANDARD 17) set(PYBIND11_FINDPYTHON ON) set(PYBIND11_PYTHON_VERSION 3) set(Python_FIND_FRAMEWORK LAST) -find_package(SofaPython3 QUIET) +if (CARIBOU_WITH_SOFA AND CARIBOU_WITH_PYTHON_3) + find_package(SofaPython3 QUIET) +endif() if (SofaPython3_FOUND) set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}) set(PYBIND11_PYTHON_VERSION ${PYTHON_VERSION}) endif() find_package(Python ${PYBIND11_PYTHON_VERSION} COMPONENTS Interpreter Development QUIET) find_package(pybind11 CONFIG QUIET) -CMAKE_DEPENDENT_OPTION(CARIBOU_WITH_PYTHON_3 "Compile the plugin with python 3 support" ON "Python_FOUND;pybind11_FOUND" OFF) +if (CARIBOU_WITH_PYTHON_3 AND (NOT Python_FOUND OR NOT pybind11_FOUND)) + SET(CARIBOU_WITH_PYTHON_3 OFF) + message(ERROR "Caribou is set to be compiled with python support, but pybind11 cannot be resolved.") +endif() + if (CARIBOU_WITH_PYTHON_3) message(STATUS "Caribou with Python support: Version: ${Python_VERSION} @@ -122,10 +131,10 @@ endif() # SOFA Python 3 if (CARIBOU_WITH_SOFA) - get_filename_component(SOFA_ROOT_DIR "${SofaFramework_DIR}/../../.." ABSOLUTE) + get_filename_component(SOFA_ROOT_DIR "${Sofa.Framework_DIR}/../../.." ABSOLUTE) message(STATUS "Caribou with SOFA support\n" - " SOFA version: ${SofaFramework_VERSION}\n" + " SOFA version: ${Sofa.Config_VERSION}\n" " SOFA location: ${SOFA_ROOT_DIR}" ) if (CARIBOU_WITH_PYTHON_3) diff --git a/cmake/FindSOFA.cmake b/cmake/FindSOFA.cmake index 1f0db7b0..f282629d 100644 --- a/cmake/FindSOFA.cmake +++ b/cmake/FindSOFA.cmake @@ -15,8 +15,11 @@ # endif() ################################################################################ +# In cases quotes were added to the SOFA_ROOT env variable +STRING(REPLACE "\"" "" SOFA_ROOT_ENV $ENV{SOFA_ROOT}) + # Try to find SOFA's cmake module directory -find_package(SofaFramework CONFIG QUIET) # This defines SOFA_ROOT if SofaFrameworkConfig.cmake is found +find_package(Sofa.Framework CONFIG QUIET) # This defines SOFA_ROOT if SofaFrameworkConfig.cmake is found find_path ( SOFA_MODULE_DIR SofaFramework/SofaFrameworkConfig.cmake PATHS @@ -24,10 +27,10 @@ find_path ( ${SOFA_ROOT}/install/lib/cmake ${SOFA_ROOT}/build/install/lib/cmake ${SOFA_ROOT}/build/master/install/lib/cmake - $ENV{SOFA_ROOT}/lib/cmake - $ENV{SOFA_ROOT}/install/lib/cmake - $ENV{SOFA_ROOT}/build/install/lib/cmake - $ENV{SOFA_ROOT}/build/master/install/lib/cmake + ${SOFA_ROOT_ENV}/lib/cmake + ${SOFA_ROOT_ENV}/install/lib/cmake + ${SOFA_ROOT_ENV}/build/install/lib/cmake + ${SOFA_ROOT_ENV}/build/master/install/lib/cmake ) if (SOFA_MODULE_DIR) @@ -63,7 +66,7 @@ if (NOT SOFA_FIND_COMPONENTS) endif() # Compatibility layer -set(SOFA_VERSION ${SofaFramework_VERSION}) +set(SOFA_VERSION ${Sofa.Framework_VERSION}) foreach(component ${SOFA_FIND_COMPONENTS}) if (SOFA_VERSION VERSION_LESS "22.06.99") string(REGEX REPLACE "Sofa.Simulation.*" "SofaSimulation" component ${component}) diff --git a/src/SofaCaribou/Algebra/EigenMatrix.h b/src/SofaCaribou/Algebra/EigenMatrix.h index 9e7a18dd..547f3a89 100644 --- a/src/SofaCaribou/Algebra/EigenMatrix.h +++ b/src/SofaCaribou/Algebra/EigenMatrix.h @@ -5,23 +5,8 @@ DISABLE_ALL_WARNINGS_BEGIN #include -#include DISABLE_ALL_WARNINGS_END - -#if (defined(SOFA_VERSION) && SOFA_VERSION < 201200) -namespace sofa { using Size = unsigned int; } -#endif - -#if (defined(SOFA_VERSION) && SOFA_VERSION < 210600) -namespace sofa::type { -using Mat3x3d = ::sofa::defaulttype::Mat3x3d; -using Mat3x3f = ::sofa::defaulttype::Mat3x3f; -using Mat2x2d = ::sofa::defaulttype::Mat2x2d; -using Mat2x2f = ::sofa::defaulttype::Mat2x2f; -template -using Mat = ::sofa::defaulttype::Mat; -} -#endif +#include #include diff --git a/src/SofaCaribou/CMakeLists.txt b/src/SofaCaribou/CMakeLists.txt index 2e516ada..629a95cd 100644 --- a/src/SofaCaribou/CMakeLists.txt +++ b/src/SofaCaribou/CMakeLists.txt @@ -146,7 +146,7 @@ if (NOT TARGET Caribou::Algebra) endif() # Sofa's packages -find_package(SOFA COMPONENTS SofaFramework Sofa.Component.LinearSolver.Iterative Sofa.Component.Topology.Container.Grid Sofa.Component.Topology.Container.Constant Sofa.Component.Topology.Container.Dynamic Sofa.LinearAlgebra QUIET REQUIRED) +find_package(SOFA COMPONENTS Sofa.Config Sofa.Component.LinearSolver.Iterative Sofa.Component.Topology.Container.Grid Sofa.Component.Topology.Container.Constant Sofa.Component.Topology.Container.Dynamic Sofa.LinearAlgebra QUIET REQUIRED) # Optional packages find_package(Eigen3 QUIET REQUIRED) @@ -159,7 +159,7 @@ endif() add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${TEMPLATE_FILES} ${HEADER_FILES}) add_library(Caribou::Plugin ALIAS ${PROJECT_NAME}) -target_link_libraries(${PROJECT_NAME} PUBLIC SofaCore Sofa.Component.Topology.Container.Grid Sofa.Component.Topology.Container.Constant Sofa.Component.Topology.Container.Dynamic Sofa.Component.LinearSolver.Iterative Sofa.LinearAlgebra) +target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Core Sofa.Component.Topology.Container.Grid Sofa.Component.Topology.Container.Constant Sofa.Component.Topology.Container.Dynamic Sofa.Component.LinearSolver.Iterative Sofa.LinearAlgebra) target_link_libraries(${PROJECT_NAME} PUBLIC Caribou::Algebra Caribou::Geometry Caribou::Topology Caribou::Mechanics) target_link_libraries(${PROJECT_NAME} PUBLIC Eigen3::Eigen) target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17) @@ -215,10 +215,12 @@ caribou_add_target_to_component ( HEADER_SRC_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/.." ) -find_package(SofaPython3 QUIET) -if (CARIBOU_WITH_SOFA AND SofaPython3_FOUND AND CARIBOU_WITH_PYTHON_3) - add_subdirectory(Python) - set(CARIBOU_WITH_SP3 ON) +if (CARIBOU_WITH_PYTHON_3) + find_package(SofaPython3 QUIET) + if (CARIBOU_WITH_SOFA AND SofaPython3_FOUND) + add_subdirectory(Python) + set(CARIBOU_WITH_SP3 ON) + endif() endif() install ( diff --git a/src/SofaCaribou/Ode/BackwardEulerODESolver.cpp b/src/SofaCaribou/Ode/BackwardEulerODESolver.cpp index 74784133..31c8aa12 100644 --- a/src/SofaCaribou/Ode/BackwardEulerODESolver.cpp +++ b/src/SofaCaribou/Ode/BackwardEulerODESolver.cpp @@ -97,7 +97,7 @@ void BackwardEulerODESolver::assemble_rhs_vector(const MechanicalParams & mec // NOTE: This correspond to the force terms dependant on the displacement, i.e. : // - f_0 = (-Ku + F) MechanicalComputeForceVisitor(&mechanical_parameters, f_id, - true /* accumulate (to mapped node) */, true /*neglectingCompliance*/) + true /* accumulate (to mapped node) */) .execute(this->getContext()); // 3. Go down in the current context tree calling `addMBKdx` on every force field components, diff --git a/src/SofaCaribou/Ode/StaticODESolver.cpp b/src/SofaCaribou/Ode/StaticODESolver.cpp index 3cbf2ee8..cddc1c03 100644 --- a/src/SofaCaribou/Ode/StaticODESolver.cpp +++ b/src/SofaCaribou/Ode/StaticODESolver.cpp @@ -44,7 +44,7 @@ void StaticODESolver::assemble_rhs_vector(const sofa::core::MechanicalParams &me // 2. Go down in the current context tree calling `addForce` on every force field components, // then go up from the leaves calling `applyJT` on every mechanical mappings MechanicalComputeForceVisitor(&mechanical_parameters, f_id, - true /* accumulate (to mapped node) */, true /*neglectingCompliance*/) + true /* accumulate (to mapped node) */) .execute(this->getContext()); // 3. Calls the "projectResponse" method of every `BaseProjectiveConstraintSet` objects found in the current diff --git a/src/SofaCaribou/Topology/FictitiousGrid.h b/src/SofaCaribou/Topology/FictitiousGrid.h index e5919fd1..6cff76af 100644 --- a/src/SofaCaribou/Topology/FictitiousGrid.h +++ b/src/SofaCaribou/Topology/FictitiousGrid.h @@ -273,7 +273,7 @@ class FictitiousGrid : public virtual BaseObject this->f_bbox.setValue(sofa::type::TBoundingBox(min, max)); } else { this->f_bbox.setValue(sofa::type::TBoundingBox( - d_min.getValue().array(),d_max.getValue().array())); + d_min.getValue().data() ,d_max.getValue().data())); } } diff --git a/src/SofaCaribou/config.h.in b/src/SofaCaribou/config.h.in index fd43f279..c74ca0f1 100644 --- a/src/SofaCaribou/config.h.in +++ b/src/SofaCaribou/config.h.in @@ -5,6 +5,7 @@ #ifdef CARIBOU_BUILD_SOFACARIBOU # define CARIBOU_TARGET SofaCaribou +# define SOFA_TARGET SofaCaribou # define CARIBOU_API SOFA_EXPORT_DYNAMIC_LIBRARY #else # define CARIBOU_API SOFA_IMPORT_DYNAMIC_LIBRARY diff --git a/unittest/Caribou/Geometry/CMakeLists.txt b/unittest/Caribou/Geometry/CMakeLists.txt index 4dc11839..b7012d6e 100644 --- a/unittest/Caribou/Geometry/CMakeLists.txt +++ b/unittest/Caribou/Geometry/CMakeLists.txt @@ -16,6 +16,8 @@ target_link_libraries(${PROJECT_NAME} Caribou::Geometry Caribou::Config) if (NOT WIN32) target_link_libraries(${PROJECT_NAME} pthread) +elseif(MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /bigobj) endif() list(APPEND target_rpath diff --git a/unittest/SofaCaribou/CMakeLists.txt b/unittest/SofaCaribou/CMakeLists.txt index 0ab493de..7522faf0 100644 --- a/unittest/SofaCaribou/CMakeLists.txt +++ b/unittest/SofaCaribou/CMakeLists.txt @@ -15,7 +15,15 @@ set(SOURCE_FILES enable_testing() -find_package(SOFA COMPONENTS SofaFramework Sofa.Simulation.Graph Sofa.Component.StateContainer Sofa.Component.Mass Sofa.Component.SceneUtility Sofa.Component.LinearSolver.Iterative Sofa.Component.Mass Sofa.Component.SolidMechanics.FEM.Elastic QUIET REQUIRED) +find_package(Sofa.Config REQUIRED) +find_package(Sofa.Helper REQUIRED) +find_package(Sofa.Component.StateContainer REQUIRED) +find_package(Sofa.Component.Mass REQUIRED) +find_package(Sofa.Component.SceneUtility REQUIRED) +find_package(Sofa.Component.LinearSolver.Iterative REQUIRED) +find_package(Sofa.Component.SolidMechanics.FEM.Elastic REQUIRED) +find_package(Sofa.Testing REQUIRED) +find_package(Sofa.SimpleApi REQUIRED) find_package(Caribou COMPONENTS Topology REQUIRED) find_package(Threads REQUIRED) @@ -31,11 +39,12 @@ endif() target_link_libraries(${PROJECT_NAME} PUBLIC gtest) target_link_libraries(${PROJECT_NAME} PUBLIC SofaCaribou) -target_link_libraries(${PROJECT_NAME} PUBLIC SofaHelper Sofa.Component.StateContainer Sofa.Component.Mass Sofa.Component.SceneUtility Sofa.Component.LinearSolver.Iterative Sofa.Component.SolidMechanics.FEM.Elastic) +target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Helper Sofa.Component.StateContainer Sofa.Component.Mass Sofa.Component.SceneUtility Sofa.Component.LinearSolver.Iterative Sofa.Component.SolidMechanics.FEM.Elastic ) +target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Testing Sofa.SimpleApi) target_link_libraries(${PROJECT_NAME} PUBLIC $<$,$,8.0>>:stdc++fs> $<$,$,9.0>>:c++fs>) -if (${SofaFramework_VERSION} VERSION_LESS "22.06.99") +if (${Sofa.Config_VERSION} VERSION_LESS "22.06.99") target_link_libraries(${PROJECT_NAME} PUBLIC SofaSimulationGraph) else() target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Simulation.Graph) diff --git a/unittest/SofaCaribou/Forcefield/test_hyperelasticforcefield.cpp b/unittest/SofaCaribou/Forcefield/test_hyperelasticforcefield.cpp index 525b6149..8ee58840 100644 --- a/unittest/SofaCaribou/Forcefield/test_hyperelasticforcefield.cpp +++ b/unittest/SofaCaribou/Forcefield/test_hyperelasticforcefield.cpp @@ -5,7 +5,7 @@ DISABLE_ALL_WARNINGS_BEGIN #include #include #include -#include +#include #include DISABLE_ALL_WARNINGS_END @@ -22,13 +22,14 @@ TEST(HyperelasticForcefield, Hexahedron_from_SOFA) { MessageDispatcher::addHandler( MainGtestMessageHandler::getInstance() ) ; EXPECT_MSG_NOEMIT(Error); - setSimulation(new sofa::simulation::graph::DAGSimulation()); auto root = getSimulation()->createNewNode("root"); createObject(root, "DefaultAnimationLoop"); createObject(root, "DefaultVisualManagerLoop"); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.StateContainer"}}); createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Constraint.Projective"}}); createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Engine.Select"}}); createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Container.Grid"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Container.Dynamic"}}); createObject(root, "RegularGridTopology", {{"name", "grid"}, {"min", "-7.5 -7.5 0"}, {"max", "7.5 7.5 80"}, {"n", "3 3 9"}}); auto meca = createChild(root, "meca"); @@ -55,7 +56,7 @@ TEST(HyperelasticForcefield, Hexahedron_from_SOFA) { createObject(meca, "QuadSetTopologyContainer", {{"name", "traction_container"}, {"quads", "@top_roi.quadInROI"}}); createObject(meca, "TractionForcefield", {{"traction", "0 -30 0"}, {"slope", "0.2"}, {"topology", "@traction_container"}}); - getSimulation()->init(root.get()); + sofa::simulation::node::init(root.get()); EXPECT_EQ(ff->number_of_elements(), 32); -} \ No newline at end of file +} diff --git a/unittest/SofaCaribou/Forcefield/test_tractionforce.cpp b/unittest/SofaCaribou/Forcefield/test_tractionforce.cpp index d008793b..a910a7e3 100644 --- a/unittest/SofaCaribou/Forcefield/test_tractionforce.cpp +++ b/unittest/SofaCaribou/Forcefield/test_tractionforce.cpp @@ -6,7 +6,7 @@ DISABLE_ALL_WARNINGS_BEGIN #include #include #include -#include +#include #include DISABLE_ALL_WARNINGS_END @@ -19,12 +19,10 @@ using namespace sofa::testing; class TractionForcefield : public BaseTest { void SetUp() override { - setSimulation(new sofa::simulation::graph::DAGSimulation()) ; root = getSimulation()->createNewNode("TractionForce"); } void TearDown() override { root.reset(); - setSimulation(nullptr); } protected: @@ -33,6 +31,8 @@ class TractionForcefield : public BaseTest { TEST_F(TractionForcefield, Triangle) { EXPECT_MSG_NOEMIT(Error, Warning) ; + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.StateContainer"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Container.Dynamic"}}); createObject(root, "DefaultAnimationLoop"); createObject(root, "DefaultVisualManagerLoop"); createObject(root, "MechanicalObject", {{"position", "-1 0 1 1 0 1 -1 0 -1 1 0 -1 0 0 1 0 0 -1 -1 0 0 1 0 0 0 0 0"}}); @@ -43,26 +43,28 @@ TEST_F(TractionForcefield, Triangle) { EXPECT_NE(traction, nullptr); - getSimulation()->init(root.get()); + sofa::simulation::node::init(root.get()); auto total_load = dynamic_cast *>(traction->findData("total_load")); for (unsigned int step = 1; step <= 5; ++step) { - getSimulation()->animate(root.get(), 1); + sofa::simulation::node::animate(root.get(), 1); EXPECT_DOUBLE_EQ(total_load->getValue(), 4*step) << "Total load at time step " << step << " is incorrect."; } } TEST_F(TractionForcefield, Quad) { EXPECT_MSG_NOEMIT(Error, Warning) ; + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.StateContainer"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Container.Dynamic"}}); createObject(root, "DefaultAnimationLoop"); createObject(root, "DefaultVisualManagerLoop"); createObject(root, "MechanicalObject", {{"position", "-1 0 1 1 0 1 -1 0 -1 1 0 -1 0 0 1 0 0 -1 -1 0 0 1 0 0 0 0 0"}}); createObject(root, "QuadSetTopologyContainer", {{"quads", "8 7 3 5 6 8 5 2 0 4 8 6 4 1 7 8"}}); auto traction = createObject(root, "TractionForcefield", {{"traction", "0 5 0"}, {"slope", std::to_string(1/5.)}}); - getSimulation()->init(root.get()); + sofa::simulation::node::init(root.get()); auto total_load = dynamic_cast *>(traction->findData("total_load")); for (unsigned int step = 1; step <= 5; ++step) { - getSimulation()->animate(root.get(), 1); + sofa::simulation::node::animate(root.get(), 1); EXPECT_DOUBLE_EQ(total_load->getValue(), 4*step) << "Total load at time step " << step << " is incorrect."; } -} \ No newline at end of file +} diff --git a/unittest/SofaCaribou/Mass/test_cariboumass.cpp b/unittest/SofaCaribou/Mass/test_cariboumass.cpp index 2c11b0bc..8d57ef9b 100644 --- a/unittest/SofaCaribou/Mass/test_cariboumass.cpp +++ b/unittest/SofaCaribou/Mass/test_cariboumass.cpp @@ -6,7 +6,7 @@ DISABLE_ALL_WARNINGS_BEGIN #include #include #include -#include +#include #include #include DISABLE_ALL_WARNINGS_END @@ -29,10 +29,13 @@ TEST(CaribouMass, LinearTetrahedron) { MessageDispatcher::addHandler( MainGtestMessageHandler::getInstance() ) ; EXPECT_MSG_NOEMIT(Error); - setSimulation(new sofa::simulation::graph::DAGSimulation()); auto root = getSimulation()->createNewNode("root"); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Mass"}}); createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Engine.Select"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Container.Grid"}}); createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Mapping"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.StateContainer"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Container.Dynamic"}}); // Some component to avoid warnings createObject(root, "DefaultAnimationLoop"); @@ -57,7 +60,7 @@ TEST(CaribouMass, LinearTetrahedron) { auto sofa_mass_diagonal = dynamic_cast *> ( createObject(root, "MeshMatrixMass", {{"name", "sofa_mass_diagonal"}, {"topology", "@topology"}, {"massDensity", "2"}, {"lumping", "true"}}).get() ); - getSimulation()->init(root.get()); + sofa::simulation::node::init(root.get()); // Get M from caribou const Eigen::SparseMatrix M = caribou_mass->M(); @@ -72,7 +75,7 @@ TEST(CaribouMass, LinearTetrahedron) { accessor.setupMatrices(); sofa::core::MechanicalParams mechanical_parameters; mechanical_parameters.setMFactor(1); - caribou_mass->addMToMatrix(&mechanical_parameters, &accessor); + caribou_mass->Mass::addMToMatrix(&mechanical_parameters, &accessor); M2.compress(); EXPECT_DOUBLE_EQ(M.sum(), M2.matrix().sum()); @@ -91,7 +94,7 @@ TEST(CaribouMass, LinearTetrahedron) { SofaCaribou::Algebra::EigenMatrix> SofaM; SofaM.resize((signed) mo->getSize()*3, (signed) mo->getSize()*3); accessor.setGlobalMatrix(&SofaM); - sofa_mass->addMToMatrix(&mechanical_parameters, &accessor); + sofa_mass->Mass::addMToMatrix(&mechanical_parameters, &accessor); SofaM.compress(); EXPECT_DOUBLE_EQ(M.sum(), SofaM.matrix().sum()); @@ -100,7 +103,7 @@ TEST(CaribouMass, LinearTetrahedron) { SofaCaribou::Algebra::EigenMatrix> SofaM_diagonal; SofaM_diagonal.resize((signed) mo->getSize()*3, (signed) mo->getSize()*3); accessor.setGlobalMatrix(&SofaM_diagonal); - sofa_mass_diagonal->addMToMatrix(&mechanical_parameters, &accessor); + sofa_mass_diagonal->Mass::addMToMatrix(&mechanical_parameters, &accessor); SofaM_diagonal.compress(); EXPECT_DOUBLE_EQ(M_diag.diagonal().sum(), SofaM_diagonal.matrix().sum()); @@ -137,10 +140,13 @@ TEST(CaribouMass, LinearHexahedron) { MessageDispatcher::addHandler( MainGtestMessageHandler::getInstance() ) ; EXPECT_MSG_NOEMIT(Error); - setSimulation(new sofa::simulation::graph::DAGSimulation()); auto root = getSimulation()->createNewNode("root"); createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Engine.Select"}}); createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Mapping"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.StateContainer"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Container.Dynamic"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Container.Grid"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Mass"}}); // Some component to avoid warnings createObject(root, "DefaultAnimationLoop"); @@ -161,7 +167,7 @@ TEST(CaribouMass, LinearHexahedron) { createObject(root, "MeshMatrixMass", {{"name", "sofa_mass"}, {"topology", "@topology"}, {"massDensity", "2"}}).get() ); - getSimulation()->init(root.get()); + sofa::simulation::node::init(root.get()); // Get M from caribou const Eigen::SparseMatrix M = caribou_mass->M(); @@ -175,7 +181,7 @@ TEST(CaribouMass, LinearHexahedron) { accessor.setupMatrices(); sofa::core::MechanicalParams mechanical_parameters; mechanical_parameters.setMFactor(1); - sofa_mass->addMToMatrix(&mechanical_parameters, &accessor); + sofa_mass->Mass::addMToMatrix(&mechanical_parameters, &accessor); SofaM.compress(); EXPECT_DOUBLE_EQ(M.sum(), SofaM.matrix().sum()); diff --git a/unittest/SofaCaribou/ODE/test_backward_euler.cpp b/unittest/SofaCaribou/ODE/test_backward_euler.cpp index 5cfbf249..b04cbfdc 100644 --- a/unittest/SofaCaribou/ODE/test_backward_euler.cpp +++ b/unittest/SofaCaribou/ODE/test_backward_euler.cpp @@ -7,7 +7,7 @@ DISABLE_ALL_WARNINGS_BEGIN #include #include #include -#include +#include #include DISABLE_ALL_WARNINGS_END @@ -21,10 +21,13 @@ TEST(BackwardEulerODESolver, Beam) { MessageDispatcher::addHandler( MainGtestMessageHandler::getInstance() ) ; EXPECT_MSG_NOEMIT(Error); - setSimulation(new sofa::simulation::graph::DAGSimulation()); auto root = getSimulation()->createNewNode("root"); createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Constraint.Projective"}}); createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Engine.Select"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Mass"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.StateContainer"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Container.Dynamic"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Container.Grid"}}); // Some component to avoid warnings createObject(root, "DefaultAnimationLoop"); @@ -124,10 +127,10 @@ TEST(BackwardEulerODESolver, Beam) { {1.647607571061131E-15, -2.710271984455126E+01, 7.464181417401340E+01} }}; - getSimulation()->init(root.get()); + sofa::simulation::node::init(root.get()); for (unsigned int step_id = 0; step_id < force_residuals.size(); ++step_id) { - getSimulation()->animate(root.get(), 1); + sofa::simulation::node::animate(root.get(), 1); // @todo uncomment the following when we have time to debug why fenics converges faster... // EXPECT_EQ(solver->squared_residuals().size(), force_residuals[step_id].size()) << "Time step # "<< step_id; @@ -151,5 +154,5 @@ TEST(BackwardEulerODESolver, Beam) { EXPECT_LE(rel_err, 0.005); } - getSimulation()->unload(root); + sofa::simulation::node::unload(root); } diff --git a/unittest/SofaCaribou/ODE/test_static.cpp b/unittest/SofaCaribou/ODE/test_static.cpp index c05499cc..bf47fd2b 100644 --- a/unittest/SofaCaribou/ODE/test_static.cpp +++ b/unittest/SofaCaribou/ODE/test_static.cpp @@ -7,7 +7,7 @@ DISABLE_ALL_WARNINGS_BEGIN #include #include #include -#include +#include #include DISABLE_ALL_WARNINGS_END @@ -21,13 +21,12 @@ TEST(StaticODESolver, InitWithoutSolver) { MessageDispatcher::addHandler( MainGtestMessageHandler::getInstance() ) ; EXPECT_MSG_EMIT(Error) ; - setSimulation(new sofa::simulation::graph::DAGSimulation()); auto root = getSimulation()->createNewNode("root"); createObject(root, "DefaultAnimationLoop"); createObject(root, "DefaultVisualManagerLoop"); createObject(root, "StaticODESolver", {{"printLog", "true"}}); - getSimulation()->init(root.get()); - getSimulation()->unload(root); + sofa::simulation::node::init(root.get()); + sofa::simulation::node::unload(root); } /** Initialization without any compatible linear solver (expecting an error) */ @@ -35,7 +34,6 @@ TEST(StaticODESolver, InitSofaSolver) { MessageDispatcher::addHandler( MainGtestMessageHandler::getInstance() ) ; EXPECT_MSG_EMIT(Error) ; - setSimulation(new sofa::simulation::graph::DAGSimulation()); auto root = getSimulation()->createNewNode("root"); createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.LinearSolver.Iterative"}}); createObject(root, "DefaultAnimationLoop"); @@ -43,8 +41,8 @@ TEST(StaticODESolver, InitSofaSolver) { createObject(root, "StaticODESolver", {{"printLog", "true"}}); createObject(root, "CGLinearSolver", {{"iterations", "25"}, {"tolerance", "1e-05"}, {"threshold", "1e-05"}}); createObject(root, "CGLinearSolver", {{"iterations", "25"}, {"tolerance", "1e-05"}, {"threshold", "1e-05"}}); - getSimulation()->init(root.get()); - getSimulation()->unload(root); + sofa::simulation::node::init(root.get()); + sofa::simulation::node::unload(root); } /** Initialization with both a Caribou linear solver and a SOFA solver (should inform the user of the choice made) */ @@ -53,7 +51,6 @@ TEST(StaticODESolver, InitCaribouSolver) { EXPECT_MSG_NOEMIT(Warning, Error); EXPECT_MSG_EMIT(Info) ; - setSimulation(new sofa::simulation::graph::DAGSimulation()); auto root = getSimulation()->createNewNode("root"); createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.LinearSolver.Iterative"}}); createObject(root, "DefaultAnimationLoop"); @@ -61,8 +58,8 @@ TEST(StaticODESolver, InitCaribouSolver) { createObject(root, "StaticODESolver", {{"printLog", "true"}}); createObject(root, "CGLinearSolver", {{"iterations", "25"}, {"tolerance", "1e-05"}, {"threshold", "1e-05"}}); createObject(root, "LDLTSolver"); - getSimulation()->init(root.get()); - getSimulation()->unload(root); + sofa::simulation::node::init(root.get()); + sofa::simulation::node::unload(root); } /** Initialization with two Caribou linear solvers (should warn the user of the choice made) */ @@ -71,15 +68,14 @@ TEST(StaticODESolver, InitMultipleCaribouSolver) { EXPECT_MSG_NOEMIT(Info, Error); EXPECT_MSG_EMIT(Warning); - setSimulation(new sofa::simulation::graph::DAGSimulation()); auto root = getSimulation()->createNewNode("root"); createObject(root, "DefaultAnimationLoop"); createObject(root, "DefaultVisualManagerLoop"); createObject(root, "StaticODESolver", {{"printLog", "true"}}); createObject(root, "LDLTSolver", {{"name", "first_solver"}}); createObject(root, "LDLTSolver", {{"name", "second_solver"}}); - getSimulation()->init(root.get()); - getSimulation()->unload(root); + sofa::simulation::node::init(root.get()); + sofa::simulation::node::unload(root); } /** Make sure residual norms at each newton steps remains the same */ @@ -87,11 +83,14 @@ TEST(StaticODESolver, Beam) { MessageDispatcher::addHandler( MainGtestMessageHandler::getInstance() ) ; EXPECT_MSG_NOEMIT(Error); - setSimulation(new sofa::simulation::graph::DAGSimulation()); auto root = getSimulation()->createNewNode("root"); createObject(root, "DefaultAnimationLoop"); createObject(root, "DefaultVisualManagerLoop"); createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Engine.Select"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Container.Grid"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Topology.Container.Dynamic"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.StateContainer"}}); + createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.Constraint.Projective"}}); createObject(root, "RegularGridTopology", {{"name", "grid"}, {"min", "-7.5 -7.5 0"}, {"max", "7.5 7.5 80"}, {"n", "3 3 9"}}); auto meca = createChild(root, "meca"); @@ -113,7 +112,7 @@ TEST(StaticODESolver, Beam) { // Fix the left side of the beam createObject(meca, "BoxROI", {{"name", "fixed_roi"}, {"quad", "@surface_topology.quad"}, {"box", "-7.5 -7.5 -0.9 7.5 7.5 0.1"}}); - createObject(meca, "FixedConstraint", {{"indices", "@fixed_roi.indices"}}); + createObject(meca, "FixedProjectiveConstraint", {{"indices", "@fixed_roi.indices"}}); // Apply traction on the right side of the beam createObject(meca, "BoxROI", {{"name", "top_roi"}, {"quad", "@surface_topology.quad"}, {"box", "-7.5 -7.5 79.9 7.5 7.5 80.1"}}); @@ -130,10 +129,10 @@ TEST(StaticODESolver, Beam) { {1.000000000000000e+00, 3.526942203674829e-03, 8.307813177405512e-04, 4.667215114394798e-05, 1.646730071539153e-07} // Step 5 }}; - getSimulation()->init(root.get()); + sofa::simulation::node::init(root.get()); for (unsigned int step_id = 0; step_id < force_residuals.size(); ++step_id) { - getSimulation()->animate(root.get(), 1); + sofa::simulation::node::animate(root.get(), 1); EXPECT_EQ(solver->squared_residuals().size(), force_residuals[step_id].size()); for (unsigned int newton_step_id = 0; newton_step_id < solver->squared_residuals().size(); ++newton_step_id) { double residual = solver->squared_residuals()[newton_step_id] / solver->squared_residuals()[0]; @@ -148,5 +147,5 @@ TEST(StaticODESolver, Beam) { EXPECT_NEAR(middle_point[1], -21.016, 1e-3); // y EXPECT_NEAR(middle_point[2], 76.190, 1e-3); // z - getSimulation()->unload(root); -} \ No newline at end of file + sofa::simulation::node::unload(root); +} diff --git a/unittest/SofaCaribou/Topology/test_fictitiousgrid.cpp b/unittest/SofaCaribou/Topology/test_fictitiousgrid.cpp index 0585e12d..aa535d19 100644 --- a/unittest/SofaCaribou/Topology/test_fictitiousgrid.cpp +++ b/unittest/SofaCaribou/Topology/test_fictitiousgrid.cpp @@ -5,7 +5,7 @@ DISABLE_ALL_WARNINGS_BEGIN #include #include #include -#include +#include #include DISABLE_ALL_WARNINGS_END @@ -18,7 +18,6 @@ using namespace sofa::testing; class FictitiousGrid : public BaseTest { void SetUp() override { - setSimulation(new sofa::simulation::graph::DAGSimulation()) ; root = getSimulation()->createNewNode("root"); createObject(root, "RequiredPlugin", {{"pluginName", "Sofa.Component.IO.Mesh"}}); createObject(root, "DefaultAnimationLoop"); @@ -26,7 +25,6 @@ class FictitiousGrid : public BaseTest { } void TearDown() override { root.reset(); - setSimulation(nullptr); } protected: @@ -44,7 +42,7 @@ TEST_F(FictitiousGrid, Liver) { {"surface_triangles", "@./loader.triangles"} }).get()); - getSimulation()->init(root.get()); + sofa::simulation::node::init(root.get()); // Get the volume FLOATING_POINT_TYPE volume = 0.; @@ -56,4 +54,4 @@ TEST_F(FictitiousGrid, Liver) { } EXPECT_NEAR(volume, 3414171, 5); -} \ No newline at end of file +}