This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to map the solution of a poissons equaion into an array along with the coordinates in the c++ implementation?

+1 vote

I am using "u.vector()->getitem(i)" to get the solution, but the solution comes kinda scrambled. How can I also get the mesh coordinated of the solution or How can I get the solution in sequence to the nodes.

asked May 16, 2015 by gaurav553 FEniCS Novice (130 points)

2 Answers

0 votes

Hi,

I think you could, firstly, get all coordinates and then get function value for the current coordinate.

You could find an example in the tutorial:
http://fenicsproject.org/documentation/tutorial/fundamentals.html#examining-the-discrete-solution

coor = mesh.coordinates()
if mesh.num_vertices() == len(u_array):
    for i in range(mesh.num_vertices()):
        print 'u(%8g,%8g) = %g' % (coor[i][0], coor[i][1], u_array(coor[i][0], coor[i][1]))

Regards, Maksim

answered May 19, 2015 by Maks FEniCS User (2,430 points)
0 votes

This is a common question - you should find something if you search the forum for dof_to_vertex maps etc. Also, if not running in parallel, you might want to turn reordering of dofs off.

answered May 20, 2015 by chris_richardson FEniCS Expert (31,740 points)
...