Hi. I have the following script, which works as a macro but not from command-line (i.e. pvpython script.py
).
Even when running as a macro, this weird thing happens where for the values of Surface Flow to be non-zero, I need to click on the associated slice (it boldens) and press ‘Apply’. I have to do this four times since the macro creates four slices, for getting the four values of Surface Flow.
I cannot get this to work using command-line, I get Surface Flow values as 0,0,0.
Please help. I’m using Paraview version 5.6.0.
#### import the simple module from the paraview
from paraview.simple import *
# create a new 'OpenFOAMReader'
logfoam = OpenFOAMReader(FileName='log.foam')
logfoam.MeshRegions = ['internalMesh']
logfoam.CellArrays = ['U', 'eigVals', 'eigVecs', 'p', 'tau', 'theta']
SetActiveSource(logfoam)
#### ABOVE CYLINDER
# create a new 'Extract Cells By Region'
extractCellsByRegion1 = ExtractCellsByRegion(Input=logfoam)
extractCellsByRegion1.IntersectWith = 'Box'
extractCellsByRegion1.IntersectWith.Position = [-0.25, 1.75, -0.25]
extractCellsByRegion1.IntersectWith.Scale = [0.01, 0.5, 1.5]
SetActiveSource(extractCellsByRegion1)
# create a new 'Slice'
slice1 = Slice(Input=extractCellsByRegion1)
slice1.SliceType = 'Plane'
slice1.SliceOffsetValues = [0.0]
slice1.SliceType.Origin = [0.0, 1.75, 0.5]
SetActiveSource(slice1)
# create a new 'Surface Flow'
surfaceFlow1 = SurfaceFlow(Input=slice1)
surfaceFlow1.SelectInputVectors = ['POINTS', 'U']
SetActiveSource(logfoam)
#### BELOW CYLINDER
# create a new 'Extract Cells By Region'
extractCellsByRegion2 = ExtractCellsByRegion(Input=logfoam)
extractCellsByRegion2.IntersectWith = 'Box'
extractCellsByRegion2.IntersectWith.Position = [-0.25, -1.25, -0.25]
extractCellsByRegion2.IntersectWith.Scale = [0.01, 0.5, 1.5]
SetActiveSource(extractCellsByRegion2)
# create a new 'Slice'
slice2 = Slice(Input=extractCellsByRegion2)
slice2.SliceType = 'Plane'
slice2.SliceOffsetValues = [0.0]
slice2.SliceType.Origin = [0.0, -1.25, 0.5]
SetActiveSource(slice2)
# create a new 'Surface Flow'
surfaceFlow2 = SurfaceFlow(Input=slice2)
surfaceFlow2.SelectInputVectors = ['POINTS', 'U']
SetActiveSource(logfoam)
#### BEFORE CYLINDER
# create a new 'Extract Cells By Region'
extractCellsByRegion3 = ExtractCellsByRegion(Input=logfoam)
extractCellsByRegion3.IntersectWith = 'Box'
extractCellsByRegion3.IntersectWith.Position = [-2.5, 0, -0.25]
extractCellsByRegion3.IntersectWith.Scale = [0.01, 1.5, 1.5]
SetActiveSource(extractCellsByRegion3)
# create a new 'Slice'
slice3 = Slice(Input=extractCellsByRegion3)
slice3.SliceType = 'Plane'
slice3.SliceOffsetValues = [0.0]
slice3.SliceType.Origin = [-2.25, 0, 0.5]
SetActiveSource(slice3)
# create a new 'Surface Flow'
surfaceFlow3 = SurfaceFlow(Input=slice3)
surfaceFlow3.SelectInputVectors = ['POINTS', 'U']
SetActiveSource(logfoam)
#### AFTER CYLINDER
# create a new 'Extract Cells By Region'
extractCellsByRegion4 = ExtractCellsByRegion(Input=logfoam)
extractCellsByRegion4.IntersectWith = 'Box'
extractCellsByRegion4.IntersectWith.Position = [2.5, 0, -0.25]
extractCellsByRegion4.IntersectWith.Scale = [0.01, 1.5, 1.5]
SetActiveSource(extractCellsByRegion4)
# create a new 'Slice'
slice4 = Slice(Input=extractCellsByRegion4)
slice4.SliceType = 'Plane'
slice4.SliceOffsetValues = [0.0]
slice4.SliceType.Origin = [2.75, 0, 0.5]
SetActiveSource(slice4)
# create a new 'Surface Flow'
surfaceFlow4 = SurfaceFlow(Input=slice4)
surfaceFlow4.SelectInputVectors = ['POINTS', 'U']
SaveData('test.csv', proxy=surfaceFlow4)