def Execute(self):

        if (self.Mesh == None):
            self.PrintError('Error: no Mesh.')

        if (self.PointId == None):
            self.PrintError('Error: no PointId.')

        if (self.ArrayName == None):
            self.PrintError('Error: no ArrayName.')

        vectorFromComponents = vmtkmeshvectorfromcomponents.vmtkMeshVectorFromComponents(
        )
        vectorFromComponents.Mesh = self.Mesh
        vectorFromComponents.VectorArrayName = self.ArrayName
        vectorFromComponents.ComponentsArrayNames = self.ComponentsArrayNames
        vectorFromComponents.RemoveComponentArrays = True
        vectorFromComponents.Execute()
        dataArray = self.Mesh.GetPointData().GetArray(self.ArrayName)
        dataValue = vtk.vtkMath.Norm((dataArray.GetTuple(self.PointId)[0],
                                      dataArray.GetTuple(self.PointId)[1],
                                      dataArray.GetTuple(self.PointId)[2]))

        self.PrintLog('')

        logLine = 'PointId: %d\n' % self.PointId
        logLine += '  Array: %s\n' % self.ArrayName
        logLine += ' Components[x,y,z]: %s,%s,%s\n' % (dataArray.GetTuple(
            self.PointId)[0], dataArray.GetTuple(
                self.PointId)[1], dataArray.GetTuple(self.PointId)[2])
        logLine += '  Magnitude: %f\n' % dataValue

        self.PrintLog(logLine)
Esempio n. 2
0
    def Execute(self):

        if (self.Mesh == None):
            self.PrintError('Error: no Mesh.')
            
        if (self.PointId == None):
            self.PrintError('Error: no PointId.')
        
        if (self.ArrayName == None):
            self.PrintError('Error: no ArrayName.')
            
        vectorFromComponents = vmtkmeshvectorfromcomponents.vmtkMeshVectorFromComponents()
        vectorFromComponents.Mesh = self.Mesh
        vectorFromComponents.VectorArrayName = self.ArrayName
        vectorFromComponents.ComponentsArrayNames = self.ComponentsArrayNames
        vectorFromComponents.RemoveComponentArrays = True
        vectorFromComponents.Execute()
        dataArray = self.Mesh.GetPointData().GetArray(self.ArrayName)
        dataValue = vtk.vtkMath.Norm((dataArray.GetTuple(self.PointId)[0],dataArray.GetTuple(self.PointId)[1],dataArray.GetTuple(self.PointId)[2]))
        
        self.PrintLog('')
        
        logLine = 'PointId: %d\n' % self.PointId
        logLine += '  Array: %s\n' % self.ArrayName
        logLine += ' Components[x,y,z]: %s,%s,%s\n' % (dataArray.GetTuple(self.PointId)[0],dataArray.GetTuple(self.PointId)[1],dataArray.GetTuple(self.PointId)[2])
        logLine += '  Magnitude: %f\n' % dataValue
        
        self.PrintLog(logLine)
    def Execute(self):

        if (self.InputDirectoryName == None):
            self.PrintError('Error: no directory.')

        if (self.Pattern == None):
            self.PrintError('Error: no pattern.')

        if (self.FirstTimeStep == None):
            self.PrintError('Error: no first timestep.')

        if (self.LastTimeStep == None):
            self.PrintError('Error: no last timestep.')

        if (self.VelocityComponentsArrayNames == None):
            self.PrintError('Error: no VelocityComponentsArrayNames.')

        for root, dirs, files in os.walk(self.InputDirectoryName):
            if root == self.InputDirectoryName:
                fileList = [x for x in files if not (x.startswith('.'))]

        timeIndexList = range(self.FirstTimeStep, self.LastTimeStep + 1,
                              self.IntervalTimeStep)
        reader = vmtkmeshreader.vmtkMeshReader()
        #if self.VelocityVector or self.WsrVector:
        if self.WsrVector:
            vectorFromComponents = vmtkmeshvectorfromcomponents.vmtkMeshVectorFromComponents(
            )

        u_name = self.VelocityComponentsArrayNames.split(' ')[0]
        v_name = self.VelocityComponentsArrayNames.split(' ')[1]
        w_name = self.VelocityComponentsArrayNames.split(' ')[2]

        if self.Wsr:
            taux_name = self.WsrComponentsArrayNames.split(' ')[0]
            tauy_name = self.WsrComponentsArrayNames.split(' ')[1]
            tauz_name = self.WsrComponentsArrayNames.split(' ')[2]

        field = vtk.vtkFieldData()
        field.AllocateArrays(1)
        timesteps = vtk.vtkIntArray()
        timesteps.SetNumberOfComponents(1)
        timesteps.SetName("timesteps")
        i = 0
        for step in timeIndexList:
            if (self.Pattern % step).replace(' ', '0') in fileList:
                timesteps.InsertTuple1(i, step)
                i += 1

                fileName = (self.Pattern % step).replace(' ', '0')
                timeIndex = step
                reader.InputFileName = os.path.abspath(
                    os.path.join(self.InputDirectoryName, fileName))
                reader.Execute()
                mesh = reader.Mesh

                if step == self.FirstTimeStep:
                    mesh.CopyStructure(mesh)
                    self.Mesh = mesh

                if self.Pressure:
                    p = mesh.GetPointData().GetArray(self.PressureArrayName)
                    p.SetName(self.PressureArrayName + str(step))
                    self.Mesh.GetPointData().AddArray(p)

                if self.Wsr:
                    taux = mesh.GetPointData().GetArray(taux_name)
                    taux.SetName(taux_name + str(step))
                    self.Mesh.GetPointData().AddArray(taux)

                    tauy = mesh.GetPointData().GetArray(tauy_name)
                    tauy.SetName(tauy_name + str(step))
                    self.Mesh.GetPointData().AddArray(tauy)

                    tauz = mesh.GetPointData().GetArray(tauz_name)
                    tauz.SetName(tauz_name + str(step))
                    self.Mesh.GetPointData().AddArray(tauz)

                if self.VelocityVector:

                    j = 0

                    u_component = vtk.vtkDoubleArray()
                    u_component.SetNumberOfComponents(1)

                    v_component = vtk.vtkDoubleArray()
                    v_component.SetNumberOfComponents(1)

                    w_component = vtk.vtkDoubleArray()
                    w_component.SetNumberOfComponents(1)

                    while j < mesh.GetPointData().GetArray(
                            self.VelocityVectorArrayName).GetNumberOfTuples():

                        u_val = mesh.GetPointData().GetArray(
                            self.VelocityVectorArrayName).GetComponent(j, 0)
                        v_val = mesh.GetPointData().GetArray(
                            self.VelocityVectorArrayName).GetComponent(j, 1)
                        w_val = mesh.GetPointData().GetArray(
                            self.VelocityVectorArrayName).GetComponent(j, 2)

                        u_component.InsertTuple1(j, u_val)
                        v_component.InsertTuple1(j, v_val)
                        w_component.InsertTuple1(j, w_val)

                        j += 1

                    u_component.SetName(u_name + "_" + str(step))
                    self.Mesh.GetPointData().AddArray(u_component)

                    v_component.SetName(v_name + "_" + str(step))
                    self.Mesh.GetPointData().AddArray(v_component)

                    w_component.SetName(w_name + "_" + str(step))
                    self.Mesh.GetPointData().AddArray(w_component)

                else:

                    u = mesh.GetPointData().GetArray(u_name)
                    u.SetName(u_name + "_" + str(step))
                    self.Mesh.GetPointData().AddArray(u)

                    v = mesh.GetPointData().GetArray(v_name)
                    v.SetName(v_name + "_" + str(step))
                    self.Mesh.GetPointData().AddArray(v)

                    w = mesh.GetPointData().GetArray(w_name)
                    w.SetName(w_name + "_" + str(step))
                    self.Mesh.GetPointData().AddArray(w)

                if self.WsrVector:
                    vectorFromComponents.Mesh = self.Mesh
                    vectorFromComponents.VectorArrayName = "Wsr_" + str(step)
                    vectorFromComponents.ComponentsArrayNames = [
                        taux.GetName(),
                        tauy.GetName(),
                        tauz.GetName()
                    ]
                    vectorFromComponents.RemoveComponentArrays = True
                    vectorFromComponents.Execute()

        field.AddArray(timesteps)
        self.Mesh.SetFieldData(field)
Esempio n. 4
0
    def Execute(self):

        if (self.InputDirectoryName == None):
            self.PrintError('Error: no directory.')

        if (self.Pattern == None):
            self.PrintError('Error: no pattern.')

        if (self.FirstTimeStep == None):
            self.PrintError('Error: no first timestep.')

        if (self.LastTimeStep == None):
            self.PrintError('Error: no last timestep.')

        if (self.VelocityComponentsArrayNames == None):
            self.PrintError('Error: no VelocityComponentsArrayNames.')

        for root, dirs, files in os.walk(self.InputDirectoryName):
            if root == self.InputDirectoryName:
                fileList = [x for x in files if not (x.startswith('.'))]

        timeIndexList = range(self.FirstTimeStep,self.LastTimeStep+1,self.IntervalTimeStep)
        reader = vmtkmeshreader.vmtkMeshReader()
        #if self.VelocityVector or self.WsrVector:
        if self.WsrVector:
            vectorFromComponents = vmtkmeshvectorfromcomponents.vmtkMeshVectorFromComponents()

        u_name = self.VelocityComponentsArrayNames.split(' ')[0]
        v_name = self.VelocityComponentsArrayNames.split(' ')[1]
        w_name = self.VelocityComponentsArrayNames.split(' ')[2]

        if self.Wsr:
        	taux_name = self.WsrComponentsArrayNames.split(' ')[0]
        	tauy_name = self.WsrComponentsArrayNames.split(' ')[1]
        	tauz_name = self.WsrComponentsArrayNames.split(' ')[2]

        field = vtk.vtkFieldData()
        field.AllocateArrays(1)
        timesteps = vtk.vtkIntArray()
        timesteps.SetNumberOfComponents(1)
        timesteps.SetName("timesteps")
        i = 0
        for step in timeIndexList:
            if (self.Pattern%step).replace(' ','0') in fileList:
                timesteps.InsertTuple1(i, step)
                i+=1

                fileName = (self.Pattern%step).replace(' ','0')
                timeIndex = step
                reader.InputFileName = os.path.abspath(os.path.join(self.InputDirectoryName,fileName))
                reader.Execute()
                mesh = reader.Mesh

                if step == self.FirstTimeStep:
                    mesh.CopyStructure(mesh)
                    self.Mesh = mesh

                if self.Pressure:
                    p = mesh.GetPointData().GetArray(self.PressureArrayName)
                    p.SetName(self.PressureArrayName+str(step))
                    self.Mesh.GetPointData().AddArray(p)

                if self.Wsr:
                	taux = mesh.GetPointData().GetArray(taux_name)
                	taux.SetName(taux_name+str(step))
                	self.Mesh.GetPointData().AddArray(taux)

                	tauy = mesh.GetPointData().GetArray(tauy_name)
                	tauy.SetName(tauy_name+str(step))
                	self.Mesh.GetPointData().AddArray(tauy)

                	tauz = mesh.GetPointData().GetArray(tauz_name)
                	tauz.SetName(tauz_name+str(step))
                	self.Mesh.GetPointData().AddArray(tauz)


                if self.VelocityVector:

                  j = 0

                  u_component = vtk.vtkDoubleArray()
                  u_component.SetNumberOfComponents(1)

                  v_component = vtk.vtkDoubleArray()
                  v_component.SetNumberOfComponents(1)

                  w_component = vtk.vtkDoubleArray()
                  w_component.SetNumberOfComponents(1)


                  while j < mesh.GetPointData().GetArray(self.VelocityVectorArrayName).GetNumberOfTuples():

                    u_val = mesh.GetPointData().GetArray(self.VelocityVectorArrayName).GetComponent(j,0)
                    v_val = mesh.GetPointData().GetArray(self.VelocityVectorArrayName).GetComponent(j,1)
                    w_val = mesh.GetPointData().GetArray(self.VelocityVectorArrayName).GetComponent(j,2)

                    u_component.InsertTuple1(j, u_val)
                    v_component.InsertTuple1(j, v_val)
                    w_component.InsertTuple1(j, w_val)

                    j+=1

                  u_component.SetName(u_name+"_"+str(step))
                  self.Mesh.GetPointData().AddArray(u_component)

                  v_component.SetName(v_name+"_"+str(step))
                  self.Mesh.GetPointData().AddArray(v_component)

                  w_component.SetName(w_name+"_"+str(step))
                  self.Mesh.GetPointData().AddArray(w_component)

                else:

                  u = mesh.GetPointData().GetArray(u_name)
                  u.SetName(u_name+"_"+str(step))
                  self.Mesh.GetPointData().AddArray(u)

                  v = mesh.GetPointData().GetArray(v_name)
                  v.SetName(v_name+"_"+str(step))
                  self.Mesh.GetPointData().AddArray(v)

                  w = mesh.GetPointData().GetArray(w_name)
                  w.SetName(w_name+"_"+str(step))
                  self.Mesh.GetPointData().AddArray(w)

                if self.WsrVector:
                    vectorFromComponents.Mesh = self.Mesh
                    vectorFromComponents.VectorArrayName = "Wsr_"+str(step)
                    vectorFromComponents.ComponentsArrayNames = [taux.GetName(),tauy.GetName(),tauz.GetName()]
                    vectorFromComponents.RemoveComponentArrays = True
                    vectorFromComponents.Execute()

        field.AddArray(timesteps)
        self.Mesh.SetFieldData(field)