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

(1D) space vs time plot

0 votes

Perhaps this is a question better asked on paraview, but, I have solved in FEniCS a PDE in one spatial dimension and would like to make a plot of the solution in space and time. That is to have the spatial coordinate on the abcissa and time coordinate on the ordinate axis with color representing the value of the function at each coordinate. I would appreciate any of the following:
How can I make a setting or filter in paraview that will let me do this?
How could I do this in a simple python script to accomplish this?
How can I read the .vtu or .pvd files into Matlab so I can make such a plot?

Thank you.

asked Jun 13, 2017 by evan FEniCS Novice (160 points)

2 Answers

0 votes

Hello...
I normally import the pvd files into paraview and use the "plot over line" filter... Not sure if that's exactly what you need, but I guess it might help...
Regards

answered Jun 13, 2017 by lhdamiani FEniCS User (2,580 points)

Thank you for your response, but, this is not what I am looking for. I think a picture would help:

picture

In this case time is on the abscissa and space on the ordinate with a "heat" colormap showing the values of the function. I am trying to make something like this from the output of the FEniCS package.

0 votes

While I would like to know how to do this in paraview. Here is a stub code that does what I would like. Note that for long time runs this can be very memory intensive and subsampling is suggested.

import numpy as np
import matplotlib.pyplot as plt
import meshio

direct = '/tmp/'

fileu = direct+'u'+str(0).zfill(6)+'.vtu'
points,cells,point_data,cell_data,field_data = meshio.read(fileu)
xlen = len(points)
xp = [] 
for x in np.linspace(0,xlen-1,xlen):
   xp.append(points[:][int(x)][0])
xp = np.asarray(xp)

tp = np.linspace(0,10,10+1)
U = np.zeros((10+1, xlen))

for filenumber in tp:
   fileu = direct+'u'+str(int(filenumber)).zfill(6)+'.vtu'
   points,cells,point_data,cell_data,field_data = meshio.read(fileu)
   keys = point_data.keys()
   key = keys[0]
   u = point_data[key]
   U[int(filenumber)] = u

U_min = U.min()
U_max = U.max()
plt.figure(1)
plt.clf()
plt.pcolor(xp,tp,U,cmap='jet',vmin=U_min,vmax=U_max)
plt.title('u(x,t)')
plt.axis([xp.min(),xp.max(),tp.min(),tp.max()])
plt.colorbar()
plt.show()
answered Jun 14, 2017 by evan FEniCS Novice (160 points)
...