sofa-framework / sofa

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

[SofaDenseSolver] Fix compilation with SOFA_FLOATING_POINT_TYPE as float #262

Closed FabienPean closed 6 years ago

FabienPean commented 7 years ago

issue sofa-framework/sofa#2 Fix compilation when option SOFA_FLOATING_POINT_TYPE in CMake selected as float

The problem arising when trying to compile with float was due to missing declaration from newmat external library. The library has been modified for sofa to use a #define SOFA_FLOAT in include.h However the SOFA_FLOAT was never defined for the extlib since the current procedure is to set CMake variable SOFA_FLOAT and SOFA_DOUBLE to 1. This was done anyway AFTER processing the cmake of the extlibs.

Therefore, this pr moves the option for floating point type in sofa in the root CMakeLists and adds the #define for the newmat library to actually create the float type functions.


This PR:

Reviewers will merge only if all these checks are true.

sofabot commented 7 years ago

Thank you for your pull request! Someone will soon check it and start the builds.

damienmarchal commented 7 years ago

[ci-build]

hugtalbot commented 7 years ago

Thank you @FabienPean for this nice PR!

guparan commented 7 years ago

Dashboard details are here: https://www.sofa-framework.org/dash/index.php?branch=pr%2Ffix%2Fissue%232

guparan commented 7 years ago

Hi @FabienPean, Any idea why RigidLinearDeformationMappings_test is failing on Windows ? See windows7_VS-2015_amd64_origin_options tests report.

EDIT: This is certainly nothing related to your PR. It is also failing for sofa-framework/sofa#261.

EDIT 2: The problem is known, see issue sofa-framework/Flexible#4.

FabienPean commented 7 years ago

I removed the sofa define from newmat/include.h and corrected the CMakeFiles. Now it activates float only when "float" is explicitly selected in root CMakeFiles

FabienPean commented 7 years ago

Ok I did not expect this problem. I understand now better what Matthieu meant.

When I removed SOFA_DOUBLE from newmat, the target_compile_definitions are only visible within newmat project with the PRIVATE attribute, which was causing problem when the newmat.h was used included in SofaDenseSolver, not having the compile definitions set. It works if the compile definition of newmat are PUBLIC, but I do not know the side effects it may cause.

damienmarchal commented 7 years ago

Thanks Fabian for the quick update of the PR... [ci-build]

guparan commented 7 years ago

Did you try compiling with SOFA_FLOATING_POINT_TYPE = float? It is still failing on my side (Windows + VS-2015).

The Dashboard is OK but compiling with SOFA_FLOATING_POINT_TYPE = both.

FabienPean commented 6 years ago

I did not manage to compile it fully. SofaDenseSolver is now ok but not the remaining of Sofa. I started to fix some errors, however it seems that this feature was not actively maintained recently. With latest commit it should compile but it gives weird runtime visualization. (Windows VS2015 also) image image image

If the feature is a must-have, maybe the CI should test with float-only and double-only instead of "both" ?

guparan commented 6 years ago

Thank you for your fixes @FabienPean !

Two remarks about consistency:

I can push these tiny corrections if you're ok 😉

FabienPean commented 6 years ago

Hi Guillaume, sure feel free ! :)

damienmarchal commented 6 years ago

The 'leaking' snake looks great :)

hugtalbot commented 6 years ago

is it ready to merge ? @guparan do you plan to push your "tiny corrections" ?

guparan commented 6 years ago

Here they are !

damienmarchal commented 6 years ago

It is unclear to me if it is ready. Isn't the screenshot from @FabienPean showing something is broken ?

guparan commented 6 years ago

At least the compilation is fixed so I'd say this PR does its job. I had the same visualization glitches on my side though. Maybe a quick review to ensure we did not create the problem - @fredroy ?

damienmarchal commented 6 years ago

Rebuild from a recent master... [ci-build]

FabienPean commented 6 years ago

My bad it seems I was quite asleep when I tried to fix the DilateEngine.cpp

damienmarchal commented 6 years ago

So it seems there is some troubles here in compiling this PR. Anyone can check ?

FabienPean commented 6 years ago

The problem comes when using 'both' it seems. For one part of the build failure, TriangleOctree / TriangleOctreeRoot must be instantiated with both precision instead of currently using the default type SReal only.

fredroy commented 6 years ago

I built it on VS2015, and got the same behavior as on the pictures. It appears to be a bug with SparseGridRamification (in caduceus.scn) If you replace it with SparseGridTopology, everything appears fine (and behaves fine)

damienmarchal commented 6 years ago

Many thanks @FabienPean for this PR as it seems quite complex to fix everything. [ci-build]

FabienPean commented 6 years ago

Ok so, hopefully the end of this PR. I reverted some commit and double/both should be back to normal. In the case of float only the DilateEngine is not available and its test deactivated. So basically it should compile fine, but some components would be limited. I quickly tried to fix it but I encountered some difficulties. I would prefer open a new issue regarding float compliance of remaining components.

To sum up, it should be back to the original goal: fix compilation, not necessarily the components with type limitation

damienmarchal commented 6 years ago

The CI disagree with you :)

FabienPean commented 6 years ago

I am on Windows and did not try on Linux, so my hopes still hold as long as that yellow dot does not become a cross for the windows VS build :D

The error on the linux build seem trivial fortunately. However it stopped at the first error... Would it be possible for the build system not to stop at this first error and try compiling the remaining ? Since I cannot test on every platform/os that would be valuable to have all potential error at once.

matthieu-nesme commented 6 years ago

Regarding the visualization problems when compiling with float only: keep in mind that double precision can be necessary in specific situations, so be careful when replacing some hard-coded double with SReal. Some double must remain double and I guess some SReal should become double also in the actual code. On platforms where double precision does not exist, tricky numerical solutions have to be employed.

guparan commented 6 years ago

I rebased your branch to clean it a bit (removing all merges and reverts). Let's see how it builds... https://www.sofa-framework.org/dash/index.php?branch=pr%2Ffix%2Fissue%232

guparan commented 6 years ago

[ci-build]

guparan commented 6 years ago

Are we good to go with this PR? @matthieu-nesme, do you see a specific line where a SReal should remain a double?

matthieu-nesme commented 6 years ago

There is no easy answer to that, numerical limits are really complex. But obviously, some double are mandatory somewhere in the components that map the snake model ^^

damienmarchal commented 6 years ago

[ci-build]