Select a single cell with pvpython script

Hi,

I apologise if I have overlooked the solution to this question, but I haven’t found it yet.

In order to determine a quasi steady state, we in the team like to square the speed and have the development over time output. Using pythoncalculator and plotDataOverTime, this takes half a day depending on the results. Therefore, I would like to select only one single cell, as the result of the pythonCalculator is written to all cells.

My example up to the selection looks like this:

import paraview

from paraview.simple import *


spreadSheetView1 = CreateView('SpreadSheetView')
spreadSheetView1.ColumnToSort = ''
spreadSheetView1.BlockSize = 1024
spreadSheetView1.HiddenColumnLabels = ['Point ID', 'LiquidVel', 'LiquidVel_Magnitude', 'Points', 'Points_Magnitude', 'vtkValidPointMask', 'Block Number']

SetActiveView(None)
layout1 = CreateLayout(name='Layout #1')
SetActiveView(spreadSheetView1)

fluidpvd = PVDReader(registrationName='Fluid.pvd', FileName=pvd_file)
fluidpvd.CellArrays = ['LiquidVel']

pythonCalculator1 = PythonCalculator(registrationName='PythonCalculator1', Input=fluidpvd)
pythonCalculator1.Expression = 'sum(mag(LiquidVel)*mag(LiquidVel))'
pythonCalculator1.ArrayAssociation = 'Cell Data'
pythonCalculator1.ArrayName = 'squaredVelocity'

Can someone tell me how to select for example the cell (0,0,0) and plot the squaredVelocity of this one cell over time?

Many thanks in advance!

Hi @mike518

Use SelectCells method ?

https://www.paraview.org/paraview-docs/latest/python/paraview.simple.html#paraview.simple.SelectCells

Hi @mwestphal

Many thanks for the quick reply Mathieu.

I have already tried a few things with SelectCells, but I don’t understand which parameters I have to enter in the function so that I get the cells 0,0,0 or 1,1,1 and can then use them for plotDataOverTime.

Could you help me with this?

Hum, if you want to select the first cell by id you can do that:

SelectIDs(IDs=[0], FieldType='CELL')

Then PlotSelectionOverTime filter.

And the input for the PlotSelectionOverTime filter is SelectedIDs or do i have to extractSelection first?

No need to extract selection first.

I have adapted the code as follows

fluidpvd = PVDReader(registrationName='Fluid.pvd', FileName=pvd_file)
fluidpvd.CellArrays = ['LiquidVel']

pythonCalculator1 = PythonCalculator(registrationName='PythonCalculator1', Input=fluidpvd)
pythonCalculator1.Expression = 'sum(mag(LiquidVel)*mag(LiquidVel))'
pythonCalculator1.ArrayAssociation = 'Cell Data'
pythonCalculator1.ArrayName = 'squaredVelocity'

SelectIDs(IDs=[0], FieldType='CELL')

plotSelectionOverTime1 = PlotSelectionOverTime(registrationName='PlotSelectionOverTime1', Input=pythonCalculator1, Selection=SelectIDs)

SetActiveView(None)

spreadSheetView3 = CreateView('SpreadSheetView')
spreadSheetView3.ColumnToSort = ''
spreadSheetView3.BlockSize = 1024
layout1 = GetLayoutByName("Layout #1")
AssignViewToLayout(view=spreadSheetView3, layout=layout1, hint=3)

plotSelectionOverTime1Display = Show(plotSelectionOverTime1, spreadSheetView3, 'SpreadSheetRepresentation')

and get the following error

File "/home/SelectCell.py", line 73, in <module>
    plotSelectionOverTime1 = PlotSelectionOverTime(registrationName='PlotSelectionOverTime1', Input=pythonCalculator1, Selection=SelectIDs)
  File "/usr/local/lib/python3.10/site-packages/paraview/simple.py", line 2706, in CreateObject
    SetProperties(px, **params)
  File "/usr/local/lib/python3.10/site-packages/paraview/simple.py", line 851, in SetProperties
    pyproxy.__setattr__(param, params[param])
  File "/usr/local/lib/python3.10/site-packages/paraview/servermanager.py", line 485, in __setattr__
    setter(self, value)
  File "/usr/local/lib/python3.10/site-packages/paraview/servermanager.py", line 2618, in setProperty
    return self.SetPropertyWithName(propName, value)
  File "/usr/local/lib/python3.10/site-packages/paraview/servermanager.py", line 344, in SetPropertyWithName
    prop.SetData(arg)
  File "/usr/local/lib/python3.10/site-packages/paraview/servermanager.py", line 1467, in SetData
    self.SMProperty.AddInputConnection(value.SMProxy, value.Port)
AttributeError: 'function' object has no attribute 'SMProxy'

were line 73 is

plotSelectionOverTime1 = PlotSelectionOverTime(registrationName='PlotSelectionOverTime1', Input=pythonCalculator1, Selection=SelectIDs)

Can you please tell me what i have done wrong?

This syntax should work:

QuerySelect(QueryString='(id == 0)', FieldType='CELL', InsideOut=0)
PlotSelectionOverTime()
CreateLayout()
CreateView('XYChartView')
AssignViewToLayout()
Show()

It worked, thank you very much!