Hi everyone, I got a problem once I want to compile a c++ code using the compile_cpp_code in fenics 2019.1.0 using the Expression class. See the code below.
PD: the c++ code is taken from https://bitbucket.org/fenics-project/dolfin/src/master/python/demo/documented/tensor-weighted-poisson/demo_tensor-weighted-poisson.py (I supposed it works good)
conductivity_code = """
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>
namespace py = pybind11;
#include <dolfin/function/Expression.h>
#include <dolfin/mesh/MeshFunction.h>
class Conductivity : public dolfin::Expression
{
public:
// Create expression with 3 components
Conductivity() : dolfin::Expression(3) {}
// Function for evaluating expression on each cell
void eval(Eigen::Ref<Eigen::VectorXd> values, Eigen::Ref<const Eigen::VectorXd> x, const ufc::cell& cell) const override
{
const uint cell_index = cell.index;
values[0] = (*c00)[cell_index];
values[1] = (*c01)[cell_index];
values[2] = (*c11)[cell_index];
}
// The data stored in mesh functions
std::shared_ptr<dolfin::MeshFunction<double>> c00;
std::shared_ptr<dolfin::MeshFunction<double>> c01;
std::shared_ptr<dolfin::MeshFunction<double>> c11;
};
PYBIND11_MODULE(SIGNATURE, m)
{
py::class_<Conductivity, std::shared_ptr<Conductivity>, dolfin::Expression>
(m, "Conductivity")
.def(py::init<>())
.def_readwrite("c00", &Conductivity::c00)
.def_readwrite("c01", &Conductivity::c01)
.def_readwrite("c11", &Conductivity::c11);
}
"""
a = compile_cpp_code(conductivity_code)
The error I get is this one:
double free or corruption (!prev)
*** Process received signal ***
Signal: Aborted (6)
Signal code: (-6)
[ 0] /lib/x86_64-linux-gnu/libc.so.6(+0x3ef20)[0x7fd46104bf20]
[ 1] /lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7)[0x7fd46104be97]
[ 2] /lib/x86_64-linux-gnu/libc.so.6(abort+0x141)[0x7fd46104d801]
[ 3] /lib/x86_64-linux-gnu/libc.so.6(+0x89897)[0x7fd461096897]
[ 4] /lib/x86_64-linux-gnu/libc.so.6(+0x9090a)[0x7fd46109d90a]
[ 5] /lib/x86_64-linux-gnu/libc.so.6(cfree+0x534)[0x7fd4610a4e84]
[ 6] /usr/lib/x86_64-linux-gnu/libdolfin.so.2019.1(_ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_ESt4lessIS5_ESaIS8_EE8_M_eraseEPSt13_Rb_tree_nodeIS8_E+0x4e)[0x7fd45e7eb7ae]
[ 7] /lib/x86_64-linux-gnu/libc.so.6(+0x43041)[0x7fd461050041]
[ 8] /lib/x86_64-linux-gnu/libc.so.6(+0x4313a)[0x7fd46105013a]
[ 9] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xee)[0x7fd46102eb9e]
[10] /usr/bin/python3(_start+0x2a)[0x5b250a]
*** End of error message ***
The thing is that when I do not use the dolfin::Expression everything works fine. Can it be a pybind11 problem with Fenics?