Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot inherit from SofaCaribou ForceFields #106

Open
AlbanOdot opened this issue Mar 17, 2022 · 6 comments
Open

Cannot inherit from SofaCaribou ForceFields #106

AlbanOdot opened this issue Mar 17, 2022 · 6 comments

Comments

@AlbanOdot
Copy link
Contributor

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
Copy link
Contributor Author

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

@jnbrunet
Copy link
Member

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
Copy link
Member

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
Copy link
Contributor Author

AlbanOdot commented Apr 28, 2022

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
Copy link
Member

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
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants