Example #1
0
    def load_tecplot_geometry(self,
                              tecplot_filename,
                              dirname,
                              name='main',
                              plot=True):
        #key = self.case_keys[self.icase]
        #case = self.result_cases[key]

        skip_reading = self._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 = Tecplot(log=self.log, debug=False)
            model.read_tecplot(tecplot_filename)

        self.model_type = 'tecplot'
        #self.model_type = model.model_type
        self.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)

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

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

        form, cases = self._fill_tecplot_case(cases, ID, model, is_surface)
        self._finish_results_io2(form, cases)

        if 0:
            # http://www.vtk.org/Wiki/VTK/Examples/Cxx/Filtering/AppendFilter
            points = vtkAppendFilter()
            #if VTK_MAJOR_VERSION <= 5:
            #appendFilter.AddInput(polydata)
            #appendFilter.AddInput(ug)
            #else:
            appendFilter.AddInputData(polydata)
            appendFilter.AddInputData()
            appendFilter.Update()
Example #2
0
    def load_tecplot_geometry(self, tecplot_filename, dirname, plot=True):
        #key = self.caseKeys[self.iCase]
        #case = self.resultCases[key]

        skip_reading = self._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 = Tecplot(log=self.log, debug=False)
            model.read_tecplot(tecplot_filename)

        self.modelType = 'tecplot'
        #self.modelType = model.modelType
        self.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)


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

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

        form, cases = self._fill_tecplot_case(cases, ID, model, is_surface)
        self._finish_results_io2(form, cases)

        if 0:
            # http://www.vtk.org/Wiki/VTK/Examples/Cxx/Filtering/AppendFilter
            points = vtkAppendFilter()
            #if VTK_MAJOR_VERSION <= 5:
                #appendFilter.AddInput(polydata)
                #appendFilter.AddInput(ug)
            #else:
            appendFilter.AddInputData(polydata)
            appendFilter.AddInputData()
            appendFilter.Update()
Example #3
0
def merge_tecplot_files(tecplot_filenames,
                        tecplot_filename_out=None,
                        log=None):
    """merges one or more tecplot files"""
    assert isinstance(tecplot_filenames,
                      (list, tuple)), type(tecplot_filenames)
    assert len(tecplot_filenames) > 0, tecplot_filenames

    xyz = []
    tri_elements = []
    quad_elements = []
    tet_elements = []
    hexa_elements = []
    results = []
    nnodes = 0

    model = Tecplot(log=log)
    if len(tecplot_filenames) == 1:
        model.read_tecplot(tecplot_filenames[0])
        if tecplot_filename_out is not None:
            model.write_tecplot(tecplot_filename_out)
        return model

    for tecplot_filename in tecplot_filenames:
        model.log.info('reading %s' % tecplot_filename)
        model.read_tecplot(tecplot_filename)
        xyz.append(model.xyz)
        if len(model.tri_elements):
            tri_elements.append(model.tri_elements + nnodes)
        if len(model.quad_elements):
            quad_elements.append(model.quad_elements + nnodes)
        if len(model.tet_elements):
            tet_elements.append(model.tet_elements + nnodes)
        if len(model.hexa_elements):
            hexa_elements.append(model.hexa_elements + nnodes)
        results.append(model.results)
        nnodes += model.nnodes

    model.xyz = vstack(xyz)
    if tri_elements:
        model.tri_elements = vstack(tri_elements)
    if quad_elements:
        model.quad_elements = vstack(quad_elements)
    if tet_elements:
        model.tet_elements = vstack(tet_elements)
    if hexa_elements:
        model.hexa_elements = vstack(hexa_elements)
    model.results = vstack(results)
    if tecplot_filename_out is not None:
        model.write_tecplot(tecplot_filename_out)
    return model
Example #4
0
def merge_tecplot_files(tecplot_filenames, tecplot_filename_out=None, log=None):
    assert isinstance(tecplot_filenames, (list, tuple)), type(tecplot_filenames)
    assert len(tecplot_filenames) > 0, tecplot_filenames

    xyz = []
    tri_elements = []
    quad_elements = []
    tet_elements = []
    hexa_elements = []
    results = []
    nnodes = 0

    model = Tecplot(log=log)
    if len(tecplot_filenames) == 1:
        model.read_tecplot(tecplot_filenames[0])
        if tecplot_filename_out is not None:
            model.write_tecplot(tecplot_filename_out)
        return model

    for tecplot_filename in tecplot_filenames:
        model.log.info('reading %s' % tecplot_filename)
        model.read_tecplot(tecplot_filename)
        xyz.append(model.xyz)
        if len(model.tri_elements):
            tri_elements.append(model.tri_elements + nnodes)
        if len(model.quad_elements):
            quad_elements.append(model.quad_elements + nnodes)
        if len(model.tet_elements):
            tet_elements.append(model.tet_elements + nnodes)
        if len(model.hexa_elements):
            hexa_elements.append(model.hexa_elements + nnodes)
        results.append(model.results)
        nnodes += model.nnodes

    model.xyz = vstack(xyz)
    if tri_elements:
        model.tri_elements = vstack(tri_elements)
    if quad_elements:
        model.quad_elements = vstack(quad_elements)
    if tet_elements:
        model.tet_elements = vstack(tet_elements)
    if hexa_elements:
        model.hexa_elements = vstack(hexa_elements)
    model.results = vstack(results)
    if tecplot_filename_out is not None:
        model.write_tecplot(tecplot_filename_out)
    return model
def tecplot_to_nastran_filename(tecplot_filename, bdf_filename):
    """
    Converts a Tecplot file to Nastran.
    """
    if isinstance(tecplot_filename, str):
        model = Tecplot()
        model.read_tecplot(tecplot_filename)
    else:
        model = tecplot_filename

    removed_nodes = False
    shell_pid = 1
    solid_pid = 2
    mid = 1
    istart = 1
    bdf_file = open(bdf_filename, 'wb')
    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
        for itri, tri in enumerate(model.tri_elements):
            card = ['CTRIA3', itri + 1, shell_pid] + list(tri)
            bdf_file.write(print_card_8(card))
        istart += itri

    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))
    bdf_file.close()

    if removed_nodes:
        model = BDF()
        model.read_bdf(bdf_filename)
        remove_unassociated_nodes(bdf_filename, bdf_filename,
                                  renumber=True)