|
[Sponsors] |
[OpenFOAM] Get cell center coordinates in a python script |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
June 18, 2014, 11:33 |
Get cell center coordinates in a python script
|
#1 |
Senior Member
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17 |
Hi all,
I've made a python script that create a slice and extract the points coordinates of the vertex as well as the velocity components. But I'm unable to obtain the cell center coordinates, howto do that ? You will see below my script which can extract the points coordinates. Code:
import numpy as np try: paraview.simple except: from paraview.simple import * paraview.simple._DisableFirstRenderCameraReset() from vtk.util import numpy_support as npvtk # Define the OpenFOAM data source case_OpenFOAM = OpenDataFile('./profile4.OpenFOAM') case_OpenFOAM.MeshParts = ['internalMesh'] case_OpenFOAM.VolumeFields = ['p', 'U'] print case_OpenFOAM.TimestepValues mergedcase_OpenFOAM = MergeBlocks(case_OpenFOAM) dataOpenFOAM = servermanager.Fetch(mergedcase_OpenFOAM) # Select the active source SetActiveSource(mergedcase_OpenFOAM) # Define the plane Slice1 = Slice(SliceType="Plane") Slice1.SliceType = 'Plane' Slice1.SliceType.Origin = [0.01,0,0] Slice1.SliceType.Normal = [1,0,0] Slice1.Triangulatetheslice = 0 # Don't triangulate the slice dataPlane = servermanager.Fetch(Slice1) nbCells = dataPlane.GetNumberOfCells() nbPoints = dataPlane.GetNumberOfPoints() print 'Number of cells in the slice', nbCells print 'Number of points in the slice', nbPoints # Put the velocity vector U into a numpy array U = npvtk.vtk_to_numpy(dataPlane.GetCellData().GetArray('U')) # Put the points coordinates in x, y and z arrays x=[] y=[] z=[] for i in range(nbPoints): coord = dataPlane.GetPoint(i) xx, yy, zz = coord[:3] x.append(xx) y.append(yy) z.append(zz) x=np.array(x) y=np.array(y) z=np.array(z) print 'x=',x print 'y=',y print 'z=',z Thanks ! François |
|
January 12, 2017, 07:47 |
|
#2 |
Senior Member
Thomas Oliveira
Join Date: Apr 2015
Posts: 114
Rep Power: 12 |
Hi,
To obtain the cell center coordinates, I run the standard utility writeCellCentres. It creates fields ccx, ccy and ccz with the x, y and z components of the cell center coordinates, which can be loaded in Paraview. There is also the cellCenters utility created by @opedrofunk, which is "similar to the writeCellCentres utility[...], except that it outputs a single file with the vector coordinates of the cell center positions". Best wishes, Thomas |
|
June 3, 2017, 09:20 |
|
#3 |
Senior Member
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17 |
Indeed the writeCellCentres do the trick.
But my goal is to obtain the cell centers in a Python script using the paraview.simple module. Anyway thank you very much Thomas for your advice, it's very nice from you. Have a good day. François |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[General] extract the cell center coordinates if the CELLID is know | openfoammaofnepo | ParaView | 2 | January 12, 2017 07:54 |
[General] Python script: Auto-scale color scale | julien.decharentenay | ParaView | 2 | December 9, 2013 06:39 |
CentFOAM Python Script Installation: Error | socon009 | OpenFOAM Installation | 2 | May 26, 2012 10:36 |
?? How to get cell center coordinates? | erica | FLUENT | 0 | May 11, 2005 23:02 |
About Cell Center | Harry | FLUENT | 0 | December 3, 2000 05:33 |