49 #include "../basecode/header.h"
59 "Sends out the value of local variable called `output`. Thus, you can"
60 " have Python statements which compute some value and assign it to the"
61 " variable called `output` (which is defined at `reinit` call). This"
62 " will be sent out to any target connected to the `output` field.");
71 "String to be executed at each time step.",
77 "String to be executed at initialization (reinit).",
83 "Name of local variable in which input balue is to be stored. Default"
84 " is `input_` (to avoid conflict with Python's builtin function"
91 "Name of local variable for storing output. Default is `output`.",
97 "Flag to indicate whether runString should be executed for both trigger and process, or one of them.",
115 "Executes the current runString whenever a message arrives. It stores"
116 " the incoming value in local variable named"
117 " `input_`, which can be used in the"
118 " `runString` (the underscore is added to avoid conflict with Python's"
119 " builtin function `input`). If debug is True, it prints the input"
125 "Runs a specified string. Does not modify existing run or init strings.",
130 "Handles process call. Runs the current runString.",
135 "Handles reinit call. Runs the current initString.",
141 "This is a shared message to receive Process messages "
142 "from the scheduler objects."
143 "The first entry in the shared msg is a MsgDest "
144 "for the Process operation. It has a single argument, "
145 "ProcInfo, which holds lots of information about current "
146 "time, thread, dt and so on. The second entry is a MsgDest "
147 "for the Reinit operation. It also uses ProcInfo. ",
148 processShared,
sizeof( processShared ) /
sizeof(
Finfo* ));
150 static Finfo * pyRunFinfos[] = {
164 static string doc[] = {
166 "Author",
"Subhasis Ray",
167 "Description",
"Runs Python statements from inside MOOSE."};
173 sizeof(pyRunFinfos) /
sizeof(
Finfo*),
176 sizeof(doc) /
sizeof(
string));
183 globals_(0), locals_(0),
184 runcompiled_(0), initcompiled_(0),
185 inputvar_(
"input_"), outputvar_(
"output")
189 cerr <<
"Could not initialize locals dict" << endl;
192 PyObject *
value = PyFloat_FromDouble(0.0);
193 if (!value && PyErr_Occurred()){
273 value = PyFloat_FromDouble(input);
274 if (!value && PyErr_Occurred()){
281 if (PyErr_Occurred()){
286 double output = PyFloat_AsDouble(value);
287 if (PyErr_Occurred()){
297 PyRun_SimpleString(statement.c_str());
300 double output = PyFloat_AsDouble(value);
301 if (PyErr_Occurred()){
317 if (PyErr_Occurred()){
322 double output = PyFloat_AsDouble(value);
323 if (PyErr_Occurred()){
337 PyObject *exc, *val, *trb;
340 if (syntax && PyErr_ExceptionMatches (PyExc_SyntaxError)){
341 PyErr_Fetch (&exc, &val, &trb);
343 if (PyArg_ParseTuple (val,
"sO", &msg, &trb) &&
344 !strcmp (msg,
"unexpected EOF while parsing")){
349 PyErr_Restore (exc, val, trb);
359 PyObject * main_module;
361 main_module = PyImport_AddModule(
"__main__");
362 globals_ = PyModule_GetDict(main_module);
368 cerr <<
"Could not initialize locals dict" << endl;
376 cerr <<
"Error compiling initString" << endl;
380 if (PyErr_Occurred()){
389 cerr <<
"Error compiling runString" << endl;
393 if (PyErr_Occurred()){
string getOutputVar() const
PYCODEOBJECT * runcompiled_
void run(const Eref &e, string statement)
void process(const Eref &e, ProcPtr p)
void setInitString(string str)
static const Cinfo * pyRunCinfo
static SrcFinfo1< double > * output()
static SrcFinfo1< double > * outputOut()
string get_program_name()
PYCODEOBJECT * initcompiled_
void setOutputVar(string name)
void reinit(const Eref &e, ProcPtr p)
string getRunString() const
static const Cinfo * initCinfo()
string getInputVar() const
void setRunString(string str)
void handleError(bool syntax)
void trigger(const Eref &e, double input)
static const Cinfo * initCinfo()
void setInputVar(string name)
string getInitString() const