Dear fellows,
I am trying to write the C++ based expression in my FEniCS python code to gather some information regarding each cell of mesh. The python code compiles without error however when I try to call the function “my_function(mesh)” from the user expression it returns following error:
WARNING: user expression has not supplied value_shape method or an element. Assuming scalar element.
Traceback (most recent call last):
File "mwe_for_UserExpression.py", line 41, in <module>
my_expression.my_function(mesh)
AttributeError: 'UserExpression' object has no attribute 'my_function'
The minimal working code (simplified from my project’s bigger code) is following:
from dolfin import *
mesh = UnitCubeMesh(5,5,5)
cppcode = """
#include "dolfin.h"
#include "ufc.h"
class E : public Expression
{
public:
E() : Expression() {}
void eval(Array<double>& values, const Array<double>& data, const ufc::cell& cell) const
{
values[0] = _values[cell.index];
}
void my_function(const boost::shared_ptr<const dolfin::Mesh> mesh)
{
std::cout << "Function is called"<<std::endl;
if (_values.size() != mesh->num_cells())
_values.resize(mesh->num_cells());
for (CellIterator cell(*mesh); !cell.end(); ++cell)
{
const uint i = cell->index();
_values[i] = i;
}
}
private:
std::vector<double> _values;
};"""
my_expression = UserExpression(cppcode, degree=0)
my_expression.my_function(mesh)
While the dolfin docker version I am using is: DOLFIN version: 2019.2.0.dev0