Filter to apply variable to blockID

Hi All,
I’ve been trying to transform some data I have output from a C++ code I have developed. It is an exodus file with elemental variables. My simulations involve grains from solidification and output a voxel mesh. I am able to load this Paraview and see my gID elemental variable, but I need a way to have those variables be assigned as the BlockID (for further processing and mesh clean up in Cubit). Is there a way to do this in Paraview?

Thanks!
P.S. I can provide a sample exodus to demonstrate my issue upon request.

Hello,

One way might be to use the vtkSplitByCellScalarFilter included in the vtk library in the Programmable Filter.

The procedure is to load the exodus file into ParaView, then use the Merge Blocks filter to convert it to Unstructured Grid, and then apply the Programmable filter. In the Programmable filter, set the Output Data Set Type to vtkMultiBlockDataSet, and write the following code in the Script field.

import vtk

input = self.GetInput()
output = self.GetOutput()

splitter = vtk.vtkSplitByCellScalarFilter()
splitter.SetInputData(input)
splitter.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS, "gID")
splitter.PassAllPointsOff()
splitter.Update()

output.ShallowCopy(splitter.GetOutput())

Hi Kyoshimi,
I tried your approach and unfortunately while the script does successfully create vtkBlockColors, I have no way to export this as BlockIDs. The exodus I export still only has one BlockID. Additionally I get an error “Block ids are not unique across the hierarchy”. It seems that although I can make vtkBlockColors, there is no way to export. I have attached a sample mesh if anyone would like to recreate the issue, or give this a try.

Thanks
Exodus_Example.tar.gz (168.1 KB)

Hello,

After saving the file as VTK Multi Block Files (*.vtm), how about adding a “Block” tag around each “DataSet” tag in the vtm file, as shown below?

<VTKFile type="vtkMultiBlockDataSet" version="1.0" byte_order="LittleEndian" header_type="UInt64">
  <vtkMultiBlockDataSet>
    <DataSet index="0" name="int_gID_72" file="aaa/aaa_0_0.vtu"/>
    <DataSet index="1" name="int_gID_323" file="aaa/aaa_1_0.vtu"/>
    <DataSet index="2" name="int_gID_239" file="aaa/aaa_2_0.vtu"/>

---->

<VTKFile type="vtkMultiBlockDataSet" version="1.0" byte_order="LittleEndian" header_type="UInt64">
  <vtkMultiBlockDataSet>
    <Block index="0" name="Blocks_0">
      <DataSet index="0" name="int_gID_72" file="aaa/aaa_0_0.vtu"/>
    </Block>
    <Block index="1" name="Blocks_1">
      <DataSet index="0" name="int_gID_323" file="aaa/aaa_1_0.vtu"/>
    </Block>
    <Block index="2" name="Blocks_2">
      <DataSet index="0" name="int_gID_239" file="aaa/aaa_2_0.vtu"/>
    </Block>

P.S. For doing this, you could use, for example, a simple Python script like the one attached:
create_blockId.py (773 Bytes)

python create_blockId.py -i aaa.vtm -o out.vtm