def load_ugrid_geometry(self, ugrid_filename, read_solids=False, name='main', plot=True): """ The entry point for UGRID geometry loading. Parameters ---------- ugrid_filename : str the ugrid filename to load read_solids : bool True : load the tets/pentas/hexas from the UGRID3D model False : UGRID2D or limits the UGRID3D model to tris/quads name : str the name of the "main" actor for the GUI plot : bool; default=True should the model be generated or should we wait until after the results are loaded """ model_name = name #skip_reading = self.remove_old_openfoam_geometry(openfoam_filename) #if skip_reading: # return model, is_2d, is_3d = get_ugrid_model(ugrid_filename, read_solids, self.gui.log) self.gui.model_type = 'ugrid' self.gui.log.debug('ugrid_filename = %s' % ugrid_filename) model.read_ugrid(ugrid_filename) self.gui.model = model nnodes = model.nodes.shape[0] ntris = model.tris.shape[0] nquads = model.quads.shape[0] ntets = 0 npenta5s = 0 npenta6s = 0 nhexas = 0 if is_2d: tris = model.tris quads = model.quads nelements = ntris + nquads else: if read_solids: ntets = model.tets.shape[0] npenta5s = model.penta5s.shape[0] npenta6s = model.penta6s.shape[0] nhexas = model.hexas.shape[0] tets = model.tets - 1 penta5s = model.penta5s - 1 penta6s = model.penta6s - 1 hexas = model.hexas - 1 nelements = ntets + npenta5s + npenta6s + nhexas else: tris = model.tris - 1 quads = model.quads - 1 nelements = ntris + nquads #self.nodes = nodes #self.tris = tris #self.quads = quads #self.pids = pids #self.tets = tets #self.penta5s = penta5s #self.penta6s = penta6s #self.hexas = hexas nodes = model.nodes self.gui.nelements = nelements self.gui.nnodes = nnodes self.gui.log.info("nnodes=%s nelements=%s" % (self.gui.nnodes, self.gui.nelements)) assert nelements > 0, nelements grid = self.gui.grid grid.Allocate(self.gui.nelements, 1000) mmax = amax(nodes, axis=0) mmin = amin(nodes, axis=0) dim_max = (mmax - mmin).max() self.gui.create_global_axes(dim_max) self.gui.log.info('max = %s' % mmax) self.gui.log.info('min = %s' % mmin) if is_3d and read_solids: diff_node_ids = model.check_hanging_nodes(stop_on_diff=False) if len(diff_node_ids): self.gui.create_alternate_vtk_grid('hanging_nodes', color=RED_FLOAT, line_width=5, opacity=1., point_size=10, representation='point') self._add_ugrid_nodes_to_grid('hanging_nodes', diff_node_ids, nodes) self.gui._add_alt_actors(self.gui.alt_grids) points = numpy_to_vtk_points(nodes) elements = [] etypes = [] if is_2d or not read_solids: if ntris: elements.append(tris) etypes.append(5) # vtkTriangle().GetCellType() if nquads: elements.append(quads) etypes.append(9) # vtkQuad().GetCellType() elif is_3d: if ntets: elements.append(tets) etypes.append(10) # VTK_TETRA().GetCellType() if npenta5s: elements.append(penta5s) etypes.append(14) # vtk.vtkPyramid().GetCellType() if npenta6s: elements.append(penta6s) etypes.append(13) # VTK_WEDGE().GetCellType() if nhexas: elements.append(hexas) etypes.append(12) # VTK_HEXAHEDRON().GetCellType() self.gui.model.elements = elements self.gui.model.etypes = etypes create_vtk_cells_of_constant_element_types(grid, elements, etypes) self.gui.nelements = nelements grid.SetPoints(points) grid.Modified() # loadCart3dResults - regions/loads self.gui.scalar_bar_actor.VisibilityOn() self.gui.scalar_bar_actor.Modified() self.gui.isubcase_name_map = {1: ['AFLR UGRID Surface', '']} cases = OrderedDict() ID = 1 if hasattr(model, 'pids'): form, cases, node_ids, element_ids = self._fill_ugrid3d_case( ugrid_filename, cases, ID, nnodes, nelements, model, read_solids) else: form, cases, node_ids, element_ids = self._fill_ugrid2d_case( cases, ID, nnodes, nelements) self.gui.node_ids = node_ids self.gui.element_ids = element_ids if plot: self.gui._finish_results_io2(model_name, form, cases)
def load_vrml_geometry(self, vrml_filename, name='main', plot=True): """loads a VRML file into the GUI""" model_name = name #key = self.case_keys[self.icase] #case = self.result_cases[key] self.gui.eid_maps[name] = {} self.gui.nid_maps[name] = {} skip_reading = self.gui._remove_old_geometry(vrml_filename) if skip_reading: return nodes, quads, tris = read_vrml(vrml_filename) points = numpy_to_vtk_points(nodes) nnodes = nodes.shape[0] assert nnodes > 0 ntris = len(tris) nquads = len(quads) nelements = ntris + nquads self.gui.nelements = nelements self.gui.nnodes = nnodes self.gui.log.info( f"nnodes={nnodes} nelements={nelements} (nquads={nquads} ntris={ntris})" ) assert nelements > 0, nelements grid = self.gui.grid grid.Allocate(self.gui.nelements, 1000) #self.gui.nid_map = {} etypes = [] elements = [] if ntris: elements.append(tris) etypes.append(5) # vtkTriangle().GetCellType() if nquads: elements.append(quads) etypes.append(9) # vtkQuad().GetCellType() assert len(etypes) > 0, etypes #self.gui.model.elements = elements #self.gui.model.etypes = etypes create_vtk_cells_of_constant_element_types(grid, elements, etypes) self.gui.nelements = nelements grid.SetPoints(points) grid.Modified() #------------------------------------------------ self.gui.scalar_bar_actor.VisibilityOn() self.gui.scalar_bar_actor.Modified() self.gui.isubcase_name_map = {1: ['AFLR UGRID Surface', '']} cases = OrderedDict() ID = 1 node_ids = np.arange(1, nnodes + 1, dtype='int32') element_ids = np.arange(1, nelements + 1, dtype='int32') self.gui.node_ids = node_ids self.gui.element_ids = element_ids #eids = arange(1, len(elements) + 1, dtype='int32') #nids = arange(1, len(nodes) + 1, dtype='int32') #regions = np.array(regions, dtype='int32') icase = 0 colormap = self.gui.settings.colormap eid_res = GuiResult(ID, header='ElementID', title='ElementID', location='centroid', scalar=element_ids) nid_res = GuiResult(ID, header='NodeID', title='NodeID', location='node', scalar=node_ids) nxyz_res = NormalResult(0, 'Normals', 'Normals', nlabels=2, labelsize=5, ncolors=2, colormap=colormap, data_format='%.1f', uname='NormalResult') geometry_form = [ ('ElementID', icase, []), ('NodeID', icase + 1, []), ('Normals', icase + 2, []), ] cases[icase] = (eid_res, (ID, 'ElementID')) cases[icase + 1] = (nid_res, (ID, 'NodeID')) cases[icase + 2] = (nxyz_res, (0, 'Normals')) form = geometry_form if plot: self.gui._finish_results_io2(model_name, form, cases)
def load_surf_geometry(self, surf_filename, name=None, plot=True): #skip_reading = self.remove_old_openfoam_geometry(openfoam_filename) #if skip_reading: # return model = SurfReader() self.gui.model_type = 'surf' self.gui.log.debug('surf_filename = %s' % surf_filename) model.read_surf(surf_filename) nnodes = model.nodes.shape[0] ntris = model.tris.shape[0] nquads = model.quads.shape[0] nelements = ntris + nquads nodes = model.nodes self.gui.nelements = nelements self.gui.nnodes = nnodes #print("nNodes = %s" % self.nnodes) #print("nElements = %s" % self.nelements) assert nelements > 0, nelements mmax = amax(nodes, axis=0) mmin = amin(nodes, axis=0) dim_max = (mmax - mmin).max() self.gui.create_global_axes(dim_max) self.gui.log.info('max = %s' % mmax) self.gui.log.info('min = %s' % mmin) points = numpy_to_vtk_points(nodes) tris = model.tris - 1 quads = model.quads - 1 grid = self.gui.grid grid.Allocate(self.gui.nelements, 1000) elements = [] etypes = [] if ntris: elements.append(tris) etypes.append(5) # vtkTriangle().GetCellType() if nquads: elements.append(quads) etypes.append(9) # vtkQuad().GetCellType() create_vtk_cells_of_constant_element_types(grid, elements, etypes) model.read_surf_failnode(surf_filename) if len(model.nodes_failed): if 'failed_nodes' not in self.gui.alt_grids: self.gui.create_alternate_vtk_grid('failed_nodes', color=YELLOW_FLOAT, line_width=3, opacity=1.0) ifailed = where(model.nodes_failed == 1)[0] nfailed = len(ifailed) failed_grid = self.gui.alt_grids['failed_nodes'] failed_grid.Allocate(nfailed, 1000) points2 = vtk.vtkPoints() points2.SetNumberOfPoints(nfailed) for j, nid in enumerate(model.nodes_failed): elem = vtk.vtkVertex() c = nodes[nid - 1, :] self.gui.log.debug('%s %s' % (nid, c)) points2.InsertPoint(j, *c) elem.GetPointIds().SetId(0, j) failed_grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) failed_grid.SetPoints(points2) self.gui._add_alt_actors(self.gui.alt_grids) actor = self.gui.geometry_actors['failed_nodes'] actor.Modified() prop = actor.GetProperty() prop.SetRepresentationToPoints() prop.SetPointSize(10) self.gui.nelements = nelements grid.SetPoints(points) grid.Modified() if hasattr(grid, 'Update'): grid.Update() #self.log_info("updated grid") # loadSurfResults - regions/loads self.gui.scalar_bar_actor.VisibilityOn() self.gui.scalar_bar_actor.Modified() self.gui.isubcase_name_map = {1: ['AFLR Surface', '']} cases = OrderedDict() ID = 1 form, cases, node_ids, element_ids = self._fill_surf_case( surf_filename, cases, ID, nnodes, nelements, model) self.gui.node_ids = node_ids self.gui.element_ids = element_ids if plot: self.gui._finish_results_io2(form, cases)