Re: [Yade-dev] Python inheritance

2019-10-08 Thread William Chèvremont

Hi,

Yes, there are the same behaviour with and without wait.

William


On 08/10/2019 12:57, Bruno Chareyre wrote:

Hi William,
I don't know precisely but in case it can help I would raise that the 
main difference between step() and run() is Py_BEGIN_ALLOW_THREADS, at 
least if O.run(...,wait=True).

Do you have the same problem with and without "wait"?

Simply passing to c++ a python expression (just a string with python 
commands) or a python function returning a value - instead of a 
derived class object - could be a simple workaround maybe.


Bruno








On Tue, 8 Oct 2019 at 10:56, William Chèvremont 
> wrote:


Hi,

@Janek

Yes, I'm aware of the doc about subclassing types in python. There
are
no problem about that, since it works when calling O.step()
instead of
O.run().

@Anton

The complete backtrace is attached to this mail. Functions of
interests
are around line 400.

Best Regards,

William


On 07/10/2019 18:19, Janek Kozicki (yade) wrote:
> Only a quick question to make sure - you have read
https://yade-dem.org/doc/prog.html#subclassing-c-types-in-python
in documentation?
>
>
> best regards
> Janek
>
> ___
> Mailing list: https://launchpad.net/~yade-dev
> Post to     : yade-dev@lists.launchpad.net

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

Unsubscribe : https://launchpad.net/~yade-dev
More help   : https://help.launchpad.net/ListHelp



--
--
___
Bruno Chareyre
Associate Professor
ENSE³ - Grenoble INP
Lab. 3SR
BP 53
38041 Grenoble cedex 9
Tél : +33 4 56 52 86 21


Email too brief?
Here's why: email charter 

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


Re: [Yade-dev] Python inheritance

2019-10-08 Thread Bruno Chareyre
Hi William,
I don't know precisely but in case it can help I would raise that the main
difference between step() and run() is Py_BEGIN_ALLOW_THREADS, at least if
O.run(...,wait=True).
Do you have the same problem with and without "wait"?

Simply passing to c++ a python expression (just a string with python
commands) or a python function returning a value - instead of a derived
class object - could be a simple workaround maybe.

Bruno








On Tue, 8 Oct 2019 at 10:56, William Chèvremont <
william.chevrem...@univ-grenoble-alpes.fr> wrote:

> Hi,
>
> @Janek
>
> Yes, I'm aware of the doc about subclassing types in python. There are
> no problem about that, since it works when calling O.step() instead of
> O.run().
>
> @Anton
>
> The complete backtrace is attached to this mail. Functions of interests
> are around line 400.
>
> Best Regards,
>
> William
>
>
> On 07/10/2019 18:19, Janek Kozicki (yade) wrote:
> > Only a quick question to make sure - you have read
> https://yade-dem.org/doc/prog.html#subclassing-c-types-in-python in
> documentation?
> >
> >
> > best regards
> > Janek
> >
> > ___
> > Mailing list: https://launchpad.net/~yade-dev
> > Post to : yade-dev@lists.launchpad.net
> > Unsubscribe : https://launchpad.net/~yade-dev
> > More help   : https://help.launchpad.net/ListHelp
> ___
> Mailing list: https://launchpad.net/~yade-dev
> Post to : yade-dev@lists.launchpad.net
> Unsubscribe : https://launchpad.net/~yade-dev
> More help   : https://help.launchpad.net/ListHelp
>


-- 
-- 
___
Bruno Chareyre
Associate Professor
ENSE³ - Grenoble INP
Lab. 3SR
BP 53
38041 Grenoble cedex 9
Tél : +33 4 56 52 86 21


Email too brief?
Here's why: email charter

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


Re: [Yade-dev] Python inheritance

2019-10-08 Thread Jerome Duriez

Hi,

For your information, I also faced at some point segfaults with 
boost::python stuff during O.run() and not O.step() : 
https://www.mail-archive.com/yade-dev@lists.launchpad.net/msg13223.html


(I never really solved / understood it.. If you know e.g. boost mutex 
more than me -- that won't be difficult -- maybe you will !)



Jérôme

--
Chargé de Recherche / Research Associate
Irstea, RECOVER
3275 route Cezanne – CS 40061 13182 Aix-en-Provence Cedex 5 FRANCE
+33 (0)4 42 66 99 21
www.irstea.fr/duriez

On 07/10/2019 16:46, William Chèvremont wrote:


Dear Yade dev,

I'm facing an issue implementing a new interaction law into Yade.

To be quick, I would like to provide normal force norm from python and 
integrate this value into the lubrication law.


The current state of my work is on branch 'potential' on gitlab. 
What's new in this branch:


- pkg/dem/LubricationWithPotential.{cpp, hpp} : Lubrication law with 
arbitraty contact law + potential solver, and some potential coded in 
c++. This part work perfectly.


- py/wrapper/yadeWrapper.cpp: I've written a wrapping class and 
boost.python exposing expressions. I want to inherit this class in 
python in order to provide the value to the solver above.


It works perfectly if I call O.step();. Problems are coming as soon as 
I launch O.run(), I got a segfault signal when the c++ code call the 
python overrided function.


What's wrong???

Summary of the code:

:::python:::

classSimplePotential(GenericPotential):
    def contactForce(self, u):
#    print("pyContactForce!");
    return 0;
    def potentialForce(self, u):
#    print("pyPotentialForce!");
    return 1;
    def hasContact(sefl, u):
    return False;

:::C++:::


class pyGenericPotential : public GenericPotential, public 
py::wrapper {

public:

    Real potential(Real const& u, LubricationPhys const&) const {
    TRACE;
    return contactForce(u) + potentialForce(u);
    }

    void applyPotential(Real const& u, LubricationPhys& phys, Vector3r 
const) {

    TRACE;
    phys.normalContactForce = contactForce(u)*n;
    phys.normalPotentialForce = potentialForce(u)*n;
    phys.contact = hasContact(u);
    }

    virtual Real contactForce(Real const& u) const {
    TRACE;
    return get_override("contactForce")(u);
    }

    virtual Real potentialForce(Real const& u) const {
    TRACE;
    return get_override("potentialForce")(u);
    }

    virtual bool hasContact(Real const& u) const {
    TRACE;
    return get_override("hasContact")(u);
    }
};


    py::class_("GenericPotential")
.def("contactForce",py::pure_virtual(::contactForce),"This 
function should return contact force norm.")
.def("potentialForce",py::pure_virtual(::potentialForce),"This 
function should return potential force norm.")
.def("hasContact",py::pure_virtual(::hasContact),"This 
function should return true if there are contact.");


--



William Chèvremont

Doctorant, PhD student
04 56 52 01 86

Laboratoire de Rhéologie et Procédés
Bureau Bureau B-365
363 Rue de la chimie - bâtiment B
Domaine Universitaire - BP 53 - 38041 Grenoble cedex 9
www.univ-grenoble-alpes.fr 
http://www.laboratoire-rheologie-et-procedes.fr/


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



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


Re: [Yade-dev] Python inheritance

2019-10-08 Thread William Chèvremont

Hi,

@Janek

Yes, I'm aware of the doc about subclassing types in python. There are 
no problem about that, since it works when calling O.step() instead of 
O.run().


@Anton

The complete backtrace is attached to this mail. Functions of interests 
are around line 400.


Best Regards,

William


On 07/10/2019 18:19, Janek Kozicki (yade) wrote:

Only a quick question to make sure - you have read 
https://yade-dem.org/doc/prog.html#subclassing-c-types-in-python in 
documentation?


best regards
Janek

___
Mailing list: https://launchpad.net/~yade-dev
Post to : yade-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~yade-dev
More help   : https://help.launchpad.net/ListHelp
william@LaptopUGA:/media/datas/These/Script/potential$ yade-mybuild -f6 
sedimentingSphere_withPotential.py
Welcome to Yade 2019-10-03.git-b45f39e 
Using python version: 3.6.8 (default, Aug 20 2019, 17:12:48) 
[GCC 8.3.0]
 _log.cpp:49 void setLevel(std::__cxx11::string, int): filter log level 
for Default has been set to 6
 Logging:187 void Logging::setNamedLogLevel(const string&, short int): 
setting "Default" log level to 6
 _log.cpp:49 void setLevel(std::__cxx11::string, int): filter log level 
for Default has been set to 6
TCP python prompt on localhost:9000, auth cookie `seacks'
XMLRPC info provider on http://localhost:21000
 OpenGLRenderer:66 void OpenGLRenderer::initgl(): (re)initializing GL 
for gldraw methods.

Running script sedimentingSphere_withPotential.py
/usr/lib/python3/dist-packages/matplotlib/__init__.py:831: 
MatplotlibDeprecationWarning: axes.color_cycle is deprecated and replaced with 
axes.prop_cycle; please use the latter.
  mplDeprecation)
/usr/lib/python3/dist-packages/matplotlib/__init__.py:801: 
MatplotlibDeprecationWarning: axes.color_cycle is deprecated and replaced with 
axes.prop_cycle; please use the latter.
  mplDeprecation)
[[ ^L clears screen, ^U kills line. F12 controller, F11 3D view (press "h" in 
3D view for help), F10 both, F9 generator, F8 plot. ]]

In [1]: O.step();
 InsertionSortCollider:227 virtual void InsertionSortCollider::action(): 
Resize bounds containers from 0 to 4, will std::sort.
 GenericPotential:836 virtual Real pyGenericPotential::potential(const 
Real&, const LubricationPhys&) const: Been here
 GenericPotential:848 virtual Real 
pyGenericPotential::contactForce(const Real&) const: Been here
 GenericPotential:853 virtual Real 
pyGenericPotential::potentialForce(const Real&) const: Been here
 GenericPotential:836 virtual Real pyGenericPotential::potential(const 
Real&, const LubricationPhys&) const: Been here
 GenericPotential:848 virtual Real 
pyGenericPotential::contactForce(const Real&) const: Been here
 GenericPotential:853 virtual Real 
pyGenericPotential::potentialForce(const Real&) const: Been here
 GenericPotential:836 virtual Real pyGenericPotential::potential(const 
Real&, const LubricationPhys&) const: Been here
 GenericPotential:848 virtual Real 
pyGenericPotential::contactForce(const Real&) const: Been here
 GenericPotential:853 virtual Real 
pyGenericPotential::potentialForce(const Real&) const: Been here
 GenericPotential:836 virtual Real pyGenericPotential::potential(const 
Real&, const LubricationPhys&) const: Been here
 GenericPotential:848 virtual Real 
pyGenericPotential::contactForce(const Real&) const: Been here
 GenericPotential:853 virtual Real 
pyGenericPotential::potentialForce(const Real&) const: Been here
 GenericPotential:836 virtual Real pyGenericPotential::potential(const 
Real&, const LubricationPhys&) const: Been here
 GenericPotential:848 virtual Real 
pyGenericPotential::contactForce(const Real&) const: Been here
 GenericPotential:853 virtual Real 
pyGenericPotential::potentialForce(const Real&) const: Been here
 GenericPotential:836 virtual Real pyGenericPotential::potential(const 
Real&, const LubricationPhys&) const: Been here
 GenericPotential:848 virtual Real 
pyGenericPotential::contactForce(const Real&) const: Been here
 GenericPotential:853 virtual Real 
pyGenericPotential::potentialForce(const Real&) const: Been here
 GenericPotential:836 virtual Real pyGenericPotential::potential(const 
Real&, const LubricationPhys&) const: Been here
 GenericPotential:848 virtual Real 
pyGenericPotential::contactForce(const Real&) const: Been here
 GenericPotential:853 virtual Real 
pyGenericPotential::potentialForce(const Real&) const: Been here
 GenericPotential:836 virtual Real pyGenericPotential::potential(const 
Real&, const LubricationPhys&) const: Been here
 GenericPotential:848 virtual Real 
pyGenericPotential::contactForce(const Real&) const: Been here
 GenericPotential:853 virtual Real 
pyGenericPotential::potentialForce(const Real&) const: Been here
 GenericPotential:836 virtual Real pyGenericPotential::potential(const 
Real&, const LubricationPhys&) const: Been here
 GenericPotential:848 virtual Real 
pyGenericPotential::contactForce(const Real&) const: Been here
 GenericPotential:853