CFD Online Logo CFD Online URL
Home > Forums > Visualization & Post-Processing Software > ParaView

[General] Python script to sum up a variable for all cells

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

LinkBack Thread Tools Search this Thread Display Modes
Old   January 28, 2019, 13:18
Default Python script to sum up a variable for all cells
Hüseyin Can Önel
Join Date: Sep 2018
Location: Ankara, Turkey
Posts: 34
Rep Power: 4
hconel is on a distinguished road
I am trying to write a Python script to use in Paraview, where I need:
( component of a vector field ) * ( cell volume )
summed up for all cells in the domain. I have no clue where to start and couldn't find a similar script. Can someone give me an idea for this?
Thanks in advance.
hconel is offline   Reply With Quote

Old   February 7, 2019, 17:59
New Member
Join Date: Feb 2019
Location: Czech Republic
Posts: 2
Rep Power: 0
tkarabela is on a distinguished road
Hi, you can use the Calculator to make a new variable from your vector field and then use the Integrate filter to compute the sum. Here is the example in Python (using Paraview 5.6, but it should work in earlier versions too):

# Load your case and extract the domain - this will be specific for your case.
# The example below is suitable for OpenFOAM case exported using foamToEnsight.
from paraview.simple import *
case = EnSightReader(CaseFileName="")
domain = ExtractBlock(case)
domain.BlockIndices = [1]

# If you have data in nodes, interpolate to cells first,
# otherwise skip this step.
domain = PointDatatoCellData(domain)

# Extract the vector component to scalar
# (here my variable is "U", replace it with your variable name).
calc = Calculator(domain)
calc.AttributeType = "Cell Data"
calc.Function = "U_X"

# Integrate over domain.
integrate = IntegrateVariables(calc)
result = integrate.GetCellDataInformation().GetArray("Result").GetRange()[0]
print "Summed value is", result
Lead software developer at ENGINN EFFECT
tkarabela is offline   Reply With Quote


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
[snappyHexMesh] SnappyHexMesh running killed! Mark JIN OpenFOAM Meshing & Mesh Conversion 3 March 12, 2020 17:50
cellZone not taking all the cells inside rahulksoni OpenFOAM 0 January 16, 2019 01:16
Help for the small implementation in turbulence model shipman OpenFOAM Programming & Development 25 March 19, 2014 10:08
emag beta feature: charge density charlotte CFX 4 March 22, 2011 09:14
Replace periodic by inlet-outlet pair lego CFX 3 November 5, 2002 20:09

All times are GMT -4. The time now is 03:42.