Call a ForceEngine attribute in Shop

Asked by Raphaël Maurin

Hi all,

I created a force engine to apply an hydrodynamic force to particles depending on a fluid velocity profile and a fluid velocity fluctuation associated to each particle. This last can be big when there is a lot of particles, so that to avoid to transmit it from python to C++ (which induces memory leakage), it is directly calculated in the C++ code of HydroForceEngine.

Now, I want to create a function in C++, using this velocity fluctuation vector, and which can be executed from python. For that, I am then creating it in Shop. My question is: is there a way to access this vector, which is an attribute of HydroForceEngine, directly in Shop ?

Thanks

Raphaël

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Kneib François
Solved:
Last query:
Last reply:
Revision history for this message
Raphaël Maurin (raphael-maurin) said :
#1

Hi all,
No one has an idea of how I can do that ? Is the question not clear ?
Raphaël

Revision history for this message
Best Kneib François (francois-kneib) said :
#2

You don't need shop there.
Use this macro is your engine : YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY(...), where CTOR can be empty.
So define your method in your class, then invoke the above macro, where the "PY" argument can be (I assume your method is called "test" :
.def("test",&HydroForceEngine::test,"Get particle deformation")
.def will link your c++ method to the python scope. I recommend you to look at TesselationWrapper.hpp for more details, there is a list of examples.
After that, call your method in Python with : O.engines[?].test(...)

Revision history for this message
Kneib François (francois-kneib) said :
#3

Sorry, "Use this macro IN your engine ..."

Revision history for this message
Raphaël Maurin (raphael-maurin) said :
#4

Great, it works !
Thank you François !
Raphaël

Revision history for this message
Raphaël Maurin (raphael-maurin) said :
#5

Thanks Kneib François, that solved my question.