# writing the solution in to the txt

Hello,

I am very new to Fenics, so sorry if this is question is very simple.

I want to save the solution in a format that I can read automatically by matlab. the problem is that I can use u_nodal_values =

u.vector()

u_array = u_nodal_

coor = mesh.coordinates()

numpy.savetxt(

numpy.savetxt(

to save the coordinate and the displacement in to two different file but since I working on 3D domain, I have 3 displacement for each node and I am not sure how these are connected.

I convert the PVD file to the CSV format in paraview manually but I am not sure how can I save the nodes and corresponding displacment to each node in to a txt file.

any suggestion?

Thanks

## Question information

- Language:
- English Edit question

- Status:
- Solved

- For:
- DOLFIN Edit question

- Assignee:
- No assignee Edit question

- Solved by:
- Nick Davies

- Solved:
- 2013-05-08

- Last query:
- 2013-05-08

- Last reply:
- 2013-05-08

Nick Davies (ntd14) said : | #1 |

I will try to help, but I dont use matlab much, and not 100 % sure what you are asking, but I think it is how can I link my displacements to my coordinates. The problem is that the u_vec and the coordinates dont have the same ordering. I have a script which does a similar thing to what you are wanting and you are welcome to use and abuse, it is modified from a script a different member (Johan Hake) on here posted. For reference what this code actually does is take the coordinates of the mesh, updates them with the displacements and returns them as new coordinates.

#these are probably already in your code as the problem setup

V = VectorFunctionS

VV = FunctionSpace(

.........

solve()

####

coor_int = interpolate(

#turing displacement into numpy array

u_vec = u.vector().array()

#calc new coordinates by subtaracting the displacement at each interploated

#node from the oringonal mesh

new_coor = coor_int+u_vec

#initalising matries

dofs_to_vert = np.zeros(

vectordofs_

vectordofs_

cellinds = np.zeros(

#creating degrees of freedom maps

dm = VV.dofmap()

dms = [V.sub(i).dofmap() for i in range(3)]

for cell in cells(mesh1):

cell_ind = cell.index()

vert_inds = cell.entities(0)

for i, (dms_i, dmcs_i) in enumerate(zip(dms, dms)):

map_mat = np.zeros(

coorxyz = np.zeros(

#make matrix of maps above

map_mat[:,0] = vectordofs_to_vert

map_mat[:,1] = vectordofs_

map_mat[:,2] = new_coor

#sort entries using maps matrix above

for ij in range(0,

if map_mat[ij,1] == 0:

if map_mat[ij,1] == 1:

if map_mat[ij,1] == 2:

Note this only works for 3D and linear elements.

coorxyz is a matrix with all of the coordinates in x, y and z columns after the displacements have been added.

You could probably modify this to deal with the displacments and coordinates separately but keep them all in the right order so that the two matrices match when imported into matlab if you want them separate.

here is a link to the original code which might help too

https:/

Good luck

Bahram (behinoo) said : | #2 |

Thanks Nick Davies, that solved my question.