Martin7
Martin7

Reputation: 105

Extract data with vtk from .case file

I would like to extract a profile along a line in my geometry, which is a mixed grid containing both hexa and tetra cells.

I tried to write a vtk script but it does not work, giving the error:

field_centers = centers_data.PointData[field[0]].Arrays[0][:, index_1, index_2]

AttributeError: 'VTKNoneArray' object has no attribute 'Arrays'

Can you help me with this?

Here is my script:

import numpy as np
import vtk
from vtk.numpy_interface import dataset_adapter as dsa
from vtk.numpy_interface import algorithms as algs

""" I/O parameters """
path='./'
in_folder = path + 'postprocessing/'
out_folder = path + 'Profiles/'
in_casefile = in_folder + 'RESULTS.case'
time_value = 999999.0 # Select the last time value

fields_vector = (
     ("Velocity", 0, None),
)
fields = fields_vector

reader = vtk.vtkEnSightGoldBinaryReader()
reader.SetCaseFileName(in_casefile)
reader.ReadAllVariablesOff()
reader.SetTimeValue(time_value)

vector=[0.0353205]

# Can handle several x locations
for Lx in vector:
    lineSource = vtk.vtkLineSource()
    lineSource.SetPoint1(Lx, 0, 0)
    lineSource.SetPoint2(Lx, 0.13, 0)
    lineSource.SetResolution(100)
    for i, field in enumerate(fields):
        # Create a probe filter
        probeFilter = vtk.vtkProbeLineFilter()
        probeFilter.SetInputConnection(lineSource.GetOutputPort())
        probeFilter.SetSourceConnection(reader.GetOutputPort())
        index_1 = field[1]
        print(index_1)        
        index_2 = field[2]                
        print(index_2)
        print(lineSource)
        centers_data = dsa.WrapDataObject(lineSource.GetOutputDataObject(0))
        print(centers_data)
        field_centers = centers_data.PointData[field[0]].Arrays[0][:, index_1, index_2]
        z_centers_uniq, z_idx, z_inv, z_cnt = np.unique(
                        centers_data.Points[:, 2].Arrays[0].round(decimals=16),
                        return_index=True,
                        return_inverse=True,
                        return_counts=True)
        np.savetxt(out_folder + field[0] , np.vstack((z_centers_uniq,field_centers[:,0])).T, delimiter=',')

I attach to this message a link (https://filesender.renater.fr/?s=download&token=8c687683-7215-4932-9d89-36ffd5d6e600) to download the following files:

Thanks a lot for your help!

Upvotes: 0

Views: 30

Answers (0)

Related Questions