Ejemplo n.º 1
0
    def test_nastran_to_ugrid_01(self):
        bdf_filename = os.path.join(MODEL_PATH, 'solid_bending', 'solid_bending.bdf')

        size = 8
        debug = False
        log = get_logger(log=None, level='warning', encoding='utf-8')
        model = read_bdf(bdf_filename, log=log, debug=debug)
        #log = model.log
        #model.get_element_faces()
        skin_bdf_filename = os.path.join(MODEL_PATH, 'solid_bending', 'solid_skin.bdf')
        model.write_skin_solid_faces(skin_bdf_filename, write_solids=True,
                                     write_shells=True,
                                     size=size, is_double=False, encoding=None)

        bdf_model = read_bdf(skin_bdf_filename, log=log, debug=debug)
        ugrid_filename_out = os.path.join(MODEL_PATH, 'solid_bending', 'solid_skin.b8.ugrid')
        ugrid_filename_out2 = os.path.join(MODEL_PATH, 'solid_bending', 'solid_skin2.b8.ugrid')
        nastran_to_ugrid(bdf_model, ugrid_filename_out, properties=None,
                         check_shells=True, check_solids=True)
        ugrid = read_ugrid(ugrid_filename_out, encoding=None, log=log,
                           debug=debug)

        skin_bdf_filename2 = os.path.join(MODEL_PATH, 'solid_bending', 'solid_skin2.bdf')
        skin_cart3d_filename = os.path.join(MODEL_PATH, 'solid_bending', 'solid_skin2.tri')
        skin_cart3d_filename3 = os.path.join(MODEL_PATH, 'solid_bending', 'solid_skin3.tri')
        skin_stl_filename3 = os.path.join(MODEL_PATH, 'solid_bending', 'solid_skin3.stl')

        #msg += "  format_converter nastran   <INPUT> <format2> <OUTPUT> [-o <OP2>] --no_xref\n"
        #msg += "  format_converter <format1> <INPUT> tecplot   <OUTPUT> [-r RESTYPE...] [-b] [--block] [-x <X>] [-y <Y>] [-z <Z>] [--scale SCALE]\n"
        #msg += "  format_converter <format1> <INPUT> stl       <OUTPUT> [-b]  [--scale SCALE]\n"
        #msg += "  format_converter cart3d    <INPUT> <format2> <OUTPUT> [-b]  [--scale SCALE]\n"
        #msg += "  format_converter <format1> <INPUT> <format2> <OUTPUT> [--scale SCALE]\n"
        argv = ['format_converter', 'nastran', bdf_filename, 'ugrid', ugrid_filename_out2]
        with self.assertRaises(RuntimeError):
            cmd_line_format_converter(argv=argv, quiet=True)

        #argv = ['format_converter', 'nastran', bdf_filename, 'cart3d', skin_cart3d_filename3]
        #cmd_line_format_converter(argv=argv)

        #argv = ['format_converter', 'nastran', bdf_filename, 'stl', skin_stl_filename3]
        #cmd_line_format_converter(argv=argv)

        ugrid.write_bdf(skin_bdf_filename2, include_shells=True, include_solids=True,
                        convert_pyram_to_penta=True, encoding=None,
                        size=size, is_double=False)
        read_bdf(skin_bdf_filename2, log=log, debug=debug)

        with self.assertRaises(AssertionError):
            nastran_to_cart3d_filename(skin_bdf_filename2, skin_cart3d_filename)

        ugrid.write_bdf(skin_bdf_filename2, include_shells=True, include_solids=False,
                        convert_pyram_to_penta=True, encoding=None,
                        size=size, is_double=False)

        nastran_to_cart3d_filename(skin_bdf_filename2, skin_cart3d_filename)
        read_cart3d(skin_cart3d_filename, log=log)

        os.remove(ugrid_filename_out)
        os.remove(skin_bdf_filename)
        os.remove(skin_bdf_filename2)
Ejemplo n.º 2
0
    def test_cart3d_io_03(self):
        """read/write geometry in ascii/binary"""
        log = get_logger(level='warning', encoding='utf-8')
        infile_name = os.path.join(MODEL_PATH, 'threePlugs.bin.tri')
        outfile_name = os.path.join(MODEL_PATH, 'threePlugs_out.tri')
        outfile_name_bin = os.path.join(MODEL_PATH, 'threePlugs_bin2.tri')
        outfile_name_bin_out = os.path.join(MODEL_PATH,
                                            'threePlugs_bin_out.tri')

        cart3d = read_cart3d(infile_name, log=log, debug=False)
        cart3d.write_cart3d(outfile_name, is_binary=False)
        cart3d.write_cart3d(outfile_name_bin, is_binary=True)

        cart3d_ascii = read_cart3d(outfile_name, log=log, debug=False)
        check_array(cart3d.points, cart3d_ascii.points)
        check_array(cart3d.elements, cart3d_ascii.elements)

        cart3d_bin = read_cart3d(outfile_name_bin, log=log, debug=False)
        check_array(cart3d.points, cart3d_bin.points)
        check_array(cart3d.elements, cart3d_ascii.elements)
        #print(cart3d_bin.points)

        #print('---------------')
        #print(cart3d_bin.points)

        os.remove(outfile_name)
        os.remove(outfile_name_bin)

        cart3d.write_cart3d(outfile_name_bin_out, is_binary=False)
        os.remove(outfile_name_bin_out)
Ejemplo n.º 3
0
    def test_bjet(self):
        log = get_logger(level='warning', encoding='utf-8')
        geometry_filename = os.path.join(MODEL_PATH, 'business_jet',
                                         'bJet.a.tri')

        model = read_cart3d(geometry_filename, log=log)
        #print(model.points.min(axis=0))
        #print(model.points.max(axis=0))
        model.make_half_model(axis='z', remap_nodes=True)  # keep +z
        #print(model.points.min(axis=0))
        #print(model.points.max(axis=0))
        geometry_filename_half = os.path.join(MODEL_PATH, 'half_bjet.a.tri')
        model.write_cart3d(geometry_filename_half)
        read_cart3d(geometry_filename_half, log=log)
Ejemplo n.º 4
0
    def test_cart3d_io_01(self):
        """geometry"""
        lines = ("7 6\n"
                 "0.000000 0.000000 0.000000\n"
                 "1.000000 0.000000 0.000000\n"
                 "2.000000 0.000000 0.000000\n"
                 "1.000000 1.000000 0.000000\n"
                 "2.000000 1.000000 0.000000\n"
                 "1.000000 -1.000000 0.000000\n"
                 "2.000000 -1.000000 0.000000\n"
                 "1 4 2\n"
                 "2 4 5\n"
                 "2 5 3\n"
                 "2 6 1\n"
                 "5 6 2\n"
                 "5 5 2\n"
                 "1\n"
                 "2\n"
                 "3\n"
                 "2\n"
                 "4\n"
                 "6\n")
        log = get_logger(level='warning', encoding='utf-8')
        infile_name = os.path.join(MODEL_PATH, 'flat_full.tri')
        out_name = os.path.join(MODEL_PATH, 'combined.tri')
        with open(infile_name, 'w') as f:
            f.write(lines)

        model = comp2tri([infile_name, infile_name],
                         out_name,
                         is_binary=False,
                         float_fmt='%6.7f',
                         log=log)
        read_cart3d(out_name, log=log, debug=False)

        cart3d = read_cart3d(infile_name, log=log, debug=False)
        assert len(cart3d.points) == 7, 'npoints=%s' % len(cart3d.points)
        assert len(cart3d.elements) == 6, 'nelements=%s' % len(cart3d.elements)
        assert len(cart3d.regions) == 6, 'nregions=%s' % len(cart3d.regions)
        assert len(cart3d.loads) == 0, 'nloads=%s' % len(cart3d.loads)
        os.remove(out_name)

        argv = [
            'format_converter', 'cart3d', infile_name, 'cart3d', out_name, '-b'
        ]
        cmd_line_format_converter(argv=argv, quiet=True)

        os.remove(infile_name)
        os.remove(out_name)
Ejemplo n.º 5
0
    def test_cart3d_io_01(self):
        """geometry"""
        lines = ("7 6\n"
                 "0.000000 0.000000 0.000000\n"
                 "1.000000 0.000000 0.000000\n"
                 "2.000000 0.000000 0.000000\n"
                 "1.000000 1.000000 0.000000\n"
                 "2.000000 1.000000 0.000000\n"
                 "1.000000 -1.000000 0.000000\n"
                 "2.000000 -1.000000 0.000000\n"
                 "1 4 2\n"
                 "2 4 5\n"
                 "2 5 3\n"
                 "2 6 1\n"
                 "5 6 2\n"
                 "5 5 2\n"
                 "1\n"
                 "2\n"
                 "3\n"
                 "2\n"
                 "4\n"
                 "6\n")
        infile_name = os.path.join(test_path, 'flat_full.tri')
        with open(infile_name, 'w') as f:
            f.write(lines)

        log = get_logger(level='warning', encoding='utf-8')
        cart3d = read_cart3d(infile_name, log=log, debug=False)
        assert len(cart3d.points) == 7, 'npoints=%s' % len(cart3d.points)
        assert len(cart3d.elements) == 6, 'nelements=%s' % len(cart3d.elements)
        assert len(cart3d.regions) == 6, 'nregions=%s' % len(cart3d.regions)
        assert len(cart3d.loads) == 0, 'nloads=%s' % len(cart3d.loads)
        os.remove(infile_name)
Ejemplo n.º 6
0
def cart3d_to_stl_filename(cart3d_filename,
                           stl_filename=None,
                           is_binary=False,
                           log=None,
                           debug=False):
    """
    Converts a Cart3D file to STL format.

    Parameters
    ----------
    cart3d_filename : str
        path to the input Cart3D file
    stl_filename : str; default=None
        path to the output STL file (or None to skip
    is_binary : bool; default=False
        writes the stl in binary
    log : log
        a logger object (or None)
    debug : bool; default=False
        True/False (used if log is not defined)

    Returns
    -------
    stl : STL()
        an STL object
    """
    if isinstance(cart3d_filename, Cart3D):
        cart3d = cart3d_filename
    else:
        cart3d = read_cart3d(cart3d_filename, log=log, debug=debug)
    return cart3d_to_stl(cart3d, stl_filename, is_binary=is_binary)
Ejemplo n.º 7
0
def process_cart3d(cart3d_filename, fmt2, fname2, log, data, quiet=False):
    """
    Converts Cart3d to STL/Nastran/Tecplot/Cart3d
    """
    assert fmt2 in ['stl', 'nastran', 'tecplot', 'cart3d'], 'format2=%s' % fmt2
    from pyNastran.converters.cart3d.cart3d import read_cart3d

    model = read_cart3d(cart3d_filename, log=log)
    if data['--scale'] != 1.0:
        model.points *= data['--scale']
        data['--scale'] = 1.0

    if fmt2 == 'stl':
        from pyNastran.converters.cart3d.cart3d_to_stl import cart3d_to_stl_filename
        cart3d_to_stl_filename(model,
                               fname2,
                               log=log,
                               is_binary=data['--binary'])
    elif fmt2 == 'nastran':
        from pyNastran.converters.cart3d.cart3d_to_nastran import cart3d_to_nastran_filename
        cart3d_to_nastran_filename(model, fname2, log=log)
    elif fmt2 == 'tecplot':
        from pyNastran.converters.cart3d.cart3d_to_tecplot import cart3d_to_tecplot
        cart3d_to_tecplot(model, fname2, log=log)
    elif fmt2 == 'cart3d':
        model.write_cart3d(fname2, is_binary=data['--binary'])
    # elif fmt2 == 'ugrid':
    # cart3d_to_ugrid(model, fname2)
    else:
        raise NotImplementedError(
            'fmt2=%s is not supported by process_cart3d' % fmt2)
Ejemplo n.º 8
0
def cart3d_to_nastran_model(cart3d_filename, log=None, debug=False):
    """
    Converts a Cart3D file to Nastran format and returns a BDF() object.

    Parameters
    ----------
    cart3d_filename : str
        path to the input Cart3D file
    log : log / None
        log : a logger object
        None : a log will be defined
    debug : bool
        True/False (used if log is not defined)

    Returns
    -------
    bdf_model : BDF
        BDF() model object
    """
    if isinstance(cart3d_filename, Cart3D):
        cart3d = cart3d_filename
    else:
        cart3d = read_cart3d(cart3d_filename, log=log, debug=debug, result_names=None)
    nodes = cart3d.nodes
    elements = cart3d.elements + 1
    regions = cart3d.regions

    if regions.min() == 0:
        # bit of a hack to take an invalid cart3d model and make it
        # work in Nastran, which requires property_ids > 0
        regions += 1

    i = 0
    nid = 1
    cid = 0
    model = BDF(log=log, debug=debug)
    for node in nodes:
        card = ['GRID', nid, cid] + list(node)
        model.add_card(card, 'GRID', is_list=True)
        nid += 1

    eid = 1
    for (n1, n2, n3), pid in zip(elements, regions):
        card = ['CTRIA3', eid, pid, n1, n2, n3]
        model.add_card(card, 'CTRIA3', is_list=True)
        #print(model.elements[eid])
        eid += 1

    t = 0.1
    E = 1e7
    nu = 0.3
    for pid in unique(regions):
        mid = pid
        card = ['PSHELL', pid, mid, t]
        model.add_card(card, 'PSHELL', is_list=True)
        card = ['MAT1', mid, E, None, nu]
        model.add_card(card, 'MAT1', is_list=True)
    model.pop_parse_errors()
    return model
Ejemplo n.º 9
0
def cart3d_to_nastran_model(cart3d_filename, log=None, debug=False):
    """
    Converts a Cart3D file to Nastran format and returns a BDF() object.

    Parameters
    ----------
    cart3d_filename : str
        path to the input Cart3D file
    log : log / None
        log : a logger object
        None : a log will be defined
    debug : bool
        True/False (used if log is not defined)

    Returns
    -------
    bdf_model : BDF
        BDF() model object
    """
    if isinstance(cart3d_filename, Cart3D):
        cart3d = cart3d_filename
    else:
        cart3d = read_cart3d(cart3d_filename, log=log, debug=debug, result_names=None)
    nodes = cart3d.nodes
    elements = cart3d.elements
    regions = cart3d.regions

    if regions.min() == 0:
        # bit of a hack to take an invalid cart3d model and make it
        # work in Nastran, which requires property_ids > 0
        regions += 1

    i = 0
    nid = 1
    cid = 0
    model = BDF(log=log, debug=debug)
    for node in nodes:
        card = ['GRID', nid, cid] + list(node)
        model.add_card(card, 'GRID', is_list=True)
        nid += 1

    eid = 1
    for (n1, n2, n3), pid in zip(elements, regions):
        card = ['CTRIA3', eid, pid, n1, n2, n3]
        model.add_card(card, 'CTRIA3', is_list=True)
        #print(model.elements[eid])
        eid += 1

    t = 0.1
    E = 1e7
    nu = 0.3
    for pid in unique(regions):
        mid = pid
        card = ['PSHELL', pid, mid, t]
        model.add_card(card, 'PSHELL', is_list=True)
        card = ['MAT1', mid, E, None, nu]
        model.add_card(card, 'MAT1', is_list=True)
    model.pop_parse_errors()
    return model
Ejemplo n.º 10
0
def cart3d_to_tecplot(cart3d_filename, tecplot_filename, log=None, debug=False):
    """
    Converts Cart3d to Tecplot
    """
    if isinstance(cart3d_filename, Cart3D):
        model = cart3d_filename
    else:
        model = read_cart3d(cart3d_filename, log=log, debug=debug)

    tecplot = Tecplot()
    tecplot.xyz = model.points
    tecplot.tri_elements = model.elements
    tecplot.write_tecplot(tecplot_filename, adjust_nids=False)
    return tecplot
Ejemplo n.º 11
0
    def test_cart3d_io_02(self):
        """geometry + results"""
        lines = ("5 3 6\n"
                 "0. 0. 0.\n"
                 "1. 0. 0.\n"
                 "2. 0. 0.\n"
                 "1. 1. 0.\n"
                 "2. 1. 0.\n"
                 "1 4 2\n"
                 "2 4 5\n"
                 "2 5 3\n"
                 "1\n"
                 "2\n"
                 "3\n"
                 "1.\n"
                 "1. 1. 1. 1. 1.\n"
                 "2.\n"
                 "2. 2. 2. 2. 2.\n"
                 "3.\n"
                 "3. 3. 3. 3. 3.\n"
                 "4.\n"
                 "4. 4. 4. 4. 4.\n"
                 "5.\n"
                 "5. 5. 5. 5. 5.\n")
        cart3d_filename = os.path.join(MODEL_PATH, 'flat.tri')
        with open(cart3d_filename, 'w') as f:
            f.write(lines)

        log = get_logger(level='warning', encoding='utf-8')
        cart3d = read_cart3d(cart3d_filename,
                             log=log,
                             debug=False,
                             result_names=None)

        assert len(cart3d.points) == 5, 'npoints=%s' % len(cart3d.points)
        assert len(cart3d.elements) == 3, 'nelements=%s' % len(cart3d.elements)
        assert len(cart3d.regions) == 3, 'nregions=%s' % len(cart3d.regions)

        assert len(
            cart3d.loads) == 14, 'nloads=%s' % len(cart3d.loads)  # was 10
        assert len(cart3d.loads['Cp']) == 5, 'nCp=%s' % len(cart3d.loads['Cp'])

        outfile_name = os.path.join(MODEL_PATH, 'flat.bin.tri')
        cart3d.loads = None
        cart3d.write_cart3d(outfile_name, is_binary=True)
        cnormals = cart3d.get_normals()
        nnormals = cart3d.get_normals_at_nodes(cnormals)
        os.remove(cart3d_filename)
        os.remove(outfile_name)
Ejemplo n.º 12
0
def write_new_cart3d_mesh(cfd_grid_file, cfd_grid_file2, wA, log=None):
    """
    Takes in half model wA, and baseline cart3d model, updates full model grids

    Parameters
    ----------
    cfd_grid_file : str
        the full model cart3d filename
    cfd_grid_file2 : str
        the half model cart3d filename???
        unused???
        seems to overwrite cfd_grid_file
    wA : dict[cart3d_nid] = zi
        cart3d_nid : int
            the cart3d node id
        zi : float
            the delta z location

    """
    log.info("---starting write_new_cart3d_mesh---")
    result_names = ['Cp']

    # reading full model
    cart = read_cart3d(cfd_grid_file, result_names=result_names)

    # make half model
    points, elements, regions, loads = cart.make_half_model()

    # adjusting points
    points2 = {}
    for (ipoint, point) in sorted(iteritems(points)):
        wai = wA[ipoint]
        (x, y, z) = point
        points2[ipoint] = [x, y, z + wai]

    # mirroring model
    points, elements, regions, loads = cart.make_mirror_model(
        points2, elements, regions, loads)

    # writing half model; no loads (cleans up leftover parameters)
    cart.points = points
    cart.elements = elements
    cart.regions = regions
    cart.write_cart3d(cfd_grid_file)

    log.info("---finished write_new_cart3d_mesh---")
    sys.stdout.flush()
Ejemplo n.º 13
0
def cart3d_to_tecplot(cart3d_filename,
                      tecplot_filename,
                      log=None,
                      debug=False):
    """
    Converts Cart3d to Tecplot
    """
    if isinstance(cart3d_filename, Cart3D):
        model = cart3d_filename
    else:
        model = read_cart3d(cart3d_filename, log=log, debug=debug)

    tecplot = Tecplot()
    tecplot.xyz = model.points
    tecplot.tri_elements = model.elements
    tecplot.write_tecplot(tecplot_filename, adjust_nids=False)
    return tecplot
Ejemplo n.º 14
0
def cart3d_to_tecplot(cart3d_filename,
                      tecplot_filename,
                      log=None,
                      debug=False):
    """
    Converts Cart3d to Tecplot
    """
    if isinstance(cart3d_filename, Cart3D):
        model = cart3d_filename
    else:
        model = read_cart3d(cart3d_filename, log=log, debug=debug)

    tecplot = Tecplot()
    tecplot.log = model.log
    zone = Zone(model.log)
    zone.headers_dict['VARIABLES'] = ['X', 'Y', 'Z']
    zone.xyz = model.points
    zone.tri_elements = model.elements + 1
    tecplot.zones = [zone]

    tecplot.write_tecplot(tecplot_filename, adjust_nids=False)
    return tecplot
Ejemplo n.º 15
0
def process_cart3d(cart3d_filename, fmt2, fname2, data):
    """
    Converts Cart3d to STL/Nastran/Tecplot/Cart3d
    """
    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)
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
def cart3d_to_stl_filename(cart3d_filename, stl_filename=None, is_binary=False, log=None, debug=False):
    """
    Converts a Cart3D file to STL format.

    Parameters
    ----------
    cart3d_filename : str
        path to the input Cart3D file
    stl_filename : str; default=None
        path to the output STL file (or None to skip
    is_binary : bool; default=False
        writes the stl in binary
    log : log
        a logger object (or None)
    debug : bool; default=False
        True/False (used if log is not defined)
    """
    if isinstance(cart3d_filename, Cart3D):
        cart3d = cart3d_filename
    else:
        cart3d = read_cart3d(cart3d_filename, log=log, debug=debug)
    return cart3d_to_stl(cart3d, stl_filename, is_binary=is_binary)
Ejemplo n.º 18
0
    def load_cart3d_geometry(self, cart3d_filename, name='main', plot=True):
        skip_reading = self._remove_old_cart3d_geometry(cart3d_filename)
        if skip_reading:
            return

        self.eid_maps[name] = {}
        self.nid_maps[name] = {}
        model = read_cart3d(cart3d_filename, log=self.log, debug=False)
        self.model_type = 'cart3d'
        nodes = model.nodes
        elements = model.elements
        regions = model.regions
        loads = model.loads

        self.nNodes = model.npoints
        self.nElements = model.nelements

        grid = self.grid
        grid.Allocate(self.nElements, 1000)

        if 0:
            fraction = 1. / self.nNodes  # so you can color the nodes by ID
            for nid, node in sorted(iteritems(nodes)):
                self.grid_result.InsertNextValue(nid * fraction)

        assert nodes is not None
        nnodes = nodes.shape[0]

        mmax = nodes.max(axis=0)
        mmin = nodes.min(axis=0)
        dim_max = (mmax - mmin).max()
        xmax, ymax, zmax = mmax
        xmin, ymin, zmin = mmin
        self.log_info("xmin=%s xmax=%s dx=%s" % (xmin, xmax, xmax-xmin))
        self.log_info("ymin=%s ymax=%s dy=%s" % (ymin, ymax, ymax-ymin))
        self.log_info("zmin=%s zmax=%s dz=%s" % (zmin, zmax, zmax-zmin))
        self.create_global_axes(dim_max)
        points = self.numpy_to_vtk_points(nodes)

        #assert elements.min() == 0, elements.min()

        etype = 5 # vtkTriangle().GetCellType()
        self.create_vtk_cells_of_constant_element_type(grid, elements, etype)

        grid.SetPoints(points)
        grid.Modified()
        if hasattr(grid, 'Update'):
            grid.Update()
        self._create_cart3d_free_edges(model, nodes, elements)


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

        assert loads is not None
        if 'Mach' in loads:
            avg_mach = mean(loads['Mach'])
            note = ':  avg(Mach)=%g' % avg_mach
        else:
            note = ''
        self.iSubcaseNameMap = {1: ['Cart3d%s' % note, '']}
        cases = {}
        ID = 1
        form, cases, icase = self._fill_cart3d_case2(cases, ID, nodes, elements, regions, model)
        mach, alpha, beta = self._create_box(cart3d_filename, ID, form, cases, icase, regions)
        #mach = None
        self._fill_cart3d_results(cases, form, icase, ID, loads, model, mach)
        self._finish_results_io2(form, cases)
Ejemplo n.º 19
0
    def load_cart3d_geometry(self, cart3d_filename, name='main', plot=True):
        """
        The entry point for Cart3d geometry loading.

        Parameters
        ----------
        cart3d_filename : str
            the cart3d filename to load
        name : str
            the name of the "main" actor for the GUI
        plot : bool; default=True
            should the model be generated or should we wait until
            after the results are loaded
        """
        skip_reading = self._remove_old_cart3d_geometry(cart3d_filename)
        if skip_reading:
            return

        self.gui.eid_maps[name] = {}
        self.gui.nid_maps[name] = {}
        model = read_cart3d(cart3d_filename, log=self.gui.log, debug=False)
        self.gui.model_type = 'cart3d'
        nodes = model.nodes
        elements = model.elements
        regions = model.regions
        loads = model.loads

        self.gui.nnodes = model.npoints
        self.gui.nelements = model.nelements

        grid = self.gui.grid
        grid.Allocate(self.gui.nelements, 1000)

        #if 0:
        #fraction = 1. / self.nnodes  # so you can color the nodes by ID
        #for nid, node in sorted(iteritems(nodes)):
        #self.grid_result.InsertNextValue(nid * fraction)

        assert nodes is not None
        #nnodes = nodes.shape[0]

        mmax = nodes.max(axis=0)
        mmin = nodes.min(axis=0)
        dim_max = (mmax - mmin).max()
        xmax, ymax, zmax = mmax
        xmin, ymin, zmin = mmin
        self.gui.log_info("xmin=%s xmax=%s dx=%s" % (xmin, xmax, xmax - xmin))
        self.gui.log_info("ymin=%s ymax=%s dy=%s" % (ymin, ymax, ymax - ymin))
        self.gui.log_info("zmin=%s zmax=%s dz=%s" % (zmin, zmax, zmax - zmin))
        self.gui.create_global_axes(dim_max)
        points = numpy_to_vtk_points(nodes)

        #assert elements.min() == 0, elements.min()

        etype = 5  # vtkTriangle().GetCellType()
        create_vtk_cells_of_constant_element_type(grid, elements, etype)

        grid.SetPoints(points)
        grid.Modified()
        if hasattr(grid, 'Update'):  # pragma: no cover
            grid.Update()
        self._create_cart3d_free_edges(model, nodes, elements)

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

        assert loads is not None
        if 'Mach' in loads:
            avg_mach = mean(loads['Mach'])
            note = ':  avg(Mach)=%g' % avg_mach
        else:
            note = ''
        self.gui.isubcase_name_map = {1: ['Cart3d%s' % note, '']}
        cases = OrderedDict()
        ID = 1
        form, cases, icase, node_ids, element_ids, data_map_dict = _fill_cart3d_geometry_objects(
            cases, ID, nodes, elements, regions, model)
        self.data_map = data_map_dict

        mach, unused_alpha, unused_beta = self._create_box(
            cart3d_filename, ID, form, cases, icase, regions)
        #mach = None
        _fill_cart3d_results(cases, form, icase, ID, loads, model, mach)

        self.gui.node_ids = node_ids
        self.gui.element_ids = element_ids
        self.gui._finish_results_io2(form, cases)
Ejemplo n.º 20
0
def read_half_cart3d_points(cfd_grid_file, log=log):
    """return half model points to shrink xK matrix"""
    cart = read_cart3d(cfd_grid_file, log=log)
    points, elements, _regions, _loads = cart.make_half_model()
    return points
Ejemplo n.º 21
0
def cart3d_to_nastran_filename(cart3d_filename,
                               bdf_filename,
                               log=None,
                               debug=False):
    """
    Converts a Cart3D file to Nastran format.

    Parameters
    ----------
    cart3d_filename : str
        path to the input Cart3D file
    bdf_filename : str
        path to the output BDF file
    log : log / None
        log : a logger object
        None : a log will be defined
    debug : bool
        True/False (used if log is not defined)

    Examples
    --------
    >>> cart3d_filename = 'threePlugs.tri'
    >>> bdf_filename = 'threePlugs.bdf'
    >>> cart3d_to_nastran_filename(cart3d_filename, bdf_filename)
    """
    if isinstance(cart3d_filename, Cart3D):
        cart3d = cart3d_filename
    else:
        cart3d = read_cart3d(cart3d_filename,
                             log=log,
                             debug=debug,
                             result_names=None)

    nodes = cart3d.nodes
    elements = cart3d.elements + 1
    regions = cart3d.regions

    if regions.min() == 0:
        # bit of a hack to take an invalid cart3d model and make it
        # work in Nastran, which requires property_ids > 0
        regions += 1

    #bdf = BDF()
    #bdf.nodes = cart3d.nodes
    #bdf.elements = cart3d.elements
    #bdf.write_bdf(bdf_filename)
    #return
    with open(bdf_filename, 'w') as bdf_file:
        bdf_file.write('CEND\n')
        bdf_file.write('BEGIN BULK\n')
        bdf_file.write('$Nodes\n')

        i = 0
        nid = 1
        cid = 0
        for node in nodes:
            card = print_card_16(['GRID', nid, cid] + list(node))
            bdf_file.write(card)
            nid += 1

        eid = 1
        bdf_file.write('$Elements\n')
        assert 0 not in elements
        for (n1, n2, n3), pid in zip(elements, regions):
            card = print_card_8(['CTRIA3', eid, pid, n1, n2, n3])
            bdf_file.write(card)
            eid += 1

        t = 0.1
        E = 1e7
        nu = 0.3
        bdf_file.write('$Properties\n')
        for pid in unique(regions):
            mid = pid
            card = print_card_8(['PSHELL', pid, mid, t])
            bdf_file.write(card)
            card = print_card_8(['MAT1', mid, E, None, nu])
            bdf_file.write(card)
        bdf_file.write('ENDDATA\n')
Ejemplo n.º 22
0
def cart3d_to_nastran_filename(cart3d_filename, bdf_filename, log=None, debug=False):
    """
    Converts a Cart3D file to Nastran format.

    Parameters
    ----------
    cart3d_filename : str
        path to the input Cart3D file
    bdf_filename : str
        path to the output BDF file
    log : log / None
        log : a logger object
        None : a log will be defined
    debug : bool
        True/False (used if log is not defined)

    Example
    -------
    cart3d_filename = 'threePlugs.tri'
    bdf_filename = 'threePlugs.bdf'
    cart3d_to_nastran_filename(cart3d_filename, bdf_filename)
    """
    if isinstance(cart3d_filename, Cart3D):
        cart3d = cart3d_filename
    else:
        cart3d = read_cart3d(cart3d_filename, log=log, debug=debug, result_names=None)

    nodes = cart3d.nodes
    elements = cart3d.elements
    regions = cart3d.regions

    if regions.min() == 0:
        # bit of a hack to take an invalid cart3d model and make it
        # work in Nastran, which requires property_ids > 0
        regions += 1

    #bdf = BDF()
    #bdf.nodes = cart3d.nodes
    #bdf.elements = cart3d.elements
    #bdf.write_bdf(bdf_filename)
    #return
    with codec_open(bdf_filename, 'w') as f:
        f.write('CEND\n')
        f.write('BEGIN BULK\n')
        f.write('$Nodes\n')

        i = 0
        nid = 1
        cid = 0
        for node in nodes:
            card = print_card_16(['GRID', nid, cid] + list(node))
            f.write(card)
            nid += 1

        eid = 1
        f.write('$Elements\n')
        for (n1, n2, n3), pid in zip(elements, regions):
            card = print_card_8(['CTRIA3', eid, pid, n1, n2, n3])
            f.write(card)
            eid += 1

        t = 0.1
        E = 1e7
        nu = 0.3
        f.write('$Properties\n')
        for pid in unique(regions):
            mid = pid
            card = print_card_8(['PSHELL', pid, mid, t])
            f.write(card)
            card = print_card_8(['MAT1', mid, E, None, nu])
            f.write(card)
        f.write('ENDDATA\n')