CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Visualization & Post-Processing Software > ParaView

[OpenFOAM] Get cell center coordinates in a python script

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By francois

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 18, 2014, 11:33
Default 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
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.

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
Any help will be warmly welcome.
Thanks !

François
Swift likes this.
francois is offline   Reply With Quote

Old   January 12, 2017, 07:47
Default
  #2
Senior Member
 
Thomas Oliveira
Join Date: Apr 2015
Posts: 114
Rep Power: 12
t.oliveira is on a distinguished road
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
t.oliveira is offline   Reply With Quote

Old   June 3, 2017, 09:20
Default
  #3
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
francois is on a distinguished road
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
francois is offline   Reply With Quote

Reply


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
[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


All times are GMT -4. The time now is 02:35.