def pass_array(self): print('passing arrays') passer = vtk.vtkPassArrays() passer.SetInputConnection(self.mesh.GetOutputPort()) passer.AddCellDataArray('elemTag') passer.Update() self.mesh = passer
def vtk_ascii_write(self, unstructuredgrid_object, fname): ''' class method that writes a vtk unstructured grid object to a file (save the mesh) unstructuredgrid_object=vtk unstructured grid object fname=text string with path/filename target for writing mesh ''' pa = vtk.vtkPassArrays() pa.SetInputConnection(unstructuredgrid_object.GetOutputPort()) writer = vtk.vtkUnstructuredGridWriter() writer.SetFileName(fname) writer.SetInputConnection(pa.GetOutputPort()) writer.Update() writer.Write()
import vtk import h5py file_path1 = "/home/ksansom/caseFiles/mri/VWI_proj/case1/vmtk/dsa2mra_trans.vtp" file_path2 = "/home/ksansom/caseFiles/mri/VWI_proj/case1/vmtk/smooth_case1_vmtk_decimate.vtp" out_path = "/home/ksansom/caseFiles/mri/VWI_proj/case1/vmtk/dsa2mra_icp.vtp" reader1 = vtk.vtkXMLPolyDataReader() reader1.SetFileName(file_path1) reader2 = vtk.vtkXMLPolyDataReader() reader2.SetFileName(file_path2) pass_filt = vtk.vtkPassArrays() pass_filt.SetInputConnection(reader1.GetOutputPort()) pass_filt.Update() # don't need this now trans_target = vtk.vtkTransform() trans_target.Scale(0.001, 0.001, 0.001) trans_target_filt = vtk.vtkTransformPolyDataFilter() trans_target_filt.SetInputConnection(reader2.GetOutputPort()) trans_target_filt.SetTransform(trans_target) trans_target_filt.Update() source = vtk.vtkPolyData() target = vtk.vtkPolyData() source.ShallowCopy(pass_filt.GetOutput()) target.ShallowCopy(trans_target_filt.GetOutput())
def Execute(args): print("clip centerlines") reader_ctr = vmtkscripts.vmtkSurfaceReader() reader_ctr.InputFileName = args.centerlines reader_ctr.Execute() print(args.clean_ctr) if (args.clean_ctr): cleaner = vtk.vtkCleanPolyData() cleaner.PointMergingOn() cleaner.ConvertPolysToLinesOff() cleaner.SetInputData(reader_ctr.Surface) cleaner.Update() centerlines = cleaner.GetOutput() else: centerlines = reader_ctr.Surface centerlines.BuildLinks() centerlines.BuildCells() reader_br = vmtkscripts.vmtkSurfaceReader() reader_br.InputFileName = args.boundary_file reader_br.Execute() boundary_reference = reader_br.Surface #print(pt1, pt2) #v = pt2 - pt1 #pt1 - pt2 #v_mag = np.linalg.norm(v) #n = v / v_mag #print("should be 1.0", np.linalg.norm(n), n) #https://en.wikipedia.org/wiki/Vector_projection # get starting point from centroid by projecting centroid onto normal direction #neck_projection = np.dot(neck_centroid-pt1, n)*n #neck_start_pt = pt1 + neck_projection new_ctr = vtk.vtkPolyData() new_ctr.DeepCopy(centerlines) locator = vtk.vtkPointLocator() locator.SetDataSet(new_ctr) locator.BuildLocator() cell_loc = vtk.vtkCellLocator() cell_loc.SetDataSet(new_ctr) cell_loc.BuildLocator() clip_ids = [] new_points = vtk.vtkPoints() new_cell_array = vtk.vtkCellArray() scalar = vtk.vtkIntArray() scalar.SetNumberOfComponents(1) scalar.SetNumberOfTuples(new_ctr.GetNumberOfPoints()) scalar.SetName("clipper") scalar.Fill(0) for i in range(boundary_reference.GetNumberOfPoints()): pt = boundary_reference.GetPoint(i) #B pt_b = np.array(pt) #print(pt) #ctr_ptId = locator.FindClosestPoint(pt) id_list = vtk.vtkIdList() locator.FindClosestNPoints(2, pt, id_list) ctr1 = np.array(new_ctr.GetPoint(id_list.GetId(0))) # A ctr2 = np.array(new_ctr.GetPoint(id_list.GetId(1))) #ctr3 = np.array(new_ctr.GetPoint(ctr_ptId + 1)) n_br = np.array(boundary_reference.GetPointData().GetArray( "BoundaryNormals").GetTuple(i)) n_s_2 = np.dot(pt_b - ctr2, n_br) n_s_1 = np.dot(pt_b - ctr1, n_br) if (n_s_1 < 0.0): proj_start = ctr2 start_id = id_list.GetId(0) elif (n_s_2 < 0.0): proj_start = ctr1 start_id = id_list.GetId(1) else: print("two closest points are on same side") #Get each vector normal to outlet n_ctr = np.array(new_ctr.GetPointData().GetArray( "FrenetTangent").GetTuple(start_id)) if (np.dot(n_br, n_ctr) < 0.0): n_ctr = -1.0 * n_ctr #outlet centroid projected onto centerline based on FrenetTangent proj_vec = np.dot(n_br, pt_b - proj_start) * n_ctr proj_end = proj_vec + proj_start two_closest = vtk.vtkIdList() locator.FindClosestNPoints(2, proj_end, two_closest) vec_closest = np.array(new_ctr.GetPoints().GetPoint( two_closest.GetId(0))) - proj_end point_furthest = proj_end - vec_closest new_ctr.GetPoints().SetPoint(two_closest.GetId(1), tuple(point_furthest)) #new_ctr.GetPoints().SetPoint(two_closest.GetId(0), proj_end_other) #new_ctr.GetPointData().GetArray("FrenetTangent").SetTuple(closest_to, tuple(n_br)) cell_id_list = vtk.vtkIdList() new_ctr.GetPointCells(two_closest.GetId(0), cell_id_list) print("haller") print(cell_id_list.GetNumberOfIds()) ctr_cell = new_ctr.GetCell(cell_id_list.GetId(0)) #print(ctr_cell) print(n_s) if (n_s < -np.finfo(float).eps): start = cell_id_match + 1 stop = ctr_cell.GetNumberOfPoints() step = int(1) else: start = cell_id_match - 1 stop = int(-1) step = int(-1) new_poly_line = vtk.vtkPolyLine() for k in range(start, stop, step): old_pt_id = ctr_cell.GetPointIds().GetId(k) scalar.SetTuple(old_pt_id, [1]) #new_pt_d = new_points.InsertNextPoint(new_ctr.GetPonts().GetPoint(old_pt_id) #new_poly_line.GetPointIds().InsertNextId(old_pt_id) new_ctr.GetPointData().AddArray(scalar) new_ctr.GetPointData().SetActiveScalars("clipper") pass_arrays = vtk.vtkPassArrays() pass_arrays.SetInputData(new_ctr) pass_arrays.UseFieldTypesOn() pass_arrays.AddArray(vtk.vtkDataObject.POINT, "clipper") pass_arrays.GetOutput().GetPointData().SetActiveScalars("clipper") pass_arrays.AddFieldType(vtk.vtkDataObject.POINT) pass_arrays.AddFieldType(vtk.vtkDataObject.CELL) pass_arrays.Update() clip = vtk.vtkClipPolyData() clip.SetValue(0.5) clip.SetInputConnection(pass_arrays.GetOutputPort()) clip.InsideOutOn() #clip.GetOutput().GetPointData().CopyScalarsOff() #clip.GetOutput().GetPointData().CopyVectorsOff() #clip.GetOutput().GetCellData().CopyScalarsOff() #clip.GetOutput().GetCellData().CopyVectorsOff() clip.Update() writer = vmtkscripts.vmtkSurfaceWriter() writer.OutputFileName = args.out_file if (args.clean_ctr): cleaner2 = vtk.vtkCleanPolyData() cleaner2.PointMergingOn() cleaner.ConvertPolysToLinesOff() cleaner2.SetInputConnection(clip.GetOutputPort()) cleaner2.Update() writer.Input = cleaner2.GetOutput() else: writer.Input = clip.GetOutput() writer.Execute()
def post_proc_cfd(dir_path, vtu_input, cell_type="point", vtu_output_1="calc_test_node.vtu", vtu_output_2="calc_test_node_stats.vtu", N_peak=3): reader = vtk.vtkXMLUnstructuredGridReader() reader.SetFileName(os.path.join(dir_path, vtu_input)) reader.Update() N = reader.GetNumberOfTimeSteps() print(N) #N = test.GetNumberOfBlocks()ls #block = test.GetBlock(0) #for i in range(N): # print(i, test.GetMetaData(i).Get(vtk.vtkCompositeDataSet.NAME())) #grid = reader.GetOutput() #wallshear = grid.GetCellData().GetArray("x_wall_shear") #print(wallshear) calc1 = vtk.vtkArrayCalculator() calc1.SetFunction("sqrt(x_wall_shear^2+y_wall_shear^2+z_wall_shear^2)") calc1.AddScalarVariable("x_wall_shear", "x_wall_shear",0) calc1.AddScalarVariable("y_wall_shear", "y_wall_shear",0) calc1.AddScalarVariable("z_wall_shear", "z_wall_shear",0) calc1.SetResultArrayName("WSS") calc1.SetInputConnection(reader.GetOutputPort()) if(cell_type == "cell"): calc1.SetAttributeModeToUseCellData() vtk_process = vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS vtk_data_type = vtk.vtkDataObject.CELL else: calc1.SetAttributeModeToUsePointData() vtk_process = vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS vtk_data_type = vtk.vtkDataObject.POINT calc1.SetResultArrayType(vtk.VTK_DOUBLE) x_WSS_grad = vtk.vtkGradientFilter() x_WSS_grad.SetInputConnection(calc1.GetOutputPort()) x_WSS_grad.ComputeGradientOn() x_WSS_grad.FasterApproximationOff() x_WSS_grad.SetResultArrayName("x_WSS_grad") x_WSS_grad.SetInputArrayToProcess(0, 0, 0, vtk_process, "x_wall_shear") y_WSS_grad = vtk.vtkGradientFilter() y_WSS_grad.SetInputConnection(x_WSS_grad.GetOutputPort()) y_WSS_grad.ComputeGradientOn() y_WSS_grad.FasterApproximationOff() y_WSS_grad.SetResultArrayName("y_WSS_grad") x_WSS_grad.SetInputArrayToProcess(0, 0, 0, vtk_process, "y_wall_shear") z_WSS_grad = vtk.vtkGradientFilter() z_WSS_grad.SetInputConnection(y_WSS_grad.GetOutputPort()) z_WSS_grad.ComputeGradientOn() z_WSS_grad.FasterApproximationOff() z_WSS_grad.SetResultArrayName("z_WSS_grad") z_WSS_grad.SetInputArrayToProcess(0, 0, 0, vtk_process, "z_wall_shear") calc2 = vtk.vtkArrayCalculator() calc2.AddScalarVariable("x_component", "x_WSS_grad",0) calc2.AddScalarVariable("y_component", "y_WSS_grad",1) calc2.AddScalarVariable("z_component", "z_WSS_grad",2) calc2.SetFunction("sqrt(x_component^2+y_component^2+z_component^2)") calc2.SetResultArrayName("WSSG") calc2.SetInputConnection(z_WSS_grad.GetOutputPort()) if(cell_type == "cell"): calc2.SetAttributeModeToUseCellData() else: calc2.SetAttributeModeToUsePointData() calc2.SetResultArrayType(vtk.VTK_DOUBLE) # initialize the output to include the peak values grid = vtk.vtkUnstructuredGrid() #N_peak = 3 reader.SetTimeStep(N_peak) print("loading {0}th timestep to copy data".format(N_peak)) calc2.Update() grid.DeepCopy(calc2.GetOutput()) #grid.SetNumberOfTimeSteps(1) #grid.SetTimeStep(0) #grid.Update() #sqrt((ddx({Wall shear-1}))**2 + (ddy({Wall shear-2}))**2 + (ddz({Wall shear-3}))**2)' def init_zero(in_array, sz_array): for i in range(sz_array): in_array.SetValue(i,0.0) def array_sum(out_array, in_array, sz_array): for i in range(sz_array): out_array.SetValue(i, out_array.GetValue(i) + in_array.GetValue(i)) def array_division(out_array, in_array, sz_array): for i in range(sz_array): out_array.SetValue(i, out_array.GetValue(i) / in_array.GetValue(i)) def array_avg(out_array, N): float_N = float(N) for i in range(N): out_array.SetValue(i, out_array.GetValue(i) / float_N) reader.SetTimeStep(0) print("loading {0}th timestep for averaging initialization".format(0)) reader.Update() calc2.Update() if(cell_type == "cell"): calc_data = calc2.GetOutput().GetCellData() grid_data = grid.GetCellData() n_sz = grid.GetNumberOfCells() else: calc_data = calc2.GetOutput().GetPointData() grid_data = grid.GetPointData() n_sz = grid.GetNumberOfPoints() TAWSS = vtk.vtkDoubleArray() TAWSS.DeepCopy(calc_data.GetArray("WSS")) TAWSS.SetName("TAWSS") TAWSSG = vtk.vtkDoubleArray() TAWSSG.DeepCopy(calc_data.GetArray("WSSG")) TAWSSG.SetName("TAWSSG") x_shear_avg = vtk.vtkDoubleArray() x_shear_avg.DeepCopy(calc_data.GetArray("x_wall_shear")) x_shear_avg.SetName("x_shear_avg") y_shear_avg = vtk.vtkDoubleArray() y_shear_avg.DeepCopy(calc_data.GetArray("y_wall_shear")) y_shear_avg.SetName("y_shear_avg") z_shear_avg = vtk.vtkDoubleArray() z_shear_avg.DeepCopy(calc_data.GetArray("z_wall_shear")) z_shear_avg.SetName("z_shear_avg") #TAWSSVector = vtk.vtkDoubleArray() #TAWSSVector.DeepCopy(calc_data.GetArray("z_wall_shear")) #TAWSSVector.SetName("TAWSSVector") #grid_data.AddArray(TAWSSVector) # def get_array_names(input): # N_point_array = input.GetOutput().GetPointData().GetNumberOfArrays() # N_WSS = 9999999 # for i in range(N_point_array): # name_WSS = input.GetOutput().GetPointData().GetArrayName(i) # if (name_WSS == "WSS"): # N_WSS = i # print(name_WSS) # # def array_sum(output, input_calc, N): # for i in range(N): # calc = output.GetValue(i) + input_calc.GetValue(i) # output.SetValue(i, calc) writer = vtk.vtkXMLUnstructuredGridWriter() #writer.SetFileName(os.path.join(out_dir,'test_outfile.vtu')) writer.SetFileName(os.path.join(dir_path, vtu_output_1)) writer.SetNumberOfTimeSteps(N) #writer.SetTimeStepRange(0,len(filelist)-1) writer.SetInputConnection(calc2.GetOutputPort()) writer.Start() #avg_map = {"TAWSS":"WSS", "TAWSSG": "WSSG", "x_shear_avg":"x_wall_shear", # "y_shear_avg":"y_wall_shear" , "z_shear_avg":"z_wall_shear"} for i in range(1,N): reader.SetTimeStep(i) print("Time step {0} for average calc".format(i)) reader.Update() calc2.Update() if(cell_type == "cell"): calc_data = calc2.GetOutput().GetCellData() else: calc_data = calc2.GetOutput().GetPointData() #get_array_names(calc2) array_sum(TAWSS, calc_data.GetArray("WSS"), n_sz) array_sum(TAWSSG, calc_data.GetArray("WSSG"), n_sz) array_sum(x_shear_avg, calc_data.GetArray("x_wall_shear"), n_sz) array_sum(y_shear_avg, calc_data.GetArray("y_wall_shear"), n_sz) array_sum(z_shear_avg, calc_data.GetArray("z_wall_shear"), n_sz) writer.WriteNextTime(reader.GetTimeStep()) writer.Stop() array_avg(TAWSS, N) array_avg(TAWSSG, N) array_avg(x_shear_avg, N) array_avg(y_shear_avg, N) array_avg(z_shear_avg, N) WSS_peak2mean = vtk.vtkDoubleArray() WSS_peak2mean.DeepCopy(grid_data.GetArray("WSS")) WSS_peak2mean.SetName("WSS_peak2mean") array_division(WSS_peak2mean, TAWSS, n_sz) WSSG_peak2mean = vtk.vtkDoubleArray() WSSG_peak2mean.DeepCopy(grid_data.GetArray("WSSG")) WSSG_peak2mean.SetName("WSSG_peak2mean") array_division(WSSG_peak2mean, TAWSSG, n_sz) grid_data.AddArray(TAWSS) grid_data.AddArray(TAWSSG) grid_data.AddArray(x_shear_avg) grid_data.AddArray(y_shear_avg) grid_data.AddArray(z_shear_avg) grid_data.AddArray(WSS_peak2mean) grid_data.AddArray(WSSG_peak2mean) print("got here") calc3 = vtk.vtkArrayCalculator() calc3.AddScalarVariable("x_shear_avg", "x_shear_avg",0) calc3.AddScalarVariable("y_shear_avg", "y_shear_avg",0) calc3.AddScalarVariable("z_shear_avg", "z_shear_avg",0) calc3.SetFunction("sqrt(x_shear_avg^2+y_shear_avg^2+z_shear_avg^2)") calc3.SetResultArrayName("TAWSSVector") calc3.SetInputData(grid) if(cell_type == "cell"): calc3.SetAttributeModeToUseCellData() else: calc3.SetAttributeModeToUsePointData() calc3.SetResultArrayType(vtk.VTK_DOUBLE) calc3.Update() calc4 = vtk.vtkArrayCalculator() calc4.AddScalarVariable("TAWSSVector", "TAWSSVector",0) calc4.AddScalarVariable("TAWSS", "TAWSS",0) calc4.SetFunction("0.5*(1.0-(TAWSSVector/(TAWSS)))") calc4.SetResultArrayName("OSI") calc4.SetInputConnection(calc3.GetOutputPort()) if(cell_type == "cell"): calc4.SetAttributeModeToUseCellData() else: calc4.SetAttributeModeToUsePointData() calc4.SetResultArrayType(vtk.VTK_DOUBLE) calc4.Update() pass_filt = vtk.vtkPassArrays() pass_filt.SetInputConnection(calc4.GetOutputPort()) pass_filt.AddArray(vtk_data_type, "WSS") pass_filt.AddArray(vtk_data_type, "WSSG") pass_filt.AddArray(vtk_data_type, "absolute_pressure") pass_filt.AddArray(vtk_data_type, "TAWSS") pass_filt.AddArray(vtk_data_type, "TAWSSG") pass_filt.AddArray(vtk_data_type, "OSI") pass_filt.AddArray(vtk_data_type, "WSS_peak2mean") pass_filt.AddArray(vtk_data_type, "WSSG_peak2mean") pass_filt.Update() #if(cell_type == "cell"): # print(pass_filt.GetOutput().GetCellData().GetArray("OSI").GetValue(0)) #else: # print(pass_filt.GetOutput().GetPointData().GetArray("OSI").GetValue(0)) writer2 = vtk.vtkXMLUnstructuredGridWriter() writer2.SetFileName(os.path.join(dir_path, vtu_output_2)) writer2.SetInputConnection(pass_filt.GetOutputPort()) writer2.Update()
def Execute(args): print("get average along line probes") cell_type = "point" if (cell_type == "cell"): vtk_process = vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS vtk_data_type = vtk.vtkDataObject.CELL else: vtk_process = vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS vtk_data_type = vtk.vtkDataObject.POINT reader = vmtkscripts.vmtkMeshReader() reader.InputFileName = args.mesh_file reader.Execute() mesh = reader.Mesh pass_filt = vtk.vtkPassArrays() pass_filt.SetInputData(mesh) pass_filt.AddArray(vtk_data_type, "velocity") pass_filt.Update() surf = vmtkscripts.vmtkMeshToSurface() surf.Mesh = pass_filt.GetOutput() surf.Execute() normals = vmtkscripts.vmtkSurfaceNormals() normals.Surface = surf.Surface #accept defaults normals.Execute() calc1 = vtk.vtkArrayCalculator() calc1.SetFunction( "velocity_X*-Normals_X+velocity_Y*-Normals_Y+velocity_Z*-Normals_Z") calc1.AddScalarVariable("velocity_X", "velocity_X", 0) calc1.AddScalarVariable("velocity_Y", "velocity_Y", 0) calc1.AddScalarVariable("velocity_Z", "velocity_Z", 0) calc1.SetResultArrayName("vdotn") calc1.SetInputData(normals.Surface) if (cell_type == "cell"): calc1.SetAttributeModeToUseCellData() else: calc1.SetAttributeModeToUsePointData() calc1.SetResultArrayType(vtk.VTK_DOUBLE) integrate_attrs = vtk.vtkIntegrateAttributes() integrate_attrs.SetInputConnection(calc1.GetOutputPort()) integrate_attrs.UpdateData() area = integrate_attrs.GetCellData().GetArray(0).GetValue(0) D = 2.0 * np.sqrt(area / np.pi) calc2 = vtk.vtkArrayCalculator() calc2.SetFunction("vdotn*10**6*60") calc2.AddScalarVariable("vdotn", "vdotn", 0) calc2.SetResultArrayName("Q") calc2.SetInputConnection(integrate_attrs.GetOutputPort()) if (cell_type == "cell"): calc2.SetAttributeModeToUseCellData() else: calc2.SetAttributeModeToUsePointData() calc2.SetResultArrayType(vtk.VTK_DOUBLE) calc2.UpdateData() calc3 = vtk.vtkArrayCalculator() calc3.SetFunction("vdotn/{0}*1050.0/0.0035*{1}".format(area, D)) calc3.AddScalarVariable("vdotn", "vdotn", 0) calc3.SetResultArrayName("Re") calc3.SetInputConnection(integrate_attrs.GetOutputPort()) if (cell_type == "cell"): calc3.SetAttributeModeToUseCellData() else: calc3.SetAttributeModeToUsePointData() calc3.SetResultArrayType(vtk.VTK_DOUBLE) calc3.UpdateData() over_time = vtk.vtkExtractDataArraysOverTime() over_time.SetInputConnection(calc3.GetOutputPort()) if (cell_type == "cell"): over_time.SetFieldAssociation(vtk_data_type) else: over_time.SetFieldAssociation(vtk_data_type) over_time.UpdateData() writer = vtk.vtkDelimitedTextWriter() writer.SetInputConnection(over_time.GetOutputPort()) writer.SetFileName(args.file_out) writer.Write()
def post_proc_cfd_diff(parameter_list): dir_path = parameter_list[0] vtu_input = parameter_list[1] cell_type = parameter_list[1] vtu_output_1 = parameter_list[3] vtu_output_2 = parameter_list[4] N_peak = parameter_list[5] reader = vtk.vtkXMLUnstructuredGridReader() reader.SetFileName(os.path.join(dir_path, vtu_input)) reader.Update() N = reader.GetNumberOfTimeSteps() print(N) if (cell_type == "cell"): vtk_process = vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS vtk_data_type = vtk.vtkDataObject.CELL else: vtk_process = vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS vtk_data_type = vtk.vtkDataObject.POINT pass_arr = vtk.vtkPassArrays() pass_arr.SetInputConnection(reader.GetOutputPort()) pass_arr.AddArray(vtk_data_type, "absolute_pressure") pass_arr.AddArray(vtk_data_type, "x_wall_shear") pass_arr.AddArray(vtk_data_type, "y_wall_shear") pass_arr.AddArray(vtk_data_type, "z_wall_shear") calc1 = vtk.vtkArrayCalculator() calc1.SetFunction("sqrt(x_wall_shear^2+y_wall_shear^2+z_wall_shear^2)") calc1.AddScalarVariable("x_wall_shear", "x_wall_shear", 0) calc1.AddScalarVariable("y_wall_shear", "y_wall_shear", 0) calc1.AddScalarVariable("z_wall_shear", "z_wall_shear", 0) calc1.SetResultArrayName("WSS") calc1.SetInputConnection(pass_arr.GetOutputPort()) if (cell_type == "cell"): calc1.SetAttributeModeToUseCellData() else: calc1.SetAttributeModeToUsePointData() calc1.SetResultArrayType(vtk.VTK_DOUBLE) x_WSS_grad = vtk.vtkGradientFilter() x_WSS_grad.SetInputConnection(calc1.GetOutputPort()) x_WSS_grad.ComputeGradientOn() x_WSS_grad.FasterApproximationOff() x_WSS_grad.ComputeDivergenceOff() x_WSS_grad.ComputeVorticityOff() x_WSS_grad.ComputeQCriterionOff() x_WSS_grad.SetResultArrayName("x_WSS_grad") x_WSS_grad.SetInputArrayToProcess(0, 0, 0, vtk_process, "x_wall_shear") y_WSS_grad = vtk.vtkGradientFilter() y_WSS_grad.SetInputConnection(x_WSS_grad.GetOutputPort()) y_WSS_grad.ComputeGradientOn() y_WSS_grad.FasterApproximationOff() y_WSS_grad.ComputeDivergenceOff() y_WSS_grad.ComputeVorticityOff() y_WSS_grad.ComputeQCriterionOff() y_WSS_grad.SetResultArrayName("y_WSS_grad") y_WSS_grad.SetInputArrayToProcess(0, 0, 0, vtk_process, "y_wall_shear") z_WSS_grad = vtk.vtkGradientFilter() z_WSS_grad.SetInputConnection(y_WSS_grad.GetOutputPort()) z_WSS_grad.ComputeGradientOn() z_WSS_grad.FasterApproximationOff() z_WSS_grad.ComputeDivergenceOff() z_WSS_grad.ComputeVorticityOff() z_WSS_grad.ComputeQCriterionOff() z_WSS_grad.SetResultArrayName("z_WSS_grad") z_WSS_grad.SetInputArrayToProcess(0, 0, 0, vtk_process, "z_wall_shear") calc2 = vtk.vtkArrayCalculator() calc2.AddScalarVariable("x_component", "x_WSS_grad", 0) calc2.AddScalarVariable("y_component", "y_WSS_grad", 1) calc2.AddScalarVariable("z_component", "z_WSS_grad", 2) calc2.SetFunction("sqrt(x_component^2+y_component^2+z_component^2)") calc2.SetResultArrayName("WSSG") calc2.SetInputConnection(z_WSS_grad.GetOutputPort()) if (cell_type == "cell"): calc2.SetAttributeModeToUseCellData() else: calc2.SetAttributeModeToUsePointData() calc2.SetResultArrayType(vtk.VTK_DOUBLE) # initialize the output to include the peak values grid = vtk.vtkUnstructuredGrid() #N_peak = 3 reader.SetTimeStep(N_peak) calc2.Update() print("loading peak: {0} timestep to copy data".format( reader.GetTimeStep())) grid.DeepCopy(calc2.GetOutput()) reader.SetTimeStep(0) #reader.Update() calc2.Update() print("loading {0}th timestep for averaging initialization".format( reader.GetTimeStep())) stats = vtk.vtkTemporalStatistics() stats.SetInputConnection(calc2.GetOutputPort()) stats.ComputeMaximumOff() stats.ComputeMinimumOff() stats.ComputeStandardDeviationOff() stats.ComputeAverageOn() stats.Update() print("what's the time step after stats :{0}".format(reader.GetTimeStep())) grid_out = vtk.vtkUnstructuredGrid() grid_out.DeepCopy(stats.GetOutput()) if (cell_type == "cell"): out_data = grid_out.GetCellData() grid_data = grid.GetCellData() else: out_data = grid_out.GetPointData() grid_data = grid.GetPointData() print("update names") out_data.AddArray(grid_data.GetArray("WSS")) out_data.GetArray("WSS").SetName("WSS_peak") out_data.AddArray(grid_data.GetArray("WSSG")) out_data.GetArray("WSSG").SetName("WSSG_peak") out_data.AddArray(grid_data.GetArray("absolute_pressure")) out_data.GetArray("absolute_pressure").SetName("pressure_peak") out_data.GetArray("WSS_average").SetName("TAWSS") out_data.GetArray("WSSG_average").SetName("TAWSSG") out_data.GetArray("absolute_pressure_average").SetName("pressure_average") print("TAWSSVector") calc3 = vtk.vtkArrayCalculator() calc3.AddScalarVariable("x_wall_shear_average", "x_wall_shear_average", 0) calc3.AddScalarVariable("y_wall_shear_average", "y_wall_shear_average", 0) calc3.AddScalarVariable("z_wall_shear_average", "z_wall_shear_average", 0) calc3.SetFunction( "sqrt(x_wall_shear_average^2+y_wall_shear_average^2+z_wall_shear_average^2)" ) calc3.SetResultArrayName("TAWSSVector") calc3.SetInputData(grid_out) if (cell_type == "cell"): calc3.SetAttributeModeToUseCellData() else: calc3.SetAttributeModeToUsePointData() calc3.SetResultArrayType(vtk.VTK_DOUBLE) calc3.Update() print("OSI") calc4 = vtk.vtkArrayCalculator() calc4.AddScalarVariable("TAWSSVector", "TAWSSVector", 0) calc4.AddScalarVariable("TAWSS", "TAWSS", 0) calc4.SetFunction("0.5*(1.0-(TAWSSVector/(TAWSS)))") calc4.SetResultArrayName("OSI") calc4.SetInputConnection(calc3.GetOutputPort()) if (cell_type == "cell"): calc4.SetAttributeModeToUseCellData() else: calc4.SetAttributeModeToUsePointData() calc4.SetResultArrayType(vtk.VTK_DOUBLE) #calc4.Update() # peak ratios calc5 = vtk.vtkArrayCalculator() calc5.AddScalarVariable("WSS_peak", "WSS_peak", 0) calc5.AddScalarVariable("TAWSS", "TAWSS", 0) calc5.SetFunction("WSS_peak/TAWSS") calc5.SetResultArrayName("WSS_peak_q_TAWSS") calc5.SetInputConnection(calc4.GetOutputPort()) if (cell_type == "cell"): calc5.SetAttributeModeToUseCellData() else: calc5.SetAttributeModeToUsePointData() calc5.SetResultArrayType(vtk.VTK_DOUBLE) #calc5.Update() calc6 = vtk.vtkArrayCalculator() calc6.AddScalarVariable("WSSG_peak", "WSSG_peak", 0) calc6.AddScalarVariable("TAWSSG", "TAWSSG", 0) calc6.SetFunction("WSSG_peak/TAWSSG") calc6.SetResultArrayName("WSSG_peak_q_TAWSSG") calc6.SetInputConnection(calc5.GetOutputPort()) if (cell_type == "cell"): calc6.SetAttributeModeToUseCellData() else: calc6.SetAttributeModeToUsePointData() calc6.SetResultArrayType(vtk.VTK_DOUBLE) calc7 = vtk.vtkArrayCalculator() calc7.AddScalarVariable("pressure_peak", "pressure_peak", 0) calc7.AddScalarVariable("pressure_average", "pressure_average", 0) calc7.SetFunction("pressure_peak/pressure_average") calc7.SetResultArrayName("pressure_peak_q_pressure_average") calc7.SetInputConnection(calc6.GetOutputPort()) if (cell_type == "cell"): calc7.SetAttributeModeToUseCellData() else: calc7.SetAttributeModeToUsePointData() calc7.SetResultArrayType(vtk.VTK_DOUBLE) pass_filt = vtk.vtkPassArrays() pass_filt.SetInputConnection(calc7.GetOutputPort()) pass_filt.AddArray(vtk_data_type, "WSS_peak") pass_filt.AddArray(vtk_data_type, "WSSG_peak") pass_filt.AddArray(vtk_data_type, "pressure_peak") pass_filt.AddArray(vtk_data_type, "pressure_average") pass_filt.AddArray(vtk_data_type, "TAWSS") pass_filt.AddArray(vtk_data_type, "TAWSSG") pass_filt.AddArray(vtk_data_type, "OSI") pass_filt.AddArray(vtk_data_type, "WSS_peak_q_TAWSS") pass_filt.AddArray(vtk_data_type, "WSSG_peak_q_TAWSSG") pass_filt.AddArray(vtk_data_type, "pressure_peak_q_pressure_average") pass_filt.Update() #if(cell_type == "cell"): # print(pass_filt.GetOutput().GetCellData().GetArray("OSI").GetValue(0)) #else: # print(pass_filt.GetOutput().GetPointData().GetArray("OSI").GetValue(0)) writer2 = vtk.vtkXMLUnstructuredGridWriter() writer2.SetFileName(os.path.join(dir_path, vtu_output_2)) writer2.SetInputConnection(pass_filt.GetOutputPort()) writer2.Update()