Confusion about learning code in CohesiveFrictionalContactLaw.cpp

Asked by xuanshenyu

Hi, everyone

I don't understand how 'the bool Law2_ScGeom6D_CohFrictPhys_CohesionMoment::go(shared_ptr<IGeom>& ig, shared_ptr<IPhys>& ip, Interaction* contact)' passes the updated normalForce to Phys.

Although the code has the following statement,
   'go(shared_ptr<IGeom>& ig, shared_ptr<IPhys>& ip, Interaction* contact)'//line132
   ' CohFrictPhys* phys = YADE_CAST<CohFrictPhys*>(ip.get())//line138'
    'phys->normalForce = Fn * geom->normal;// line 226'
I did not find a definition or declaration of normalForce in shared_ptr<IPhys> and CohFrictPhys*.

Probably my biggest confusion is not finding a definition or declaration of NormalForce.

PS:Maybe it's just that I didn't learn C++ well :(.

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
xuanshenyu
Solved:
Last query:
Last reply:
Revision history for this message
Jan Stránský (honzik) said (last edit ):
#1

Hello,

TLTR: inheritance

> I don't understand how ... Law2_ScGeom6D_CohFrictPhys_CohesionMoment::go(...)' passes the updated normalForce to Phys.
> phys->normalForce = Fn * geom->normal;

yes, with this line [1].

> I did not find a definition or declaration of normalForce in shared_ptr<IPhys> and CohFrictPhys*.
> Probably my biggest confusion is not finding a definition or declaration of NormalForce.

What editor / IDE are you using?
I think an ordinary IDE should have capability of finding declaration / definition (although I do not have experience with C++ in IDE).

The key concept here is inheritance and polymorphism.
Type of "ip" variable is of type IPhys [2] which is then casted to "phys" variable of type CohFrictPhys [3].
CohFrictPhys is derived from RotStiffFrictPhys [4].
RotStiffFrictPhys is derived from FrictPhys [5].
FrictPhys is derived from NormShearPhys [6].
NormShearPhys is derived from NormPhys. [7]
(for completeness, NormPhys is derived from IPhys [8], so CohFrictPhys is derived from IPhys)
"normalForce" is declared in NormPhys as a Vector3r attribute [9].

You can also see documentation [10,11] and climb up the inheritance until the origin of normalForce (present in NormPhys, not any more in IPhys).

Cheers
Jan

[1] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/CohesiveFrictionalContactLaw.cpp#L133
[2] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/CohesiveFrictionalContactLaw.cpp#L109
[3] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/CohesiveFrictionalContactLaw.cpp#L115
[4] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/CohesiveFrictionalContactLaw.hpp#L49
[5] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/FrictPhys.hpp#L43
[6] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/FrictPhys.hpp#L17
[7] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/common/NormShearPhys.hpp#L23
[8] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/common/NormShearPhys.hpp#L9
[9] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/common/NormShearPhys.hpp#L15
[10] https://yade-dem.org/doc/yade.wrapper.html#yade.wrapper.CohFrictPhys
[11] https://yade-dem.org/doc/yade.wrapper.html#iphys

Revision history for this message
xuanshenyu (shenyuxuan) said :
#2

Thanks for Jan's generous help, this is a great forum. My problem has been solved!