Implementing a new contact law very different from the usual ones

Asked by Rioual on 2020-04-28

Hello,

This question concerns the way to implement a new tricky contact law that can not be derived from the other classical
 contact laws from Yade. It follows the previous advices of Jan (https://answers.launchpad.net/yade/+question/690234).
I want to implement in yade this new contact law that can be expressed as:

Force on normal direction of contact:
F_n = f1(alfa,mu, R_0) * (Normal_strain_rate) + g(alfa,gamma,R_0)

Force on tangential direction:
F_t = f2(alfa,mu,R_0)*(Tangential_strain_rate)

+

d(alfa)/dt = f3( mu,R_0, gamma, Normal_strain_rate, alfa)

with R_0: average radius of the particle ; mu: viscosity of the material of the particle; gamma: surface tension.
f1,f2,f3,g: functions
alfa(t) is a dynamical geometrical parameter of the contact.

As far as I have seen (https://answers.launchpad.net/yade/+question/681016), I must define:
- a new Law2 functor
- a new IPhys
- a new lp2 functor

Could you give guidance on the way and methodology to implement this new law in Yade ???
(I am a quite recent Yade user and have very little knowledge of c++...)

Thank you very much for your assistance in this ambitious project,

All the best!

Vincent,

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
2020-05-11
Last reply:
2020-05-11
Jan Stránský (honzik) said : #1

Hello,

just a note, are you sure that what you are looking for is not already implemented in Yade? Just scanning the documentation, I see surface tension, viscosity.. so double check if it really does not exist yet..

> that can not be derived from the other classical contact laws from Yade

in fact, (almost) all Yade laws (Law2) are derived independently [1].
Sometimes Material and/or IPhys are shared, but it is usual that a law is independent bundle of Material, IPhys, Ip2, Law2.

> Could you give guidance on the way and methodology to implement this new law in Yade ???

the best guidance is to have a look at existing laws, e.g. the "best known" FrictMat [2], Ip2_FrictMat_FrictMat_FrictPhys [3,4], FrictPhys [5], Law2_ScGeom_FrictPhys_CundallStrack [6,7].
We can help with partial questions here.

In your case, I think the clean way could be:
- new Material storing material parameters (mu,gamma)
- new IPhys, storing interaction data (mu,gamma,alpha)
- new Ip2, combining two Matrial and creating IPhys
- new Law2, computing forces and updating alpha

cheers
Jan

[1] https://yade-dem.org/doc/yade.wrapper.html#lawfunctor
[2] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/common/ElastMat.hpp#L23
[3] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/FrictPhys.hpp#L45
[4] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/FrictPhys.cpp#L10
[5] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/FrictPhys.hpp#L17
[6] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/ElasticContactLaw.hpp#L18
[7] https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/ElasticContactLaw.cpp#L62

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

Hello,

...OK, Jan, thanks for your answer.
This means that I have to create 5 new files related to my new law:

SintMat.hpp : new material
SintPhys.hpp : new IPhys, new lp2
SintPhys.cpp : new lp2
SintLaw.hpp : new Law2
SintLaw.cpp : new Law2

- can I follow the same implementation in each file as for FrictPhys_CundallStrack ??

- How do you i integrate these 5 files of definition of the law in the yade core code ??

My best wishes,

Vincent,

Jan Stránský (honzik) said : #3

> This means that I have to create 5 new files related to my new law

you do not have and actually I suggest to put all the code in one file (well, two files, one .hpp, one .cpp). Have a look e.g. at CpmMat [1,2], where all the stuff related to one specific material law is on one place.
The links I provided was just as a reference of actual implementation.

> can I follow the same implementation in each file as for FrictPhys_CundallStrack ??

yes (in general).
For Material, follow FrictMat, for IPhys follow FrictPhys etc.

> How do you i integrate these 5 files of definition of the law in the yade core code ??

There is no special integration (if I got your question correctly), just put the .hpp and .cpp files in pkg/dem directory.

cheers
Jan

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

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

... Thanks, Jan, now I can start to tackle the problem now from references to FrictMat but I have real difficulties to interpret the command lines in ElasticContactLaw.cpp:
https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/ElasticContactLaw.cpp#L62

-l61: "CREATE_LOGGER(Law2_ScGeom_FrictPhys_CundallStrack)";
https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/ElasticContactLaw.cpp#L61
what does this mean ??

-l62: "bool Law2_ScGeom_FrictPhys_CundallStrack::go(shared_ptr<IGeom>& ig, shared_ptr<IPhys>& ip, Interaction* contact)":
https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/ElasticContactLaw.cpp#L62
 can you explain all this and <<shared_ptr>> ??

-"int id1 = contact->getId1(), id2 = contact->getId2();"
https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/ElasticContactLaw.cpp#L64
getId1?? getId2 ??

-"ScGeom* geom = static_cast<ScGeom*>(ig.get());
 FrictPhys* phys = static_cast<FrictPhys*>(ip.get());"
https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/ElasticContactLaw.cpp#L66
Can you comment about these statements ? static_cast ?? ig.get, ip.get() ??

and in the file ElasticContactLaw.hpp:
(https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/ElasticContactLaw.hpp):

- https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/ElasticContactLaw.hpp#L18
what is LawFunctor ??

- https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/ElasticContactLaw.hpp#L21
what does this mean ?

- https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/ElasticContactLaw.hpp#L26
what is YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY ??

-https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/ElasticContactLaw.hpp#L38
FUNCTOR2D ?? DECLARE ??

I am so sorry for my ignorance but i have to face these issues in order to solve my problem !

Thank you very much again for your support,

Vincent

Jan Stránský (honzik) said : #6

Hello,

for next time, I suggest to open separate question for each problem. It would left the conversation clean and also (therefore) could be useful for future readers.

for implementing a new law in C++, you do not need any high level of C++ knowledge, but obviously you need to know the syntax and basic structures (shared_ptr, static_cast).

Basically you can copy-paste all the Frict* code, changing "Frict" to a different suitable name, e.g. SurfTenson, so FrictMat -> SurfTensionMat etc.

If it works, then you can start to modify the logic inside.

> CREATE_LOGGER

you do not need loggers (at least for the beginning)

> can you explain all this

please be more specific what is "all this"

> <<shared_ptr>> ??

[1]

> int id1 = contact->getId1(), id2 = contact->getId2();
> getId1?? getId2 ??

this should be self-explanatory, or? id1 is id1 of the contact, id2 is id2 of the contact

> FrictPhys* phys = static_cast<FrictPhys*>(ip.get());"
> Can you comment about these statements ? static_cast ?? ig.get, ip.get() ??

ip is of type shared_ptr<FrictPhys>
ip.get() returns ordinary pointer from the shared pointer
static_cast casts it to the type FrictMat (in case it is a derived class), static **here** means it is performed at compile time

> what is LawFunctor ??

it is the base class of specific Law2 subclasses

> what does this mean ?

again, please be more specific

> what is YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY ??

a macro [2]

> FUNCTOR2D ??

it tells Yade that this class (Law2_ScGeom_FrictPhys_CundallStrack in this case) deals with the combination of ScGeom and FrictPhys

cheers
Jan

[1] https://yade-dem.org/doc/prog.html#shared-pointers
[2] https://yade-dem.org/doc/prog.html#yade-class-base-doc-macro-family

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

I will do séparate queries next time, message well received!!
Best

Can you help with this problem?

Provide an answer of your own, or ask Rioual for more information if necessary.

To post a message you must log in.