Learning of ig2_ Sphere_ Sphere_ ScGeom.cpp

Asked by xuanshenyu

Dear all,

I am learning the code of Yade about interaction, but that is very difficulty.

So I want to ask you to interpret the code of ig2_ Sphere_ Sphere_ ScGeom.cpp[1]

######l15~l22#####
1 bool Ig2_Sphere_Sphere_ScGeom::go(
        const shared_ptr<Shape>& cm1,
        const shared_ptr<Shape>& cm2,
        const State& state1,
        const State& state2,
        const Vector3r& shift2,
        const bool& force,
        const shared_ptr<Interaction>& c)
######
What does cm1, cm2,state1,shift2, force stand for in this function?

#######l25###########
2 const Se3r& se31 = state1.se3;

What does state.se3 stand for ?

########l28#########

3 Vector3r normal = (se32.position + shift2) - se31.position;

What does normal stand for in this function?

Thanks in advance.
Shenyu

[1] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/Ig2_Sphere_Sphere_ScGeom.cpp

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 :
#1

Hello,

> I am learning the code of Yade

You should first understand the "python layer" and meaning, interplay and design of the simulation components.
Then learning C++ code is much easier.

> What does cm1, cm2,state1,shift2, force stand for in this function?

As the signature of Ig2_Sphere_Sphere_ScGeom::go tells:
- cmX ... Shape
- stateX ... State
- shift2 ... "periodic shift" of the interacting bodies, used in periodic simulations, zero Vector3 by default

cm1, state1 ... shape and state of 1st interacting body
cm2, state2 ... shape and state of 2nd interacting body

> What does state.se3 stand for ?

state.pos and state.ori as one object [1].
Type declared in [2].

> What does normal stand for in this function?

in this line of code, it is some Vector3r type variable.
Specifically a vector connecting centers of the two bodies.
Later in the function it is normalized and in scm->precompute assigned to geom.normal

Cheers
Jan

[1] https://gitlab.com/yade-dev/trunk/-/blob/master/core/State.hpp#L55
[2] https://gitlab.com/yade-dev/trunk/-/blob/master/lib/high-precision/MathEigenTypes.hpp#L135

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

Hi, Jan

Thank you very much for your kind reply. I have understood several questions above.

But I still have questions about the following functions.

1########ScGeom6D::go()########
bool Ig2_Sphere_Sphere_ScGeom6D::go(
        const shared_ptr<Shape>& cm1,
        const shared_ptr<Shape>& cm2,
        const State& state1,
        const State& state2,
        const Vector3r& shift2,
        const bool& force,
        const shared_ptr<Interaction>& c)
{
 bool isNew = !c->geom;
 if (Ig2_Sphere_Sphere_ScGeom::go(cm1, cm2, state1, state2, shift2, force, c)) { //the 3 DOFS from ScGeom are updated here
  if (isNew) { //generate a 6DOF interaction from the 3DOF one generated by Ig2_Sphere_Sphere_ScGeom
   shared_ptr<ScGeom6D> sc(new ScGeom6D());
   *(YADE_PTR_CAST<ScGeom>(sc)) = *(YADE_PTR_CAST<ScGeom>(c->geom));
   c->geom = sc;
  }
  if (updateRotations) YADE_PTR_CAST<ScGeom6D>(c->geom)->precomputeRotations(state1, state2, isNew, creep);
  return true;
 } else
  return false;
}
##############

2#####ScGeom6D::goReverse()######
bool Ig2_Sphere_Sphere_ScGeom6D::goReverse(
        const shared_ptr<Shape>& cm1,
        const shared_ptr<Shape>& cm2,
        const State& state1,
        const State& state2,
        const Vector3r& shift2,
        const bool& force,
        const shared_ptr<Interaction>& c)
{
 return go(cm1, cm2, state2, state1, -shift2, force, c);
}

YADE_PLUGIN((Ig2_Sphere_Sphere_ScGeom6D));

} // namespace yade
##################

What do these the functions of go() and goReverse() do?

3#############
bool isNew = !c->geom;

what does this sentence mean?

##############

Shenyu

Revision history for this message
Jan Stránský (honzik) said :
#3

> What do these the functions of go() and goReverse() do?

go is the "main" function of (not only) the Ig2 functor.
In this case:
- if the interaction is new (see below), creates new IGeom and assign it to the interaction
- some setting of the IGeom (e.g. precomputeRotations)
- returns true / false

goReverse is called with reversed order.
(It seems there is a bug and that cm1 and cm2 should also be reversed?)

> bool isNew = !c->geom;
> what does this sentence mean?

"c" is Interaction instance.
c->geom is its IGeom instance.
If there is no IGeom (!c->geom), it is new interaction, remembering it as isNew bool variable.

Cheers
Jan

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

Hi, Jan

Thank you very much for your kind reply.

Now, I am learning the code of Yade about CohesiveFrictionalContactLaw.hpp and .cpp.

Can I continue to ask questions here? Or start a new post.

Shenyu

Revision history for this message
Jan Stránský (honzik) said :
#5

If the question is about specific parts of code, I would vote for a new question.
Thanks
Jan

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

ok, my question have been sloved.

Thanks Jan for you help.

Shenyu