Hi all,
I am new in vtk and I try to extract a profile along a line in my geometry. My issue is that, for certain locations in the streamwise direction, I do not obtain the same profiles with the Paraview visualization and the plot extraction.
It works well and I obtain the same plot with Paraview and vtk extraction for this location (Lx=0.0353205m) :
But not for this one (Lx=0.0873205m) :
Here is my vtk script. Note that my computation is not periodic in the x, y, or z direction that is why I am not averaging in a particular direction, I draw 2 slices in my 3D geometry to create a line and save the fields associated to this line. My mesh is made of structured cells.
#!/usr/bin/env python3.8
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='/home/david/Partage_JZ/04-jet0/06_HTLES/01_TEST_HTLES_v534/01_RANS_B_open/RESU/20231219-2125/'
in_folder = path + 'postprocessing/'
out_folder = path + 'Profiles3/'
in_casefile = in_folder + 'RESULTS.case'
time_value = 999999.0 # Select the last time value
fields_vector = (
("Velocity", 0, None),
)
fields = fields_vector
origins_normals_y = (((0.0, 0.0, 0.0), (0, 1, 0)), )
reader = vtk.vtkEnSightGoldBinaryReader()
reader.SetCaseFileName(in_casefile)
reader.ReadAllVariablesOff()
reader.SetTimeValue(time_value)
vector=[0.0873205]
# Can handle several x locations
for Lx in vector:
origins_normals_x = (((Lx, 0.0, 0.0), (1, 0, 0)), )
reader = vtk.vtkEnSightGoldBinaryReader()
reader.SetCaseFileName(in_casefile)
reader.ReadAllVariablesOff()
reader.SetTimeValue(time_value)
# Can handle several fields
for i, field in enumerate(fields):
print(field)
reader.SetCellArrayStatus(field[0], 1)
reader.Update()
fluid_domain = vtk.vtkExtractBlock()
fluid_domain.SetInputConnection(reader.GetOutputPort())
fluid_domain.AddIndex(1)
fluid_domain.SetPruneOutput(True)
fluid_domain.Update()
# Possibly several y plans
for j, org_nor in enumerate(origins_normals_y):
plane1 = vtk.vtkPlane()
plane1.SetOrigin(org_nor[0])
plane1.SetNormal(org_nor[1])
slice1 = vtk.vtkCutter()
slice1.SetCutFunction(plane1)
slice1.SetInputConnection(fluid_domain.GetOutputPort(0))
slice1.GenerateTrianglesOff()
slice1.Update()
# Possibly several x plans
for k, org_nor_x in enumerate(origins_normals_x):
plane2 = vtk.vtkPlane()
plane2.SetOrigin(org_nor_x[0])
plane2.SetNormal(org_nor_x[1])
slice2 = vtk.vtkCutter()
slice2.SetCutFunction(plane2)
slice2.SetInputConnection(slice1.GetOutputPort(0))
slice2.GenerateTrianglesOff()
slice2.Update()
cell_centers = vtk.vtkCellCenters()
cell_centers.SetInputConnection(slice2.GetOutputPort(0))
cell_centers.Update()
index_1 = field[1]
index_2 = field[2]
centers_data = dsa.WrapDataObject(cell_centers.GetOutputDataObject(0))
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=',')
Can someone explain me why it is not working for all the locations?
Thanks a lot !