definition of iphys in the .hpp file related to a contact law

Asked by Rioual on 2020-05-13


I try to understand the way we can implement the definition of iPhys of a contact law.
I take example on CpmPhys (
The goal is to store in iPhys the relevant parameters of a given interaction.

I don't understand why certain parameters are declared with simple brakets:

why other parameters are declared with .def prefix as in

and others with .def_readonly

thank you for the explanations,


Question information

English Edit question
Yade Edit question
No assignee Edit question
Solved by:
Jérôme Duriez
Last query:
Last reply:
Jan Stránský (honzik) said : #1

- put all attributes in "simple brackets"
- use .def and .staticmethod to use C++ functions in python and therefore to enable python testing

More details:
"simple brackets":
it is inside a macro, that makes the values public attributes of the class. You can then access them from the class and also from other parts of the C++ code. It has also other advantages:
- readable / assignable from python
- adds python docstrings
- adds it to automatically built documentation
- saved / loaded with / O.load
- ... ?

.def, .staticmethod
is to expose methods (functions) to python (referenced are already existing/declared methods, e.g. funcG)

in python it is to return values of the class attributes, but you cannot set them from python.
("simple brackets" can be both read and assigned)
References existing objects, e.g. omega.
The point is to prevent accidental change of some "computed" values. E.g. omega is a function of kappaD, so changing omega alone is not meaningful.
It has disadvantage that it is not saved / loaded with / O.load
Do not bother with .def_readonly for now.


Best Jérôme Duriez (jduriez) said : #2


- simple brackets refer to the ATTRS part of the YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY macro [*].

- the .def() lines enter the PY part of the latter. I see this part as directly obeying the syntax of the boost::python C++ Library, eg [**]. Unlike real attributes, it is about methods (functions) here


Rioual (francois-rioual-v) said : #3

Thanks Jérôme Duriez, that solved my question.