write the values of function in c++ to file

8 months ago by

This is my first post so I apologize if the question has already been asked before.

In the Poisson demo in c++  I would like to output my solution  function u from the line : Function u(V);  to a txt file or any other file (other than pvd) I can actually see the values of this function. I can clearly see them in the vtk output file as data array but I need to read these values again from the file and I can't find I way to access them. I am also open to the idea of converting the function u into a vector then output the values of that vector to a file but I can't seem to find a line of code in C++ to do so.

Any help will be much appreciated and if my question is unclear I am very happy to simplify it further.
Thanks in advance!
Community: FEniCS Project

1 Answer

8 months ago by
Try XYZFile interface, http://fenics.readthedocs.io/projects/dolfin/en/latest/apis/api_io.html?#xyzfile. But be careful, it is an old interface and use it only for testing purposes.

Or you can fill std::vector<double> values with the method u.compute_vertex_values(values, mesh); where u is your Function on Mesh. Or you can obtain vector of expansion coefficients calling method .vector() on your Function.
Thank you for your help! I did finally manage to access to solution elements by using this code:

Vector testvec(*u.vector());
auto testarray=std::vector<double>();

then you can open and close a file normally to write the elements of testarray[i].

Thanks again for your comment!
written 7 months ago by rabulabdeh  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »