Big advantage of pybind11 is also that is does automatic type conversion for you between Python and C++, so you can easily convert between C++ std::vector and Python’s list etc...
> On 9. Sep 2021, at 15:03, Timo Koch <[email protected]> wrote: > > Hi Leo, > > I would definitely look into this with pybind11 which reads very nice on the > C++ side too. There are some instructions at the end here > dune-project.org/doc/pythonbindings and in dune-common/dune/python/test/ you > also find two small examples for embedded Python. We also have some testing > code with a fluid system using embedded Python on the branch > “feature/python-fluidsystem” in dumux (MR !2001). > > And of course some test for dumux is also welcome. > > Timo > >> 9. sep. 2021 kl. 13:36 skrev [email protected]: >> >> >> Hi Bernd, >> >> thank you for this nice example. I've used embedded Python 10 years ago. My >> code was much less elegant and so I thought that one has to do this nowadays >> with Pybind11. However, looking into your example it looks like the Python/C >> API does also the job. For me it helps a lot to see how the Python >> interpreter is initialized and finalized in problem.hh and how data is >> converted. >> >> Actually I need a simple Python function for the source term so there are >> just a few parameters which have to be passed between C++ and Python. >> >> Best regards, >> >> Leo >> >>> Flemisch, Bernd <[email protected]> hat am 09.09.2021 >>> 12:27 geschrieben: >>> >>> >>> Hi Leo, >>> >>> >>> >>> we're doing this here: >>> >>> https://git.iws.uni-stuttgart.de/dumux-appl/dumux-turing/-/tree/master/test/stochastic >>> >>> <https://git.iws.uni-stuttgart.de/dumux-appl/dumux-turing/-/tree/master/test/stochastic> >>> I needed the python3-dev package and had to run the executable with >>> >>> PYTHONPATH=. ./test_stochastic >>> >>> >>> >>> >>> Kind regards >>> >>> Bernd >>> >>> <https://git.iws.uni-stuttgart.de/dumux-appl/dumux-turing/-/tree/master/test/stochastic> >>> >>> -- >>> _________________________________________________________________ >>> >>> Bernd Flemisch >>> IWS, Universität Stuttgart phone: +49 711 685 69162 >>> Pfaffenwaldring 61 email: [email protected] >>> D-70569 Stuttgart url: www.iws.uni-stuttgart.de/en/lh2/ >>> <http://www.iws.uni-stuttgart.de/en/lh2/> >>> _________________________________________________________________ >>> Von: DuMux <[email protected]> im Auftrag von >>> [email protected] <[email protected]> >>> Gesendet: Donnerstag, 9. September 2021 11:58:04 >>> An: [email protected] >>> Betreff: [DuMux] Using Embedded Python in DuMux >>> >>> Dear DuMux developers and users, >>> >>> I'm interested to call Python from a DuMux application (embedded Python). >>> Has anyone tried this before with DuMux? I'm also interested to use >>> embedded Python in a parallel application in combination with MPI4py. >>> >>> Maybe it is a good idea if I open an issue in gitlab and try to add a small >>> test (dumux/test/python) to check if/how embedded Python works. >>> >>> Best regards, >>> >>> Leo >>> >>> Im Auftrag >>> >>> Dr.-Ing. Leopold Stadler >>> >>> -- >>> Referat Numerische Verfahren im Wasserbau >>> Abteilung Wasserbau im Binnenbereich >>> >>> Bundesanstalt für Wasserbau >>> Federal Waterways Engineering and Research Institute >>> Kußmaulstraße 17 | 76187 Karlsruhe >>> >>> https://www.baw.de >>> >>> >>> _______________________________________________ >>> DuMux mailing list >>> [email protected] >>> https://listserv.uni-stuttgart.de/mailman/listinfo/dumux >> >> Im Auftrag >> >> Dr.-Ing. Leopold Stadler >> >> -- >> Referat Numerische Verfahren im Wasserbau >> Abteilung Wasserbau im Binnenbereich >> >> Bundesanstalt für Wasserbau >> Federal Waterways Engineering and Research Institute >> Kußmaulstraße 17 | 76187 Karlsruhe >> >> >> https://www.baw.de >> >> >> _______________________________________________ >> DuMux mailing list >> [email protected] >> https://listserv.uni-stuttgart.de/mailman/listinfo/dumux > _______________________________________________ > DuMux mailing list > [email protected] > https://listserv.uni-stuttgart.de/mailman/listinfo/dumux
_______________________________________________ DuMux mailing list [email protected] https://listserv.uni-stuttgart.de/mailman/listinfo/dumux
