Hi !
I am programming in C++ and using FEniCS for the FE discretization. Now, I have given an Eigen::VectorXd and I want to transform this vector into a dolfin::function. How can I handle this?
I am very thankful for any help, frieder
I do it this way:
std::shared_ptr<FunctionSpace> V; // this is your FunctionSpace Eigen:: VectorXd eigenvec; // this is your vector EigenVector evec(eigenvec); // convert it into dolfin EigenVector Vector vec(*(evec.copy())); // convert it into dolfin Vector Function u(V,vec.copy()); // convert it into dolfin function
If you create a dolfin::Function with the function space you want (continuous/discontinuous, correct polynomial degree etc) you can then get the underlying data by calling the vector() method on the function object. The function's FunctionSpace will have a dofmap() method that you can query to find out which element owns which indices in the vector and hence where to put the data you have into a vector that dolfin will know how to handle as a function. Do not assume in your code that the elements of the function vector are ordered in a geometric or other "sensible" way. This will most likely not be the case.