Saving\loading the solution
Dear all, I'm saving a scalar field as vtu file. I can view is as paraview "function_3" in "Cell\Point Array Status window", but when I try to read it with the following script: import numpy from vtk import * from vtk.util import numpy_support as VN reader = vtkXMLPUnstructuredGridReader() reader.SetFileName('w_0.vtu') # file is attached reader.Update() from pprint import pprint #pprint(dir(reader)) data = reader.GetOutput() print data I don't see any arrays, it implicitly says "Number Of Arrays: 0" How do I access above-mentioned data? Sincerely, George
On 26/04/16 12:49, George Ovchinnikov wrote:
Dear all,
I'm saving a scalar field as vtu file. I can view is as paraview "function_3" in "Cell\Point Array Status window", but when I try to read it with the following script:
import numpy from vtk import * from vtk.util import numpy_support as VN
reader = vtkXMLPUnstructuredGridReader()
That should be vtkXMLUnstructuredGridReader() for a .vtu Cheers Stephan
Thank you. Another question: how do I find corresponding cell? Say, I have a mesh from gmsh in a square.msh file. I want to save values of my scalar field with index of corresponding cell, so external program which understands .msh format could import my data. At the moment I have the following code which outputs values and grid vertices: from numpy import * from vtk import * from vtk.util import numpy_support as VN reader = vtkXMLUnstructuredGridReader() reader.SetFileName('w_0.vtu') reader.Update() data = reader.GetOutput() array = data.GetPointData().GetArray('function_3') u = VN.vtk_to_numpy(array) #u = u.reshape(vec,order='F') x = zeros(data.GetNumberOfPoints()) y = zeros(data.GetNumberOfPoints()) for i in range(data.GetNumberOfPoints()): x[i],y[i], t = data.GetPoint(i) print len(x), x print len(y), y print len(u), u 4096 [ 0. 0. 0.03125 ..., 1. 0.96875 1. ] 4096 [ 0. 0.03125 0. ..., 0.96875 1. 1. ] 4096 [ 0.001 0.001 0.001 ..., 0.001 0.001 0.001] 26.04.2016 15:14, Stephan Kramer пишет:
On 26/04/16 12:49, George Ovchinnikov wrote:
Dear all,
I'm saving a scalar field as vtu file. I can view is as paraview "function_3" in "Cell\Point Array Status window", but when I try to read it with the following script:
import numpy from vtk import * from vtk.util import numpy_support as VN
reader = vtkXMLPUnstructuredGridReader()
That should be vtkXMLUnstructuredGridReader() for a .vtu
Cheers Stephan
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
participants (2)
-
George Ovchinnikov
-
Stephan Kramer