Beispiel #1
0
    def load_ugrid_geometry(self, ugrid_filename, 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)

        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)

        points = self.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(ugrid_filename, cases, ID,
                                                  nnodes, nelements, model)

        if plot:
            self._finish_results_io2(form, cases)
Beispiel #2
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
        read_solids = False
        if is_binary_file(ugrid_filename):
            model = UGRID(log=self.log, debug=True, read_solids=read_solids)
            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)
        self.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.nelements = nelements
        self.nnodes = nnodes

        self.log.info("nnodes=%s nelements=%s" % (self.nnodes, self.nelements))
        assert nelements > 0, nelements

        grid = self.grid
        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 and read_solids:
            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)

        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(tetras)
                etypes.append(12)  # VTK_HEXAHEDRON().GetCellType()

        self.model.elements = elements
        self.model.etypes = etypes
        create_vtk_cells_of_constant_element_types(grid, elements, etypes)

        self.nelements = nelements
        grid.SetPoints(points)
        grid.Modified()
        if hasattr(grid, 'Update'):  # pragma: no cover
            grid.Update()

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

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

        if hasattr(model, 'pids'):
            form, cases = self._fill_ugrid3d_case(ugrid_filename, cases, ID,
                                                  nnodes, nelements, model,
                                                  read_solids)
        else:
            form, cases = self._fill_ugrid2d_case(cases, ID, nnodes, nelements)

        if plot:
            self._finish_results_io2(form, cases)