dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #19680
[Question #125106]: C++ code for user-defined Expression
New question #125106 on DOLFIN:
https://answers.launchpad.net/dolfin/+question/125106
I have a problem in which I need to define an Expression using "complicated" C++ code. Before making the real code, I am trying to test it, with the following trivial code:
-----------------------------------------------------------
from dolfin import *
code = '''
class SomeExpr : public Expression
{
public:
SomeExpr() : Expression(1) {}
void eval(Array<double>& values, const Data& data) const
{
values[0] = data.x[0];
}
};
'''
mesh = UnitInterval(10)
V = FunctionSpace(mesh, 'CG', 2)
u = TrialFunction(V)
v = TestFunction(V)
f = Expression(code)
a = f*inner(grad(u),grad(v))*dx
L = Constant(0)*v*dx
-----------------------------------------------------------
When running it, I get the error message:
Trying to integrate expression of rank 1 with free indices ().
On the other hand, if I just write
f = Expression('x[0]'),
which is what I try to do in the above code, no error messages are issued.
--
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.
Follow ups