Scripting for run same Python code 20-40 times (corresponding to different slices)

Hello all,

I am trying to average the data in the span-wise direction referring to the previous posts:

I am now slicing the span-wise area in 10-20 slices and then will average these slices to get the averaged span-wise slice. Using the help of @ paraview_ran I got a running script for taking the slice which is as follows:

from paraview.simple import *
#### disable automatic camera reset on 'Show'

# create a new 'OpenFOAMReader'
demofoam = OpenFOAMReader(FileName='<FOAM_PATH>')
demofoam.MeshRegions = ['CYLINDER']
demofoam.CellArrays = ['U', 'p']

# Properties modified on demofoam
demofoam.CellArrays = ['U']

# get active view
renderView1 = GetActiveViewOrCreate('RenderView')

####Then slice data using the code similar to this:

# find source
e0foam = FindSource('demo.foam')

# create a new 'Plot On Intersection Curves'
plotOnIntersectionCurves1 = PlotOnIntersectionCurves(Input=e0foam)
plotOnIntersectionCurves1.SliceType = 'Plane'

# Properties modified on plotOnIntersectionCurves1.SliceType
plotOnIntersectionCurves1.SliceType.Origin = [0.0, 0.0, 0.9]
plotOnIntersectionCurves1.SliceType.Normal = [0.0, 0.0, 1.0]

# get layout
layout1 = GetLayout()

# save data
SaveData('SAVE_LOACATION/demo.csv', proxy=plotOnIntersectionCurves1)

To work with this I need to run this code (pvpython at different span-wise location for 10 times, instead I want to automate this slicing process by script/bash file, is it easily doable ? Any comment suggestions will be a great help.

Yes, use a for loop in your script ?

1 Like

Thanks @mwestphal for your help. Could you please share some link or video to include the looping ?

1 Like

Thanks a lot @mwestphal for your prompt reply and sharing this.

@mwestphal I guess this is a general link for the Python, is there any specific video/link dealing with the loop for the slices (closely related to Paraview)?

@proxy I don’t know if this will be helpful, but here’s an example of a script I created last year to loop through both time and end point coordinates for a line, gathering the data in a Pandas DataFrame, and finally saving out as a CSV file. I ran it as a macro in Paraview after loading the data source I wanted.

Embedded in the comments is a reference to a video I watched that helped me set up the basics for the script. I know it’s not looping through slices, but hopefully you can get some ideas from how I loop through line end point coordinates.

1 Like