This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Using an Expression with parameters

0 votes

I want to use parameters in a Expression. For simple calculations, I can use

f = Expression('A*x[0]', A=2.0 ),

as seen here.

However, for a "Complex user-defined JIT-compiled Expressions" ( from the same page ), it looks like this fails. Say I have this code.

namespace dolfin { 
    classMyFun : public Expression
    {
    public:
        MyFun(): Expression(){};
        void eval( Array<double>& values, Array<double>& x) const {
            values[0] = A *x[0];
        }
    };
}

If this is stored in some string code in python then the following fails to compile.

f = Expression( code, A=2.0 )

Any way around this issue? One thing I've tried is to make python substitute A in the string to whatever it needs to be. A major drawback is that compiling is required every time A is changed.

asked Dec 22, 2015 by Yair Daon FEniCS User (1,350 points)
...