Eval a function on a hex-mesh in c++

Hi all,

I’m struggling to query a function on a hexmesh in c++, generated with:

auto cubemesh = UnitCubeMesh::create(MPI_COMM_WORLD, {16, 16, 16}, CellType::Type::hexahedron);
auto mesh = std::make_shared<Mesh>(cubemesh);
W = std::make_shared<FunctionSpace>(mesh);
u = std::make_shared<Function>(W);

and filled with some solution.

The straightforward approach:

Array<double> u_p (3);
Array<double> p (3);
p[0] = 0.5; p[1] = 0.5; p[2] = 0.5; 
u->eval(u_p,p);

spits out the error that this has not been implemented for hex meshes. So I’m hoping that I can use the alternative function that I find in the docs:

void eval(Array<double> &values, const Array<double> &x, const Cell &dolfin_cell, const ufc::cell &ufc_cell) const

This requires the cell object associated to the coordinate P, as well as a UFC::Cell object for the hexahedral element. My attempted implementation is very convoluted, and I still haven’t managed to get it to run. I feel like there should be a very straightforward way to do this. I’d be very grateful if someone could share a code-snippet :slight_smile:

Eval for quadrilaterals and hexahedrons is now available in dolfinx. See this PR for an example on how to use evaluate from the Python interface.

Since all the things done in the Python interface are wrappers around the C++ interface, you can easily port the functionality.