Trying to pass on property from python to shape

Asked by Danny (Dingeman) van der Haven

Hi all,

I wasn't sure if it was best to ask this here or on the yade-dev launchpad. Anyway, the problem is the following:

I have given my level set particles two additional properties by modifying LevelSet.hpp. I found a way to use these properties to speed up the calculations for the LS-DEM method I'm working on. I now want to be able to define these properties in the input python scripts for YADE.

I would like to do this by, for example, saying the following when defining a new level set body:
levelSetBody(""superellipsoid",
                         extents=(rMaxVal,rMinVal,rMinVal),
                         epsilons=(0.2,0.2),
                         spacing=0.01,
                         useProperty=True,
                         property=(1,3,3))

Within YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY, I have added:

((bool, useProperty, false,,"Flag whether to use property to speed up calculations."))
((Vector3r,property,,,"The property to use to speed up calculations."))

Within the file utils.py the function levelSetBody:

I added the arguments
`useProperty=False,property=Vector3.Zero` to the function
Inside the function, I added near the end:
b.shape.hasProperty = hasProperty
if hasProperty:
     b.shape.property = property

This compiles successfully and runs without any error messages. However, the property turns out not to be defined when I run a simulation. How do I adjust my code such that the properties are correctly forwarded from Python to C++ level?

I already looked whether I had to add something in _utils.cpp, but can't find the problem.

Kind regards,
Danny

Question information

Language:
English Edit question
Status:
Expired
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Karol Brzezinski (kbrzezinski) said :
#1

Hi Danny,

are you sure that you need to modify the *.hpp file? You can add a new property to the body directly from Yade (Python) console. Since you are modifying the utils file, I guess that your function is pure Python. Try this:

####
bid = O.bodies.append(sphere((0,0,0),1))
b = O.bodies[bid]
b.shape.myProperty = Vector3(1,2,3)
print(b.shape.myProperty)
####

The disadvantage of this approach is that the property won't be saved by O.save function.

Cheers,
Karol

Revision history for this message
Danny (Dingeman) van der Haven (dlhvdh) said :
#2

Hi Karol,

Thank you for the suggestion. Unfortunately, it didn't work.

I should have specified. But I need both properties to be available within a *.cpp file that uses the shape defined in the LevelSet.*pp files. I need to be able to access both properties from the LevelSet shape container of a given body.

Basically, the Python function levelSetBody() needs to initialise my two properties for C++ to use. Pretty much in the same way that levelSetBody() does for the variables 'nSurfNodes' and 'nodesPath'.

Cheers,
Danny

Revision history for this message
Launchpad Janitor (janitor) said :
#3

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Danny (Dingeman) van der Haven (dlhvdh) said :
#4

I found the problem. I had given a function in YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY() with .def() then same name as one of the properties and that interferred. Renaming the function solved the problem.