Re: [Yade-users] [Question #697142]: Writing new Ip2 functor / order of contact partners

2021-05-20 Thread Bettina Suhr
Question #697142 on Yade changed:
https://answers.launchpad.net/yade/+question/697142

Bettina Suhr confirmed that the question is solved:
Thanks Jan Stránský, that solved my question.

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.

___
Mailing list: https://launchpad.net/~yade-users
Post to : yade-users@lists.launchpad.net
Unsubscribe : https://launchpad.net/~yade-users
More help   : https://help.launchpad.net/ListHelp


Re: [Yade-users] [Question #697142]: Writing new Ip2 functor / order of contact partners

2021-05-20 Thread Bettina Suhr
Question #697142 on Yade changed:
https://answers.launchpad.net/yade/+question/697142

Status: Answered => Solved

Bettina Suhr confirmed that the question is solved:
Thank you, Jan! The dynamic cast works really fine. 
The std::swap caused a compilation error, but it was easy to avoid the swap 
command, after knowing which pointer is which one.

Best regards,
Bettina

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.

___
Mailing list: https://launchpad.net/~yade-users
Post to : yade-users@lists.launchpad.net
Unsubscribe : https://launchpad.net/~yade-users
More help   : https://help.launchpad.net/ListHelp


Re: [Yade-users] [Question #697142]: Writing new Ip2 functor / order of contact partners

2021-05-20 Thread Jan Stránský
Question #697142 on Yade changed:
https://answers.launchpad.net/yade/+question/697142

Status: Open => Answered

Jan Stránský proposed the following answer:
Hello,

to test the specific instance, you can dynamic_cast the pointer and test
if the cast was successful or not, something like:

/
Ip2_FrictMat_myMaterial_myPhysics :: go(const shared_ptr& b1, const 
shared_ptr& b2, const shared_ptr& interaction) {
   MyMaterial myMatTest* = dynamic_cast(b2.get());
   if (!myMatTest) { // b2 is not MyMaterial instance
  std::swap(b1,b2);
   }
   /// now b1 is FrictMat and b2 is MyMaterial
   ...
}
/


A (non-Yade) illustration MWE:
// g++ test.cpp -o test && ./test
#include
#include
class Base { public: virtual ~Base(){} };
class Derived1 : public Base {};
class Derived2 : public Base {};
int main() {
   std::shared_ptr b1(new Derived1());
   std::shared_ptr b2(new Derived2());
   //
   Base* base1 = dynamic_cast(b1.get());
   if (base1) std::cout << "base1 is Base\n";
   else std::cout << "base1 is NOT Base\n";
   //
   Base* base2 = dynamic_cast(b2.get());
   if (base2) std::cout << "base2 is Base\n";
   else std::cout << "base2 is NOT Base\n";
   //
   Derived1* d11 = dynamic_cast(b1.get());
   if (d11) std::cout << "b1 is Derived1\n";
   else std::cout << "b1 is NOT Derived1\n";
   //
   Derived2* d21 = dynamic_cast(b1.get());
   if (d21) std::cout << "b1 is Derived2\n";
   else std::cout << "b1 is NOT Derived2\n";
   //
   //
   Derived1* d12 = dynamic_cast(b2.get());
   if (d12) std::cout << "b1 is Derived1\n";
   else std::cout << "b1 is NOT Derived1\n";
   //
   Derived2* d22 = dynamic_cast(b2.get());
   if (d22) std::cout << "b2 is Derived2\n";
   else std::cout << "b2 is NOT Derived2\n";
   return 0;
}
//

Cheers
Jan

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.

___
Mailing list: https://launchpad.net/~yade-users
Post to : yade-users@lists.launchpad.net
Unsubscribe : https://launchpad.net/~yade-users
More help   : https://help.launchpad.net/ListHelp


Re: [Yade-users] [Question #697142]: Writing new Ip2 functor / order of contact partners

2021-05-20 Thread Bettina Suhr
Question #697142 on Yade changed:
https://answers.launchpad.net/yade/+question/697142

Status: Answered => Open

Bettina Suhr is still having a problem:
Hi Vasileios,

Thank you for the explanation, now I understand better why I have this
problem.

Your suggestion to use the DEFINE_FUNCTOR_ORDER_2D sounded like an
elegant solution, unfortunately it doesn’t work. The behaviour remains
unchanged, even when I put the
DEFINE_FUNCTOR_ORDER_2D(FrictMat,myMaterial) command.

Any other Idea how I could solve this problem?

Can I check to which class b1, b2 are pointing?

Best regards,
Bettina

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.

___
Mailing list: https://launchpad.net/~yade-users
Post to : yade-users@lists.launchpad.net
Unsubscribe : https://launchpad.net/~yade-users
More help   : https://help.launchpad.net/ListHelp


Re: [Yade-users] [Question #697142]: Writing new Ip2 functor / order of contact partners

2021-05-19 Thread Vasileios Angelidakis
Question #697142 on Yade changed:
https://answers.launchpad.net/yade/+question/697142

Status: Open => Answered

Vasileios Angelidakis proposed the following answer:
Hi Bettina,

The order of contact partners is determined inside the Ig2 functors
using:

FUNCTOR2D(Shape1,Shape2);
DEFINE_FUNCTOR_ORDER_2D(Shape1,Shape2);

as in [1]. Your example also shows the same behaviour.

Currently this DEFINE_FUNCTOR_ORDER_2D is not used in any other Ip2
functors, but it could be worthwhile trying:
DEFINE_FUNCTOR_ORDER_2D(FrictMat,myMaterial) when defining your
Ip2_FrictMat_myMaterial_myPhysics class in its header file. More info on
DEFINE_FUNCTOR_ORDER_2D in [2,3].

Hope this helps,

Vasileios

[1] 
https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/dem/Ig2_Facet_Sphere_ScGeom.hpp#L43-44
[2] 
https://gitlab.com/yade-dev/trunk/-/blob/master/lib/multimethods/FunctorWrapper.hpp
[3] 
https://gitlab.com/yade-dev/trunk/-/blob/master/lib/multimethods/DynLibDispatcher.hpp

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.

___
Mailing list: https://launchpad.net/~yade-users
Post to : yade-users@lists.launchpad.net
Unsubscribe : https://launchpad.net/~yade-users
More help   : https://help.launchpad.net/ListHelp