def coProcess(grid, time, step, scriptname, wholeExtent): import vtkCoProcessorPython import os scriptpath, scriptname = os.path.split(scriptname) sys.path.append(scriptpath) if scriptname.endswith(".py"): print 'script name is ', scriptname scriptname = scriptname[0:len(scriptname)-3] try: cpscript = __import__(scriptname) except: print 'Cannot find ', scriptname, ' -- no coprocessing will be performed.' return datadescription = vtkCoProcessorPython.vtkCPDataDescription() datadescription.SetTimeData(time, step) datadescription.AddInput("input") cpscript.RequestDataDescription(datadescription) inputdescription = datadescription.GetInputDescriptionByName("input") if inputdescription.GetIfGridIsNecessary() == False: return inputdescription.SetGrid(grid) if grid.IsA("vtkImageData") == True or grid.IsA("vtkRectilinearGrid") == True \ or grid.IsA("vtkStructuredGrid") == True: inputdescription.SetWholeExtent(wholeExtent) cpscript.DoCoProcessing(datadescription)
# arbitrary simulation parameters numtimesteps = 10 starttime = 0. endtime = 1. timestep = (endtime-starttime)/numtimesteps # importing the coprocessing libraries needed for the adaptor import vtkCoProcessorPython # this is the actual coprocessing script created from the ParaView plugin import cp_pythonadaptorscript for step in range(numtimesteps): currenttime = step*timestep datadescription = vtkCoProcessorPython.vtkCPDataDescription() datadescription.SetTimeData(currenttime, step) datadescription.AddInput("input") # determine if we want to perform coprocessing this time step cp_pythonadaptorscript.RequestDataDescription(datadescription) inputdescription = datadescription.GetInputDescriptionByName("input") if inputdescription.GetIfGridIsNecessary() == True: # since we do want to perform coprocessing, create grid and field data points = vtk.vtkPoints() for i in range(2): points.InsertNextPoint(float(i+mpi.rank), 0, 0) points.InsertNextPoint(float(i+mpi.rank), 0, 1) points.InsertNextPoint(float(i+mpi.rank), 1, 1) points.InsertNextPoint(float(i+mpi.rank), 1, 0)
# arbitrary simulation parameters numtimesteps = 10 starttime = 0. endtime = 1. timestep = (endtime - starttime) / numtimesteps # importing the coprocessing libraries needed for the adaptor import vtkCoProcessorPython # this is the actual coprocessing script created from the ParaView plugin import cp_pythonadaptorscript for step in range(numtimesteps): currenttime = step * timestep datadescription = vtkCoProcessorPython.vtkCPDataDescription() datadescription.SetTimeData(currenttime, step) datadescription.AddInput("input") # determine if we want to perform coprocessing this time step cp_pythonadaptorscript.RequestDataDescription(datadescription) inputdescription = datadescription.GetInputDescriptionByName("input") if inputdescription.GetIfGridIsNecessary() == True: # since we do want to perform coprocessing, create grid and field data points = vtk.vtkPoints() for i in range(2): points.InsertNextPoint(float(i + mpi.rank), 0, 0) points.InsertNextPoint(float(i + mpi.rank), 0, 1) points.InsertNextPoint(float(i + mpi.rank), 1, 1) points.InsertNextPoint(float(i + mpi.rank), 1, 0)