Exemple #1
0
 def test_is_binary(self):
     """tests if a file is binary"""
     bdf_filename = os.path.join(PKG_PATH, '..', 'models', 'solid_bending',
                                 'solid_bending.bdf')
     op2_filename = os.path.join(PKG_PATH, '..', 'models', 'solid_bending',
                                 'solid_bending.op2')
     self.assertTrue(is_binary_file(op2_filename))
     self.assertFalse(is_binary_file(bdf_filename))
    def read_cart3d(self, infilename, result_names=None):
        """extracts the points, elements, and Cp"""
        self.infilename = infilename
        self.log.info("---starting reading cart3d file...%r---" % self.infilename)

        self.infilename = infilename
        if is_binary_file(infilename):
            self.infile = open(infilename, 'rb')
            (self.nPoints, self.nElements) = self.read_header_binary()
            points = self.read_points_binary(self.nPoints)
            elements = self.read_elements_binary(self.nElements)
            regions = self.read_regions_binary(self.nElements)
            loads = {}
        else:
            self.infile = open(infilename, 'r')
            self.read_header_ascii()
            points = self.read_points_ascii()
            elements = self.read_elements_ascii(bypass=False)
            regions = self.read_regions_ascii(bypass=False)
            loads = self.read_results_ascii(0, self.infile, result_names=result_names)

        self.infile.close()
        self.log.info("nPoints=%s nElements=%s" % (self.nPoints, self.nElements))
        self.log.info("---finished reading cart3d file...%r---" % self.infilename)
        assert self.nPoints > 0, 'nPoints=%s' % self.nPoints
        assert self.nElements > 0, 'nElements=%s' % self.nElements
        return (points, elements, regions, loads)
Exemple #3
0
    def read_cart3d(self, infilename, result_names=None):
        """extracts the points, elements, and Cp"""
        self.infilename = infilename
        self.log.info("---starting reading cart3d file...%r---" % self.infilename)

        self.infilename = infilename
        if is_binary_file(infilename):
            with open(infilename, 'rb') as self.infile:
                npoints, nelements, nresults = self._read_header_binary()
                self.points = self._read_points_binary(npoints)
                self.elements = self._read_elements_binary(nelements)
                self.regions = self._read_regions_binary(nelements)
                # TODO: loads
        else:
            with codec_open(_filename(infilename), 'r', encoding=self._encoding) as self.infile:
                npoints, nelements, nresults = self._read_header_ascii()
                self.points = self._read_points_ascii(npoints)
                self.elements = self._read_elements_ascii(nelements)
                self.regions = self._read_regions_ascii(nelements)
                self._read_results_ascii(0, self.infile, nresults, result_names=result_names)

        self.log.debug("npoints=%s nelements=%s" % (self.npoints, self.nelements))
        self.log.info("---finished reading cart3d file...%r---" % self.infilename)
        assert self.npoints > 0, 'npoints=%s' % self.npoints
        assert self.nelements > 0, 'nelements=%s' % self.nelements
Exemple #4
0
    def read_stl(self, stl_filename):
        self.infilename = stl_filename
        self.log.info("---starting reading STL file...%r---" % self.infilename)

        if is_binary_file(stl_filename):
            self.read_binary_stl(stl_filename)
        else:
            self.read_ascii_stl(stl_filename)

        #self.log.info("nPoints=%s  nElements=%s" % (self.nPoints, self.nElements))
        self.log.info("---finished reading STL file...%r---" % self.infilename)
Exemple #5
0
    def read_tecplot(self, tecplot_filename):
        """
        Reads an ASCII/binary Tecplot file.

        The binary file reader must have ONLY CHEXAs and be Tecplot 360 with
        `rho`, `u`, `v`, `w`, and `p`.
        The ASCII file reader has only been tested with Tecplot 10, but will
        probably work on Tecplot360.  It **should** work with any set of
        variables.
        """
        if is_binary_file(tecplot_filename):
            return self.read_tecplot_binary(tecplot_filename)
        return self.read_tecplot_ascii(tecplot_filename)
Exemple #6
0
    def read_tecplot(self, tecplot_filename):
        """
        Reads an ASCII/binary Tecplot file.

        The binary file reader must have ONLY CHEXAs and be Tecplot 360 with
        `rho`, `u`, `v`, `w`, and `p`.
        The ASCII file reader has only been tested with Tecplot 10, but will
        probably work on Tecplot360.  It **should** work with any set of
        variables.
        """
        if is_binary_file(tecplot_filename):
            return self.read_tecplot_binary(tecplot_filename)
        return self.read_tecplot_ascii(tecplot_filename)
Exemple #7
0
def get_ugrid_model(ugrid_filename, read_solids, log):
    """helper method for UGRID_IO"""
    if read_solids or is_binary_file(ugrid_filename):
        model = UGRID(log=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=log, debug=True)
        is_2d = True
    is_3d = not is_2d

    assert ext == 'ugrid', ugrid_filename
    return model, is_2d, is_3d
Exemple #8
0
    def read_stl(self, stl_filename):
        """
        Reads an STL file

        Parameters
        ----------
        stl_filename : str
            the filename to read
        """
        self.infilename = stl_filename
        self.log.info("---reading STL...%r---" % self.infilename)

        if is_binary_file(stl_filename):
            self.read_binary_stl(stl_filename)
        else:
            self.read_ascii_stl(stl_filename)
Exemple #9
0
    def read_stl(self, stl_filename: str) -> None:
        """
        Reads an STL file

        Parameters
        ----------
        stl_filename : str
            the filename to read

        """
        self.infilename = stl_filename
        self.log.info(f'---reading STL...{self.infilename}---')

        if is_binary_file(stl_filename):
            self.read_binary_stl(stl_filename)
        else:
            self.read_ascii_stl(stl_filename)
Exemple #10
0
    def read_stl(self, stl_filename):
        """
        Reads an STL file

        Parameters
        ----------
        stl_filename : str
            the filename to read
        """
        self.infilename = stl_filename
        self.log.info("---starting reading STL file...%r---" % self.infilename)

        if is_binary_file(stl_filename):
            self.read_binary_stl(stl_filename)
        else:
            self.read_ascii_stl(stl_filename)

        #self.log.info("nodes=%s  nelements=%s" % (self.nodes, self.nelements))
        self.log.info("---finished reading STL file...%r---" % self.infilename)
Exemple #11
0
    def read_cart3d(self, infilename, result_names=None):
        """extracts the points, elements, and Cp"""
        self.infilename = infilename
        self.log.info("---reading cart3d...%r---" % self.infilename)

        self.infilename = infilename
        if is_binary_file(infilename):
            with open(infilename, 'rb') as self.infile:
                try:
                    npoints, nelements, nresults = self._read_header_binary()
                    self.points = self._read_points_binary(npoints)
                    self.elements = self._read_elements_binary(nelements)
                    self.regions = self._read_regions_binary(nelements)
                    # TODO: loads
                except:
                    msg = 'failed reading %r' % infilename
                    self.log.error(msg)
                    raise

        else:
            with codec_open(_filename(infilename),
                            'r',
                            encoding=self._encoding) as self.infile:
                try:
                    npoints, nelements, nresults = self._read_header_ascii()
                    self.points = self._read_points_ascii(npoints)
                    self.elements = self._read_elements_ascii(nelements)
                    self.regions = self._read_regions_ascii(nelements)
                    self._read_results_ascii(0,
                                             self.infile,
                                             nresults,
                                             result_names=result_names)
                except:
                    msg = 'failed reading %r' % infilename
                    self.log.error(msg)
                    raise

        self.log.debug("npoints=%s nelements=%s" %
                       (self.npoints, self.nelements))
        assert self.npoints > 0, 'npoints=%s' % self.npoints
        assert self.nelements > 0, 'nelements=%s' % self.nelements
Exemple #12
0
def run_lots_of_files(files,
                      make_geom: bool = True,
                      combine: bool = True,
                      write_bdf: bool = False,
                      write_f06: bool = True,
                      delete_f06: bool = True,
                      delete_op2: bool = True,
                      delete_hdf5: bool = True,
                      delete_debug_out: bool = True,
                      build_pandas: bool = True,
                      write_op2: bool = False,
                      write_hdf5: bool = True,
                      debug: bool = True,
                      skip_files: Optional[List[str]] = None,
                      exclude: Optional[str] = None,
                      stop_on_failure: bool = False,
                      nstart: int = 0,
                      nstop: int = 1000000000,
                      short_stats: bool = False,
                      binary_debug: bool = False,
                      compare: bool = True,
                      quiet: bool = False,
                      dev: bool = True,
                      xref_safe: bool = False):
    """used by op2_test.py to run thousands of files"""
    if skip_files is None:
        skip_files = []
    #n = ''
    assert make_geom in [True, False]
    assert combine in [True, False]
    assert write_bdf in [True, False]
    assert write_f06 in [True, False]
    assert write_op2 in [True, False]
    assert write_hdf5 in [True, False]
    assert build_pandas in [True, False]
    if binary_debug in [True, False]:
        binary_debug = [binary_debug]

    subcases = []
    failed_cases = []
    nfailed = 0
    ntotal = 0
    npassed = 0
    #t0 = time.time()
    for i, op2file in enumerate(files[nstart:nstop], nstart):  # 149
        if not is_binary_file(op2file):
            continue

        basename = os.path.basename(op2file)
        #if basename not in skip_files and not basename.startswith('acms') and i not in nskip:
        sys.stderr.write(f'{i} file={op2file}\n')
        if basename not in skip_files and '#' not in op2file:
            print("%" * 80)
            print(f'file={op2file}\n')
            #n = '%s ' % i
            ntotal += 1

            is_passed = True
            for binary_debugi in binary_debug:
                print(f'------running binary_debug={binary_debugi}------')
                is_passedi = run_op2(op2file,
                                     make_geom=make_geom,
                                     combine=combine,
                                     write_bdf=write_bdf,
                                     write_f06=write_f06,
                                     write_op2=write_op2,
                                     is_mag_phase=False,
                                     delete_f06=delete_f06,
                                     delete_op2=delete_op2,
                                     delete_hdf5=delete_hdf5,
                                     delete_debug_out=delete_debug_out,
                                     build_pandas=build_pandas,
                                     write_hdf5=write_hdf5,
                                     exclude=exclude,
                                     short_stats=short_stats,
                                     subcases=subcases,
                                     debug=debug,
                                     stop_on_failure=stop_on_failure,
                                     binary_debug=binary_debug,
                                     compare=compare,
                                     dev=dev,
                                     xref_safe=xref_safe)[1]
                if not is_passedi:
                    is_passed = False
                    break

            if not is_passed:
                sys.stderr.write(f'**file={op2file}\n')
                failed_cases.append(op2file)
                nfailed += 1
            else:
                npassed += 1
    return failed_cases
Exemple #13
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)
Exemple #14
0
 def test_is_binary(self):
     bdf_filename = os.path.join(pkg_path, '..', 'models', 'solid_bending', 'solid_bending.bdf')
     op2_filename = os.path.join(pkg_path, '..', 'models', 'solid_bending', 'solid_bending.op2')
     self.assertTrue(is_binary_file(op2_filename))
     self.assertFalse(is_binary_file(bdf_filename))
Exemple #15
0
    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)
Exemple #16
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)
Exemple #17
0
 def test_is_binary(self):
     """tests if a file is binary"""
     bdf_filename = os.path.join(pkg_path, "..", "models", "solid_bending", "solid_bending.bdf")
     op2_filename = os.path.join(pkg_path, "..", "models", "solid_bending", "solid_bending.op2")
     self.assertTrue(is_binary_file(op2_filename))
     self.assertFalse(is_binary_file(bdf_filename))