Ejemplo n.º 1
0
def ugrid3d_to_nastran(ugrid_filename,
                       bdf_filename,
                       include_shells=True,
                       include_solids=True,
                       convert_pyram_to_penta=False,
                       encoding=None,
                       size=16,
                       is_double=False,
                       log=None):
    """
    Converts a UGRID to a BDF.

    Parameters
    ----------
    ugrid_filename : str
        the input UGRID filename
    bdf_filename : str
        the output BDF filename
    include_shells : bool; default=True
        should the shells be written
    include_solids : bool; default=True
        should the solids be written
    convert_pyram_to_penta : bool; default=False
        False : NX Nastran
        True : MSC Nastran
    size : int; {8, 16}; default=16
        the bdf write precision
    is_double : bool; default=False
        the field precision to write
    log : logger; default=None
        a logger object

    Returns
    -------
    ugrid_model : UGRID()
        the ugrid model
    """
    model = UGRID(log=log, debug=False)
    check_path(ugrid_filename, 'ugrid_filename')
    model.read_ugrid(ugrid_filename)
    model.write_bdf(bdf_filename,
                    include_shells=include_shells,
                    include_solids=include_solids,
                    convert_pyram_to_penta=convert_pyram_to_penta,
                    encoding=encoding,
                    size=size,
                    is_double=is_double)
    return model
Ejemplo n.º 2
0
def process_ugrid(ugrid_filename, fmt2, fname2, log, data=None, quiet=False):
    """
    Converts UGRID to Nastran/Cart3d/STL/Tecplot
    """
    assert fmt2 in ['stl', 'nastran', 'cart3d', 'tecplot'], 'format2=%s' % fmt2
    read_shells = True
    read_solids = True
    if fmt2 in ['stl', 'cart3d']:
        read_shells = True
        read_solids = False

    from pyNastran.converters.aflr.ugrid.ugrid_reader import UGRID
    model = UGRID(read_shells=read_shells, read_solids=read_solids, log=log)
    model.read_ugrid(ugrid_filename)
    if fmt2 == 'nastran':
        # ugrid_to_nastran(model, fname2
        include_shells = True
        include_solids = True
        bdf_filename = fname2
        model.write_bdf(bdf_filename,
                        include_shells=include_shells,
                        include_solids=include_solids)
    elif fmt2 == 'cart3d':
        include_shells = True
        include_solids = False
        bdf_filename = fname2 + '.bdf'
        model.write_bdf(bdf_filename,
                        include_shells=include_shells,
                        include_solids=include_solids)
        # ugrid_to_cart3d(model, fname2)
        process_nastran(bdf_filename, 'cart3d', fname2, data=None)
    elif fmt2 == 'stl':
        include_shells = True
        include_solids = False
        bdf_filename = fname2 + '.bdf'
        model.write_bdf(bdf_filename,
                        include_shells=include_shells,
                        include_solids=include_solids)
        process_nastran(bdf_filename, 'cart3d', fname2, data=None)
        # ugrid_to_stl(model, fname2)
    elif fmt2 == 'tecplot':
        from pyNastran.converters.aflr.ugrid.ugrid3d_to_tecplot import ugrid_to_tecplot
        # ugrid_to_tecplot(model, fname2)
        tecplot, unused_zone = ugrid_to_tecplot(model)
        element_slice(tecplot, data)
        tecplot_filename = fname2
        tecplot.write_tecplot(tecplot_filename)
    else:
        raise NotImplementedError('fmt2=%s is not supported by process_ugrid' %
                                  fmt2)