def load_ugrid_geometry(self, ugrid_filename, dirname, name='main', plot=True): #skip_reading = self.remove_old_openfoam_geometry(openfoam_filename) #if skip_reading: # return if is_binary_file(ugrid_filename): model = UGRID(log=self.log, debug=True) base, fmt, ext = os.path.basename(ugrid_filename).split('.') is_2d = False else: base, ext = os.path.basename(ugrid_filename).split('.') model = UGRID2D_Reader(log=self.log, debug=True) is_2d = True self.model_type = 'ugrid' print('ugrid_filename = %s' % ugrid_filename) assert ext == 'ugrid', ugrid_filename model.read_ugrid(ugrid_filename) if is_2d: tris = model.tris quads = model.quads else: tris = model.tris - 1 quads = model.quads - 1 #self.nodes = nodes #self.tris = tris #self.quads = quads #self.pids = pids #self.tets = tets #self.penta5s = penta5s #self.penta6s = penta6s #self.hexas = hexas nnodes = model.nodes.shape[0] ntris = model.tris.shape[0] nquads = model.quads.shape[0] nelements = ntris + nquads nodes = model.nodes self.nElements = nelements self.nNodes = nnodes print("nNodes = %s" % self.nNodes) print("nElements = %s" % self.nElements) assert nelements > 0, nelements self.grid.Allocate(self.nElements, 1000) points = vtk.vtkPoints() points.SetNumberOfPoints(self.nNodes) mmax = amax(nodes, axis=0) mmin = amin(nodes, axis=0) dim_max = (mmax - mmin).max() self.create_global_axes(dim_max) self.log.info('max = %s' % mmax) self.log.info('min = %s' % mmin) diff_node_ids = model.check_hanging_nodes(stop_on_diff=False) if len(diff_node_ids): red = (1., 0., 0.) self.create_alternate_vtk_grid('hanging_nodes', color=red, line_width=5, opacity=1., point_size=10, representation='point') self._add_ugrid_nodes_to_grid('hanging_nodes', diff_node_ids, nodes) self._add_alt_actors(self.alt_grids) for inode, node in enumerate(nodes): points.InsertPoint(inode, node) if ntris: for eid, element in enumerate(tris): elem = vtkTriangle() elem.GetPointIds().SetId(0, element[0]) elem.GetPointIds().SetId(1, element[1]) elem.GetPointIds().SetId(2, element[2]) self.grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) if nquads: for eid, element in enumerate(quads): elem = vtkQuad() elem.GetPointIds().SetId(0, element[0]) elem.GetPointIds().SetId(1, element[1]) elem.GetPointIds().SetId(2, element[2]) elem.GetPointIds().SetId(3, element[3]) self.grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) self.nElements = nelements self.grid.SetPoints(points) self.grid.Modified() print('update...') if hasattr(self.grid, 'Update'): self.grid.Update() #print("updated grid") # loadCart3dResults - regions/loads self. turn_text_on() self.scalarBar.VisibilityOn() self.scalarBar.Modified() self.iSubcaseNameMap = {1: ['AFLR UGRID Surface', '']} cases = {} ID = 1 if hasattr(model, 'pids'): form, cases = self._fill_ugrid3d_case(ugrid_filename, cases, ID, nnodes, nelements, model) else: form, cases = self._fill_ugrid2d_case(ugrid_filename, cases, ID, nnodes, nelements, model) if plot: self._finish_results_io2(form, cases)
def load_ugrid_geometry(self, ugrid_filename, dirname, name='main', plot=True): #skip_reading = self.remove_old_openfoam_geometry(openfoam_filename) #if skip_reading: # return if is_binary_file(ugrid_filename): model = UGRID(log=self.log, debug=True) base, fmt, ext = os.path.basename(ugrid_filename).split('.') is_2d = False else: base, ext = os.path.basename(ugrid_filename).split('.') model = UGRID2D_Reader(log=self.log, debug=True) is_2d = True self.model_type = 'ugrid' self.log.debug('ugrid_filename = %s' % ugrid_filename) assert ext == 'ugrid', ugrid_filename model.read_ugrid(ugrid_filename) if is_2d: tris = model.tris quads = model.quads else: tris = model.tris - 1 quads = model.quads - 1 #self.nodes = nodes #self.tris = tris #self.quads = quads #self.pids = pids #self.tets = tets #self.penta5s = penta5s #self.penta6s = penta6s #self.hexas = hexas nnodes = model.nodes.shape[0] ntris = model.tris.shape[0] nquads = model.quads.shape[0] nelements = ntris + nquads nodes = model.nodes self.nElements = nelements self.nNodes = nnodes self.log.info("nnodes=%s nelements=%s" % (self.nNodes, self.nElements)) assert nelements > 0, nelements self.grid.Allocate(self.nElements, 1000) points = vtk.vtkPoints() points.SetNumberOfPoints(self.nNodes) mmax = amax(nodes, axis=0) mmin = amin(nodes, axis=0) dim_max = (mmax - mmin).max() self.create_global_axes(dim_max) self.log.info('max = %s' % mmax) self.log.info('min = %s' % mmin) diff_node_ids = model.check_hanging_nodes(stop_on_diff=False) if len(diff_node_ids): red = (1., 0., 0.) self.create_alternate_vtk_grid('hanging_nodes', color=red, line_width=5, opacity=1., point_size=10, representation='point') self._add_ugrid_nodes_to_grid('hanging_nodes', diff_node_ids, nodes) self._add_alt_actors(self.alt_grids) data_type = vtk.VTK_FLOAT points_array = numpy_to_vtk( num_array=nodes, deep=True, array_type=data_type ) points.SetData(points_array) if ntris: for eid, element in enumerate(tris): elem = vtkTriangle() elem.GetPointIds().SetId(0, element[0]) elem.GetPointIds().SetId(1, element[1]) elem.GetPointIds().SetId(2, element[2]) self.grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) if nquads: for eid, element in enumerate(quads): elem = vtkQuad() elem.GetPointIds().SetId(0, element[0]) elem.GetPointIds().SetId(1, element[1]) elem.GetPointIds().SetId(2, element[2]) elem.GetPointIds().SetId(3, element[3]) self.grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) self.nElements = nelements self.grid.SetPoints(points) self.grid.Modified() self.log.info('update...') if hasattr(self.grid, 'Update'): self.grid.Update() #self.log.info("updated grid") # loadCart3dResults - regions/loads self. turn_text_on() self.scalarBar.VisibilityOn() self.scalarBar.Modified() self.iSubcaseNameMap = {1: ['AFLR UGRID Surface', '']} cases = {} ID = 1 if hasattr(model, 'pids'): form, cases = self._fill_ugrid3d_case( ugrid_filename, cases, ID, nnodes, nelements, model) else: form, cases = self._fill_ugrid2d_case( ugrid_filename, cases, ID, nnodes, nelements, model) if plot: self._finish_results_io2(form, cases)