Exemple #1
0
def main():
    dirnames = ['ascii', 'binary']
    log = get_logger2(debug=False)
    for dirname in dirnames:
        fnames = [os.path.join(dirname, fname) for fname in os.listdir(dirname)
                  if not fname.endswith('.png')]
        for fname in fnames:
            try:
                read_tecplot(fname, log=log)
                log.info('read %r' % fname)
            except Exception as e:
                log.warning('failed reading %r' % fname)
                log.error(e)
                print('')
Exemple #2
0
    def test_tecplot_01(self):
        """CTRIA3 elements"""
        log = SimpleLogger(level='warning')
        tecplot_filename1 = os.path.join(MODEL_PATH, 'ascii',
                                         'point_fetri_2d_02.dat')
        #tecplot_filename2 = os.path.join(MODEL_PATH, 'ascii', 'point_fetri_2d_02.dat_out')

        unused_tecplot = read_tecplot(tecplot_filename1, log=log)
        #tecplot.write_tecplot(tecplot_filename2, res_types=None,
        #is_points=True, adjust_nids=True)
        #os.remove(tecplot_filename2)

        #tecplot_to_cart3d_filename()
        argv = [
            'format_converter', 'tecplot', tecplot_filename1, 'cart3d',
            'cart3d.tri'
        ]
        cmd_line_format_converter(argv=argv, quiet=True)
        os.remove('cart3d.tri')

        argv = [
            'format_converter', 'tecplot', tecplot_filename1, 'stl',
            'cart3d.stl'
        ]
        cmd_line_format_converter(argv=argv, quiet=True)
        os.remove('cart3d.stl')
Exemple #3
0
    def test_tecplot_01(self):
        log = get_logger(level='warning')
        tecplot_filename1 = os.path.join(MODEL_PATH, 'ascii',
                                         'point_fetri_2d_02.dat')
        #tecplot_filename2 = os.path.join(MODEL_PATH, 'ascii', 'point_fetri_2d_02.dat_out')

        tecplot = read_tecplot(tecplot_filename1, log=log)
Exemple #4
0
    def test_tecplot_01(self):
        tecplot_filename1 = os.path.join(model_path, 'ascii',
                                         'point_fetri_2d_02.dat')
        tecplot_filename2 = os.path.join(model_path, 'ascii',
                                         'point_fetri_2d_02.dat_out')

        tecplot = read_tecplot(tecplot_filename1)
def tecplot_to_cart3d(tecplot_filename, cart3d_filename=None, debug=True):
    """
    Converts a Tecplot file to Cart3d.

    It's assumed that quads are actually degenerate triangles
    """
    if isinstance(tecplot_filename, str):
        model = read_tecplot(tecplot_filename, debug=debug)
    else:
        model = tecplot_filename

    if len(model.tri_elements) and len(model.quad_elements):
        tris = np.vstack([
            model.tri_elements,
            model.quad_elements[:, :3],
        ])
    elif len(model.tri_elements):
        tris = model.tri_elements
    elif len(model.quad_elements):
        tris = model.quad_elements[:, :3]
    else:
        raise NotImplementedError('need quads/tris')

    npoints = model.xyz.shape[0]
    nelements = tris.shape[0]
    assert tris.shape[1] == 3, tris.shape
    #print('npoints=%s nelements=%s' % (npoints, nelements))

    #removed_nodes = False
    regions = np.zeros(nelements, dtype='int32')
    ones_float = np.ones(npoints, dtype='float64')

    cart3d_model = Cart3D()
    cart3d_model.points = model.xyz
    cart3d_model.regions = regions
    cart3d_model.elements = tris + 1

    headers_no_xyz = model.variables[3:] # drop the xyz, get what's left
    if 'cp' in headers_no_xyz:
        iCp = headers_no_xyz.index('cp')
        cp = model.results[:, iCp]
        assert len(cp) == npoints
        cart3d_model.loads = {
            'Cp' : cp, # nodal Cp
            'rho' : ones_float,
            'rhoU' : ones_float,
            'rhoV' : ones_float,
            'rhoW' : ones_float,
            'E' : ones_float,
        }
    else:
        model.log.debug('skipping Cp')

    if cart3d_filename is not None:
        cart3d_model.write_cart3d(cart3d_filename)
    return cart3d_model
Exemple #6
0
def tecplot_to_cart3d(tecplot_filename, cart3d_filename=None, debug=True):
    """
    Converts a Tecplot file to Cart3d.

    It's assumed that quads are actually degenerate triangles
    """
    if isinstance(tecplot_filename, str):
        model = read_tecplot(tecplot_filename, debug=debug)
    else:
        model = tecplot_filename

    if len(model.tri_elements) and len(model.quad_elements):
        tris = np.vstack([
            model.tri_elements,
            model.quad_elements[:, :3],
        ])
    elif len(model.tri_elements):
        tris = model.tri_elements
    elif len(model.quad_elements):
        tris = model.quad_elements[:, :3]
    else:
        raise NotImplementedError('need quads/tris')

    npoints = model.xyz.shape[0]
    nelements = tris.shape[0]
    assert tris.shape[1] == 3, tris.shape
    #print('npoints=%s nelements=%s' % (npoints, nelements))

    #removed_nodes = False
    regions = np.zeros(nelements, dtype='int32')
    ones_float = np.ones(npoints, dtype='float64')

    cart3d_model = Cart3D()
    cart3d_model.points = model.xyz
    cart3d_model.regions = regions
    cart3d_model.elements = tris + 1

    headers_no_xyz = model.variables[3:]  # drop the xyz, get what's left
    if 'cp' in headers_no_xyz:
        iCp = headers_no_xyz.index('cp')
        cp = model.results[:, iCp]
        assert len(cp) == npoints
        cart3d_model.loads = {
            'Cp': cp,  # nodal Cp
            'rho': ones_float,
            'rhoU': ones_float,
            'rhoV': ones_float,
            'rhoW': ones_float,
            'E': ones_float,
        }
    else:
        model.log.debug('skipping Cp')

    if cart3d_filename is not None:
        cart3d_model.write_cart3d(cart3d_filename)
    return cart3d_model
Exemple #7
0
    def load_tecplot_geometry(self, tecplot_filename, name='main', plot=True):
        model_name = name
        #key = self.case_keys[self.icase]
        #case = self.result_cases[key]

        skip_reading = self._remove_old_cart3d_geometry(tecplot_filename)
        #skip_reading = False
        if skip_reading:
            return

        #if 0:
        #fnames = os.listdir('time20000')
        #fnames = [os.path.join('time20000', fname) for fname in fnames]
        #model = merge_tecplot_files(fnames, tecplot_filename_out=None, log=self.log)
        #else:
        model = read_tecplot(tecplot_filename, log=self.gui.log, debug=False)

        self.gui.model_type = 'tecplot'
        self.gui.nnodes = sum([zone.nnodes for zone in model.zones])
        variables = None
        for zone in model.zones:
            variables = zone.variables
            break

        #self._make_tecplot_geometry(model, self.nnodes, quads_only=True) # cart3d
        is_surface = self._make_tecplot_geometry(model, quads_only=False)

        #self._create_cart3d_free_edegs(model, nodes, elements)

        # loadTecplotResults - regions/loads
        self.gui.scalar_bar_actor.VisibilityOn()
        self.gui.scalar_bar_actor.Modified()

        loads = []
        assert loads is not None
        if 'Mach' in loads:
            avg_mach = np.mean(loads['Mach'])
            note = ':  avg(Mach)=%g' % avg_mach
        else:
            note = ''
        self.gui.isubcase_name_map = {1: ['Tecplot%s' % note, '']}
        cases = OrderedDict()
        ID = 1

        form, cases, node_ids, element_ids = self._fill_tecplot_case(
            cases, ID, model, variables, is_surface)
        self.gui.node_ids = node_ids
        self.gui.element_ids = element_ids
        self.gui._finish_results_io2(model_name, form, cases)
Exemple #8
0
def run_filenames(fnames, log):
    for fname in fnames:
        #print(fname)
        #continue
        try:
            model = read_tecplot(fname, log=log)
            log.info('read %r' % fname)
        except Exception as error:
            log.warning('failed reading %r' % fname)
            log.error(error)
            print('')
            raise
            continue
        print(model)
        model.write_tecplot('junk.plt', res_types=None, adjust_nids=True)
Exemple #9
0
    def load_tecplot_geometry(self, tecplot_filename, name='main', plot=True):
        #key = self.case_keys[self.icase]
        #case = self.result_cases[key]

        skip_reading = self.parent._remove_old_cart3d_geometry(tecplot_filename)
        if skip_reading:
            return

        #if 0:
            #fnames = os.listdir('time20000')
            #fnames = [os.path.join('time20000', fname) for fname in fnames]
            #model = merge_tecplot_files(fnames, tecplot_filename_out=None, log=self.log)
        #else:
        model = read_tecplot(tecplot_filename, log=self.parent.log, debug=False)

        self.parent.model_type = 'tecplot'
        self.parent.nnodes = model.nnodes

        #self._make_tecplot_geometry(model, self.nnodes, quads_only=True) # cart3d
        is_surface = self._make_tecplot_geometry(model, quads_only=False)

        #self._create_cart3d_free_edegs(model, nodes, elements)


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

        loads = []
        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: ['Tecplot%s' % note, '']}
        cases = {}
        ID = 1

        form, cases = self._fill_tecplot_case(cases, ID, model, is_surface)
        self.parent._finish_results_io2(form, cases)
Exemple #10
0
    def test_tecplot_ascii_models(self):
        tecplot_filenames = [
            'ascii/3dgeom.dat',  #  good; multi-zone, geometry
            'ascii/block_febrick_3d.dat',  # 3d unstructured block; good
            #'ascii/block_fetet_3d.dat', # bad; no decimal values
            'ascii/channel.dat',  # 2d structured point; good
            #'ascii/cylinder_slice.dat', # 3d structured point; block 2 has poor formatting
            #'ascii/cylindrical.dat',  # 3d structured empty lines; good
            'ascii/ell.dat',  # 2d; good
            'ascii/humanoid_quad.dat',  # good
            'ascii/humanoid_tri.dat',  # good
            'ascii/movie.dat',  # csv -> good
            'ascii/multzn2d.dat',  #  2d structured; good
            'ascii/plane_slice.dat',  # 2d structured multi-line; good
            #'ascii/point_febrick_3d_02.dat',  # difficult header and funny write bug; bad
            'ascii/point_fequad_2d.dat',  # 2d; good
            'ascii/point_fetet_3d.dat',  # good
            'ascii/point_fetri_2d_01.dat',  # good
            'ascii/point_fetri_2d_02.dat',  # good
            'ascii/point_fetri_2d_03.dat',  # good

            #'ascii/simp3dbk.dat',  # 3d structured block - bad
            'ascii/simp3dpt.dat',  #  good
            #'ascii/simpscat.dat', #  bad -> text
            #'ascii/simpxy.dat',  # no xyz; it's a plot -> bad
            #'ascii/simpxy2.dat',  # no xyz; it's a plot -> bad
            'ascii/tiny.dat',  # good
        ]
        log = SimpleLogger(level='warning', encoding='utf-8')
        junk_plt = os.path.join(MODEL_PATH, 'junk.plt')
        for fname in tecplot_filenames:
            tecplot_filename = os.path.join(MODEL_PATH, fname)
            #print(fname)
            log.info('read %r' % fname)
            model = read_tecplot(tecplot_filename, log=log)
            str(model)
            model.write_tecplot(junk_plt, res_types=None, adjust_nids=True)
        os.remove(junk_plt)
Exemple #11
0
def tecplot_to_nastran(tecplot_filename, bdf_filename, log=None, debug=True):
    """Converts a Tecplot file to Nastran."""
    if isinstance(tecplot_filename, str):
        model = read_tecplot(tecplot_filename, log=log, debug=debug)
    else:
        model = tecplot_filename

    removed_nodes = False
    shell_pid = 1
    solid_pid = 2
    mid = 1
    istart = 1
    with open(bdf_filename, 'w') as bdf_file:
        bdf_file.write('$pyNastran : punch=True\n')
        for inode, node in enumerate(model.xyz):
            card = [
                'GRID',
                inode + 1,
                None,
            ] + list(node)
            bdf_file.write(print_card_8(card))

        itri = 0
        if len(model.tri_elements):
            # tris only
            for itri, tri in enumerate(model.tri_elements):
                card = ['CTRIA3', itri + 1, shell_pid] + list(tri)
                bdf_file.write(print_card_8(card))
            #istart += bdf_model

        if len(model.quad_elements):
            if len(model.tri_elements) != 0:
                # if there are tris, then we assume the quads are good
                for iquad, quad in enumerate(model.quad_elements):
                    card = ['CQUAD4', iquad + 1, shell_pid] + list(quad)
                    bdf_file.write(print_card_8(card))
            else:
                # need to split out the CQUAD4 elements
                istart = itri + 1
                for iquad, quad in enumerate(model.quad_elements):
                    if quad[2] == quad[3]:
                        # if it's a tri
                        card = ['CTRIA3', istart + iquad, shell_pid] + list(
                            quad[:3])
                    else:
                        card = ['CQUAD4', istart + iquad, shell_pid
                                ] + list(quad)
                    bdf_file.write(print_card_8(card))
            istart += iquad

        if len(model.tri_elements) + len(model.quad_elements):
            card = ['PSHELL', shell_pid, mid, 0.1]
            bdf_file.write(print_card_8(card))

        if len(model.tet_elements) + len(model.hexa_elements):
            card = ['PSOLID', solid_pid, mid]
            bdf_file.write(print_card_8(card))

        if len(model.tet_elements):
            for itet, tet in enumerate(model.tet_elements):
                card = ['CTETRA', istart + itet, solid_pid] + list(tet)
                bdf_file.write(print_card_8(card))

        if len(model.hexa_elements):
            # need to split out the CTETRA and CPENTA elements
            for ihex, hexa in enumerate(model.hexa_elements):
                uhexa = unique(hexa)
                nnodes_unique = len(uhexa)
                nids = hexa[:nnodes_unique]
                centroid_y = model.xyz[nids, 1].max()
                if centroid_y < 0:
                    removed_nodes = True
                    continue
                if nnodes_unique == 4:
                    card = ['CTETRA', istart + ihex, solid_pid] + list(nids)
                    assert len(card) == 7, len(card)
                elif nnodes_unique == 5:
                    card = ['CPYRAM', istart + ihex, solid_pid] + list(nids)
                    assert len(card) == 8, len(card)
                elif nnodes_unique == 6:
                    card = ['CPENTA', istart + ihex, solid_pid] + list(nids)
                    assert len(card) == 9, len(card)
                elif nnodes_unique == 8:
                    card = ['CHEXA', istart + ihex, solid_pid] + list(hexa)
                bdf_file.write(print_card_8(card))

        E = 3.0e7
        G = None
        nu = 0.3
        card = ['MAT1', mid, E, G, nu]
        bdf_file.write(print_card_8(card))

    if removed_nodes:
        bdf_model = BDF(debug=debug)
        bdf_model.read_bdf(bdf_filename)
        remove_unused(bdf_model)
Exemple #12
0
def tecplot_to_cart3d(tecplot_filename,
                      cart3d_filename=None,
                      remove_degenerate_tris=True,
                      log=None,
                      debug=True):
    """
    Converts a Tecplot file to Cart3d.

    Parameters
    ----------
    remove_degenerate_tris : bool; default=False
        removes degenerate triangles (triangles with an area of 0.0)
    """
    if isinstance(tecplot_filename, str):
        model = read_tecplot(tecplot_filename, log=log, debug=debug)
    else:
        model = tecplot_filename

    assert len(model.zones) == 1, 'only 1 zone is supported'
    for izone, zone in enumerate(model.zones):
        #print(zone)
        tris, xyz = get_zone_tris_xyz(zone)
        if remove_degenerate_tris:
            assert tris.shape[0] > 0, tris.shape
            assert xyz.shape[0] > 0, xyz.shape
            A = _get_tri_area(tris, xyz)
            iarea = np.where(A > 0.)[0]
            tris = tris[iarea, :]

        npoints = xyz.shape[0]
        assert npoints > 0, xyz.shape
        nelements = tris.shape[0]
        assert nelements > 0, nelements
        assert tris.shape[1] == 3, tris.shape
        #print('npoints=%s nelements=%s' % (npoints, nelements))

        #removed_nodes = False
        regions = np.zeros(nelements, dtype='int32')
        ones_float = np.ones(npoints, dtype='float64')

    cart3d_model = Cart3D(log=log)
    cart3d_model.points = xyz
    cart3d_model.regions = regions
    cart3d_model.elements = tris  # + 1
    assert npoints > 0, npoints

    headers_no_xyz = model.variables[3:]  # drop the xyz, get what's left
    if 'cp' in headers_no_xyz:
        iCp = headers_no_xyz.index('cp')
        cp = model.results[:, iCp]
        assert len(cp) == npoints
        cart3d_model.loads = {
            'Cp': cp,  # nodal Cp
            'rho': ones_float,
            'rhoU': ones_float,
            'rhoV': ones_float,
            'rhoW': ones_float,
            'E': ones_float,
        }
    else:
        model.log.debug('skipping Cp')

    if cart3d_filename is not None:
        cart3d_model.write_cart3d(cart3d_filename)
    return cart3d_model
def tecplot_to_nastran(tecplot_filename, bdf_filename, debug=True):
    """Converts a Tecplot file to Nastran."""
    if isinstance(tecplot_filename, str):
        model = read_tecplot(tecplot_filename, debug=debug)
    else:
        model = tecplot_filename

    removed_nodes = False
    shell_pid = 1
    solid_pid = 2
    mid = 1
    istart = 1
    with open(bdf_filename, 'wb') as bdf_file:
        bdf_file.write('$pyNastran : punch=True\n')
        for inode, node in enumerate(model.xyz):
            card = ['GRID', inode + 1, None,] + list(node)
            bdf_file.write(print_card_8(card))

        if len(model.tri_elements):
            # tris only
            itri = 0
            for itri, tri in enumerate(model.tri_elements):
                card = ['CTRIA3', itri + 1, shell_pid] + list(tri)
                bdf_file.write(print_card_8(card))
            #istart += bdf_model

        if len(model.quad_elements):
            if len(model.tri_elements) != 0:
                # if there are tris, then we assume the quads are good
                for iquad, quad in enumerate(model.quad_elements):
                    card = ['CQUAD4', iquad + 1, shell_pid] + list(quad)
                    bdf_file.write(print_card_8(card))
            else:
                # need to split out the CQUAD4 elements
                istart = itri + 1
                for iquad, quad in enumerate(model.quad_elements):
                    if quad[2] == quad[3]:
                        # if it's a tri
                        card = ['CTRIA3', istart + iquad, shell_pid] + list(quad[:3])
                    else:
                        card = ['CQUAD4', istart + iquad, shell_pid] + list(quad)
                    bdf_file.write(print_card_8(card))
            istart += iquad

        if len(model.tri_elements) + len(model.quad_elements):
            card = ['PSHELL', shell_pid, mid, 0.1]
            bdf_file.write(print_card_8(card))

        if len(model.tet_elements) + len(model.hexa_elements):
            card = ['PSOLID', solid_pid, mid]
            bdf_file.write(print_card_8(card))

        if len(model.tet_elements):
            for itet, tet in enumerate(model.tet_elements):
                card = ['CTETRA', istart + itet, solid_pid] + list(tet)
                bdf_file.write(print_card_8(card))

        if len(model.hexa_elements):
            # need to split out the CTETRA and CPENTA elements
            for ihex, hexa in enumerate(model.hexa_elements):
                uhexa = unique(hexa)
                nnodes_unique = len(uhexa)
                nids = hexa[:nnodes_unique]
                centroid_y = model.xyz[nids, 1].max()
                if centroid_y < 0:
                    removed_nodes = True
                    continue
                if nnodes_unique == 4:
                    card = ['CTETRA', istart + ihex, solid_pid] + list(nids)
                    assert len(card) == 7, len(card)
                elif nnodes_unique == 5:
                    card = ['CPYRAM', istart + ihex, solid_pid] + list(nids)
                    assert len(card) == 8, len(card)
                elif nnodes_unique == 6:
                    card = ['CPENTA', istart + ihex, solid_pid] + list(nids)
                    assert len(card) == 9, len(card)
                elif nnodes_unique == 8:
                    card = ['CHEXA', istart + ihex, solid_pid] + list(hexa)
                bdf_file.write(print_card_8(card))

        E = 3.0e7
        G = None
        nu = 0.3
        card = ['MAT1', mid, E, G, nu]
        bdf_file.write(print_card_8(card))

    if removed_nodes:
        bdf_model = BDF(debug=debug)
        bdf_model.read_bdf(bdf_filename)
        remove_unused(bdf_model)
Exemple #14
0
    def test_tecplot_01(self):
        tecplot_filename1 = os.path.join(model_path, 'ascii', 'point_fetri_2d_02.dat')
        tecplot_filename2 = os.path.join(model_path, 'ascii', 'point_fetri_2d_02.dat_out')

        tecplot = read_tecplot(tecplot_filename1)