|
[Sponsors] |
[General] Python script to sum up a variable for all cells |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 28, 2019, 14:18 |
Python script to sum up a variable for all cells
|
#1 |
Member
Hüseyin Can Önel
Join Date: Sep 2018
Location: Ankara, Turkey
Posts: 47
Rep Power: 8 |
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. |
|
February 7, 2019, 18:59 |
|
#2 |
New Member
Join Date: Feb 2019
Location: Czech Republic
Posts: 2
Rep Power: 0 |
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 |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[snappyHexMesh] SnappyHexMesh running killed! | Mark JIN | OpenFOAM Meshing & Mesh Conversion | 7 | June 14, 2022 02:37 |
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 |