Ejemplo n.º 1
0
def main():  # pragma: no cover
    bdf_filename = 'bay.bdf'
    bc_file = 'bc'

    bdf_filename2 = 'bay2.bdf'
    cart3d_filename = 'bay.i.tri'
    stl_filename = 'bay.stl'
    #in_format = 'nastran'
    flip_normals = True

    volume_bdfname = 'bay.vol.bdf'

    module = __import__(bc_file)
    pid_map = module.__dict__['pid_map']
    boundary_conditions = module.__dict__['boundary_conditions']

    #print(dir(module))
    #e = execfile(bc_file, globals(), locals())
    #print(globals())
    #print(dir(e))

    pid_map
    boundary_conditions
    assert isinstance(pid_map, dict)
    assert isinstance(boundary_conditions, dict)

    get_bcs(bdf_filename, pid_map, boundary_conditions, log=None)
    #if flip_normals:
    #bdf = BDF(debug=False)
    #bdf.read_bdf(bdf_filename, xref=False)
    #bdf.flip_normals()
    #bdf.write_bdf(bdf_filename2)
    #del bdf
    #else:
    #bdf_filename2 = bdf_filename

    if 0:
        nastran_to_cart3d_filename(bdf_filename, cart3d_filename, log=log)
        cart3d_to_stl_filename(cart3d_filename, stl_filename, log=log)
    else:
        nastran_to_stl_filename(bdf_filename, stl_filename, log=log)
        stl_to_nastran_filename(stl_filename, bdf_filename2, log=log)
    print('----------')
    #nastran_to_cart3d(bdf_filename2, cart3d_filename)
    #cart3d = Cart3d()
    #cart3d.read_cart3d(cart3d_filename)

    stl = STL()
    stl.read_stl(stl_filename)

    if flip_normals:
        stl.flip_normals()
    stl.project_boundary_layer(stl.nodes, stl.elements, volume_bdfname)
Ejemplo n.º 2
0
def main():
    bdf_filename = 'bay.bdf'
    bc_file = 'bc'

    bdf_filename2 = 'bay2.bdf'
    cart3d_filename = 'bay.i.tri'
    stl_filename = 'bay.stl'
    #in_format = 'nastran'
    flip_normals = True

    volume_bdfname = 'bay.vol.bdf'

    module = __import__(bc_file)
    pid_map = module.__dict__['pid_map']
    boundary_conditions = module.__dict__['boundary_conditions']

    #print(dir(module))
    #e = execfile(bc_file, globals(), locals())
    #print(globals())
    #print(dir(e))

    pid_map
    boundary_conditions
    assert isinstance(pid_map, dict)
    assert isinstance(boundary_conditions, dict)

    get_bcs(bdf_filename, pid_map, boundary_conditions, log=None)
    #if flip_normals:
       #bdf = BDF()
       #bdf.read_bdf(bdf_filename, xref=False)
       #bdf.flip_normals()
       #bdf.write_bdf(bdf_filename2)
       #del bdf
    #else:
    #bdf_filename2 = bdf_filename

    if 0:
        nastran_to_cart3d_filename(bdf_filename, cart3d_filename, log=log)
        cart3d_to_stl_filename(cart3d_filename, stl_filename, log=log)
    else:
        nastran_to_stl_filename(bdf_filename, stl_filename, log=log)
        stl_to_nastran_filename(stl_filename, bdf_filename2, log=log)
    print("----------")
    #nastran_to_cart3d(bdf_filename2, cart3d_filename)
    #cart3d = Cart3d()
    #cart3d.read_cart3d(cart3d_filename)

    stl = STL()
    stl.read_stl(stl_filename)

    if flip_normals:
        stl.flip_normals()
    stl.project_boundary_layer(stl.nodes, stl.elements, volume_bdfname)
Ejemplo n.º 3
0
def main():  # pragma: no cover
    import os

    #base = 'gear'
    #read_tetgen(base, dimension_flag=2)
    #return

    from pyNastran.converters.stl.stl import STL
    m1 = STL()
    m1.read_stl('tetgen_test.stl')
    m1.flip_normals()
    m1.write_stl('tetgen_test_flipped.stl')
    del m1

    os.system('tetgen.exe -pqcvVqY tetgen_test_flipped.stl')

    m = Tetgen()
    base = 'tetgen_test_flipped.1'
    m.read_tetgen(base + '.node', base + '.smesh', base + '.ele', dimension_flag=3)
    m.write_nastran(base + '.bdf')
Ejemplo n.º 4
0
def stl_reshape(data):
    if '--xy' not in data:
        data['--xy'] = False
    if '--yz' not in data:
        data['--yz'] = False
    if '--xz' not in data:
        data['--xz'] = False
    if '--scale' not in data:
        data['--scale'] = None

    if '--xscale' not in data:
        data['--xscale'] = None
    if '--yscale' not in data:
        data['--yscale'] = None
    if '--zscale' not in data:
        data['--zscale'] = None

    if '<xshift>' not in data:
        data['<xshift>'] = None
    if '<yshift>' not in data:
        data['<yshift>'] = None
    if '<zshift>' not in data:
        data['<zshift>'] = None

    if '--stats' not in data:
        data['--stats'] = None
    if '--mirror' not in data:
        data['--mirror'] = None
    if '--flip_normals' not in data:
        data['--flip_normals'] = None

    in_stl_filename = data['<in_stl_filename>']
    out_stl_filename = data['<out_stl_filename>']
    assert in_stl_filename != out_stl_filename

    stl = STL()
    stl.read_stl(in_stl_filename)

    if data['<fmt>'] in ['False', False]:
        is_binary = True
        fmt = None
    else:
        fmt = data['<fmt>']
        is_binary = False
    print('is_binary=%s' % is_binary)

    if data['--xy'] or data['--yz'] or data['--xz']:
        scale = 1.
        if data['--scale'] is not None:
            scale = float(data['--scale'])

        if data['--xy']:
            assert data['--yz'] is False
            assert data['--xz'] is False
            axes = 'xy'
        elif data['--yz']:
            assert data['--xy'] is False
            assert data['--xz'] is False
            axes = 'yz'
        elif data['--xz']:
            assert data['--xy'] is False
            assert data['--yz'] is False
            axes = 'xz'
        #print('flip_axes = %r' % axes)
        #print(data)
        stl.flip_axes(axes, scale)

    elif data['--xscale'] or data['--yscale'] or data['--zscale']:
        xscale = 1.
        yscale = 1.
        zscale = 1.
        if data['--xscale'] is not None:
            xscale = float(data['--xscale'].strip("'"))
        if data['--yscale'] is not None:
            yscale = float(data['--yscale'].strip("'"))
        if data['--zscale'] is not None:
            zscale = float(data['--zscale'].strip("'"))
        x = deepcopy(stl.nodes[:, 0])
        y = deepcopy(stl.nodes[:, 1])
        z = deepcopy(stl.nodes[:, 2])
        stl.nodes[:, 0] = x * xscale
        stl.nodes[:, 1] = y * yscale
        stl.nodes[:, 2] = z * zscale
    elif data['<xshift>'] or data['<yshift>'] or data['<zshift>']:
        xshift = 1.
        yshift = 1.
        zshift = 1.
        if data['<xshift>'] is not None:
            if isinstance(xshift, basestring):
                xshift = float(data['<xshift>'].strip("'"))
            else:
                xshift = float(data['<xshift>'])

        if data['<yshift>'] is not None:
            if isinstance(xshift, basestring):
                yshift = float(data['<yshift>'].strip("'"))
            else:
                yshift = float(data['<yshift>'])

        if data['<zshift>'] is not None:
            if isinstance(xshift, basestring):
                zshift = float(data['<zshift>'].strip("'"))
            else:
                zshift = float(data['<zshift>'])

        print('delta = (%s, %s, %s)' % (xshift, yshift, zshift))
        stl.nodes[:, 0] += xshift
        stl.nodes[:, 1] += yshift
        stl.nodes[:, 2] += zshift
    elif data['--scale']:
        scale = float(data['--scale'])
        stl.nodes *= scale
    elif data['--stats']:
        xmax, ymax, zmax = stl.nodes.max(axis=0)
        xmin, ymin, zmin = stl.nodes.min(axis=0)
        print('xyz_max = (%g, %g, %g)' % (xmax, ymax, zmax))
        print('xyz_min = (%g, %g, %g)' % (xmin, ymin, zmin))
        return
    elif data['--mirror']:
        #plane = data['plane']
        #assert plane in ['xy', 'yz', 'xz'], 'plane=%r' % plane
        xyz = data['<xyz>']
        tol = float(data['<tol>'])
        stl.create_mirror_model(xyz, tol)
    elif data['--flip_normals']:
        stl.flip_normals()
    else:
        raise RuntimeError('unsupported reshape...data=%s' % data)

    stl.write_stl(out_stl_filename, is_binary=is_binary, float_fmt=fmt)
Ejemplo n.º 5
0
def stl_reshape(data):
    if '--xy' not in data:
        data['--xy'] = False
    if '--yz' not in data:
        data['--yz'] = False
    if '--xz' not in data:
        data['--xz'] = False
    if '--scale' not in data:
        data['--scale'] = None

    if '--xscale' not in data:
        data['--xscale'] = None
    if '--yscale' not in data:
        data['--yscale'] = None
    if '--zscale' not in data:
        data['--zscale'] = None

    if '<xshift>' not in data:
        data['<xshift>'] = None
    if '<yshift>' not in data:
        data['<yshift>'] = None
    if '<zshift>' not in data:
        data['<zshift>'] = None

    if '--stats' not in data:
        data['--stats'] = None
    if '--mirror' not in data:
        data['--mirror'] = None
    if '--flip_normals' not in data:
        data['--flip_normals'] = None

    in_stl_filename = data['<in_stl_filename>']
    out_stl_filename = data['<out_stl_filename>']
    assert in_stl_filename != out_stl_filename

    stl = STL()
    stl.read_stl(in_stl_filename)

    if data['<fmt>'] in ['False', False]:
        is_binary = True
        fmt = None
    else:
        fmt = data['<fmt>']
        is_binary = False
    print('is_binary=%s' % is_binary)

    if data['--xy'] or data['--yz'] or data['--xz']:
        scale = 1.
        if data['--scale'] is not None:
            scale = float(data['--scale'])

        if data['--xy']:
            assert data['--yz'] is False
            assert data['--xz'] is False
            axes = 'xy'
        elif data['--yz']:
            assert data['--xy'] is False
            assert data['--xz'] is False
            axes = 'yz'
        elif data['--xz']:
            assert data['--xy'] is False
            assert data['--yz'] is False
            axes = 'xz'
        #print('flip_axes = %r' % axes)
        #print(data)
        stl.flip_axes(axes, scale)

    elif data['--xscale'] or data['--yscale'] or data['--zscale']:
        xscale = 1.
        yscale = 1.
        zscale = 1.
        if data['--xscale'] is not None:
            xscale = float(data['--xscale'].strip("'"))
        if data['--yscale'] is not None:
            yscale = float(data['--yscale'].strip("'"))
        if data['--zscale'] is not None:
            zscale = float(data['--zscale'].strip("'"))
        x = deepcopy(stl.nodes[:, 0])
        y = deepcopy(stl.nodes[:, 1])
        z = deepcopy(stl.nodes[:, 2])
        stl.nodes[:, 0] = x * xscale
        stl.nodes[:, 1] = y * yscale
        stl.nodes[:, 2] = z * zscale
    elif data['<xshift>'] or data['<yshift>'] or data['<zshift>']:
        xshift = 1.
        yshift = 1.
        zshift = 1.
        if data['<xshift>'] is not None:
            if isinstance(xshift, basestring):
                xshift = float(data['<xshift>'].strip("'"))
            else:
                xshift = float(data['<xshift>'])

        if data['<yshift>'] is not None:
            if isinstance(xshift, basestring):
                yshift = float(data['<yshift>'].strip("'"))
            else:
                yshift = float(data['<yshift>'])

        if data['<zshift>'] is not None:
            if isinstance(xshift, basestring):
                zshift = float(data['<zshift>'].strip("'"))
            else:
                zshift = float(data['<zshift>'])

        print('delta = (%s, %s, %s)' % (xshift, yshift, zshift))
        stl.nodes[:, 0] += xshift
        stl.nodes[:, 1] += yshift
        stl.nodes[:, 2] += zshift
    elif data['--scale'] :
        scale = float(data['--scale'])
        stl.nodes *= scale
    elif data['--stats'] :
        xmax, ymax, zmax = stl.nodes.max(axis=0)
        xmin, ymin, zmin = stl.nodes.min(axis=0)
        print('xyz_max = (%g, %g, %g)' % (xmax, ymax, zmax))
        print('xyz_min = (%g, %g, %g)' % (xmin, ymin, zmin))
        return
    elif data['--mirror']:
        #plane = data['plane']
        #assert plane in ['xy', 'yz', 'xz'], 'plane=%r' % plane
        xyz = data['<xyz>']
        tol = float(data['<tol>'])
        stl.create_mirror_model(xyz, tol)
    elif data['--flip_normals']:
        stl.flip_normals()
    else:
        raise RuntimeError('unsupported reshape...data=%s' % data)

    stl.write_stl(out_stl_filename, is_binary=is_binary, float_fmt=fmt)