예제 #1
0
 def _update_grid(self, nodes):
     """deflects the geometry"""
     grid = self.grid
     points = grid.GetPoints()
     #inan = np.where(nodes.ravel() == np.nan)[0]
     #if len(inan) > 0:
         #raise RuntimeError('nan in nodes...')
     numpy_to_vtk_points(nodes, points=points, dtype='<f', deep=1)
     grid.Modified()
     self.grid_selected.Modified()
     self._update_follower_grids(nodes)
예제 #2
0
    def set_quad_grid(self,
                      name,
                      nodes,
                      elements,
                      color,
                      line_width=5,
                      opacity=1.):
        """
        Makes a CQUAD4 grid
        """
        self.create_alternate_vtk_grid(name,
                                       color=color,
                                       line_width=line_width,
                                       opacity=opacity,
                                       representation='wire')

        nnodes = nodes.shape[0]
        nquads = elements.shape[0]
        #print(nodes)
        if nnodes == 0:
            return
        if nquads == 0:
            return

        #print('adding quad_grid %s; nnodes=%s nquads=%s' % (name, nnodes, nquads))
        assert isinstance(nodes, np.ndarray), type(nodes)

        points = numpy_to_vtk_points(nodes)
        grid = self.alt_grids[name]
        grid.SetPoints(points)

        etype = 9  # vtk.vtkQuad().GetCellType()
        create_vtk_cells_of_constant_element_type(grid, elements, etype)

        self._add_alt_actors({name: self.alt_grids[name]})

        #if name in self.geometry_actors:
        self.geometry_actors[name].Modified()
예제 #3
0
    def _create_cart3d_free_edges(self, model, nodes, elements):
        """creates the free edges to help identify unclosed models"""
        free_edges_array = model.get_free_edges(elements)
        nfree_edges = len(free_edges_array)

        if nfree_edges:
            # yellow = (1., 1., 0.)
            pink = (0.98, 0.4, 0.93)
            npoints = 2 * nfree_edges
            if 'free_edges' not in self.alt_grids:
                self.create_alternate_vtk_grid('free_edges',
                                               color=pink,
                                               line_width=3,
                                               opacity=1.0,
                                               representation='surface')

            alt_grid = self.alt_grids['free_edges']
            etype = 3  # vtk.vtkLine().GetCellType()
            elements2 = np.arange(0, npoints,
                                  dtype='int32').reshape(nfree_edges, 2)
            create_vtk_cells_of_constant_element_type(alt_grid, elements2,
                                                      etype)

            #alt_grid.Allocate(nfree_edges, 1000)
            free_edge_nodes = nodes[free_edges_array.ravel(), :]
            points = numpy_to_vtk_points(free_edge_nodes)
            alt_grid.SetPoints(points)

        else:
            # TODO: clear free edges
            pass

        if 'free_edges' in self.alt_grids:
            self._add_alt_actors(self.alt_grids)
            self.geometry_actors['free_edges'].Modified()
            if hasattr(self.geometry_actors['free_edges'], 'Update'):
                self.geometry_actors['free_edges'].Update()
예제 #4
0
    def load_cart3d_geometry(self, cart3d_filename, name='main', plot=True):
        """
        The entry point for Cart3d geometry loading.

        Parameters
        ----------
        cart3d_filename : str
            the cart3d filename to load
        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
        """
        skip_reading = self._remove_old_cart3d_geometry(cart3d_filename)
        if skip_reading:
            return

        self.eid_maps[name] = {}
        self.nid_maps[name] = {}
        model = read_cart3d(cart3d_filename, log=self.log, debug=False)
        self.model_type = 'cart3d'
        nodes = model.nodes
        elements = model.elements
        regions = model.regions
        loads = model.loads

        self.nnodes = model.npoints
        self.nelements = model.nelements

        grid = self.grid
        grid.Allocate(self.nelements, 1000)

        #if 0:
        #fraction = 1. / self.nnodes  # so you can color the nodes by ID
        #for nid, node in sorted(iteritems(nodes)):
        #self.grid_result.InsertNextValue(nid * fraction)

        assert nodes is not None
        #nnodes = nodes.shape[0]

        mmax = nodes.max(axis=0)
        mmin = nodes.min(axis=0)
        dim_max = (mmax - mmin).max()
        xmax, ymax, zmax = mmax
        xmin, ymin, zmin = mmin
        self.log_info("xmin=%s xmax=%s dx=%s" % (xmin, xmax, xmax - xmin))
        self.log_info("ymin=%s ymax=%s dy=%s" % (ymin, ymax, ymax - ymin))
        self.log_info("zmin=%s zmax=%s dz=%s" % (zmin, zmax, zmax - zmin))
        self.create_global_axes(dim_max)
        points = numpy_to_vtk_points(nodes)

        #assert elements.min() == 0, elements.min()

        etype = 5  # vtkTriangle().GetCellType()
        create_vtk_cells_of_constant_element_type(grid, elements, etype)

        grid.SetPoints(points)
        grid.Modified()
        if hasattr(grid, 'Update'):
            grid.Update()
        self._create_cart3d_free_edges(model, nodes, elements)

        # loadCart3dResults - regions/loads
        self.scalarBar.VisibilityOn()
        self.scalarBar.Modified()

        assert loads is not None
        if 'Mach' in loads:
            avg_mach = mean(loads['Mach'])
            note = ':  avg(Mach)=%g' % avg_mach
        else:
            note = ''
        self.isubcase_name_map = {1: ['Cart3d%s' % note, '']}
        cases = {}
        ID = 1
        form, cases, icase = self._fill_cart3d_geometry_objects(
            cases, ID, nodes, elements, regions, model)
        mach, alpha, beta = self._create_box(cart3d_filename, ID, form, cases,
                                             icase, regions)
        #mach = None
        self._fill_cart3d_results(cases, form, icase, ID, loads, model, mach)
        self._finish_results_io2(form, cases)
예제 #5
0
    def load_openfoam_geometry(self,
                               openfoam_filename,
                               mesh_3d,
                               name='main',
                               plot=True,
                               **kwargs):
        #key = self.caseKeys[self.iCase]
        #case = self.resultCases[key]

        #skip_reading = self.remove_old_openfoam_geometry(openfoam_filename)
        skip_reading = self._remove_old_geometry(openfoam_filename)
        if skip_reading:
            return
        reset_labels = True
        #print('self.modelType=%s' % self.modelType)
        print('mesh_3d = %s' % mesh_3d)
        if mesh_3d in ['hex', 'shell']:
            model = BlockMesh(log=self.log,
                              debug=False)  # log=self.log, debug=False
        elif mesh_3d == 'faces':
            model = BlockMesh(log=self.log,
                              debug=False)  # log=self.log, debug=False
            boundary = Boundary(log=self.log, debug=False)

        self.modelType = 'openfoam'
        #self.modelType = model.modelType
        print('openfoam_filename = %s' % openfoam_filename)

        is_face_mesh = False
        if mesh_3d == 'hex':
            is_3d_blockmesh = True
            is_surface_blockmesh = False
            (nodes, hexas, quads, names,
             patches) = model.read_openfoam(openfoam_filename)
        elif mesh_3d == 'shell':
            is_3d_blockmesh = False
            is_surface_blockmesh = True
            (nodes, hexas, quads, names,
             patches) = model.read_openfoam(openfoam_filename)
        elif mesh_3d == 'faces':
            is_3d_blockmesh = False
            is_surface_blockmesh = False
            is_face_mesh = True
            #(nodes, hexas, quads, names, patches) = model.read_openfoam(openfoam_filename)
        else:
            raise RuntimeError(mesh_3d)

        tris = []

        if mesh_3d == 'hex':
            self.nelements = len(hexas)
        elif mesh_3d == 'shell':
            self.nelements = len(quads)
        elif mesh_3d == 'faces':
            dirname = os.path.dirname(openfoam_filename)
            point_filename = os.path.join(dirname, 'points')
            face_filename = os.path.join(dirname, 'faces')
            boundary_filename = os.path.join(dirname, 'boundary')
            assert os.path.exists(face_filename), print_bad_path(face_filename)
            assert os.path.exists(point_filename), print_bad_path(
                point_filename)
            assert os.path.exists(boundary_filename), print_bad_path(
                boundary_filename)

            hexas = None
            patches = None
            nodes, quads, names = boundary.read_openfoam(
                point_filename, face_filename, boundary_filename)
            self.nelements = len(quads) + len(tris)
        else:
            raise RuntimeError(mesh_3d)

        self.nnodes = len(nodes)
        print("nnodes = %s" % self.nnodes)
        print("nelements = %s" % self.nelements)

        grid = self.grid
        grid.Allocate(self.nelements, 1000)
        #self.gridResult.SetNumberOfComponents(self.nelements)

        self.nid_map = {}

        assert nodes is not None
        nnodes = nodes.shape[0]

        #nid = 0

        xmax, ymax, zmax = nodes.max(axis=0)
        xmin, ymin, zmin = nodes.min(axis=0)
        nodes -= np.array([xmin, ymin, zmin])
        self.log.info('xmax=%s xmin=%s' % (xmax, xmin))
        self.log.info('ymax=%s ymin=%s' % (ymax, ymin))
        self.log.info('zmax=%s zmin=%s' % (zmax, zmin))
        dim_max = max(xmax - xmin, ymax - ymin, zmax - zmin)

        #print()
        #dim_max = (mmax - mmin).max()
        assert dim_max > 0

        # breaks the model without subracting off the delta
        #self.update_axes_length(dim_max)
        self.create_global_axes(dim_max)

        #print('is_face_mesh=%s is_3d_blockmesh=%s is_surface_blockmesh=%s' % (
        #is_face_mesh, is_3d_blockmesh, is_surface_blockmesh))
        with open('points.bdf', 'w') as bdf_file:
            bdf_file.write('CEND\n')
            bdf_file.write('BEGIN BULK\n')

            unames = unique(names)
            for pid in unames:
                bdf_file.write('PSHELL,%i,1,0.1\n' % pid)
            bdf_file.write('MAT1,1,1.0e7,,0.3\n')

            if is_face_mesh:
                points = vtk.vtkPoints()
                points.SetNumberOfPoints(self.nnodes)

                unodes = unique(quads)
                unodes.sort()
                # should stop plotting duplicate nodes
                for inode, node in enumerate(nodes):
                    if inode in unodes:
                        bdf_file.write('GRID,%i,,%s,%s,%s\n' % (
                            inode + 1,
                            node[0],
                            node[1],
                            node[2],
                        ))
                    points.InsertPoint(inode, node)
            else:
                points = numpy_to_vtk_points(nodes)

            #elements -= 1
            normals = None
            if is_3d_blockmesh:
                nelements = hexas.shape[0]
                cell_type_hexa8 = vtkHexahedron().GetCellType()
                create_vtk_cells_of_constant_element_type(
                    grid, hexas, cell_type_hexa8)

            elif is_surface_blockmesh:
                nelements = quads.shape[0]
                cell_type_quad4 = vtkQuad().GetCellType()
                create_vtk_cells_of_constant_element_type(
                    grid, quads, cell_type_quad4)

            elif is_face_mesh:

                elems = quads
                nelements = quads.shape[0]
                nnames = len(names)
                normals = zeros((nelements, 3), dtype='float32')
                if nnames != nelements:
                    msg = 'nnames=%s nelements=%s names.max=%s names.min=%s' % (
                        nnames, nelements, names.max(), names.min())
                    raise RuntimeError(msg)
                for eid, element in enumerate(elems):
                    ineg = where(element == -1)[0]

                    nnodes = 4
                    if ineg:
                        nnodes = ineg.max()

                    #pid = 1
                    pid = names[eid]
                    if nnodes == 3:  # triangle!
                        bdf_file.write('CTRIA3,%i,%i,%i,%i,%i\n' %
                                       (eid + 1, pid, element[0] + 1,
                                        element[1] + 1, element[2] + 1))
                        elem = vtkTriangle()
                        a = nodes[element[1], :] - nodes[element[0], :]
                        b = nodes[element[2], :] - nodes[element[0], :]
                        n = cross(a, b)
                        normals[eid, :] = n / norm(n)

                        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())
                    elif nnodes == 4:
                        bdf_file.write(
                            'CQUAD4,%i,%i,%i,%i,%i,%i\n' %
                            (eid + 1, pid, element[0] + 1, element[1] + 1,
                             element[2] + 1, element[3] + 1))
                        a = nodes[element[2], :] - nodes[element[0], :]
                        b = nodes[element[3], :] - nodes[element[1], :]
                        n = cross(a, b)
                        normals[eid, :] = n / norm(n)

                        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())
                    else:
                        raise RuntimeError('nnodes=%s' % nnodes)
            else:
                msg = 'is_surface_blockmesh=%s is_face_mesh=%s; pick one' % (
                    is_surface_blockmesh, is_face_mesh)
                raise RuntimeError(msg)
            bdf_file.write('ENDDATA\n')

        self.nelements = nelements
        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()

        self.scalarBar.VisibilityOn()
        self.scalarBar.Modified()

        self.isubcase_name_map = {0: ['OpenFoam BlockMeshDict', '']}
        cases = {}
        ID = 1

        #print("nElements = ",nElements)
        if mesh_3d == 'hex':
            form, cases = self._fill_openfoam_case(cases, ID, nodes, nelements,
                                                   patches, names, normals,
                                                   is_surface_blockmesh)
        elif mesh_3d == 'shell':
            form, cases = self._fill_openfoam_case(cases, ID, nodes, nelements,
                                                   patches, names, normals,
                                                   is_surface_blockmesh)
        elif mesh_3d == 'faces':
            if len(names) == nelements:
                is_surface_blockmesh = True
            form, cases = self._fill_openfoam_case(cases, ID, nodes, nelements,
                                                   patches, names, normals,
                                                   is_surface_blockmesh)
        else:
            raise RuntimeError(mesh_3d)

        if plot:
            self._finish_results_io2(form, cases, reset_labels=reset_labels)
        else:
            self._set_results(form, cases)
예제 #6
0
    def load_su2_geometry(self, su2_filename, name='main', plot=True):
        #print("load_su2_geometry...")
        skip_reading = self._remove_old_geometry(su2_filename)
        if skip_reading:
            return

        model = SU2(log=self.log, debug=False)
        #self.model_type = model.model_type
        ndim, nodes, elements, regions = model.read_su2(su2_filename)

        nnodes = nodes.shape[0]
        nelements = 0
        for etype, elems in iteritems(elements):
            nsub_elements = elems.shape[0]
            if nsub_elements:
                nelements += nsub_elements
                #print('min of type = %s' % elems.min())
        assert nnodes > 0, nnodes
        assert nelements > 0, nelements

        self.nnodes = nnodes
        self.nelements = nelements

        self.log.info('nnodes=%s nelements=%s' % (self.nnodes, self.nelements))
        self.grid.Allocate(self.nelements, 1000)
        #self.gridResult.SetNumberOfComponents(self.nelements)

        #vectorReselt.SetNumberOfComponents(3)
        self.nid_map = {}

        assert nodes is not None
        nnodes = nodes.shape[0]
        if ndim == 3:
            xmax, ymax, zmax = nodes.max(axis=0)
            xmin, ymin, zmin = nodes.min(axis=0)
            self.log.info('xmax=%s xmin=%s' % (xmax, xmin))
            self.log.info('ymax=%s ymin=%s' % (ymax, ymin))
            self.log.info('zmax=%s zmin=%s' % (zmax, zmin))
            dim_max = max(xmax-xmin, ymax-ymin, zmax-zmin)
        elif ndim == 2:
            xmax, ymax = nodes.max(axis=0)
            xmin, ymin = nodes.min(axis=0)
            self.log.info('xmax=%s xmin=%s' % (xmax, xmin))
            self.log.info('ymax=%s ymin=%s' % (ymax, ymin))
            dim_max = max(xmax-xmin, ymax-ymin)

        self.create_global_axes(dim_max)

        if ndim == 2:
            nodes = np.hstack([nodes, np.zeros((nnodes, 1), dtype=nodes.dtype)])
        #else:
            # ndim=3

        points = numpy_to_vtk_points(nodes)


        #nelements = 0
        #elements = {
            #5 : tris,
            #9 : quads,
        #}
        #print('dict =', elements)
        for etype, elems in iteritems(elements):
            #print(etype, elems)
            if isinstance(elems, list):
                #print('continue')
                continue
            #print(type(elems))
            nsub_elements = elems.shape[0]
            if nsub_elements == 0:
                #print('continue')
                continue
            #print('eid_min =', elems.min())
            assert nsub_elements > 0, nsub_elements
            if etype == 5:
                for eid in range(nsub_elements):
                    elem = vtkTriangle()
                    node_ids = elems[eid, :]
                    elem.GetPointIds().SetId(0, node_ids[0])
                    elem.GetPointIds().SetId(1, node_ids[1])
                    elem.GetPointIds().SetId(2, node_ids[2])
                    self.grid.InsertNextCell(5, elem.GetPointIds())  #elem.GetCellType() = 5  # vtkTriangle
            elif etype == 9:
                for eid in range(nsub_elements):
                    elem = vtk.vtkQuad()
                    node_ids = elems[eid, :]
                    elem.GetPointIds().SetId(0, node_ids[0])
                    elem.GetPointIds().SetId(1, node_ids[1])
                    elem.GetPointIds().SetId(2, node_ids[2])
                    elem.GetPointIds().SetId(3, node_ids[3])
                    self.grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds())
            else:
                raise NotImplementedError(etype)

        self.grid.SetPoints(points)
        self.grid.Modified()
        if hasattr(self.grid, 'Update'):
            self.grid.Update()
            self.log_info("updated grid")

        # loadSTLResults - regions/loads
        self.scalarBar.VisibilityOff()
        self.scalarBar.Modified()

        cases = {}
        self.isubcase_name_map = {}
        ID = 1

        form, cases = self._fill_su2_case(cases, ID, nelements, nnodes)
        self._finish_results_io2(form, cases)
예제 #7
0
    def load_usm3d_geometry(self, cogsg_filename, name='main', plot=True):
        skip_reading = self._remove_old_geometry(cogsg_filename)
        if skip_reading:
            return

        self.eid_maps[name] = {}
        self.nid_maps[name] = {}
        model = Usm3d(log=self.log, debug=False)

        base_filename, ext = os.path.splitext(cogsg_filename)
        #node_filename = base_filename + '.node'
        #ele_filename = base_filename + '.ele'
        if ext == '.cogsg':
            dimension_flag = 3
        #elif ext == '.ele':
        #dimension_flag = 3
        else:
            raise RuntimeError(
                'unsupported extension.  Use "cogsg" or "front".')

        read_loads = True
        nodes, tris_tets, tris, bcs, mapbc, loads, flo_filename = model.read_usm3d(
            base_filename, dimension_flag, read_loads=read_loads)
        del tris_tets
        nodes = model.nodes
        tris = model.tris
        tets = model.tets
        bcs = model.bcs
        mapbc = model.mapbc
        loads = model.loads

        self.out_filename = None
        if flo_filename is not None:
            self.out_filename = flo_filename

        bcmap_to_bc_name = model.bcmap_to_bc_name

        self.nnodes = nodes.shape[0]
        ntris = 0
        ntets = 0
        if tris is not None:
            ntris = tris.shape[0]

        if dimension_flag == 2:
            pass
        elif dimension_flag == 3:
            ntets = tets.shape[0]
            ntets = 0
        else:
            raise RuntimeError()
        self.nelements = ntris + ntets

        self.log.debug("nnodes = %i" % self.nnodes)
        self.log.debug("nelements = %i" % self.nelements)

        grid = self.grid
        grid.Allocate(self.nelements, 1000)

        self.nid_map = {}
        self.eid_map = {}

        assert nodes is not None
        nnodes = nodes.shape[0]

        points = numpy_to_vtk_points(nodes)
        if ntris:
            self.element_ids = np.arange(1, ntris + 1, dtype='int32')
            etype = 5  # vtkTriangle().GetCellType()
            create_vtk_cells_of_constant_element_type(grid, tris, etype)
        else:
            ntets = tets.shape[0]
            self.element_ids = np.arange(1, ntets + 1, dtype='int32')

        if dimension_flag == 2:
            pass
        elif dimension_flag == 3:
            if ntets:
                etype = 10  # vtkTetra().GetCellType()
                assert tets.max() > 0, tets.min()
                create_vtk_cells_of_constant_element_type(grid, tets, etype)
        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 = {}
        form = []
        form, cases = self._fill_usm3d_results(cases,
                                               form,
                                               bcs,
                                               mapbc,
                                               bcmap_to_bc_name,
                                               loads,
                                               is_geometry=True)
        self._finish_results_io2(form, cases)
예제 #8
0
파일: avus_io.py 프로젝트: zbhfut/pyNastran
    def _make_avus_geometry(self, model, quads_only=False):
        nodes = model.nodes
        #nnodes = self.nnodes

        grid = self.grid
        #self.gridResult.Allocate(self.nnodes, 1000)
        #vectorReselt.SetNumberOfComponents(3)
        #self.nid_map = {}
        #elem.SetNumberOfPoints(nNodes)

        #assert nodes is not None
        #nnodes = nodes.shape[0]

        mmax = amax(nodes, axis=0)
        mmin = amin(nodes, axis=0)
        dim_max = (mmax - mmin).max()
        self.create_global_axes(dim_max)
        points = numpy_to_vtk_points(nodes)

        #elements = model.elements
        quads = model.quad_elements
        hexas = model.hexa_elements
        tets = model.tet_elements
        tris = model.tri_elements

        nquads = len(quads)
        ntris = len(tris)
        nhexas = len(hexas)
        ntets = len(tets)

        is_shells = nquads + ntris
        is_solids = ntets + nhexas
        if is_shells:
            is_surface = True
            if nquads:
                elements = quads
                for face in quads:
                    elem = vtkQuad()
                    epoints = elem.GetPointIds()
                    epoints.SetId(0, face[0])
                    epoints.SetId(1, face[1])
                    epoints.SetId(2, face[2])
                    epoints.SetId(3, face[3])
                    #elem.GetCellType() = 5  # vtkTriangle
                    grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds())
            if ntris:
                elements = tris
                for face in tris:
                    elem = vtkTriangle()
                    epoints = elem.GetPointIds()
                    epoints.SetId(0, face[0])
                    epoints.SetId(1, face[1])
                    epoints.SetId(2, face[2])
                    #elem.GetCellType() = 5  # vtkTriangle
                    grid.InsertNextCell(5, elem.GetPointIds())

        elif is_solids:
            if ntets:
                elements = tets
                is_surface = False
                self.nelements = model.nelements
                grid.Allocate(self.nelements, 1000)

                nelements = elements.shape[0]
                for node_ids in elements:
                    elem = vtkTetra()
                    epoints = elem.GetPointIds()
                    epoints.SetId(0, node_ids[0])
                    epoints.SetId(1, node_ids[1])
                    epoints.SetId(2, node_ids[2])
                    epoints.SetId(3, node_ids[3])
                    #elem.GetCellType() = 5  # vtkTriangle
                    grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds())

            if nhexas:
                elements = hexas
                is_surface = True
                # is_surface = False
                is_volume = not is_surface

                if is_surface:
                    self.nelements = model.nelements
                    free_faces = array(model.get_free_faces(),
                                       dtype='int32')  # + 1
                    nfaces = len(free_faces)
                    elements = free_faces
                    grid.Allocate(nfaces, 1000)

                    for face in free_faces:
                        elem = vtkQuad()
                        epoints = elem.GetPointIds()
                        epoints.SetId(0, face[0])
                        epoints.SetId(1, face[1])
                        epoints.SetId(2, face[2])
                        epoints.SetId(3, face[3])
                        #elem.GetCellType() = 5  # vtkTriangle
                        grid.InsertNextCell(elem.GetCellType(),
                                            elem.GetPointIds())

                elif is_volume:
                    self.nelements = model.nelements
                    grid.Allocate(self.nelements, 1000)

                    nelements = elements.shape[0]
                    for eid in range(nelements):
                        elem = vtkHexahedron()
                        node_ids = elements[eid, :]
                        epoints = elem.GetPointIds()
                        epoints.SetId(0, node_ids[0])
                        epoints.SetId(1, node_ids[1])
                        epoints.SetId(2, node_ids[2])
                        epoints.SetId(3, node_ids[3])
                        epoints.SetId(4, node_ids[4])
                        epoints.SetId(5, node_ids[5])
                        epoints.SetId(6, node_ids[6])
                        epoints.SetId(7, node_ids[7])
                        #elem.GetCellType() = 5  # vtkTriangle
                        grid.InsertNextCell(elem.GetCellType(),
                                            elem.GetPointIds())
        else:
            raise NotImplementedError()

        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)
        grid.Modified()
        if hasattr(grid, 'Update'):
            grid.Update()
        return is_surface
예제 #9
0
파일: stl_io.py 프로젝트: zbhfut/pyNastran
    def load_stl_geometry(self, stl_filename, name='main', plot=True):
        #print("load_stl_geometry...")
        skip_reading = self._remove_old_geometry(stl_filename)
        if skip_reading:
            return

        model = read_stl(stl_filename, log=self.log, debug=False)
        #self.model_type = model.model_type
        nodes = model.nodes
        elements = model.elements

        normals = model.get_normals(elements, stop_on_failure=False)
        areas = model.get_area(elements, stop_on_failure=False)
        #nnormals = model.get_normals_at_nodes(elements)
        self.nnodes = nodes.shape[0]
        self.nelements = elements.shape[0]

        self.log.info('nnodes=%s nelements=%s' % (self.nnodes, self.nelements))
        grid = self.grid
        grid.Allocate(self.nelements, 1000)
        #self.gridResult.SetNumberOfComponents(self.nelements)

        points = numpy_to_vtk_points(nodes)
        self.nid_map = {}
        #elem.SetNumberOfPoints(nnodes)
        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)
                #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 nodes is not None
        nnodes = nodes.shape[0]
        xmax, ymax, zmax = nodes.max(axis=0)
        xmin, ymin, zmin = nodes.min(axis=0)
        self.log.info('xmax=%s xmin=%s' % (xmax, xmin))
        self.log.info('ymax=%s ymin=%s' % (ymax, ymin))
        self.log.info('zmax=%s zmin=%s' % (zmax, zmin))
        dim_max = max(xmax - xmin, ymax - ymin, zmax - zmin)
        self.create_global_axes(dim_max)

        etype = 5  # vtkTriangle().GetCellType()
        create_vtk_cells_of_constant_element_type(grid, elements, etype)

        grid.SetPoints(points)
        grid.Modified()
        if hasattr(grid, 'Update'):
            grid.Update()
            self.log_info("updated grid")

        # loadSTLResults - regions/loads
        self.scalarBar.VisibilityOff()
        self.scalarBar.Modified()

        cases = {}
        self.isubcase_name_map = {}
        ID = 1

        form, cases = self._fill_stl_case(cases, ID, elements, nodes, normals,
                                          areas)
        self._finish_results_io2(form, cases)
예제 #10
0
    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.model_type = 'surf'
        self.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.nelements = nelements
        self.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.create_global_axes(dim_max)
        self.log.info('max = %s' % mmax)
        self.log.info('min = %s' % mmin)

        points = numpy_to_vtk_points(nodes)
        tris = model.tris - 1
        quads = model.quads - 1

        grid = self.grid
        grid.Allocate(self.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.alt_grids:
                yellow = (1., 1., 0.)
                self.create_alternate_vtk_grid('failed_nodes', color=yellow,
                                               line_width=3, opacity=1.0)

            ifailed = where(model.nodes_failed == 1)[0]
            nfailed = len(ifailed)
            failed_grid = self.alt_grids['failed_nodes']
            failed_grid.Allocate(nfailed, 1000)
            #grid2 = failed_grid
            points2 = vtk.vtkPoints()
            points2.SetNumberOfPoints(nfailed)

            for j, nid in enumerate(model.nodes_failed):
                elem = vtk.vtkVertex()
                c = nodes[nid - 1, :]
                self.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._add_alt_actors(self.alt_grids)

            actor = self.geometry_actors['failed_nodes']
            actor.Modified()
            prop = actor.GetProperty()
            prop.SetRepresentationToPoints()
            prop.SetPointSize(10)

        self.nelements = nelements
        grid.SetPoints(points)
        grid.Modified()
        if hasattr(grid, 'Update'):
            grid.Update()
        #self.log_info("updated grid")

        # loadSurfResults - regions/loads
        self.scalarBar.VisibilityOn()
        self.scalarBar.Modified()

        self.isubcase_name_map = {1: ['AFLR Surface', '']}
        cases = {}
        ID = 1

        form, cases = self._fill_surf_case(surf_filename, cases, ID, nnodes, nelements, model)
        if plot:
            self._finish_results_io2(form, cases)
예제 #11
0
    def load_ugrid_geometry(self, ugrid_filename, name='main', plot=True):
        """
        The entry point for UGRID geometry loading.

        Parameters
        ----------
        ugrid_filename : str
            the ugrid filename to load
        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
        """
        #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)
            ext = os.path.basename(ugrid_filename).split('.')[
                2]  # base, fmt, ext
            is_2d = False
        else:
            ext = os.path.basename(ugrid_filename).split('.')[1]  # base, ext
            model = UGRID2D_Reader(log=self.log, debug=True)
            is_2d = True
        is_3d = not is_2d

        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)

        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)

        if is_3d:
            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)

        points = numpy_to_vtk_points(nodes)

        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.scalarBar.VisibilityOn()
        self.scalarBar.Modified()

        self.isubcase_name_map = {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(cases, ID, nnodes, nelements)

        if plot:
            self._finish_results_io2(form, cases)
예제 #12
0
    def load_bedge_geometry(self, bedge_filename, name='main', plot=True):
        #skip_reading = self.remove_old_openfoam_geometry(openfoam_filename)
        #if skip_reading:
        #    return

        self.modelType = 'bedge'

        model = read_bedge(bedge_filename)
        self.log.info('bedge_filename = %s' % bedge_filename)
        nnodes = model.nodes.shape[0]
        nbars = model.bars.shape[0]
        nelements = nbars

        nodes = model.nodes
        self.nelements = nelements
        self.nnodes = nnodes

        self.log.debug("nNodes = %s" % self.nnodes)
        self.log.debug("nElements = %s" % self.nelements)
        assert nelements > 0, nelements

        black = (0., 0., 0.)
        self.create_alternate_vtk_grid(
            'nodes', color=black, line_width=5, opacity=1., point_size=3,
            representation='point')
        alt_grid = self.alt_grids['nodes']
        alt_grid.Allocate(nnodes, 1000)

        grid = self.grid
        grid.Allocate(self.nelements, 1000)

        points = numpy_to_vtk_points(nodes)

        mmax = np.amax(nodes, axis=0)
        mmin = np.amin(nodes, axis=0)
        dim_max = (mmax - mmin).max()
        self.log.info('max = %s' % mmax)
        self.log.info('min = %s' % mmin)
        #print('dim_max =', dim_max)
        #self.update_axes_length(dim_max)

        etype = 1  # vtk.vtkVertex().GetCellType()
        #elements = np.arange(0, len(nodes), dtype='int32')
        #assert len(elements) == len(nodes)
        #create_vtk_cells_of_constant_element_type(alt_grid, elements, etype)
        for inode, node in enumerate(nodes):
            elem = vtk.vtkVertex()
            elem.GetPointIds().SetId(0, inode)
            alt_grid.InsertNextCell(etype, elem.GetPointIds())

        bars = model.bars

        etype = 3  # vtkLine().GetCellType()
        create_vtk_cells_of_constant_element_type(grid, bars, etype)

        self.nelements = nelements
        alt_grid.SetPoints(points)
        grid.SetPoints(points)
        grid.Modified()
        if hasattr(grid, 'Update'):
            grid.Update()
        #print("updated grid")

        # loadBedgeResults - regions/loads
        #self.TurnTextOn()
        self.scalarBar.VisibilityOn()
        self.scalarBar.Modified()

        self.isubcase_name_map = {1: ['AFLR BEDGE', '']}
        cases = {}
        ID = 1

        self._add_alt_actors(self.alt_grids)
        form, cases = self._fill_bedge_case(bedge_filename, cases, ID, nnodes, nelements, model)
        if plot:
            self._finish_results_io2(form, cases)
예제 #13
0
파일: obj_io.py 프로젝트: zbhfut/pyNastran
    def load_obj_geometry(self, obj_filename, name='main', plot=True):
        """
        The entry point for OBJ geometry loading.

        Parameters
        ----------
        obj_filename : str
            the obj filename to load
        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
        """
        skip_reading = self._remove_old_obj_geometry(obj_filename)
        if skip_reading:
            return

        self.eid_maps[name] = {}
        self.nid_maps[name] = {}
        model = read_obj(obj_filename, log=self.log, debug=False)
        self.model_type = 'obj'
        nodes = model.nodes
        nelements = model.nelements

        self.nnodes = model.nnodes
        self.nelements = nelements

        grid = self.grid
        grid.Allocate(self.nelements, 1000)

        assert nodes is not None
        #nnodes = nodes.shape[0]

        mmax = nodes.max(axis=0)
        mmin = nodes.min(axis=0)
        dim_max = (mmax - mmin).max()
        xmax, ymax, zmax = mmax
        xmin, ymin, zmin = mmin
        self.log_info("xmin=%s xmax=%s dx=%s" % (xmin, xmax, xmax-xmin))
        self.log_info("ymin=%s ymax=%s dy=%s" % (ymin, ymax, ymax-ymin))
        self.log_info("zmin=%s zmax=%s dz=%s" % (zmin, zmax, zmax-zmin))
        self.create_global_axes(dim_max)
        points = numpy_to_vtk_points(nodes)

        #assert elements.min() == 0, elements.min()

        tri_etype = 5 # vtkTriangle().GetCellType()
        #self.create_vtk_cells_of_constant_element_type(grid, elements, etype)
        quad_etype = 9 # vtk.vtkQuad().GetCellType()

        tris = model.tri_faces
        quads = model.quad_faces
        if len(tris):
            for eid, element in enumerate(tris):
                elem = vtk.vtkTriangle()
                elem.GetPointIds().SetId(0, element[0])
                elem.GetPointIds().SetId(1, element[1])
                elem.GetPointIds().SetId(2, element[2])
                self.grid.InsertNextCell(tri_etype, elem.GetPointIds())
        if len(quads):
            for eid, element in enumerate(quads):
                elem = vtk.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(quad_etype, elem.GetPointIds())

        grid.SetPoints(points)
        grid.Modified()
        if hasattr(grid, 'Update'):
            grid.Update()


        self.scalarBar.VisibilityOn()
        self.scalarBar.Modified()

        self.isubcase_name_map = {1: ['OBJ', '']}
        cases = {}
        ID = 1
        form, cases, icase = self._fill_obj_geometry_objects(
            cases, ID, nodes, nelements, model)
        self._finish_results_io2(form, cases)
예제 #14
0
파일: fast_io.py 프로젝트: zbhfut/pyNastran
    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)

        ext = os.path.splitext(fgrid_filename)[1]
        ext = ext.lower()
        if ext == '.fgrid':
            dimension_flag = 3
        else:
            raise RuntimeError(
                'unsupported extension=%r.  Use "cogsg" or "front".' % ext)

        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 = 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)
                #elem.GetCellType() = 5  # vtkTriangle
                grid.InsertNextCell(5, elem.GetPointIds())
        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)
                    #elem.GetCellType() = 5  # vtkTriangle
                    grid.InsertNextCell(10, elem.GetPointIds())
        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)
예제 #15
0
    def _make_tecplot_geometry(self, model, quads_only=False):
        nodes = model.xyz
        nnodes = self.nnodes
        grid = self.grid

        #points = vtk.vtkPoints()
        #points.SetNumberOfPoints(nnodes)
        #self.gridResult.Allocate(self.nnodes, 1000)
        #vectorReselt.SetNumberOfComponents(3)
        #self.nid_map = {}
        #elem.SetNumberOfPoints(nNodes)

        #assert nodes is not None
        #nnodes = nodes.shape[0]

        mmax = amax(nodes, axis=0)
        mmin = amin(nodes, axis=0)
        dim_max = (mmax - mmin).max()
        self.create_global_axes(dim_max)

        points = numpy_to_vtk_points(nodes)
        #for i in range(nnodes):
            #points.InsertPoint(i, nodes[i, :])

        #elements = model.elements
        quads = model.quad_elements
        hexas = model.hexa_elements
        tets = model.tet_elements
        tris = model.tri_elements

        nquads = len(quads)
        ntris = len(tris)
        nhexas = len(hexas)
        ntets = len(tets)

        nshells = nquads + ntris
        nsolids = ntets + nhexas
        if nshells:
            is_surface = True
            self._create_tecplot_shells(nquads, quads, ntris, tris)
            self.nelements = nshells

        elif nsolids:
            #if 0:
                #tris, quads = model.skin_elements()
                #is_tris = bool(len(tris))
                #is_quads = bool(len(quads))
                #self._create_tecplot_shells(is_quads, quads, is_tris, tris)
            #else:
            is_surface = False
            if is_surface:
                if nhexas:
                    free_faces = array(model.get_free_faces(), dtype='int32')# + 1
                    nfaces = len(free_faces)
                    self.nelements = nfaces
                    elements = free_faces
                    grid.Allocate(nfaces, 1000)

                    for face in free_faces:
                        elem = vtkQuad()
                        epoints = elem.GetPointIds()
                        epoints.SetId(0, face[0])
                        epoints.SetId(1, face[1])
                        epoints.SetId(2, face[2])
                        epoints.SetId(3, face[3])
                        #elem.GetCellType() = 5  # vtkTriangle
                        grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds())
            else:
                # is_volume
                grid.Allocate(nsolids, 1000)
                self.nelements = nsolids
                if ntets:
                    for node_ids in tets:
                        elem = vtkTetra()
                        epoints = elem.GetPointIds()
                        epoints.SetId(0, node_ids[0])
                        epoints.SetId(1, node_ids[1])
                        epoints.SetId(2, node_ids[2])
                        epoints.SetId(3, node_ids[3])
                        #elem.GetCellType() = 5  # vtkTriangle
                        grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds())


                if nhexas:
                    for node_ids in hexas:
                        elem = vtkHexahedron()
                        epoints = elem.GetPointIds()
                        epoints.SetId(0, node_ids[0])
                        epoints.SetId(1, node_ids[1])
                        epoints.SetId(2, node_ids[2])
                        epoints.SetId(3, node_ids[3])
                        epoints.SetId(4, node_ids[4])
                        epoints.SetId(5, node_ids[5])
                        epoints.SetId(6, node_ids[6])
                        epoints.SetId(7, node_ids[7])
                        #elem.GetCellType() = 5  # vtkTriangle
                        grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds())
        else:
            raise NotImplementedError()

        grid.SetPoints(points)
        grid.Modified()
        if hasattr(grid, 'Update'):
            grid.Update()
        return is_surface
예제 #16
0
    def load_tetgen_geometry(self, smesh_filename, name='main', plot=True):
        #print("load_tetgen_geometry...")
        skip_reading = self._remove_old_geometry(smesh_filename)
        if skip_reading:
            return

        model = Tetgen(log=self.log, debug=False)

        base_filename, ext = os.path.splitext(smesh_filename)
        ext = ext.lower()
        node_filename = base_filename + '.node'
        ele_filename = base_filename + '.ele'
        if ext == '.smesh':
            dimension_flag = 2
        elif ext == '.ele':
            dimension_flag = 3
        else:
            raise RuntimeError('unsupported extension.  Use "smesh" or "ele".')
        model.read_tetgen(node_filename, smesh_filename, ele_filename,
                          dimension_flag)
        nodes = model.nodes
        tris = model.tris
        tets = model.tets

        self.nnodes = nodes.shape[0]
        ntris = 0
        ntets = 0
        if dimension_flag == 2:
            ntris = tris.shape[0]
        elif dimension_flag == 3:
            ntets = tets.shape[0]
        else:
            raise RuntimeError()
        self.nelements = ntris + ntets

        #print("nnodes = ",self.nnodes)
        #print("nelements = ", self.nelements)

        grid = self.grid
        grid.Allocate(self.nelements, 1000)
        #self.gridResult.SetNumberOfComponents(self.nelements)

        assert nodes is not None
        points = numpy_to_vtk_points(nodes)
        self.nid_map = {}

        #elements -= 1
        if dimension_flag == 2:
            etype = 5  # vtkTriangle().GetCellType()
            create_vtk_cells_of_constant_element_type(grid, tris, etype)
        elif dimension_flag == 3:
            etype = 10  # vtkTetra().GetCellType()
            create_vtk_cells_of_constant_element_type(grid, tets, etype)
        else:
            raise RuntimeError('dimension_flag=%r; expected=[2, 3]' %
                               dimension_flag)

        grid.SetPoints(points)
        grid.Modified()
        if hasattr(grid, 'Update'):
            grid.Update()

        # loadTetgenResults - regions/loads
        self.scalarBar.VisibilityOff()
        self.scalarBar.Modified()

        cases = {}
        ID = 1

        #cases = self._fill_tetgen_case(cases, ID, elements)
        self._finish_results_io(cases)