I’m trying to post-process an openFOAM simulation and I need to perform the analysis on one of the blocks of the solution (the one referring to the wall patch called ‘plate’). I need to apply an extractBlock filter on the solution and get this patch. The point is that I saw that the block index can vary from case to case and I would like to select the block to extract by its name (‘plate’). I there a way to do this?
This is what my spript currently looks like:
from paraview.simple import *
import os
import vtk.numpy_interface.dataset_adapter as dsa
import numpy as np
casefoam = OpenFOAMReader(FileName=‘case.foam’)
casefoam.MeshRegions = [‘inlet’, ‘internalMesh’, ‘outlet’, ‘plate’, ‘side1’, ‘side2’, ‘upperWall’]
animationScene1 = GetAnimationScene()
animationScene1.GoToLast()
extractBlock1 = ExtractBlock(Input=casefoam)
extractBlock1.BlockIndices = [5]
I’d like to find a way to know what index is assigned to every mesh region name.
A while ago I faced the same problem and took the time to write a small function that returns a dictionnary in which the key is the block name, and the value is the block index. It looks like this:
def getBlockIndices(compositeDataInformation, index=0):
localDict = {}
if compositeDataInformation.GetDataIsMultiPiece():
index += compositeDataInformation.GetNumberOfChildren()
else:
if compositeDataInformation.GetDataIsComposite():
for i in range(compositeDataInformation.GetNumberOfChildren()):
index += 1
_blockName = compositeDataInformation.GetName(i)
localDict[_blockName] = index
leafDict, index = getBlockIndices(compositeDataInformation.GetDataInformation(i).GetCompositeDataInformation(), index)
localDict.update(leafDict)
return localDict, index
#Usage:
getBlockIndices(yourMultiBlockSourceorFilter.GetDataInformation().DataInformation.GetCompositeDataInformation())
I´m still struggeling to run this srcipt (sorry, I´m really new to ParaView/Python).
What exactly do I have to insert in “yourMultiBlockSourceorFilter.” ?
I already tried the filepath of my input file but it´s not working…
Again, thank you for your support!
Okay. I´m still not able to extract the Indices. The file format of my input file in Paraview is .plt or .e. Could this be a part of the problem? I would like to extract the Indices form the Blocks “FuselageBugSection_01, FuselageBugSection_02,…” (picture). I´ve managed to get the names of the Element Blocks with “.ElementBlocks.Available” but this contains no information about the Blockindices.
I use this code to get the names of the ElementBlocks. In this case I opened the exodusfile to get the names.
from paraview.simple import *
reader = ExodusIIReader(FileName=['C:\\Users\\paul\\........\\exodusfile.e'])
name=reader.ElementBlocks.Available
print(name)
To get the Indices with youre function, I tried this:
from paraview.simple import *
reader = ExodusIIReader(FileName=['C:\\Users\\paul\\.........\\exodusfile.e'])
def getBlockIndices(compositeDataInformation, index=0):
localDict = {}
if compositeDataInformation.GetDataIsMultiPiece():
index += compositeDataInformation.GetNumberOfChildren()
else:
if compositeDataInformation.GetDataIsComposite():
for i in range(compositeDataInformation.GetNumberOfChildren()):
index += 1
_blockName = compositeDataInformation.GetName(i)
localDict[_blockName] = index
leafDict, index = getBlockIndices(compositeDataInformation.GetDataInformation(i).GetCompositeDataInformation(), index)
localDict.update(leafDict)
return localDict, index
Indices=getBlockIndices(reader.GetDataInformation().DataInformation.GetCompositeDataInformation())
print(Indices)
I´ve tried to use the following code but it prints out the same results. Is “OpenDataFile” the right way to read the .plt file?
from paraview.simple import *
reader = OpenDataFile('C:\\Users\\paul\\.............\\techplotfile.plt')
def getBlockIndices(compositeDataInformation, index=0):
localDict = {}
if compositeDataInformation.GetDataIsMultiPiece():
index += compositeDataInformation.GetNumberOfChildren()
else:
if compositeDataInformation.GetDataIsComposite():
for i in range(compositeDataInformation.GetNumberOfChildren()):
index += 1
_blockName = compositeDataInformation.GetName(i)
localDict[_blockName] = index
leafDict, index = getBlockIndices(compositeDataInformation.GetDataInformation(i).GetCompositeDataInformation(), index)
localDict.update(leafDict)
return localDict, index
Indices=getBlockIndices(reader.GetDataInformation().DataInformation.GetCompositeDataInformation())
print(Indices)
I found that this only works once all the parts are imported, otherwise it returns that there is nothing in the tree. If you select BlockIndices=[0] it imports everything, so I did something like this:
extractBlock1 = ExtractBlock(registrationName=‘ExtractBlock1’, Input=‘case.foam’)
extractBlock1.BlockIndices = [0]
renderView1 = GetActiveViewOrCreate(‘RenderView’)
extractBlock1Display = Show(extractBlock1, renderView1, ‘GeometryRepresentation’)
Then I could use the above code to create the full dictionary, then select individual blocks by name, convert it to a list and set extractBlock1.BlockIndices using the new list.
Hi, when i run this function with ParaView-5.8.0 it works perfectly, but when i run it with the latest version, \ParaView-5.11.0, does not work.
Do you know if i have to add any command or something similar?
Thank you.
I have many multiblock datasets where “Selectors” list is unknown a priori.
I’d like to loop through a given multiblock and integrate variables per block and output a table of blockname1, integrated_var1, integrated_var2,…, but I don’t see documentation on where to find the list of blocks within a multiBlock object.
How does one get the list of available Selectors, using python, in the new method?