Testing the implémentation of a new contact law

Asked by Rioual on 2020-05-12

Hello,

I am about to create new cpp and hpp files related to
to the implémentation of a new contact law in yade.
Is There a simple way to test my files and débug without
the run of a yade simulation ???

Thank you very much

V.

Question information

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

Hello,

I am not sure if I got the point, could you please provide some more background, ideas etc?

what is a problem with yade simulation?

In general it is possible e.g. to define a physical law ("the equations") as an external C++ library independent of Yade, then you can test it independently of Yade and in Yade you "just include it and wrap it".

But the standard (and the easiest) way for testing IS yade simulations..
Could be very simple, like "one-interaction tests" = two particles with all blocked DOFs and prescribed velocities, just to test the most basic response.
Or a complex simulation (because the structural behavior may be very different from mere extrapolation of one-interaction tests)

cheers
Jan

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

Below is a skeleton.

For testing, here just a value is printed, probably there are some frameworks for C++ testing, but I have no experience with them.
I prefer creating python interface and test python code calling the C++ code. Which is also possible with Yade actually.. it really depends on your expectations and the definition of "without the run of a yade simulation"..

MyModelEquations.hpp and MyModelEquations.cpp are Yade-independent files declaring and defining the "model equations"
test.cpp is the testing file.
MyModel.hpp and MyModel.cpp are the skeleton of actual Yade files.

// file yade/pkg/dem/MyModelEquations.hpp ///////////////////////
double computeNormalForce(double stiffness, double penetrationDepth);

// file yade/pkg/dem/MyModelEquations.cpp ///////////////////////
#include "MyModelEquations.hpp"
double computeNormalForce(double stiffness, double penetrationDepth) {
   return stiffness * penetrationDepth;
}

// file test.cpp ///////////////////////
#include<iostream>
#include "/path/to/yade/pkg/dem/MyModelEquations.hpp"

int main() {
   double stiffness = 1e9;
   double penetrationDepth = 1e-3;
   double force = computeNormalForce(stiffness,penetrationDepth);
   std::cout << force << std::endl;
}

// file yade/pkg/dem/MyModel.hpp ///////////////////////
...
class Law2_ScGeom_MyPhys_Something : public LawFunctor {
   ...
}

// file yade/pkg/dem/MyModel.cpp ///////////////////////
#include "MyModelEquations.hpp"
...
Law2_ScGeom_MyPhys_Something :: go(...) {
   ...
   fn = computeNormalForce(...)
   ...
}
...

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

The approach using just Yade (here using a static method):

// file yade/pkg/dem/MyModel.hpp ////////////////
...
class Law2_ScGeom_MyPhys_Something : public LawFunctor {
   static Real computeNormalForce(Real stiffness, Real penetrationDepth);
   YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY(Law2_ScGeom_MyPhys_Something, LawFunctor,"...",
      ...
      .staticmethod("computeNormalForce")
      ...
   );
   ...
};
...

// file yade/pkg/dem/MyModel.cpp ////////////////
...
   Real Law2_ScGeom_MyPhys_Something :: computeNormalForce(Real stiffness, Real penetrationDepth) {
       return stiffness * penetrationDepth;
   }
...
   Law2_ScGeom_MyPhys_Something :: go(...) {
      ...
      fn = computeNormalForce(...)
      ...
   }
...
///////////////

Then in yade terminal:
law2 = Law2_ScGeom_MyPhys_Something
law2.computeNormalForce(1e6,1e-3)

Hi,
Unless you are familiar with compiling your own c++ and sort include/lib issues I would really recommend to proceed as Jan suggests, possibly in an even simpler way (no need to handle bodies or engines).
Write a yade class and insert all the "prints" you like in it.
Add functions for doing your tests with python wrappers.

Then start yade and:
myClass.test1()
myClass.test2()
etc.

That's not a simulation, it's just exploiting python wrapping of Yade.

Cheers

Bruno

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

Thanks Bruno Chareyre, that solved my question.