def load_panair_geometry(self, panair_filename, dirname, name='main', plot=True): self.nid_map = {} #key = self.case_keys[self.icase] #case = self.result_cases[key] skip_reading = self._remove_old_geometry(panair_filename) if skip_reading: return model = PanairGrid(log=self.log, debug=self.debug) self.model_type = model.model_type model.read_panair(panair_filename) nodes, elements, regions = model.get_points_elements_regions() #for nid,node in enumerate(nodes): #print "node[%s] = %s" %(nid,str(node)) self.nNodes = len(nodes) self.nElements = len(elements) #print("nNodes = ",self.nNodes) #print("nElements = ", self.nElements) self.grid.Allocate(self.nElements, 1000) #self.gridResult.SetNumberOfComponents(self.nElements) points = vtk.vtkPoints() points.SetNumberOfPoints(self.nNodes) #self.gridResult.Allocate(self.nNodes, 1000) #vectorReselt.SetNumberOfComponents(3) #elem.SetNumberOfPoints(nNodes) if 0: fraction = 1. / nnodes # so you can color the nodes by ID for nid, node in sorted(iteritems(nodes)): points.InsertPoint(nid - 1, *point) self.gridResult.InsertNextValue(nid * fraction) #print str(element) #elem = vtk.vtkVertex() #elem.GetPointIds().SetId(0, i) #self.aQuadGrid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) #vectorResult.InsertTuple3(0, 0.0, 0.0, 1.0) assert len(nodes) > 0 mmax = amax(nodes, axis=0) mmin = amin(nodes, axis=0) dim_max = (mmax - mmin).max() self.create_global_axes(dim_max) for nid, node in enumerate(nodes): points.InsertPoint(nid, *node) assert len(elements) > 0 elem = vtkQuad() quad_type = elem.GetCellType() for eid, element in enumerate(elements): (p1, p2, p3, p4) = element elem = vtkQuad() elem.GetPointIds().SetId(0, p1) elem.GetPointIds().SetId(1, p2) elem.GetPointIds().SetId(2, p3) elem.GetPointIds().SetId(3, p4) self.grid.InsertNextCell(quad_type, elem.GetPointIds()) self.grid.SetPoints(points) #self.grid.GetPointData().SetScalars(self.gridResult) #print dir(self.grid) #.SetNumberOfComponents(0) #self.grid.GetCellData().SetNumberOfTuples(1); #self.grid.GetCellData().SetScalars(self.gridResult) self.grid.Modified() if hasattr(self.grid, 'Update'): self.grid.Update() # loadPanairResults - regions/loads self. turn_text_on() self.scalarBar.VisibilityOn() self.scalarBar.Modified() self.iSubcaseNameMap = {1: ['Panair', '']} cases = {} ID = 1 #print "nElements = ",nElements loads = [] form, cases = self._fill_panair_geometry_case(cases, ID, nodes, elements, regions, loads) self._finish_results_io2(form, cases)
def load_panair_geometry(self, panairFileName, dirname, plot=True): self.nidMap = {} #key = self.caseKeys[self.iCase] #case = self.resultCases[key] skipReading = self.removeOldGeometry(panairFileName) if skipReading: return model = PanairGrid(log=self.log, debug=self.debug) self.modelType = model.modelType model.read_panair(panairFileName) nodes, elements, regions = model.getPointsElementsRegions() #for nid,node in enumerate(nodes): #print "node[%s] = %s" %(nid,str(node)) self.nNodes = len(nodes) self.nElements = len(elements) #print("nNodes = ",self.nNodes) #print("nElements = ", self.nElements) self.grid.Allocate(self.nElements, 1000) #self.gridResult.SetNumberOfComponents(self.nElements) self.grid2.Allocate(1, 1000) points = vtk.vtkPoints() points.SetNumberOfPoints(self.nNodes) #self.gridResult.Allocate(self.nNodes, 1000) #vectorReselt.SetNumberOfComponents(3) #elem.SetNumberOfPoints(nNodes) if 0: fraction = 1. / nNodes # so you can color the nodes by ID for nid, node in sorted(iteritems(nodes)): points.InsertPoint(nid - 1, *point) self.gridResult.InsertNextValue(nid * fraction) #print str(element) #elem = vtk.vtkVertex() #elem.GetPointIds().SetId(0, i) #self.aQuadGrid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) #vectorResult.InsertTuple3(0, 0.0, 0.0, 1.0) assert len(nodes) > 0 mmax = amax(nodes, axis=0) mmin = amin(nodes, axis=0) dim_max = (mmax - mmin).max() self.update_axes_length(dim_max) for nid, node in enumerate(nodes): points.InsertPoint(nid, *node) assert len(elements) > 0 for eid, element in enumerate(elements): (p1, p2, p3, p4) = element #print "element = ",element elem = vtkQuad() elem.GetPointIds().SetId(0, p1) elem.GetPointIds().SetId(1, p2) elem.GetPointIds().SetId(2, p3) elem.GetPointIds().SetId(3, p4) self.grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) #print("eid = ", eid) self.grid.SetPoints(points) #self.grid2.SetPoints(points2) #self.grid.GetPointData().SetScalars(self.gridResult) #print dir(self.grid) #.SetNumberOfComponents(0) #self.grid.GetCellData().SetNumberOfTuples(1); #self.grid.GetCellData().SetScalars(self.gridResult) self.grid.Modified() self.grid2.Modified() if hasattr(self.grid, 'Update'): self.grid.Update() self.grid2.Update() print("updated grid") #return # loadCart3dResults - regions/loads self.TurnTextOn() self.scalarBar.VisibilityOn() self.scalarBar.Modified() self.iSubcaseNameMap = {1: ['Panair', '']} cases = {} ID = 1 #print "nElements = ",nElements loads = [] cases = self.fillPanairGeometryCase(cases, ID, nodes, elements, regions, loads) self._finish_results_io(cases)
def load_panair_geometry(self, panairFileName, dirname, plot=True): self.nidMap = {} #key = self.caseKeys[self.iCase] #case = self.resultCases[key] skipReading = self.removeOldGeometry(panairFileName) if skipReading: return model = PanairGrid(log=self.log, debug=self.debug) self.modelType = model.modelType model.read_panair(panairFileName) nodes, elements, regions = model.getPointsElementsRegions() #for nid,node in enumerate(nodes): #print "node[%s] = %s" %(nid,str(node)) self.nNodes = len(nodes) self.nElements = len(elements) #print("nNodes = ",self.nNodes) #print("nElements = ", self.nElements) self.grid.Allocate(self.nElements, 1000) #self.gridResult.SetNumberOfComponents(self.nElements) self.grid2.Allocate(1, 1000) points = vtk.vtkPoints() points.SetNumberOfPoints(self.nNodes) #self.gridResult.Allocate(self.nNodes, 1000) #vectorReselt.SetNumberOfComponents(3) #elem.SetNumberOfPoints(nNodes) if 0: fraction = 1. / nNodes # so you can color the nodes by ID for nid, node in sorted(iteritems(nodes)): points.InsertPoint(nid - 1, *point) self.gridResult.InsertNextValue(nid * fraction) #print str(element) #elem = vtk.vtkVertex() #elem.GetPointIds().SetId(0, i) #self.aQuadGrid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) #vectorResult.InsertTuple3(0, 0.0, 0.0, 1.0) assert len(nodes) > 0 mmax = amax(nodes, axis=0) mmin = amin(nodes, axis=0) dim_max = (mmax - mmin).max() self.update_axes_length(dim_max) for nid, node in enumerate(nodes): points.InsertPoint(nid, *node) assert len(elements) > 0 for eid, element in enumerate(elements): (p1, p2, p3, p4) = element #print "element = ",element elem = vtkQuad() elem.GetPointIds().SetId(0, p1) elem.GetPointIds().SetId(1, p2) elem.GetPointIds().SetId(2, p3) elem.GetPointIds().SetId(3, p4) self.grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) #print("eid = ", eid) self.grid.SetPoints(points) #self.grid2.SetPoints(points2) #self.grid.GetPointData().SetScalars(self.gridResult) #print dir(self.grid) #.SetNumberOfComponents(0) #self.grid.GetCellData().SetNumberOfTuples(1); #self.grid.GetCellData().SetScalars(self.gridResult) self.grid.Modified() self.grid2.Modified() self.grid.Update() self.grid2.Update() print("updated grid") #return # loadCart3dResults - regions/loads self.TurnTextOn() self.scalarBar.VisibilityOn() self.scalarBar.Modified() self.iSubcaseNameMap = {1: ['Panair', '']} cases = {} ID = 1 #print "nElements = ",nElements loads = [] cases = self.fillPanairGeometryCase(cases, ID, nodes, elements, regions, loads) self._finish_results_io(cases)
def write_panair(self, panair_filename, panair_case_filename): #panair_file = open(panair_filename, 'wb') pan = PanairGrid() pan.mach = 0.5 pan.isEnd = True pan.ncases = 2 pan.alphas = [0., 5.] i = 0 pan.nNetworks = 1 kt = 1 cpNorm = 1 for name, comps in sorted(iteritems(self.components)): #panair_file.write('$ name = %r\n' % name) for comp in comps: namei = name + str(i) x = deepcopy(comp.lifting_surface_xyz[:, 0]) y = deepcopy(comp.lifting_surface_xyz[:, 1]) z = deepcopy(comp.lifting_surface_xyz[:, 2]) x = x.reshape((comp.lifting_surface_nx, comp.lifting_surface_ny)) y = y.reshape((comp.lifting_surface_nx, comp.lifting_surface_ny)) z = z.reshape((comp.lifting_surface_nx, comp.lifting_surface_ny)) patch = PanairPatch(pan.nNetworks, namei, kt, cpNorm, x, y, z, self.log) pan.patches[i] = patch pan.nNetworks += 1 i += 1 if 'wing' in name.lower(): # make a wing cap namei = 'cap%i' % i #assert comp.lifting_surface_nx == 6, comp.lifting_surface_nx assert comp.lifting_surface_ny == 33, comp.lifting_surface_ny #print(x.shape) xend = deepcopy(x[-1, :]) print(xend) yend = deepcopy(y[-1, :]) zend = deepcopy(z[-1, :]) imid = comp.lifting_surface_ny // 2 x = zeros((imid+1, 2), dtype='float32') y = zeros((imid+1, 2), dtype='float32') z = zeros((imid+1, 2), dtype='float32') print(imid, xend[imid], xend.min()) xflip = list(xend[0:imid+1]) yflip = list(yend[0:imid+1]) zflip = list(zend[0:imid+1]) x[:, 0] = xflip[::-1] y[:, 0] = yflip[::-1] z[:, 0] = zflip[::-1] x[:, 1] = xend[imid:] y[:, 1] = yend[imid:] z[:, 1] = zend[imid:] print x #x = xend[0:imid:-1].extend(x[imid:]) #y = yend[0:imid:-1].extend(y[imid:]) #z = zend[0:imid:-1].extend(z[imid:]) #print(x) x = x.reshape((2, imid+1)) y = y.reshape((2, imid+1)) z = z.reshape((2, imid+1)) #print(xend) patch = PanairPatch(pan.nNetworks, namei, kt, cpNorm, x.T, y.T, z.T, self.log) pan.patches[i] = patch pan.nNetworks += 1 i += 1 #i += 1 pan.write_panair(panair_filename)
def load_panair_geometry(self, panairFileName, dirname): self.nidMap = {} #key = self.caseKeys[self.iCase] #case = self.resultCases[key] skipReading = self.removeOldGeometry(panairFileName) if skipReading: return model = PanairGrid(panairFileName, log=self.log, debug=self.debug) self.modelType = model.modelType model.read_panair() nodes, elements, regions = model.getPointsElementsRegions() #for nid,node in enumerate(nodes): #print "node[%s] = %s" %(nid,str(node)) self.nNodes = len(nodes) self.nElements = len(elements) #print("nNodes = ",self.nNodes) print("nElements = ", self.nElements) self.grid.Allocate(self.nElements, 1000) #self.gridResult.SetNumberOfComponents(self.nElements) self.grid2.Allocate(1, 1000) points = vtk.vtkPoints() points.SetNumberOfPoints(self.nNodes) #self.gridResult.Allocate(self.nNodes, 1000) #vectorReselt.SetNumberOfComponents(3) #elem.SetNumberOfPoints(nNodes) if 0: fraction = 1. / nNodes # so you can color the nodes by ID for nid, node in sorted(nodes.iteritems()): points.InsertPoint(nid - 1, *point) self.gridResult.InsertNextValue(nid * fraction) #print str(element) #elem = vtk.vtkVertex() #elem.GetPointIds().SetId(0, i) #self.aQuadGrid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) #vectorResult.InsertTuple3(0, 0.0, 0.0, 1.0) for nid, node in enumerate(nodes): points.InsertPoint(nid, *node) #print "nid = ",nid for eid, element in enumerate(elements): (p1, p2, p3, p4) = element #print "element = ",element elem = vtkQuad() elem.GetPointIds().SetId(0, p1) elem.GetPointIds().SetId(1, p2) elem.GetPointIds().SetId(2, p3) elem.GetPointIds().SetId(3, p4) self.grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) print("eid = ", eid) self.grid.SetPoints(points) #self.grid2.SetPoints(points2) #self.grid.GetPointData().SetScalars(self.gridResult) #print dir(self.grid) #.SetNumberOfComponents(0) #self.grid.GetCellData().SetNumberOfTuples(1); #self.grid.GetCellData().SetScalars(self.gridResult) self.grid.Modified() self.grid2.Modified() self.grid.Update() self.grid2.Update() print("updated grid") #return # loadCart3dResults - regions/loads self.TurnTextOn() self.scalarBar.VisibilityOn() self.scalarBar.Modified() self.iSubcaseNameMap = {1: ['Panair', '']} cases = {} ID = 1 #print "nElements = ",nElements loads = [] cases = self.fillPanairGeometryCase(cases, ID, nodes, elements, regions, loads) self.resultCases = cases self.caseKeys = sorted(cases.keys()) print "caseKeys = ",self.caseKeys #print "type(caseKeys) = ",type(self.caseKeys) self.iCase = -1 self.nCases = len(self.resultCases) #- 1 # number of keys in dictionary if self.nCases > 1: self.nCases -= 1 self.cycleResults() # start at nCase=0