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 = Cart3dReader()
    #cart3d.read_cart3d(cart3d_filename)

    stl = STLReader()
    stl.read_stl(stl_filename)

    if flip_normals:
        stl.flip_normals()
    stl.project_boundary_layer(stl.nodes, stl.elements, volume_bdfname)
Exemple #2
0
def main():  # pragma: no cover
    import os

    import pyNastran
    root_path = pyNastran.__path__[0]
    print("root_path = %s" % root_path)

    from pyNastran.converters.cart3d.cart3d_to_stl import cart3d_to_stl_filename

    cart3d_filename = os.path.join(root_path, 'converters', 'cart3d', 'threePlugs_bin.tri')
    stl_filename = os.path.join(root_path, 'converters', 'stl', 'threePlugs.stl')
    bdf_filename = os.path.join(root_path, 'converters', 'stl', 'threePlugs.bdf')

    cart3d_to_stl_filename(cart3d_filename, stl_filename)
    stl_to_nastran(stl_filename, bdf_filename)
Exemple #3
0
def main():  # pragma: no cover
    import os

    import pyNastran
    root_path = pyNastran.__path__[0]
    print("root_path = %s" % root_path)

    from pyNastran.converters.cart3d.cart3d_to_stl import cart3d_to_stl_filename

    cart3d_filename = os.path.join(root_path, 'converters', 'cart3d', 'threePlugs_bin.tri')
    stl_filename = os.path.join(root_path, 'converters', 'stl', 'threePlugs.stl')
    bdf_filename = os.path.join(root_path, 'converters', 'stl', 'threePlugs.bdf')

    cart3d_to_stl_filename(cart3d_filename, stl_filename)
    stl_to_nastran(stl_filename, bdf_filename)
def process_cart3d(cart3d_filename, fmt2, fname2, data):
    """
    Converts Cart3d to STL/Nastran
    """
    assert fmt2 in ['stl', 'nastran', 'tecplot'], 'format2=%s' % fmt2
    # model = Cart3D()
    # model.read_cart3d(cart3d_filename, fname2)
    if fmt2 == 'stl':
        cart3d_to_stl_filename(cart3d_filename, fname2, is_binary=data['--binary'])
    elif fmt2 == 'nastran':
        cart3d_to_nastran_filename(cart3d_filename, fname2)
    elif fmt2 == 'tecplot':
        cart3d_to_tecplot(cart3d_filename, fname2)
    # elif fmt2 == 'ugrid':
        # cart3d_to_ugrid(model, fname2)
    else:
        raise NotImplementedError(fmt2)
Exemple #5
0
def process_cart3d(cart3d_filename, fmt2, fname2, data):
    """
    Converts Cart3d to STL/Nastran
    """
    assert fmt2 in ['stl', 'nastran', 'tecplot', 'cart3d'], 'format2=%s' % fmt2
    model = read_cart3d(cart3d_filename)
    if data['--scale'] != 1.0:
        model.points *= data['--scale']
        data['--scale'] = 1.0

    if fmt2 == 'stl':
        cart3d_to_stl_filename(model, fname2, is_binary=data['--binary'])
    elif fmt2 == 'nastran':
        cart3d_to_nastran_filename(model, fname2)
    elif fmt2 == 'tecplot':
        cart3d_to_tecplot(model, fname2)
    elif fmt2 == 'cart3d':
        model.write_cart3d(fname2, is_binary=data['--binary'])
    # elif fmt2 == 'ugrid':
        # cart3d_to_ugrid(model, fname2)
    else:
        raise NotImplementedError(fmt2)
def cart3d_to_openfoam(cart3d_filename, inpt_filename, basepath):
    """
    https://openfoamwiki.net/images/f/f0/Final-AndrewJacksonSlidesOFW7.pdf
    """
    stl_filename = 'cart3d.stl'
    cart3d_to_stl_filename(cart3d_filename, stl_filename)

    cart3d = Cart3d()
    cart3d.read_cart3d(cart3d_filename)
    points = cart3d.points
    elements = cart3d.elements

    # convert to 0 based
    elements -= 1

    cart3d.void = (1., 0., 0.)

    #create_openfoam_inputs(inpt_filename)
    inpt = Inpt()
    inpt.read_cart3d_inpt(inpt_filename)

    basepath = 'hsct'
    os.makedirs(basepath)
    os.makedirs(os.path.join(basepath, 'constant', 'polyMesh'))
    os.mkdir(os.path.join(basepath, 'system'))

    fsnappy = open(os.path.join(basepath, 'constant', 'snappyHexMeshDict'))
    fblock = open(os.path.join(basepath, 'constant', 'polyMesh', 'blockMeshDict'))
    fcontrol = open(os.path.join(basepath, 'system', 'controlMeshDict'))
    fsnappy.write(get_header())
    fblock.write(get_header())
    fcontrol.write(get_header())

    snappy = ''
    block = ''
    control = ''

    block += write_foam_file(data, 'blockMeshDict', 'constant/polyMesh')
    snappy += write_foam_file(data, 'autoMeshDict')
    control += write_foam_file(data, 'controlMeshDict', 'constant/polyMesh')

    maxR = inpt.maxR
    xmax, ymax, zmax = points.max(axis=1)
    xmin, ymin, zmin = points.min(axis=1)

    dx = xmax - xmin
    dy = ymax - ymin
    dz = zmax - zmin

    xmin -= dx * maxR
    ymin -= dy * maxR
    zmin -= dz * maxR

    xmax += dx * maxR
    ymax += dy * maxR
    zmax += dz * maxR

    p = array([
        [xmin, ymin, zmin],
        [xmin, ymin, zmax],
        [xmin, ymax, zmax],
        [xmin, ymax, zmin],

        [xmax, ymin, zmin],
        [xmax, ymin, zmax],
        [xmax, ymax, zmax],
        [xmax, ymax, zmin],
    ])

    block += 'vertices\n'
    block += '{\n'
    for point in p:
        block += '    (%s, %s, %s)\n' % tuple(point)
    block += '};\n'

    block += 'elements\n'
    block += '{\n'
    block += '    hex (0 1 2 3 4 5 6 7) (%s %s %s) (1.0 1.0 1.0)\n' % inpt.xyz_start
    block += '};\n\n'

    snappy += 'castellatedMesh true;\n'
    snappy += 'snap            true;\n'
    snappy += 'addLayers       false;\n'

    block += 'patches\n'
    block += '{\n'
    block += '    inflow\n'
    block += '    (\n'
    block += '       4 (0 1 2 3)\n'
    block += '    outflow\n'
    block += '       4 (4 5 6 7)\n'
    block += '    )\n'
    block += '};\n\n'
    block += 'mergePatchParis();\n'

    assert os.path.exists(stl_filename), stl_filename
    stl_base, ext = os.path.splitext(stl_filename)

    snappy += 'geometry;\n'
    snappy += '{\n'
    snappy += '    %s // STL filename;\n' % os.path.basename(stl_filename)
    snappy += '    {\n'
    snappy += '        type triSurfaceMesh;;\n'
    snappy += '        name %s;\n' % stl_base
    snappy += '    }\n'
    snappy += '};\n'

    snappy += 'snapControls\n'
    snappy += '{\n'
    snappy += '    nSmoothPatch     3;\n'
    snappy += '    tolerance        1.0;\n'
    snappy += '    nSolveIter       300;\n'
    snappy += '    nRelaxIter       5;\n'
    snappy += '    nFeatureSnapIter 10;\n'
    snappy += '};\n'

    inpt.max_cells = 2
    inpt.min_refinement_cells = 1
    inpt.ncells_between_levels = 2
    castel += '{'
    castel += '    maxGlobalCells      %i\n' % inpt.max_cells * 1e6
    castel += '    minRefinementCells  %s\n' % inpt.min_refinement_cells
    castel += '    nCellsBetweenLevels %s\n\n' % inpt.ncells_between_levels

    castel += '    features();\n'
    castel += '}\n\n'

    castel += '// refinementSurfaces'
    castel += 'resolveFeatureAngle        %s\n' % inpt.feature_angle
    castel += 'locationInMesh             (%s %s %s);\n' % tuple(cart3d.void)
    castel += 'allowFreeStandingZoneFaces true;  // ?????\n'
    castel += '}'

    fsnappy.write(snappy)
    fblock.write(block)
    fcontrol.write(control)
    fcastel.write(castel)

    fsnappy.close()
    fblock.close()
    fcontrol.close()
    fcastle.close()
        eid += 1

    t = 0.1
    card = ['PSHELL', pid, mid, t]
    bdf.write(print_card_8(card))

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

    bdf.write('ENDDATA\n')
    bdf.close()

if __name__ == '__main__':  # pragma: no cover
    import os

    import pyNastran
    root_path = pyNastran.__path__[0]
    print("root_path = %s" % root_path)

    from pyNastran.converters.cart3d.cart3d_to_stl import cart3d_to_stl_filename

    cart3d_filename = os.path.join(root_path, 'converters', 'cart3d', 'threePlugs_bin.tri')
    stl_filename = os.path.join(root_path, 'converters', 'stl', 'threePlugs.stl')
    bdf_filename = os.path.join(root_path, 'converters', 'stl', 'threePlugs.bdf')

    cart3d_to_stl_filename(cart3d_filename, stl_filename)
    stl_to_nastran_filename(stl_filename, bdf_filename)