def get_ugrid_model(ugrid_filename, log=None, debug=False):
    """helper method for loading UGRID models

    Parameters
    ----------
    ugrid_filename : varies
        str : the input UGRID filename
        UGRID : the UGRID object

    Returns
    -------
    ugrid_model : UGRID()
        the UGRID object
    """
    if isinstance(ugrid_filename, str):
        #assert os.path.exists(ugrid_filename), '%r doesnt exist' % ugrid_filename
        model = read_ugrid(ugrid_filename=ugrid_filename,
                           encoding=None,
                           log=log,
                           debug=debug,
                           read_shells=True,
                           read_solids=True,
                           check=True)
        #UGRID(log=log, debug=debug)
        #model.read_ugrid(ugrid_filename)
    else:
        model = ugrid_filename
        assert isinstance(
            model, UGRID), 'expected UGRID; type(model)=%s' % type(model)
    return model
Exemple #2
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)
def main():  # pragma: no cover
    """Tests UGrid"""
    ugrid_filename = 'bay_steve_recon1_fixed0.b8.ugrid'
    #bdf_filename = 'bay_steve_recon1_fixed0.b8.bdf'
    foam_filename = 'bay_steve_recon1_fixed0.b8.foam'
    tag_filename = 'bay_steve.tags'
    assert os.path.exists(tag_filename)
    ugrid_model = read_ugrid(ugrid_filename)
    #ugrid_model.write_bdf(bdf_filename)
    write_foam(ugrid_model, foam_filename, tag_filename)
Exemple #4
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')
        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')
        ugrid.write_bdf(skin_bdf_filename2,
                        include_shells=True,
                        include_solids=True,
                        convert_pyram_to_penta=True,
                        encoding=None,
                        size=size,
                        is_double=False)
        model2 = read_bdf(skin_bdf_filename2, log=log, debug=debug)

        os.remove(ugrid_filename_out)
        os.remove(skin_bdf_filename)
        os.remove(skin_bdf_filename2)