yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #03699
Re: Another python software
Why does this not work in my Yade C file? It gives segmentation fault
#include "Python.h"
Py_Initialize();
PyRun_SimpleString("x=1");
PyRun_SimpleString("print x");
Py_Finalize();
I am planning to do this is C:
#include<yade/scripts/boon/aaa.py
PyRun_SimpleString("abc(input parameters)");
And in aaa.py:
def abc(input parameters):
some subroutine algorithm for abc
Please correct me.
Yours,
Boon
From: booncw@xxxxxxxxxxx
To: yade-dev@xxxxxxxxxxxxxxxxxxx
Date: Fri, 26 Mar 2010 08:05:08 +0800
Subject: Re: [Yade-dev] Another python software
Thanks, Vaclav for this pointing out. In this case, I'd like to call PeriodicPythonRunner in my .cpp file. But the function/command to give as input to PeriodicPython runner would have to be in python, e.g. 'AddPlotData'. Could you tell me how to do that please?
PeriodicPythonRunner(virtPeriod=3e-5/strainRateTension,realLim=5,command='addPlotData()',label='plotDataCollector'),
Also, since I want to use my CvxOpt when 'required' and not governed by time, what do I give as input to virtPeriod?
Yours,
Boon
> From: eudoxos@xxxxxxxx
> To: yade-dev@xxxxxxxxxxxxxxxxxxx
> Date: Thu, 25 Mar 2010 22:52:59 +0100
> Subject: Re: [Yade-dev] Another python software
>
>
> > Although the FORTRAN code/software/library is my first choice, I am
> > also planning to try this python opensource code:
> >
> > http://abel.ee.ucla.edu/cvxopt/examples/other/embed_cvxopt.html
> >
> > There are examples how to link python to C. But how do I do it for
> > YADE?
>
> The simplest is to install python-cvxopt package and use it from your
> python scripts.
>
> Calling python code from c++ is (in yade's context) discouraged, as you
> want to have only computationally demanding parts in c++, where calling
> python would harm performance (except for various hooks, which are
> called only rarely). There are still several options:
>
> 1. use PeriodicPythonRunner engine to call any python function you
> define, which will do what you need in pure python.
>
> 2. use pure python/c API (whic his shown in the example you referenced)
> or boost::python to run python code. Have a look at PeriodicPythonRunner
> how it does that for simple case, where you don't need to pass c++
> objects to the function called.
>
> HTH, Vaclav
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-dev
> Post to : yade-dev@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~yade-dev
> More help : https://help.launchpad.net/ListHelp
Hotmail: Trusted email with powerful SPAM protection. Sign up now.
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
https://signup.live.com/signup.aspx?id=60969
Follow ups
References