CFD Online Logo CFD Online URL
Home > Forums > OpenFOAM Paraview & paraFoam

Get cell center coordinates in a python script

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

LinkBack Thread Tools Display Modes
Old   June 18, 2014, 10:33
Default Get cell center coordinates in a python script
Senior Member
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 142
Rep Power: 9
francois is on a distinguished road
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.

import numpy as np

try: paraview.simple
except: from paraview.simple import *

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

# 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

for i in range(nbPoints):
    coord = dataPlane.GetPoint(i)
    xx, yy, zz = coord[:3]


print 'x=',x
print 'y=',y
print 'z=',z
Any help will be warmly welcome.
Thanks !

francois is offline   Reply With Quote

Old   January 12, 2017, 07:47
Thomas Oliveira
Join Date: Apr 2015
Posts: 88
Rep Power: 3
t.oliveira is on a distinguished road

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,
t.oliveira is offline   Reply With Quote


Thread Tools
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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
extract the cell center coordinates if the CELLID is know openfoammaofnepo ParaView 2 January 12, 2017 07:54
?? How to get cell center coordinates? erica FLUENT 0 May 11, 2005 22:02
interpolation from cell center to vertices Zhang Main CFD Forum 3 August 22, 2003 07:31
calculate cell volume, center...? Paul Main CFD Forum 5 June 21, 2003 12:55
About Cell Center Harry FLUENT 0 December 3, 2000 05:33

All times are GMT -4. The time now is 14:43.