CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 28, 2019, 14:18
Default Python script to sum up a variable for all cells
  #1
Member
 
Hüseyin Can Önel
Join Date: Sep 2018
Location: Ankara, Turkey
Posts: 30
Rep Power: 4
hconel is on a distinguished road
Hello,
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, 18:59
Default
  #2
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):

Code:
# 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="my-ensight-data.case")
Show(case)
domain = ExtractBlock(case)
domain.BlockIndices = [1]
Show(domain)

# 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

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


All times are GMT -4. The time now is 12:54.