mimesis-inria / caribou

Multi-physics computation library
GNU Lesser General Public License v3.0
29 stars 17 forks source link

Cannot inherit from SofaCaribou ForceFields #106

Open AlbanOdot opened 2 years ago

AlbanOdot commented 2 years ago

Hello, I was wondering if it is possible to create a Forcefield using both caribou and sofa caribou.

I'm having a bit of a headache understanding where to start. The idea would be to inherit from HyperElasticForcefield but I have no idea how to handle the template.

When I print the class of a HyperElasticForceField component from my Sofa scene the name it returns is <class 'SofaCaribou.SofaCaribou.HyperelasticForcefield<Hexahedron>'> Which is not a valid name for a Python class.

I can inherit from HexahedronElasticForce but I cannot add it to my scene though. [ERROR] [SofaRuntime] TypeError: MyHexahedronElasticForce: No constructor defined!

The SofaPython3 EmptyForceField works properly.

I just want to rewrite the addForce function in python so I can easily access to computation data on the fly. Any input on how to do so is welcome !

Have a good day. Alban Odot

AlbanOdot commented 2 years ago

Up ! Any update on why we cannot inherit from caribou Forcefield?

jnbrunet commented 2 years ago

Hey @AlbanOdot

Sorry for the delay, it is taking me a bit more time than planned. The thing is, since SOFA data<VecDeriv> and data<VecCoord> aren't bind to python (yet?), we will have to rely expensive copy of vectors in some scenarios. I will start a PR soon with the fix and an example scenario of an expensive copy.

jnbrunet commented 2 years ago

Hey @AlbanOdot ,

Can you try the branch of this PR ? I have a link issue that remains to be fixed but I think it is only on MacOS.

Finally I did not resort to an expensive copy, so it should not have a too big performance drawback.

AlbanOdot commented 2 years ago

Hi, I haven't managed to compile it yet. It's using pybind11 version 2.5+ members which is not default on ubuntu 20.04 (2.4).

I compiled the latest stable (2.9) and it compiles well until it reaches the SofaCaribou.cpython-39-x86_64-linux-gnu.so creation. It crashes on undefined reference to sofapython3::BindingBase::SetAttr(pybind11::object, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, pybind11::object)

Which version of SofaPython3 are you using? I'm on the latest stable v21.12. (both SofaPython3 and Caribou are being compiled using the pybind11 version 2.9)

jnbrunet commented 2 years ago

I've fixed the pybind11 v2.6 and less issue.

As for the link error, looks like what I had on macos is also there on Linux. I will investigate. If you don't mind having no attribute to your root.addObject(MyFF()) (for example printLog=True), you can comment this line, it should fix the link error temporary until I find a real fix.

AlbanOdot commented 2 years ago

After a lot of extensive tests, it works very well. I haven't found a way to compile it without commenting the said line tough.