def test_fgrid_io_01(self): infile_name = os.path.join(test_path, 'flow_demo1', 'om6inviscid.fgrid') fgrid = FGridReader(log=None, debug=False) fgrid.read_fgrid(infile_name) #self.nodes = nodes #self.tris = tris #self.tets = tets assert len(fgrid.nodes) == 2800, 'nodes=%s' % len(fgrid.nodes) assert len(fgrid.tris) == 2004, 'tris=%s' % len(fgrid.tris) assert len(fgrid.tets) == 13576, 'tets=%s' % len(fgrid.tets)
def test_fgrid_io_01(self): infile_name = os.path.join(TEST_PATH, 'flow_demo1', 'om6inviscid.fgrid') fgrid = FGridReader(log=None, debug=None) fgrid.read_fgrid(infile_name) #self.nodes = nodes #self.tris = tris #self.tets = tets assert len(fgrid.nodes) == 2800, 'nodes=%s' % len(fgrid.nodes) assert len(fgrid.tris) == 2004, 'tris=%s' % len(fgrid.tris) assert len(fgrid.tets) == 13576, 'tets=%s' % len(fgrid.tets)
def load_fast_geometry(self, fgrid_filename, dirname, name='main', plot=True): skip_reading = self._remove_old_geometry(fgrid_filename) if skip_reading: return model = FGridReader(log=self.log, debug=False) base_filename, ext = os.path.splitext(fgrid_filename) if '.fgrid' == ext: dimension_flag = 3 #elif '.ele' == ext: #dimension_flag = 3 else: raise RuntimeError('unsupported extension. Use "cogsg" or "front".') read_loads = True model.read_fgrid(fgrid_filename, dimension_flag) dimension_flag = 3 nodes = model.nodes tris = model.tris - 1 tets = model.tets - 1 nnodes = nodes.shape[0] ntris = tris.shape[0] ntets = tets.shape[0] #print('node0 = %s' % str(nodes[0, :])) #print('node%i = %s' % (1, str(nodes[1, :]))) #print('node%i = %s' % (2, str(nodes[2, :]))) #print('node%i = %s' % (nnodes, str(nodes[-1, :]))) #print('tris.max/min = ', tris.max(), tris.min()) #print('tets.max/min = ', tets.max(), tets.min()) #bcs = model.bcs #mapbc = model.mapbc #loads = model.loads self.nNodes = nnodes self.nElements = ntris + ntets #print("nNodes = %i" % self.nNodes) #print("nElements = %i" % self.nElements) self.grid.Allocate(self.nElements, 1000) #self.gridResult.SetNumberOfComponents(self.nElements) points = vtk.vtkPoints() points.SetNumberOfPoints(self.nNodes) self.nid_map = {} if 0: fraction = 1. / self.nNodes # so you can color the nodes by ID for nid, node in sorted(iteritems(nodes)): points.InsertPoint(nid - 1, *node) self.gridResult.InsertNextValue(nid * fraction) assert nodes is not None nnodes = nodes.shape[0] nid = 0 for i in range(nnodes): points.InsertPoint(nid, nodes[i, :]) nid += 1 if dimension_flag == 2: for (n0, n1, n2) in tris: elem = vtkTriangle() #node_ids = elements[eid, :] elem.GetPointIds().SetId(0, n0) elem.GetPointIds().SetId(1, n1) elem.GetPointIds().SetId(2, n2) self.grid.InsertNextCell(5, elem.GetPointIds()) #elem.GetCellType() = 5 # vtkTriangle elif dimension_flag == 3: if ntets: for (n0, n1, n2, n3) in tets: elem = vtkTetra() elem.GetPointIds().SetId(0, n0) elem.GetPointIds().SetId(1, n1) elem.GetPointIds().SetId(2, n2) elem.GetPointIds().SetId(3, n3) self.grid.InsertNextCell(10, elem.GetPointIds()) #elem.GetCellType() = 5 # vtkTriangle else: raise RuntimeError('dimension_flag=%r' % dimension_flag) self.grid.SetPoints(points) self.grid.Modified() if hasattr(self.grid, 'Update'): self.grid.Update() # regions/loads self. turn_text_on() self.scalarBar.Modified() cases = {} #cases = self.result_cases self._fill_fast_results(cases, model, results=False) self._finish_results_io(cases)
def load_fast_geometry(self, fgrid_filename, name='main', plot=True): skip_reading = self._remove_old_geometry(fgrid_filename) if skip_reading: return model = FGridReader(log=self.log, debug=False) base_filename, ext = os.path.splitext(fgrid_filename) if '.fgrid' == ext: dimension_flag = 3 #elif '.ele' == ext: #dimension_flag = 3 else: raise RuntimeError( 'unsupported extension. Use "cogsg" or "front".') read_loads = True model.read_fgrid(fgrid_filename, dimension_flag) dimension_flag = 3 nodes = model.nodes tris = model.tris - 1 tets = model.tets - 1 nnodes = nodes.shape[0] ntris = tris.shape[0] ntets = tets.shape[0] #print('node0 = %s' % str(nodes[0, :])) #print('node%i = %s' % (1, str(nodes[1, :]))) #print('node%i = %s' % (2, str(nodes[2, :]))) #print('node%i = %s' % (nnodes, str(nodes[-1, :]))) #print('tris.max/min = ', tris.max(), tris.min()) #print('tets.max/min = ', tets.max(), tets.min()) #bcs = model.bcs #mapbc = model.mapbc #loads = model.loads self.nNodes = nnodes self.nElements = ntris + ntets #print("nNodes = %i" % self.nNodes) #print("nElements = %i" % self.nElements) grid = self.grid grid.Allocate(self.nElements, 1000) #self.gridResult.SetNumberOfComponents(self.nElements) points = self.numpy_to_vtk_points(nodes) self.nid_map = {} if 0: fraction = 1. / self.nNodes # so you can color the nodes by ID for nid, node in sorted(iteritems(nodes)): self.gridResult.InsertNextValue(nid * fraction) assert nodes is not None nnodes = nodes.shape[0] if dimension_flag == 2: for (n0, n1, n2) in tris: elem = vtkTriangle() #node_ids = elements[eid, :] elem.GetPointIds().SetId(0, n0) elem.GetPointIds().SetId(1, n1) elem.GetPointIds().SetId(2, n2) grid.InsertNextCell( 5, elem.GetPointIds()) #elem.GetCellType() = 5 # vtkTriangle elif dimension_flag == 3: if ntets: for (n0, n1, n2, n3) in tets: elem = vtkTetra() elem.GetPointIds().SetId(0, n0) elem.GetPointIds().SetId(1, n1) elem.GetPointIds().SetId(2, n2) elem.GetPointIds().SetId(3, n3) grid.InsertNextCell(10, elem.GetPointIds( )) #elem.GetCellType() = 5 # vtkTriangle else: raise RuntimeError('dimension_flag=%r' % dimension_flag) grid.SetPoints(points) grid.Modified() if hasattr(grid, 'Update'): grid.Update() # regions/loads self.scalarBar.Modified() cases = {} #cases = self.result_cases self._fill_fast_results(cases, model, results=False) self._finish_results_io(cases)