CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

​ Paraview vs OpenFOAM vtp slice plotting with matplotlib

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 8, 2022, 06:16
Default ​ Paraview vs OpenFOAM vtp slice plotting with matplotlib
  #1
Senior Member
 
Join Date: Jan 2014
Posts: 179
Rep Power: 12
hxaxtma is on a distinguished road
Hi

maybe you can help me out with a right comment or hint for my problem.

Pretty easy, I would like to plot a 2D slice vtp file (OpenFOAM) via matplotlib as tricontourf plot.

1.) Creating the vtp slice by Paraview and saving as vtp file works like a charme

2.) Using the runtime vtp file, created by cuttingPlane - libsampling OpenFOAM creates a weird triangle order.

In the attachement you can find a the zip file, containing the python script and vtp files.


What am I missing?

Best,

Code:
def loadVTPFile(filename):
    import vtk
    from vtk.util.numpy_support import vtk_to_numpy
    from vtk.util import numpy_support as npvtk
    
    reader = vtk.vtkXMLPolyDataReader()
    reader.SetFileName(filename)
    reader.Update()
    data = reader.GetOutput()
       
    points = data.GetPoints()
    npts = points.GetNumberOfPoints()
    x = vtk_to_numpy(points.GetData())
    
        
    triangles=  vtk_to_numpy(data.GetPolys().GetData())
    ntri = triangles.size // 4  # number of cells
    tri = np.take(triangles,[n for n in range(triangles.size) if n%4 != 0]).reshape(ntri,3)
    
    n_arrays = reader.GetNumberOfPointArrays()
    for i in range(n_arrays):
        print(reader.GetPointArrayName(i))
    
    X = vtk_to_numpy(points.GetData())
    x=X[:,0]
    y=X[:,1]
    z=X[:,2]
    
    # Define the velocity components U=(u,v,w)
    U = vtk_to_numpy(data.GetPointData().GetArray('UMean'))
    u = U[:,0]
    v = U[:,1]
    w = U[:,2]
    magU=np.sqrt(u**2+v**2+w**2)
    
    p = vtk_to_numpy(data.GetPointData().GetArray('pMean'))
    Ma = vtk_to_numpy(data.GetPointData().GetArray('MaMean'))
    rho = vtk_to_numpy(data.GetPointData().GetArray('rhoMean'))    
   

    
    return x,y,z,u,v,w,magU,p,Ma,rho,tri
1st: Paraview slice - vtp file
2nd: cuttingPlane vtp file
Attached Images
File Type: png pvCut.png (88.2 KB, 32 views)
File Type: jpg OFCut.jpg (71.2 KB, 26 views)

Last edited by hxaxtma; December 8, 2022 at 09:00.
hxaxtma is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to contribute to the community of OpenFOAM users and to the OpenFOAM technology wyldckat OpenFOAM 17 November 10, 2017 16:54
Updated native OpenFOAM reader for ParaView 5.3 opencfd OpenFOAM Announcements from ESI-OpenCFD 4 July 13, 2017 11:14
OpenFOAM v3.0+ ?? SBusch OpenFOAM 22 December 26, 2016 15:24
OpenFOAM Training Jan-Apr 2017, Virtual, London, Houston, Berlin cfd.direct OpenFOAM Announcements from Other Sources 0 September 21, 2016 12:50
OpenFOAM Training, London, Chicago, Munich, Houston 2016-2017 cfd.direct OpenFOAM Announcements from Other Sources 0 September 14, 2016 04:19


All times are GMT -4. The time now is 09:23.