Esempio n. 1
0
    def test_group(self):
        """reads a GROUP card"""
        op2 = OP2Geom(make_geom=True,
                      debug=False,
                      log=None,
                      debug_file=None,
                      mode='msc')
        op2.op2_reader.factor = 1
        op2.idtype = 'int32'
        op2.idtype8 = 'int32'
        op2._uendian = '<'
        data = (17400, 174, 616, 55, 0, -5, 90011, -1, -1, 65, 0, -5, 90012,
                -1, -1, 75, 0, -5, 90013, -1, -1)
        data_bytes1 = struct.pack(f'{len(data)}i', *data)
        op2._read_group(data_bytes1, 12)

        data2 = (17400, 174, 616, 111, 5, b'THIS IS GROUP 111   ', -2, 5,
                 b'THIS IS METADATA', -1, -5, 1, 0, 10, -1, -1)
        data_bytes2 = struct.pack(b'5i 20s 2i 16s 7i', *data2)
        op2._read_group(data_bytes2, 12)

        data3 = (17400, 174, 616, 55, 0, -5, 90011, -1, -1, 65, 0, -5, 90012,
                 -1, -1, 75, 0, -5, 90013, -1, -1)
        data_bytes3 = struct.pack(f'{len(data)}i', *data3)
        op2._read_group(data_bytes3, 12)
Esempio n. 2
0
 def test_snorm(self):
     op2 = OP2Geom(make_geom=True,
                   debug=False,
                   log=None,
                   debug_file=None,
                   mode='msc')
     #op2.idtype8 = 'int32'
     op2._endian = b'<'
     op2.op2_reader.factor = 1
     data = (
         5678,
         71,
         475,
         1059,
         10,
         0.0,
         0.2,
         0.0,
         -1059,
         101000001,
         0.0,
         0.2,
         0.0,
     )
     fmt1 = b'3i ' + b'2i3f ' * 2
     data_bytes = struct.pack(fmt1, *data)
     op2._read_snorm(data_bytes, 12)
Esempio n. 3
0
    def test_rbe3(self):
        """
        data = [99           99 123456 1.0    123    44    45  48  49  -1    -3]
        data = [61           71 123456 1.0    123    70    75  77      -1    -3
                62           71 123456 1.0    123    58    59  72      -1    -3]
        data = [1001100 1001100 123456 1.0 123456 10011 10002          -1 -2 -3
                1002500 1002500 123456 1.0 123456 10025 10020          -1 -2 -3]
                eid     refg    refc   wt  c      g     ...
        """
        model = OP2Geom()
        data = [99, 99, 123456, 1.0, 123, 44, 45, 48, 49, -1, -3]
        rbes = read_rbe3s_from_idata_fdata(model, np.array(data,
                                                           dtype='int32'),
                                           np.array(data, dtype='float32'))
        assert len(rbes) == 1, rbes

        data = [
            61, 71, 123456, 1.0, 123, 70, 75, 77, -1, -3, 62, 71, 123456, 1.0,
            123, 58, 59, 72, -1, -3
        ]
        rbes = read_rbe3s_from_idata_fdata(model, np.array(data,
                                                           dtype='int32'),
                                           np.array(data, dtype='float32'))
        assert len(rbes) == 2, rbes

        data = [
            11, 10, 123456, 1.0, 456, 111, 100, -1, -2, -3, 25, 50, 123456,
            1.0, 456, 125, 103, -1, -2, -3
        ]
        rbes = read_rbe3s_from_idata_fdata(model, np.array(data,
                                                           dtype='int32'),
                                           np.array(data, dtype='float32'))
        assert len(
            rbes) == 2, rbes  ## TODO: not supported b/c the -2; should be 2
Esempio n. 4
0
 def test_seset(self):
     op2 = OP2Geom(make_geom=True,
                   debug=False,
                   log=None,
                   debug_file=None,
                   mode='msc')
     op2.idtype8 = 'int32'
     data = (5601, 56, 296, 1, 33, 34, 37, 38, -1, 1, 93, -98, -1, 7, 1, -8,
             -1)
     fmt1 = b'i' * len(data)
     data_bytes = struct.pack(fmt1, *data)
     op2._read_seset(data_bytes, 12)
Esempio n. 5
0
 def test_uset1(self):
     """tests USET1"""
     op2 = OP2Geom(make_geom=True,
                   debug=False,
                   log=None,
                   debug_file=None,
                   mode='msc')
     op2.op2_reader.factor = 1
     op2.idtype = 'int32'
     op2.idtype8 = 'int32'
     op2.fdtype8 = 'float32'
     op2._uendian = '<'
     data = (2110, 21, 194, 2.0, 123456, 0, 44, 45, 48, 49, -1)
     data_bytes = struct.pack(b'3i f 7i', *data)
     op2._read_uset1(data_bytes, 12)
Esempio n. 6
0
    def test_seelt(self):
        op2 = OP2Geom(make_geom=True,
                      debug=False,
                      log=None,
                      debug_file=None,
                      mode='msc')
        op2.idtype8 = 'int32'
        #op2.fdtype8 = 'float32'
        #op2._uendian = '<'

        data = (7902, 79, 302, 5, 24, -1, 66, 662001, 662003, 662007, 662019,
                -1, 67, 672001, 672008, 672015, -1, 68, 682001, 682019, -1)
        fmt1 = b'i' * len(data)
        data_bytes = struct.pack(fmt1, *data)
        op2._read_seelt(data_bytes, 12)
Esempio n. 7
0
    def test_read_grid_11(self):
        op2 = OP2Geom(make_geom=True,
                      debug=False,
                      log=None,
                      debug_file=None,
                      mode='msc')
        op2._endian = b'<'
        op2.op2_reader.factor = 1
        data = (
            4501,
            45,
            1,
            # nid, cp, x1, x2, x3, cd, ps, seid
            1,
            0,
            1.,
            0.,
            0.,
            1,
            0,
            0,
            2,
            0,
            2.,
            0.,
            0.,
            1,
            0,
            0,
            3,
            0,
            3.,
            0.,
            0.,
            1,
            0,
            0,
        )
        fmt = b'<3i ' + b'2i 3d 3i ' * 3
        data_bytes = struct.pack(fmt, *data)
        assert len(data_bytes) == 144, len(data_bytes)

        op2.table_name = b'GEOM1'
        with self.assertRaises(AssertionError):
            op2._read_grid(data_bytes, 12)

        op2.table_name = b'GEOM1N'
        op2._read_grid(data_bytes, 12)
Esempio n. 8
0
    def test_extrn(self):
        """reads an EXTRN"""
        op2 = OP2Geom(make_geom=True,
                      debug=False,
                      log=None,
                      debug_file=None,
                      mode='msc')
        op2.idtype8 = 'int32'
        #op2.fdtype8 = 'float32'
        #op2._uendian = '<'

        data = (1627, 16, 463, 1, 123456, 2, 123456, 3, 123456, 4, 123456,
                100001, 1, 100002, 1, 100003, 1, 100004, 1, -1, -1)
        fmt1 = b'i' * len(data)
        data_bytes = struct.pack(fmt1, *data)
        op2._read_extrn(data_bytes, 12)
Esempio n. 9
0
    def test_nsml1_nx(self):
        """tests NSML1-NX"""
        op2 = OP2Geom(make_geom=True,
                      debug=False,
                      log=None,
                      debug_file=None,
                      mode='msc')
        op2.idtype8 = 'int32'
        op2.fdtype8 = 'float32'
        op2._uendian = '<'

        fmt1 = (b'<3i ' + b'i 8s f ' + b'2i8s2i ' * 4 + b' i ' + b'i 8s f ' +
                b'2i8s2i ' * 7 + b' i')
        data = (3701, 37, 995, 1, b'ELEMENT ', 466.2, 3, 249311, b'THRU    ',
                250189, -1, 3, 250656, b'THRU    ', 251905, -1, 3, 270705,
                b'THRU    ', 275998, -1, 3, 332687, b'THRU    ', 334734, -1,
                -2, 2, b'ELEMENT ', 77.7, 3, 225740, b'THRU    ', 227065, -1,
                3, 227602, b'THRU    ', 228898, -1, 3, 229435, b'THRU    ',
                230743, -1, 3, 231280, b'THRU    ', 233789, -1, 3, 233922,
                b'THRU    ', 235132, -1, 3, 235265, b'THRU    ', 236463, -1, 3,
                338071, b'THRU    ', 341134, -1, -2)
        data_bytes = struct.pack(fmt1, *data)
        op2._read_nsml1_nx(data_bytes, 12)
Esempio n. 10
0
def run_op2(op2_filename: str,
            make_geom: bool = False,
            write_bdf: bool = False,
            read_bdf: Optional[bool] = None,
            write_f06: bool = True,
            write_op2: bool = False,
            write_hdf5: bool = True,
            is_mag_phase: bool = False,
            is_sort2: bool = False,
            is_nx: Optional[bool] = None,
            delete_f06: bool = False,
            build_pandas: bool = True,
            subcases: Optional[str] = None,
            exclude: Optional[str] = None,
            short_stats: bool = False,
            compare: bool = True,
            debug: bool = False,
            log: Any = None,
            binary_debug: bool = False,
            quiet: bool = False,
            stop_on_failure: bool = True,
            dev: bool = False,
            xref_safe: bool = False,
            post: Any = None,
            load_as_h5: bool = False) -> Tuple[OP2, bool]:
    """
    Runs an OP2

    Parameters
    ----------
    op2_filename : str
        path of file to test
    make_geom : bool; default=False
        should the GEOMx, EPT, MPT, DYNAMIC, DIT, etc. tables be read
    write_bdf : bool; default=False
        should a BDF be written based on the geometry tables
    write_f06 : bool; default=True
        should an F06 be written based on the results
    write_op2 : bool; default=False
        should an OP2 be written based on the results
    is_mag_phase : bool; default=False
        False : write real/imag results
        True : write mag/phase results
        For static results, does nothing
    is_sort2 : bool; default=False
        False : writes "transient" data is SORT1
        True : writes "transient" data is SORT2
    is_nx : bool; default=None
        True : use NX Nastran
        False : use MSC Nastran
        None : guess
    delete_f06 : bool; default=False
        deletes the F06 (assumes write_f06 is True)
    subcases : List[int, ...]; default=None
        limits subcases to specified values; default=None -> no limiting
    exclude : List[str, ...]; default=None
        limits result types; (remove what's listed)
    short_stats : bool; default=False
        print a short version of the op2 stats
    compare : bool
        True : compares vectorized result to slow vectorized result
        False : doesn't run slow vectorized result
    debug : bool; default=False
        debug flag for OP2
    log : logger; default=None
        a custom logger
        None : use debug
    binary_debug : bool; default=False
        creates a very cryptic developer debug file showing exactly what was parsed
    quiet : bool; default=False
        don't write debug messages
    stop_on_failure : bool; default=True
        is this used???
    dev : bool; default=False
        flag that is used by op2_test.py to ignore certain errors
        False : crash on errors
        True : don't crash

    Returns
    -------
    op2 : OP2()
        the op2 object
    is_passed : bool
        did the test pass

    """
    assert build_pandas in [True, False]

    if read_bdf is None:
        read_bdf = write_bdf
    op2 = None
    op2_nv = None
    if subcases is None:
        subcases = []
    if exclude is None:
        exclude = []
    if isinstance(is_sort2, bool):
        sort_methods = [is_sort2]
    else:
        sort_methods = is_sort2

    assert '.op2' in op2_filename.lower(
    ), 'op2_filename=%s is not an OP2' % op2_filename
    is_passed = False

    fname_base = os.path.splitext(op2_filename)[0]
    bdf_filename = fname_base + '.test_op2.bdf'

    if isinstance(subcases, str):
        if '_' in subcases:
            subcases = [int(i) for i in subcases.split('_')]
        else:
            subcases = [int(subcases)]

    debug_file = None
    model = os.path.splitext(op2_filename)[0]
    if binary_debug or write_op2:
        debug_file = model + '.debug.out'
    #print('debug_file = %r' % debug_file, os.getcwd())

    if make_geom:
        op2 = OP2Geom(debug=debug, log=log)
        op2_nv = OP2Geom(debug=debug, log=log, debug_file=debug_file)
        op2_bdf = OP2Geom(debug=debug, log=log)
        if is_nx is None:
            pass
        elif is_nx:
            op2.set_as_nx()
            op2_nv.set_as_nx()
            op2_bdf.set_as_nx()
        else:
            op2.set_as_msc()
            op2_nv.set_as_msc()
            op2_bdf.set_as_msc()

        if post is not None:
            op2.post = -4
            op2_nv.post = -4
            op2_bdf.post = -4
        if load_as_h5 and IS_HDF5:
            # you can't open the same h5 file twice
            op2.load_as_h5 = load_as_h5
            #op2_nv.load_as_h5 = load_as_h5
            #op2_bdf.load_as_h5 = load_as_h5

        op2_bdf.set_error_storage(nparse_errors=0,
                                  stop_on_parsing_error=True,
                                  nxref_errors=0,
                                  stop_on_xref_error=True)
    else:
        op2 = OP2(debug=debug, log=log)
        # have to double write this until ???
        op2_nv = OP2(debug=debug, log=log, debug_file=debug_file)

        if is_nx is None:
            pass
        elif is_nx:
            print('set as nx')
            op2.set_as_nx()
            op2_nv.set_as_nx()
        else:
            op2.set_as_msc()
            op2_nv.set_as_msc()

        if post is not None:
            op2.post = -4
            op2_nv.post = -4
        if load_as_h5 and IS_HDF5:
            # you can't open the same h5 file twice
            op2.load_as_h5 = load_as_h5
            #op2_nv.load_as_h5 = load_as_h5
        op2_bdf = None
    op2_nv.use_vector = False

    if not quiet:
        op2.log.debug('subcases = %s' % subcases)
    op2.set_subcases(subcases)
    op2_nv.set_subcases(subcases)
    op2.remove_results(exclude)
    op2_nv.remove_results(exclude)

    try:
        #op2.read_bdf(op2.bdf_filename, includeDir=None, xref=False)
        if compare:
            op2_nv.read_op2(op2_filename)
        op2.read_op2(op2_filename)
        #if not make_geom:  # TODO: enable this...
        #op2.save()

        #op2a.get_op2_stats()
        op2.get_op2_stats()
        op2.get_op2_stats(short=True)
        op2.object_attributes()
        op2.object_methods()
        if not quiet:
            print("---stats for %s---" % op2_filename)
            print(op2.get_op2_stats(short=short_stats))
            op2.print_subcase_key()

        write_op2_as_bdf(op2,
                         op2_bdf,
                         bdf_filename,
                         write_bdf,
                         make_geom,
                         read_bdf,
                         dev,
                         xref_safe=xref_safe)

        if compare:
            assert op2 == op2_nv

        if IS_HDF5 and write_hdf5:
            from pyNastran.op2.op2_interface.hdf5_interface import load_op2_from_hdf5_filename
            h5_filename = model + '.test_op2.h5'
            op2.export_hdf5_filename(h5_filename)
            load_op2_from_hdf5_filename(h5_filename, log=op2.log)
        if write_f06:
            for is_sort2 in sort_methods:
                op2.write_f06(model + '.test_op2.f06',
                              is_mag_phase=is_mag_phase,
                              is_sort1=not is_sort2,
                              quiet=quiet,
                              repr_check=True)

            if delete_f06:
                try:
                    os.remove(model + '.test_op2.f06')
                except:
                    pass

        # we put it down here so we don't blame the dataframe for real errors
        if IS_PANDAS and build_pandas:
            op2.build_dataframe()
        #if compare:
        #op2_nv.build_dataframe()

        if write_op2:
            model = os.path.splitext(op2_filename)[0]
            op2_filename2 = model + '.test_op2.op2'
            op2w = OP2Writer(op2)
            total_case_count = op2w.write_op2(
                op2_filename2,
                obj=op2,
                #is_mag_phase=is_mag_phase,
                endian=b'<')
            if total_case_count > 0:
                #print('------------------------------')
                op2a = OP2(debug_file='debug.out', log=log)
                op2a.use_vector = False
                op2a.read_op2(op2_filename2)
                os.remove(op2_filename2)
            #read_op2(op2_filename2)
            if delete_f06:
                try:
                    os.remove(op2_filename2)
                except:
                    pass

        #table_names_f06 = parse_table_names_from_F06(op2.f06FileName)
        #table_names_op2 = op2.getTableNamesFromOP2()
        #print("subcases = ", op2.subcases)

        #if table_names_f06 != table_names_op2:
        #msg = 'table_names_f06=%s table_names_op2=%s' % (table_names_f06, table_names_op2)
        #raise RuntimeError(msg)
        #op2.case_control_deck.sol = op2.sol
        #print(op2.case_control_deck.get_op2_data())
        #print(op2.case_control_deck.get_op2_data())
        is_passed = True
    except MemoryError:
        raise
    except KeyboardInterrupt:
        sys.stdout.flush()
        print_exc(file=sys.stdout)
        sys.stderr.write('**file=%s\n' % op2_filename)
        sys.exit('keyboard stop...')
    #except SortCodeError: # inherits from Runtime; comment this
    #is_passed = True

    #except RuntimeError: # the op2 is bad, not my fault; comment this
    #is_passed = True
    #if stop_on_failure:
    #raise
    #else:
    #is_passed = True
    #except RuntimeError:
    #pass
    #except ValueError:
    #pass
    #except IndexError:
    #pass
    #except FortranMarkerError:
    #pass
    except IOError:  # missing file; this block should be uncommented
        #if stop_on_failure:
        #raise
        if not dev:
            raise
        is_passed = True
    #except UnicodeDecodeError:  # this block should be commented
    #is_passed = True
    #except NotImplementedError:  # this block should be commented
    #is_passed = True
    except FatalError:  # this block should be commented
        #if stop_on_failure:
        #raise
        if not dev:
            raise
        is_passed = True
    #except KeyError:  # this block should be commented
    #is_passed = True
    #except DeviceCodeError:  # this block should be commented
    #is_passed = True

    #except AssertionError:  # this block should be commented
    #is_passed = True
    #except RuntimeError: #invalid analysis code; this block should be commented
    #is_passed = True
    #except ValueError:  # this block should be commented
    #is_passed = True
    #except NotImplementedError:  # this block should be commented
    #is_passed = True
    #except FortranMarkerError:  # this block should be commented
    #is_passed = True

    except DuplicateIDsError:
        if not dev:
            raise
        is_passed = True

    except SystemExit:
        #print_exc(file=sys.stdout)
        #sys.exit('stopping on sys.exit')
        raise
    #except NameError:  # variable isnt defined
    #    if stop_on_failure:
    #        raise
    #    else:
    #        is_passed = True
    #except IndexError: # this block should be commented
    #is_passed = True
    #except SyntaxError: #Param Parse; this block should be commented
    #if stop_on_failure:
    #raise
    #is_passed = True
    except:
        #print(e)
        if stop_on_failure:
            raise
        else:
            print_exc(file=sys.stdout)
            is_passed = False

    return op2, is_passed
Esempio n. 11
0
def run_op2(op2_filename,
            make_geom=False,
            write_bdf=False,
            read_bdf=None,
            write_f06=True,
            write_op2=False,
            write_xlsx=False,
            is_mag_phase=False,
            is_sort2=False,
            is_nx=None,
            delete_f06=False,
            skip_dataframe=False,
            subcases=None,
            exclude=None,
            short_stats=False,
            compare=True,
            debug=False,
            binary_debug=False,
            quiet=False,
            check_memory=False,
            stop_on_failure=True,
            dev=False):
    """
    Runs an OP2

    Parameters
    ----------
    op2_filename : str
        path of file to test
    make_geom : bool; default=False
        should the GEOMx, EPT, MPT, DYNAMIC, DIT, etc. tables be read
    write_bdf : bool; default=False
        should a BDF be written based on the geometry tables
    write_f06 : bool; default=True
        should an F06 be written based on the results
    write_op2 : bool; default=False
        should an OP2 be written based on the results
    write_xlsx : bool; default=False
        should an XLSX be written based on the results
    is_mag_phase : bool; default=False
        False : write real/imag results
        True : write mag/phase results
        For static results, does nothing
    is_sort2 : bool; default=False
        False : writes "transient" data is SORT1
        True : writes "transient" data is SORT2
    is_nx : bool; default=None
        True : use NX Nastran
        False : use MSC Nastran
        None : guess
    delete_f06 : bool; default=False
        deletes the F06 (assumes write_f06 is True)
    subcases : List[int, ...]; default=None
        limits subcases to specified values; default=None -> no limiting
    exclude : List[str, ...]; default=None
        limits result types; (remove what's listed)
    short_stats : bool; default=False
        print a short version of the op2 stats
    compare : bool
        True : compares vectorized result to slow vectorized result
        False : doesn't run slow vectorized result
    debug : bool; default=False
        debug flag for OP2
    binary_debug : bool; default=False
        creates a very cryptic developer debug file showing exactly what was parsed
    quiet : bool; default=False
        don't write debug messages
    stop_on_failure : bool; default=True
        is this used???
    dev : bool; default=False
        flag that is used by op2_test.py to ignore certain errors
        False : crash on errors
        True : don't crash

    Returns
    -------
    op2 : OP2()
        the op2 object
    is_passed : bool
        did the test pass
    """
    if read_bdf is None:
        read_bdf = write_bdf
    op2 = None
    op2_nv = None
    if subcases is None:
        subcases = []
    if exclude is None:
        exclude = []
    assert '.op2' in op2_filename.lower(
    ), 'op2_filename=%s is not an OP2' % op2_filename
    is_passed = False

    fname_base = os.path.splitext(op2_filename)[0]
    bdf_filename = fname_base + '.test_op2.bdf'

    if isinstance(subcases, string_types):
        if '_' in subcases:
            subcases = [int(i) for i in subcases.split('_')]
        else:
            subcases = [int(subcases)]

    debug_file = None
    model = os.path.splitext(op2_filename)[0]
    if binary_debug or write_op2:
        debug_file = model + '.debug.out'
    #print('debug_file = %r' % debug_file, os.getcwd())

    if make_geom and not is_geom:
        raise RuntimeError('make_geom=%s is not supported' % make_geom)
    if make_geom:
        op2 = OP2Geom(debug=debug)
        op2_nv = OP2Geom(debug=debug, debug_file=debug_file)
        op2_bdf = OP2Geom(debug=debug)
        if is_nx is None:
            pass
        elif is_nx:
            op2.set_as_nx()
            op2_nv.set_as_nx()
            op2_bdf.set_as_nx()
        else:
            op2.set_as_msc()
            op2_nv.set_as_msc()
            op2_bdf.set_as_msc()

        op2_bdf.set_error_storage(nparse_errors=0,
                                  stop_on_parsing_error=True,
                                  nxref_errors=0,
                                  stop_on_xref_error=True)
    else:
        op2 = OP2(debug=debug)
        op2_nv = OP2(debug=debug,
                     debug_file=debug_file)  # have to double write this until
    op2_nv.use_vector = False

    if not quiet:
        op2.log.debug('subcases = %s' % subcases)
    op2.set_subcases(subcases)
    op2_nv.set_subcases(subcases)
    op2.remove_results(exclude)
    op2_nv.remove_results(exclude)

    if is_memory and check_memory:  # pragma: no cover
        if is_linux:  # linux
            kb = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
        else:  # windows
            kb = get_memory_usage() / 1024
        mb = kb / 1024.
        print("Memory usage start: %s (KB); %.2f (MB)" % (kb, mb))

    try:
        #op2.read_bdf(op2.bdf_filename, includeDir=None, xref=False)
        if compare:
            op2_nv.read_op2(op2_filename)
        op2.read_op2(op2_filename)

        #op2a.get_op2_stats()
        op2.get_op2_stats()
        op2.get_op2_stats(short=True)
        op2.object_attributes()
        op2.object_methods()
        if not quiet:
            print("---stats for %s---" % op2_filename)
            print(op2.get_op2_stats(short=short_stats))
            op2.print_subcase_key()

        if write_bdf:
            assert make_geom, 'make_geom=%s' % make_geom
            op2._nastran_format = 'msc'
            op2.executive_control_lines = ['CEND\n']
            op2.validate()
            op2.write_bdf(bdf_filename, size=8)
            op2.log.debug('bdf_filename = %s' % bdf_filename)
            if read_bdf:
                try:
                    op2_bdf.read_bdf(bdf_filename)
                except:
                    if dev and len(op2_bdf.card_count) == 0:
                        pass
                    else:
                        raise
            #os.remove(bdf_filename)
        if compare:
            assert op2 == op2_nv

        if is_memory and check_memory:  # pragma: no cover
            if is_linux:  # linux
                kb = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
            else:  # windows
                kb = get_memory_usage() / 1024
            mb = kb / 1024.
            print("Memory usage     end: %s (KB); %.2f (MB)" % (kb, mb))

        if write_f06:
            op2.write_f06(model + '.test_op2.f06',
                          is_mag_phase=is_mag_phase,
                          is_sort1=not is_sort2,
                          quiet=quiet,
                          repr_check=True)
            if delete_f06:
                try:
                    os.remove(model + '.test_op2.f06')
                except:
                    pass

        # we put it down here so we don't blame the dataframe for real errors
        if is_pandas and not skip_dataframe:
            op2.build_dataframe()
        #if compare:
        #op2_nv.build_dataframe()

        if write_op2:
            model = os.path.splitext(op2_filename)[0]
            op2.write_op2(model + '.test_op2.op2', is_mag_phase=is_mag_phase)
            if delete_f06:
                try:
                    os.remove(model + '.test_op2.op2')
                except:
                    pass

        if write_xlsx:
            model = os.path.splitext(op2_filename)[0]
            op2.write_xlsx(model + '.test_op2.xlsx', is_mag_phase=is_mag_phase)
            if delete_f06:
                try:
                    os.remove(model + '.test_op2.xlsx')
                except:
                    pass

        if is_memory and check_memory:
            op2 = None
            del op2_nv
            if is_linux:  # linux
                kb = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
            else:  # windows
                kb = get_memory_usage() / 1024
            mb = kb / 1024.
            print("Memory usage cleanup: %s (KB); %.2f (MB)" % (kb, mb))

        #table_names_f06 = parse_table_names_from_F06(op2.f06FileName)
        #table_names_op2 = op2.getTableNamesFromOP2()
        #print("subcases = ", op2.subcases)

        #if table_names_f06 != table_names_op2:
        #msg = 'table_names_f06=%s table_names_op2=%s' % (table_names_f06, table_names_op2)
        #raise RuntimeError(msg)
        #op2.case_control_deck.sol = op2.sol
        #print(op2.case_control_deck.get_op2_data())
        #print(op2.case_control_deck.get_op2_data())
        is_passed = True
    except KeyboardInterrupt:
        sys.stdout.flush()
        print_exc(file=sys.stdout)
        sys.stderr.write('**file=%s\n' % op2_filename)
        sys.exit('keyboard stop...')
    #except SortCodeError: # inherits from Runtime; comment this
    #is_passed = True

    #except RuntimeError: # the op2 is bad, not my fault; comment this
    #is_passed = True
    #if stop_on_failure:
    #raise
    #else:
    #is_passed = True
    #except RuntimeError:
    #pass
    #except ValueError:
    #pass
    #except FortranMarkerError:
    #pass
    except IOError:  # missing file; this block should be uncommented
        #if stop_on_failure:
        #raise
        if not dev:
            raise
        is_passed = True
    #except UnicodeDecodeError:  # this block should be commented
    #is_passed = True
    #except NotImplementedError:  # this block should be commented
    #is_passed = True
    except FatalError:  # this block should be commented
        #if stop_on_failure:
        #raise
        if not dev:
            raise
        is_passed = True
    #except KeyError:  # this block should be commented
    #is_passed = True
    #except DeviceCodeError:  # this block should be commented
    #is_passed = True
    #except AssertionError:  # this block should be commented
    #is_passed = True
    #except RuntimeError: #invalid analysis code; this block should be commented
    #is_passed = True
    except SystemExit:
        #print_exc(file=sys.stdout)
        #sys.exit('stopping on sys.exit')
        raise
    #except NameError:  # variable isnt defined
    #    if stop_on_failure:
    #        raise
    #    else:
    #        is_passed = True
    #except IndexError: # this block should be commented
    #is_passed = True
    #except SyntaxError: #Param Parse; this block should be commented
    #if stop_on_failure:
    #raise
    #is_passed = True
    except:
        #print(e)
        if stop_on_failure:
            raise
        else:
            print_exc(file=sys.stdout)
            is_passed = False

    return op2, is_passed
Esempio n. 12
0
    def test_op2_bwb_spanwise(self):  # pragma: no cover
        """how to plot an shear-moment-torque"""
        log_ = SimpleLogger(level='critical')
        BWB_PATH = MODEL_PATH / 'bwb'
        bdf_filename = BWB_PATH / 'bwb_saero_smt.bdf'
        op2_filename = BWB_PATH / 'bwb_saero.op2'
        with WarningRedirector(log_) as log:
            model = OP2Geom(debug=False, log=log, mode=None)
            model.include_exclude_results(include_results='grid_point_forces')
            model.read_op2(op2_filename=op2_filename)
            model.cross_reference()

        gpforce = model.grid_point_forces[1]  # type: RealGridPointForcesArray
        nids, nid_cd, xyz_cid0, icd_transform, eids, element_centroids_cid0 = smt_setup(model)

        #coord_out = model.coords[0]

        # spanwise
        # defines the starting point for the shear, moment, torque plot
        p1 = np.array([1388.9, 1262.0, 86.3471])  # 1/4c wing_tip

        # defines the end point for the shear, moment, torque plot
        p3 = np.array([910.93, 0.1, 0.0])  # 1/4c wing_root

        # y = 1262 (p3)
        # 0-0.1

        # defines the XZ plane for the shears/moments
        zaxis = p1 + np.array([0., 0., 1.])

        method = 'CORD2R'

        # coord_march:
        # - x: aft
        # - z: up

        # xz plane
        p2 = p1 + np.array([0., -1., 0.])

        xyz1, xyz2, xyz3, i, k, coord_out, iaxis_march, stations = get_stations(
            model, p1, p2, p3, zaxis,
            method=method, cid_p1=0, cid_p2=0, cid_p3=0,
            cid_zaxis=0, nplanes=50)

        nstations = len(stations)
        coord_origins = np.zeros((nstations, 3))
        for istation, station in enumerate(stations):
            coord_origin = coord_out.origin + iaxis_march * station
            coord_origins[istation, :] = coord_origin
        ylocations = coord_origins[:, 1]
        #coord_origins2 = coord_march.origin[:, np.newaxis] + coord_march.i[:, np.newaxis] * stations
        #assert np.array_equal(coord_origins, coord_origins2)

        #print(f'stations = {stations}')
        assert np.abs(stations).max() > 1350.
        assert np.array_equal(i, [0., -1., 0.])
        assert np.array_equal(k, [0., 0., 1.])

        # i/j/k vector is nan
        #print('coord_out:')
        #print(f'origin: {coord_out.origin}')
        #print(f'zaxis: {coord_out.e2}')
        #print(f'xzplane: {coord_out.e3}')
        #print(f'i: {coord_out.i}')
        #print(f'j: {coord_out.j}')
        #print(f'k: {coord_out.k}')

        #print('coord_march:')
        #print(f'i: {iaxis_march}')

        force_sum, moment_sum, new_coords, nelems, nnodes = gpforce.shear_moment_diagram(
            nids, xyz_cid0, nid_cd, icd_transform,
            eids, element_centroids_cid0,
            stations, model.coords, coord_out,
            iaxis_march=iaxis_march,
            itime=0, debug=True,
            nodes_tol=25., log=model.log)

        for cid, coord in new_coords.items():
            model.coords[cid] = coord
        model.sol = 144
        model.write_bdf(bdf_filename)
        plot_smt(ylocations, force_sum/1000, moment_sum/1000, nelems, nnodes,
                 plot_force_components=False,
                 plot_moment_components=False,
                 root_filename=os.path.join(BWB_PATH, 'bwb'),
                 show=False,
                 xtitle='Y', xlabel='Spanwise Location, Y (in)',
                 force_unit='kip', moment_unit='in-kip')
        y = 1
Esempio n. 13
0
    def test_op2_bwb_axial(self):  # pragma: no cover
        """how to plot an shear-moment-torque"""
        log = SimpleLogger(level='warning')
        BWB_PATH = MODEL_PATH / 'bwb'
        op2_filename = BWB_PATH / 'bwb_saero.op2'
        model = OP2Geom(debug=False, log=log, debug_file=None, mode=None)
        #model.load_as_h5 = True
        model.read_op2(op2_filename=op2_filename, combine=True,
                     build_dataframe=False, skip_undefined_matrices=False,
                     encoding=None)

        model.cross_reference()
        gpforce = model.grid_point_forces[1]  # type: RealGridPointForcesArray

        #out = model.get_xyz_in_coord_array(cid=0)
        #nid_cp_cd, xyz_cid0, xyz_cp, icd_transform, icp_transform = out
        #nids = nid_cp_cd[:, 0]
        #nid_cd = nid_cp_cd[:, [0, 2]]
        #eids, element_centroids_cid0 = get_element_centroids(model)
        nids, nid_cd, xyz_cid0, icd_transform, eids, element_centroids_cid0 = smt_setup(model)

        coord_out = model.coords[0]

        #cid_p1 = 0 # start
        #cid_p3 = 0 # end
        #cid_p2 = 0 # coord
        #p1-p2 defines the x-axis
        #k is defined by the z-axis
        #p1 = np.array([1354., 0., 0.]) # origin
        #p2 = np.array([1354., 1245., 0.]) # xaxis
        #p3 = np.array([1354., 1245., 0.]) # end
        #zaxis = np.array([0., 0., 1.])
        #method = 'Z-Axis Projection'
        #idir = 0

        #p1 = np.array([1354., 0., 0.]) # origin
        #p2 = np.array([1354., 0., 1.]) # xzplane
        #p3 = np.array([1354., 1245., 0.]) # end
        #zaxis = np.array([0., 0., 1.])
        #method = 'CORD2R'
        #idir = 1 # x-direction in this rotated system

        # axial
        p1 = np.array([0., 0., 0.]) # origin/start
        p2 = np.array([1600., 0., 0.]) # xaxis/end
        p3 = np.array([1600., 0., 0.]) # xzplane/end
        zaxis = np.array([0., 0., 1.])
        method = 'Z-Axis Projection'

        xyz1, xyz2, xyz3, i, k, coord_out, iaxis_march, stations = get_stations(
            model, p1, p2, p3, zaxis,
            method=method, cid_p1=0, cid_p2=0, cid_p3=0,
            cid_zaxis=0, nplanes=100)
        #print(f'stations = {stations}')

        # i/j/k vector is nan
        #print(f'origin: {coord_out.origin}')
        #print(f'zaxis: {coord_out.e2}')
        #print(f'xzplane: {coord_out.e3}')

        force_sum, moment_sum, new_coords, nelems, nnodes = gpforce.shear_moment_diagram(
            nids, xyz_cid0, nid_cd, icd_transform,
            eids, element_centroids_cid0,
            stations, model.coords, coord_out,
            iaxis_march=iaxis_march,
            itime=0, debug=True, log=model.log)
        plot_smt(stations, force_sum, moment_sum, nelems, nnodes, show=False)
Esempio n. 14
0
def run_op2(op2FileName,
            make_geom=False,
            write_bdf=False,
            write_f06=True,
            write_op2=False,
            is_mag_phase=False,
            is_vector=False,
            delete_f06=False,
            iSubcases=[],
            exclude=[],
            debug=False,
            binary_debug=False,
            stopOnFailure=True):
    assert '.op2' in op2FileName.lower(
    ), 'op2FileName=%s is not an OP2' % op2FileName
    isPassed = False

    fname_base, ext = os.path.splitext(op2FileName)
    bdf_filename = fname_base + '.test_op2.bdf'

    if isinstance(iSubcases, string_types):
        if '_' in iSubcases:
            iSubcases = [int(i) for i in iSubcases.split('_')]
        else:
            iSubcases = [int(iSubcases)]
    print('iSubcases = %s' % iSubcases)

    #debug = True
    try:
        debug_file = None
        if binary_debug or write_op2:
            debug_file = 'debug.out'

        if is_vector:
            if make_geom:
                op2 = OP2Geom_Vectorized(debug=debug, debug_file=debug_file)
            else:
                op2 = OP2V(make_geom=make_geom,
                           debug=debug,
                           debug_file=debug_file)
        else:
            if make_geom:
                op2 = OP2Geom(make_geom=make_geom,
                              debug=debug,
                              debug_file=debug_file)
            else:
                op2 = OP2(debug=debug, debug_file=debug_file)

        op2.set_subcases(iSubcases)
        op2.remove_results(exclude)

        if is_memory:
            if is_linux:  # linux
                kb = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
            else:  # windows
                kb = get_memory_usage() / 1024
            mb = kb / 1024.
            #mbs.append(mb)
            print("Memory usage start: %s (KB); %.2f (MB)" % (kb, mb))

        #op2.read_bdf(op2.bdfFileName,includeDir=None,xref=False)
        op2.read_op2(op2FileName)
        print("---stats for %s---" % op2FileName)
        #op2.get_op2_stats()
        print(op2.get_op2_stats())
        if write_bdf:
            op2.write_bdf(bdf_filename)
        if write_bdf and 0:
            op2.write_bdf('fem.bdf.out', interspersed=True)
        #tableNamesF06 = parse_table_names_from_F06(op2.f06FileName)
        #tableNamesOP2 = op2.getTableNamesFromOP2()

        if is_memory:
            if is_linux:  # linux
                kb = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
            else:  # windows
                kb = get_memory_usage() / 1024
            mb = kb / 1024.
            #mbs.append(mb)
            print("Memory usage     end: %s (KB); %.2f (MB)" % (kb, mb))

        if write_f06:
            (model, ext) = os.path.splitext(op2FileName)
            op2.write_f06(model + '.test_op2.f06', is_mag_phase=is_mag_phase)
            if delete_f06:
                try:
                    os.remove(model + '.test_op2.f06')
                except:
                    pass

        if write_op2:
            (model, ext) = os.path.splitext(op2FileName)
            op2.write_op2(model + '.test_op2.op2', is_mag_phase=is_mag_phase)
            if delete_f06:
                try:
                    os.remove(model + '.test_op2.op2')
                except:
                    pass

        del op2
        if is_memory:
            if is_linux:  # linux
                kb = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
            else:  # windows
                kb = get_memory_usage() / 1024
            mb = kb / 1024.
            #mbs.append(mb)
            print("Memory usage cleanup: %s (KB); %.2f (MB)" % (kb, mb))

        #print("subcases = ",op2.subcases)

        #assert tableNamesF06==tableNamesOP2,'tableNamesF06=%s tableNamesOP2=%s' %(tableNamesF06,tableNamesOP2)
        #op2.caseControlDeck.sol = op2.sol
        #print(op2.caseControlDeck.get_op2_data())
        #print(op2.caseControlDeck.get_op2_data())
        isPassed = True
    except KeyboardInterrupt:
        sys.stdout.flush()
        print_exc(file=sys.stdout)
        sys.stderr.write('**file=%s\n' % op2FileName)
        sys.exit('keyboard stop...')
    #except RuntimeError: # the op2 is bad, not my fault
    #    isPassed = True
    #    if stopOnFailure:
    #        raise
    #    else:
    #        isPassed = True

    except IOError:  # missing file
        if stopOnFailure:
            raise
    except FatalError:
        if stopOnFailure:
            raise
        isPassed = True
    #except AssertionError:
    #    isPassed = True
    #except RuntimeError: #invalid analysis code
    #    isPassed = True
    except SystemExit:
        #print_exc(file=sys.stdout)
        #sys.exit('stopping on sys.exit')
        raise
    #except NameError:  # variable isnt defined
    #    if stopOnFailure:
    #        raise
    #    else:
    #        isPassed = True
    #except IndexError: # bad bdf
    #    isPassed = True
    except SyntaxError:  #Param Parse
        if stopOnFailure:
            raise
        isPassed = True
    except:
        #print e
        if stopOnFailure:
            raise
        else:
            print_exc(file=sys.stdout)
            isPassed = False

    return isPassed
Esempio n. 15
0
    def test_rbe3(self):
        """
        data = [99           99 123456 1.0    123    44    45  48  49  -1    -3]
        data = [61           71 123456 1.0    123    70    75  77      -1    -3
                62           71 123456 1.0    123    58    59  72      -1    -3]
        data = [1001100 1001100 123456 1.0 123456 10011 10002          -1 -2 -3
                1002500 1002500 123456 1.0 123456 10025 10020          -1 -2 -3]
                eid     refg    refc   wt  c      g     ...
        """
        model = OP2Geom()
        data = [99, 99, 123456, 1.0, 123, 44, 45, 48, 49, -1, -3]
        rbes = read_rbe3s_from_idata_fdata(model, np.array(data,
                                                           dtype='int32'),
                                           np.array(data, dtype='float32'))
        assert len(rbes) == 1, rbes

        rbes_expected = [[
            'RBE3',
            '99',
            '99',
            '123456',
            '1.',
            '123',
            '44',
            '45',
            '48',
            '49',
        ]]
        for rbe, rbe_expected in zip(rbes, rbes_expected):
            msg = 'rbe:\n%s\nexpected:\n%s' % (rbe.rstrip().split(),
                                               rbe_expected)
            assert rbe.rstrip().split() == rbe_expected, msg
        #--------------------------------------------------------------

        data = [
            61, 71, 123456, 1.0, 123, 70, 75, 77, -1, -3, 62, 71, 123456, 1.0,
            123, 58, 59, 72, -1, -3
        ]
        rbes = read_rbe3s_from_idata_fdata(model, np.array(data,
                                                           dtype='int32'),
                                           np.array(data, dtype='float32'))
        assert len(rbes) == 2, rbes
        rbes_expected = [
            ['RBE3', '61', '71', '123456', '1.', '123', '70', '75', '77'],
            ['RBE3', '62', '71', '123456', '1.', '123', '58', '59', '72'],
        ]
        for rbe, rbe_expected in zip(rbes, rbes_expected):
            msg = 'rbe:\n%s\nexpected:\n%s' % (rbe.rstrip().split(),
                                               rbe_expected)
            assert rbe.rstrip().split() == rbe_expected, msg

        #--------------------------------------------------------------
        data = [
            11, 10, 123456, 1.0, 456, 111, 100, -1, -2, -3, 25, 50, 123456,
            1.0, 456, 125, 103, -1, -2, -3
        ]
        rbes = read_rbe3s_from_idata_fdata(model, np.array(data,
                                                           dtype='int32'),
                                           np.array(data, dtype='float32'))
        assert len(rbes) == 2, rbes

        rbes_expected = [
            'RBE3          11              10  123456      1.     456     111     100',
            'RBE3          25              50  123456      1.     456     125     103',
        ]
        for rbe, rbe_expected in zip(rbes, rbes_expected):
            assert rbe.rstrip() == rbe_expected, rbe
        #--------------------------------------------------------------
        data = [
            407, 4, 123, 1.0, 123, 41201, 41210, 41212, 41221, -1, -0.25, 123,
            41200, 41202, 41220, 41222, -1, -2, -3, 0.0, 408, 4, 456, 1.0, 123,
            41201, 41210, 41212, 41221, -1, 1.0, 123, 41200, 41202, 41220,
            41222, -1, -2, -3, 0.0
        ]
        rbes = read_rbe3s_from_idata_fdata(model, np.array(data,
                                                           dtype='int32'),
                                           np.array(data, dtype='float32'))
        assert len(rbes) == 2, rbes