← Back to team overview

yade-dev team mailing list archive

Python inheritance

 

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<GenericPotential> {
public:

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

    void applyPotential(Real const& u, LubricationPhys& phys, Vector3r const&n) {
        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_<pyGenericPotential, boost::noncopyable>("GenericPotential")
.def("contactForce",py::pure_virtual(&pyGenericPotential::contactForce),"This function should return contact force norm.") .def("potentialForce",py::pure_virtual(&pyGenericPotential::potentialForce),"This function should return potential force norm.") .def("hasContact",py::pure_virtual(&pyGenericPotential::hasContact),"This function should return true if there are contact.");

--
<http://www.univ-grenoble-alpes.fr>
	

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.univ-grenoble-alpes.fr/>
http://www.laboratoire-rheologie-et-procedes.fr/


Follow ups