def CreatePipeline(self): ''' Create slice and integration filters different slices can be saved by adjusting the slice filter's position ''' self.slice = pvs.Slice(Input = self.reader) self.integrator = pvs.IntegrateVariables(Input = self.slice) self.integrator.DivideCellDataByVolume = True
def calc_surf_to_vol(filename, arr_name, sample_rate): import paraview.simple as ps import numpy as np import paraview as pv from vtk.util.numpy_support import vtk_to_numpy # have paraview open the vtk data file reader = ps.OpenDataFile(filename) sys_data = pv.servermanager.Fetch(reader) nx, ny, nz = sys_data.GetDimensions() dx, dy, dz = sys_data.GetSpacing() # downsample the data (makes for a smoother contour surface) ds = ps.ExtractSubset() ds.SampleRateI = sample_rate ds.SampleRateJ = sample_rate ds.SampleRateK = sample_rate ds.VOI[1] = nx - 1 ds.VOI[3] = ny - 1 ds.VOI[4] = 1 # leave off bottom layer for CHBDThinFilm ds.VOI[5] = nz - 2 # leave off top layer for CHBDThinFilm ds.IncludeBoundary = 1 ds.UpdatePipeline() # have paraview apply a contour surface at a concentration value of cont_val contour = ps.Contour() cont_val = 0.5 # this might change depending on order parameter contour.ContourBy = ['POINTS', arr_name] # Viz is the name of the vtk array contour.Isosurfaces = [cont_val] contour.SetPropertyWithName('ComputeNormals', 0) contour.UpdatePipeline() # integrate the surface area and curvature summed_curv = ps.IntegrateVariables() summed_curv_data = pv.servermanager.Fetch(summed_curv) surf_area = summed_curv_data.GetCellData().GetArray(0).GetValue(0) # calculate the surface area to volume ratio volume = nx * dx * ny * dy * nz * dz surf_to_vol = surf_area / volume # delete paraview sources and filters ps.Delete(reader) ps.Delete(ds) ps.Delete(contour) ps.Delete(summed_curv) del (sys_data) del (summed_curv_data) return surf_to_vol, surf_area, volume
#-------------------------------------------------------------------------||---# Coords = Read_dat("XXX_COORDINATES.alya") for coord in Coords: print coord, Simple.SetActiveSource(InputData) Slice01 = Simple.Slice( guiName="Slice2", SliceOffsetValues=[0.0], SliceType="Plane" ) Slice01.SliceType.Origin = coord Slice01.SliceType.Normal = [0.0, 0.0, 1.0] Simple.SetActiveSource(Slice01) Calculator01 = Simple.Calculator(guiName="Calculator1", Function='VELOC_Z*TEMPE', ResultArrayName='UT') Simple.SetActiveSource(Calculator01) IntegrateVariables01 = Simple.IntegrateVariables( guiName="IntegrateVariables2" ) Simple.SetActiveSource(IntegrateVariables01) PF = Simple.ProgrammableFilter() PF.Script = Script02 Simple.Show(PF) #print "ok!" #-------------------------------------------------------------------------||---# #-------------------------------------------------------------------------||---# #-------------------------------------------------------------------------||---# #-------------------------------------------------------------------------||---# import os
def get_curvatures(vtk_file, vtk_file_dir, output_file, output_file_dir, arr_name, sample_rate, gauss_filter, mean_filter): import paraview.simple as ps import numpy as np import paraview as pv from vtk.util.numpy_support import vtk_to_numpy # have paraview open the vtk data file reader = ps.OpenDataFile(vtk_file_dir + vtk_file) sys_data = pv.servermanager.Fetch(reader) nx, ny, nz = sys_data.GetDimensions() dx, dy, dz = sys_data.GetSpacing() # downsample the data (makes for a smoother contour surface) ds = ps.ExtractSubset(reader) ds.SampleRateI = sample_rate ds.SampleRateJ = sample_rate ds.SampleRateK = sample_rate ds.VOI[1] = nx - 1 ds.VOI[3] = ny - 1 ds.VOI[5] = nz - 1 ds.IncludeBoundary = 1 ds.UpdatePipeline() # have paraview apply a contour surface at a concentration value of cont_val contour = ps.Contour(ds) cont_val = 0.0 # this might change depending on order parameter contour.ContourBy = ['POINTS', arr_name] # Viz is the name of the vtk array contour.Isosurfaces = [cont_val] contour.SetPropertyWithName('ComputeNormals', 0) contour.UpdatePipeline() # have paraview calculate the curvature (default is Gaussian) curvature = ps.Curvature(contour) # filter the curvatures threshold = ps.Threshold(curvature) threshold.Scalars = ['POINTS', 'Gauss_Curvature'] threshold.ThresholdRange = [-gauss_filter, gauss_filter] threshold.AllScalars = 1 threshold.UpdatePipeline() gauss_data = pv.servermanager.Fetch(threshold) size_gauss = gauss_data.GetPointData().GetArray(0).GetSize() # convert vtk array to numpy array gauss_curv = vtk_to_numpy(gauss_data.GetPointData().GetArray(0)) # integrate the surface area and curvature summed_curv = ps.IntegrateVariables(threshold) summed_curv_data = pv.servermanager.Fetch(summed_curv) g_surf_area = summed_curv_data.GetCellData().GetArray(0).GetValue(0) # have paraview recalculate the mean curvature curvature.SetPropertyWithName('CurvatureType', 'Mean') curvature.UpdatePipeline() threshold = ps.Threshold(curvature) threshold.Scalars = ['POINTS', 'Mean_Curvature'] threshold.ThresholdRange = [-mean_filter, mean_filter] threshold.UpdatePipeline() summed_curv = ps.IntegrateVariables(threshold) summed_curv.UpdatePipeline() summed_curv_data = pv.servermanager.Fetch(summed_curv) m_surf_area = summed_curv_data.GetCellData().GetArray(0).GetValue(0) mean_data = pv.servermanager.Fetch(threshold) # convert vtk array to numpy array mean_curv = vtk_to_numpy(mean_data.GetPointData().GetArray(0)) # calculate the surface area to volume ratio g_surf_to_vol = g_surf_area / (nx * dx * ny * dy * nz * dz) m_surf_to_vol = m_surf_area / (nx * dx * ny * dy * nz * dz) # calculate percent of data used in threshold curvature_data = pv.servermanager.Fetch(curvature) size_curv = curvature_data.GetPointData().GetArray(0).GetSize() # save the numpy arrays for later manipulation np.savez(output_file_dir + output_file, gauss_curv, mean_curv, g_surf_to_vol, g_surf_area, m_surf_to_vol, m_surf_area) # delete paraview sources and filters ps.Delete(summed_curv) ps.Delete(contour) ps.Delete(ds) ps.Delete(reader) del (sys_data) del (summed_curv_data) return 0
def StreamlinesScript(Input1, Input2, Output, N1=None, N2=None, Offset1=0.0, Offset2=0.0, CamDirVec=None, CamUpVec=None, Origin=None): ''' Creates an image with the streamlines from two VTUs. Inputs: Input1 - VTU with first direction of curvatures Input2 - VTU with second direction of curvatures N1 - List of normal of slice for VTU1 N2 - List of normal of slice for VTU2 Offset1 - Value of offset for slice of VTU1 Offset2 - Value of offset for slice of VTU2 CamDirVec - Vector for camera direction CamUpVec - Vector for camera up direction Origin - Vector with the position for the origin''' #### disable automatic camera reset on 'Show' pvs._DisableFirstRenderCameraReset() # create a new 'XML Unstructured Grid Reader' VTU1 = pvs.XMLUnstructuredGridReader(FileName=[Input1]) VTU1.PointArrayStatus = ['Curvature'] ## Fix data for Slices if N1 is None: N1 = [0.9, 0.4, 0.2] if N2 is None: # N2 = np.cross(N1,[0,0,1]) N2 = [-0.8, 0.5, 0.16] if Origin is None: Origin = paraview.servermanager.Fetch( pvs.IntegrateVariables(Input=VTU1)).GetPoint(0) # create a new 'XML Unstructured Grid Reader' VTU2 = pvs.XMLUnstructuredGridReader(FileName=[Input2]) VTU2.PointArrayStatus = ['Curvature'] # get active view renderView1 = pvs.GetActiveViewOrCreate('RenderView') # show data in view VTU1Display = pvs.Show(VTU1, renderView1) VTU1Display.Representation = 'Surface' VTU1Display.Diffuse = 0.85 VTU1Display.Ambient = 0.25 # show data in view VTU2Display = pvs.Show(VTU2, renderView1) VTU2Display.Representation = 'Surface' VTU2Display.Diffuse = 0.85 VTU2Display.Ambient = 0.25 # create a new 'Slice' slice1 = pvs.Slice(Input=VTU1) slice1.SliceType.Origin = Origin slice1.SliceType.Normal = N1 slice1.SliceType.Offset = 0.0 slice1.SliceOffsetValues = [Offset1] # create a new 'Slice' slice2 = pvs.Slice(Input=VTU2) slice2.SliceType.Origin = Origin slice2.SliceType.Normal = N2 slice2.SliceType.Offset = 0.0 slice2.SliceOffsetValues = [Offset2] # make stremlines makestream(VTU1, slice1, renderView1, [1.0, 0.0, 0.0]) makestream(VTU2, slice2, renderView1, [0.0, 0.0, 1.0]) # Save Screenshot AdjustCameraAndSave(renderView1, Output, ImageResolution=(2048, 2048), CamDirVec=CamDirVec, CamUpVec=CamUpVec) # set active source pvs.SetActiveSource(None) pvs.SetActiveView(None) pvs.Disconnect()