Пример #1
0
def run_fem2(bdfModel, outModel, xref, punch,
             sum_load, size, precision,
             reject, debug=False, log=None):
    assert os.path.exists(bdfModel), bdfModel
    assert os.path.exists(outModel), outModel

    double = get_double_from_precision(precision)
    if reject:
        fem2 = BDFReplacer(bdfModel + '.rej', debug=debug, log=None)
    else:
        fem2 = BDF(debug=debug, log=None)
    fem2.log.info('starting fem2')
    sys.stdout.flush()
    try:
        fem2.read_bdf(outModel, xref=xref, punch=punch)
    except:
        print("failed reading %r" % outModel)
        raise

    outModel2 = bdfModel + '_out2'

    if sum_load:
        p0 = array([0., 0., 0.])
        subcases = fem2.caseControlDeck.get_subcase_list()
        for isubcase in subcases[1:]:  # drop isubcase = 0
            loadcase_id, options = fem2.caseControlDeck.get_subcase_parameter(isubcase, 'LOAD')
            F, M = fem2.sum_forces_moments(p0, loadcase_id, include_grav=False)
            print('  isubcase=%i F=%s M=%s' % (isubcase, F, M))
    fem2.write_bdf(outModel2, interspersed=False, size=size, is_double=double)
    #fem2.writeAsCTRIA3(outModel2)
    os.remove(outModel2)
    return (fem2)
Пример #2
0
def run_fem2(bdfModel, outModel, xref, punch,
             sum_load, size, is_double,
             reject, debug=False, log=None):
    """Reads/writes the BDF to verify nothing has been lost"""
    assert os.path.exists(bdfModel), bdfModel
    assert os.path.exists(outModel), outModel

    if reject:
        fem2 = BDFReplacer(bdfModel + '.rej', debug=debug, log=None)
    else:
        fem2 = BDF(debug=debug, log=None)
    fem2.log.info('starting fem2')
    sys.stdout.flush()
    try:
        fem2.read_bdf(outModel, xref=xref, punch=punch)
    except:
        print("failed reading %r" % outModel)
        raise

    outModel2 = bdfModel + '_out2'

    if sum_load:
        p0 = array([0., 0., 0.])
        subcases = fem2.caseControlDeck.get_subcase_list()
        for isubcase in subcases[1:]:  # drop isubcase = 0
            loadcase_id, options = fem2.caseControlDeck.get_subcase_parameter(isubcase, 'LOAD')
            F, M = fem2.sum_forces_moments(p0, loadcase_id, include_grav=False)
            print('  isubcase=%i F=%s M=%s' % (isubcase, F, M))
    fem2.write_bdf(outModel2, interspersed=False, size=size, is_double=is_double)
    #fem2.writeAsCTRIA3(outModel2)
    os.remove(outModel2)
    return fem2
Пример #3
0
def run_fem2(bdfModel, outModel, xref, punch, reject, debug=False, log=None):
    assert os.path.exists(bdfModel), bdfModel
    assert os.path.exists(outModel), outModel

    if reject:
        fem2 = BDFReplacer(bdfModel + '.rej', debug=debug, log=None)
    else:
        fem2 = BDF(debug=debug, log=None)
    fem2.log.info('starting fem2')
    sys.stdout.flush()
    try:
        fem2.read_bdf(outModel, xref=xref, punch=punch)
    except:
        print("failed reading %r" % (outModel))
        raise

    #fem2.sumForces()
    #fem2.sumMoments()
    outModel2 = bdfModel + '_out2'
    fem2.write_bdf(outModel2, interspersed=True)
    #fem2.writeAsCTRIA3(outModel2)
    os.remove(outModel2)
    return (fem2)
Пример #4
0
def run_bdf(folder,
            bdfFilename,
            debug=False,
            xref=True,
            check=True,
            punch=False,
            cid=None,
            meshForm='combined',
            isFolder=False,
            print_stats=False,
            reject=False,
            dynamic_vars={}):
    bdfModel = str(bdfFilename)
    print("bdfModel = %r" % bdfModel)
    if isFolder:
        bdfModel = os.path.join(test_path, folder, bdfFilename)

    assert os.path.exists(bdfModel), '%r doesnt exist' % bdfModel

    if reject:
        fem1 = BDFReplacer(bdfModel + '.rej', debug=debug, log=None)
    else:
        fem1 = BDF(debug=debug, log=None)
    if dynamic_vars:
        fem1.set_dynamic_syntax(dynamic_vars)

    fem1.log.info('starting fem1')
    sys.stdout.flush()
    fem2 = None
    diffCards = []
    try:
        (outModel) = run_fem1(fem1, bdfModel, meshForm, xref, punch, cid)
        (fem2) = run_fem2(bdfModel,
                          outModel,
                          xref,
                          punch,
                          reject,
                          debug=debug,
                          log=None)
        (diffCards) = compare(fem1,
                              fem2,
                              xref=xref,
                              check=check,
                              print_stats=print_stats)

    except KeyboardInterrupt:
        sys.exit('KeyboardInterrupt...sys.exit()')
    except IOError:
        pass
    #except AttributeError:  # only temporarily uncomment this when running lots of tests
    #pass
    #except SyntaxError:  # only temporarily uncomment this when running lots of tests
    #pass
    #except AssertionError:  # only temporarily uncomment this when running lots of tests
    #pass
    except SystemExit:
        sys.exit('sys.exit...')
    except:
        #exc_type, exc_value, exc_traceback = sys.exc_info()
        #print "\n"
        traceback.print_exc(file=sys.stdout)
        #print msg
        print("-" * 80)
        raise

    print("-" * 80)
    return (fem1, fem2, diffCards)
Пример #5
0
def run_bdf(folder, bdf_filename, debug=False, xref=True, check=True, punch=False,
            cid=None, meshForm='combined', isFolder=False, print_stats=False,
            sum_load=False, size=8, is_double=False,
            reject=False, nastran='', post=-1, dynamic_vars=None):
    if dynamic_vars is None:
        dynamic_vars = {}

    # TODO: why do we need this?
    bdfModel = str(bdf_filename)
    print("bdfModel = %s" % bdfModel)
    if isFolder:
        bdfModel = os.path.join(test_path, folder, bdf_filename)

    assert os.path.exists(bdfModel), '%r doesnt exist' % bdfModel

    if reject:
        fem1 = BDFReplacer(bdfModel + '.rej', debug=debug, log=None)
    else:
        fem1 = BDF(debug=debug, log=None)
    fem1.set_error_storage(nparse_errors=100, stop_on_parsing_error=True,
                           nxref_errors=100, stop_on_xref_error=True)
    if dynamic_vars:
        fem1.set_dynamic_syntax(dynamic_vars)

    fem1.log.info('starting fem1')
    sys.stdout.flush()
    fem2 = None
    diffCards = []

    try:
        #nastran = 'nastran scr=yes bat=no old=no news=no '
        nastran = ''
        #try:
        outModel = run_fem1(fem1, bdfModel, meshForm, xref, punch, sum_load, size, is_double, cid)
        fem2 = run_fem2(bdfModel, outModel, xref, punch, sum_load, size, is_double, reject, debug=debug, log=None)
        diffCards = compare(fem1, fem2, xref=xref, check=check, print_stats=print_stats)
        test_get_cards_by_card_types(fem2)
        #except:
            #return 1, 2, 3

        run_nastran(bdfModel, nastran, post, size, is_double)

    except KeyboardInterrupt:
        sys.exit('KeyboardInterrupt...sys.exit()')
    except IOError:  # only temporarily uncomment this when running lots of tests
        pass
    except CardParseSyntaxError:  # only temporarily uncomment this when running lots of tests
        print('failed test because CardParseSyntaxError...ignoring')
        pass
    except DuplicateIDsError:  # only temporarily uncomment this when running lots of tests
        print('failed test because DuplicateIDsError...ignoring')
        pass
    except RuntimeError:  # only temporarily uncomment this when running lots of tests
        if 'GRIDG' not in fem1.card_count:
            print('failed test because mesh adaption (GRIDG)...ignoring')
            raise
    #except AttributeError:  # only temporarily uncomment this when running lots of tests
        #pass
    #except SyntaxError:  # only temporarily uncomment this when running lots of tests
        #pass
    #except AssertionError:  # only temporarily uncomment this when running lots of tests
        #pass
    except SystemExit:
        sys.exit('sys.exit...')
    except:
        #exc_type, exc_value, exc_traceback = sys.exc_info()
        #print "\n"
        traceback.print_exc(file=sys.stdout)
        #print msg
        print("-" * 80)
        raise

    print("-" * 80)
    return (fem1, fem2, diffCards)
Пример #6
0
def run_fem2(bdf_model, out_model, xref, punch,
             sum_load, size, is_double,
             reject, encoding=None, debug=False, log=None):
    """
    Reads/writes the BDF to verify nothing has been lost

    Parameters
    ----------
    bdf_model : str
        the filename to run
    out_model
    xref : bool
       xrefs
    punch : bool
       punches
    sum_load : bool
       sums static load
    size : int
    is_double : bool
    reject : bool
        True : rejects the cards
    debug : bool
        debugs
    log : logger / None
        ignored
    """
    assert os.path.exists(bdf_model), bdf_model
    assert os.path.exists(out_model), out_model

    if reject:
        fem2 = BDFReplacer(bdf_model + '.rej', debug=debug, log=None)
    else:
        fem2 = BDF(debug=debug, log=None)
    fem2.log.info('starting fem2')
    sys.stdout.flush()
    try:
        fem2.read_bdf(out_model, xref=xref, punch=punch, encoding=encoding)
    except:
        print("failed reading %r" % out_model)
        raise

    out_model_2 = bdf_model + '_out2'

    if xref and sum_load:
        p0 = array([0., 0., 0.])

        subcase_keys = fem2.case_control_deck.get_subcase_list()
        subcases = fem2.subcases

        sol_200_map = fem2.case_control_deck.sol_200_map
        sol_base = fem2.sol
        is_restart = False
        for line in fem2.executive_control_lines:
            if 'RESTART' in line:
                is_restart = True
        if not is_restart:
            validate_case_control(fem2, p0, sol_base, subcase_keys, subcases, sol_200_map)

    fem2.write_bdf(out_model_2, interspersed=False, size=size, is_double=is_double)
    #fem2.writeAsCTRIA3(out_model_2)
    os.remove(out_model_2)
    return fem2
Пример #7
0
def run_bdf(folder, bdf_filename, debug=False, xref=True, check=True, punch=False,
            cid=None, mesh_form='combined', is_folder=False, print_stats=False,
            encoding=None, sum_load=False, size=8, is_double=False,
            reject=False, stop=False, nastran='', post=-1, dynamic_vars=None,
            quiet=False, dumplines=False, dictsort=False, nerrors=0, dev=False):
    """
    Runs a single BDF

    Parameters
    ----------
    folder : str
        the folder where the bdf_filename is
    bdf_filename : str
        the bdf file to analyze
    debug : bool, optional
        run with debug logging (default=False)
    xref : bool / str, optional
        True : cross reference the model
        False  : don't cross reference the model
        'safe' : do safe cross referencing
    check : bool, optional
        validate cards for things like mass, area, etc.
    punch : bool, optional
        this is a PUNCH file (no executive/case control decks)
    cid : int / None, optional
        convert the model grids to an alternate coordinate system (default=None; no conversion)
    mesh_form : str, optional, {'combined', 'separate'}
        'combined' : interspersed=True
        'separate' : interspersed=False
    is_folder : bool, optional
        attach the test path and the folder to the bdf_filename
    print_stats : bool, optional
        get a nicely formatted message of all the cards in the model
    sum_load : bool, optional
        Sum the static loads (doesn't work for frequency-based loads)
    size : int, optional, {8, 16}
        The field width of the model
    is_double : bool, optional
        Is this a double precision model?
            True : size = 16
            False : six = {8, 16}
    reject : bool, optional
        True : all the cards are rejected
        False : the model is read
    nastran : str, optional
        the path to nastran (default=''; no analysis)
    post : int, optional
        the PARAM,POST,value to run
    dynamic vars : dict[str]=int / float / str / None
        support OpenMDAO syntax  %myvar; max variable length=7
    quiet : bool; default=False
        suppresses print messages
    dumplines: bool; default=False
        writes pyNastran_dump.bdf
    dictsort : bool; default=False
        writes pyNastran_dict.bdf
    """
    if dynamic_vars is None:
        dynamic_vars = {}

    # TODO: why do we need this?
    bdf_model = str(bdf_filename)
    print("bdf_model = %s" % bdf_model)
    if is_folder:
        bdf_model = os.path.join(test_path, folder, bdf_filename)

    assert os.path.exists(bdf_model), '%r doesnt exist' % bdf_model

    if reject:
        fem1 = BDFReplacer(bdf_model + '.rej', debug=debug, log=None)
    else:
        fem1 = BDF(debug=debug, log=None)

    fem1.set_error_storage(nparse_errors=nerrors, stop_on_parsing_error=True,
                           nxref_errors=nerrors, stop_on_xref_error=True)
    #fem1.set_error_storage(nparse_errors=0, stop_on_parsing_error=True,
    #                      nxref_errors=0, stop_on_xref_error=True)
    if dynamic_vars:
        fem1.set_dynamic_syntax(dynamic_vars)

    fem1.log.info('starting fem1')
    sys.stdout.flush()
    fem2 = None
    diff_cards = []

    try:
        #nastran = 'nastran scr=yes bat=no old=no news=no '
        nastran = ''
        #try:
        out_model, fem1 = run_fem1(fem1, bdf_model, mesh_form, xref, punch, sum_load, size,
                                   is_double, cid, encoding=encoding)
        if stop:
            print('card_count:')
            print('-----------')
            for card_name, card_count in sorted(iteritems(fem1.card_count)):
                print('key=%-8s value=%s' % (card_name, card_count))
            return fem1, None, None
        fem2 = run_fem2(bdf_model, out_model, xref, punch, sum_load, size, is_double, reject,
                        encoding=encoding, debug=debug, log=None)

        diff_cards = compare(fem1, fem2, xref=xref, check=check, print_stats=print_stats, quiet=quiet)
        test_get_cards_by_card_types(fem2)
        #except:
            #return 1, 2, 3

        run_nastran(bdf_model, nastran, post, size, is_double)

    except KeyboardInterrupt:
        sys.exit('KeyboardInterrupt...sys.exit()')
    except IOError:  # only temporarily uncomment this when running lots of tests
        if not dev:
            raise
    except CardParseSyntaxError:  # only temporarily uncomment this when running lots of tests
        if not dev:
            raise
        print('failed test because CardParseSyntaxError...ignoring')
    except DuplicateIDsError:  # only temporarily uncomment this when running lots of tests
        if not dev:
            raise
        print('failed test because DuplicateIDsError...ignoring')
    #except RuntimeError:  # only temporarily uncomment this when running lots of tests
        #if 'GRIDG' in fem1.card_count:
            #print('failed test because mesh adaption (GRIDG)...ignoring')
            #raise
    #except AttributeError:  # only temporarily uncomment this when running lots of tests
        #pass
    #except SyntaxError:  # only temporarily uncomment this when running lots of tests
        #pass
    #except AssertionError:  # only temporarily uncomment this when running lots of tests
        #pass
    except SystemExit:
        sys.exit('sys.exit...')
    except:
        #exc_type, exc_value, exc_traceback = sys.exc_info()
        #print "\n"
        traceback.print_exc(file=sys.stdout)
        #print msg
        print("-" * 80)
        raise

    print("-" * 80)
    return (fem1, fem2, diff_cards)
Пример #8
0
def run_fem2(bdf_model, out_model, xref, punch,
             sum_load, size, is_double,
             reject, encoding=None, debug=False, log=None):
    """
    Reads/writes the BDF to verify nothing has been lost

    Parameters
    ----------
    bdf_model : str
        the filename to run
    out_model
    xref : bool
       xrefs
    punch : bool
       punches
    sum_load : bool
       sums static load
    size : int
    is_double : bool
    reject : bool
        True : rejects the cards
    debug : bool
        debugs
    log : logger / None
        ignored
    """
    assert os.path.exists(bdf_model), bdf_model
    assert os.path.exists(out_model), out_model

    if reject:
        fem2 = BDFReplacer(bdf_model + '.rej', debug=debug, log=None)
    else:
        fem2 = BDF(debug=debug, log=None)
    fem2.log.info('starting fem2')
    sys.stdout.flush()
    try:
        fem2.read_bdf(out_model, xref=xref, punch=punch, encoding=encoding)
    except:
        print("failed reading %r" % out_model)
        raise

    out_model_2 = bdf_model + '_out2'

    if xref and sum_load:
        p0 = array([0., 0., 0.])

        subcase_keys = fem2.case_control_deck.get_subcase_list()
        subcases = fem2.subcases

        sol_200_map = fem2.case_control_deck.sol_200_map
        sol_base = fem2.sol
        for isubcase in subcase_keys[1:]:  # drop isubcase = 0
            subcase = subcases[isubcase]
            if sol_base == 200:
                analysis = subcase.get_parameter('ANALYSIS')[0]
                sol = sol_200_map[analysis]
            else:
                sol = sol_base

            if sol == 101:
                assert 'SPC' in subcase, subcase
                assert True in subcase.has_parameter('LOAD', 'TEMPERATURE(LOAD)'), subcase
            elif sol == 103:
                assert 'METHOD' in subcase, subcase
            elif sol == 108: # freq
                assert 'FREQUENCY' in subcase, subcase
            elif sol == 111:  # time
                assert any(subcase.has_parameter('TIME', 'TSTEP', 'TSTEPNL')), subcase
            elif sol == 111:  # modal frequency
                assert subcase.has_parameter('FREQUENCY'), subcase
            elif sol == 112:  # modal transient
                assert any(subcase.has_parameter('TIME', 'TSTEP', 'TSTEPNL')), subcase

            elif sol == 129:  # nonlinear transient
                assert any(subcase.has_parameter('TIME', 'TSTEP', 'TSTEPNL')), subcase
            elif sol == 159:  # thermal transient
                assert any(subcase.has_parameter('TIME', 'TSTEP', 'TSTEPNL')), subcase

            elif sol == 144:
                assert 'SUPORT1' in subcase or len(fem2.suport), subcase
                if 'SUPORT1' in subcase:
                    value, options = subcase.get_parameter('SUPORT1')
                    assert value in fem2.suport1, fem2.suport1
                assert 'TRIM' in subcase, subcase
            elif sol == 145:
                assert 'METHOD'in subcase, subcase
                assert 'FMETHOD' in subcase, subcase  # FLUTTER
            elif sol == 146:
                assert 'METHOD'in subcase, subcase
                assert any(subcase.has_parameter('FREQUENCY', 'TIME', 'TSTEP', 'TSTEPNL')), subcase
                assert any(subcase.has_parameter('GUST', 'LOAD')), subcase
            elif sol == 200:
                assert 'DESOBJ' in subcase, subcase
                assert 'ANALYSIS' in subcase, subcase

            if 'METHOD' in subcase:
                method_id = subcase.get_parameter('METHOD')[0]
                if method_id in fem2.methods:
                    method = fem2.methods[method_id]
                #elif method_id in fem2.cMethods:
                    #method = fem2.cMethods[method_id]
                else:
                    raise RuntimeError('METHOD = %s' % method_id)

                assert sol in [5, 76, 101, 103, 105, 106, 107, 108, 110, 111,
                               112, 144, 145, 146, 187], 'sol=%s METHOD' % sol
            if 'CMETHOD' in subcase:
                method_id = subcase.get_parameter('CMETHOD')[0]
                method = fem2.cMethods[method_id]
                assert sol in [107, 110, 145], 'sol=%s CMETHOD' % sol

            if 'LOAD' in subcase:
                loadcase_id = fem2.case_control_deck.get_subcase_parameter(isubcase, 'LOAD')[0]
                force, moment = fem2.sum_forces_moments(p0, loadcase_id, include_grav=False)
                print('  isubcase=%i F=%s M=%s' % (isubcase, force, moment))
                assert sol in [1, 5, 24, 61, 64, 66, 101, 103, 105, 106, 107, 108, 110, 112,
                               144, 145, 153, 400, 601], 'sol=%s LOAD' % sol
            else:
                # print('is_load =', subcase.has_parameter('LOAD'))
                pass

            if 'FREQUENCY' in subcase:
                freq_id = subcase.get_parameter('FREQUENCY')[0]
                freq = fem2.frequencies[freq_id]
                assert sol in [26, 68, 76, 78, 88, 108, 101, 111, 112, 118, 146], 'sol=%s FREQUENCY' % sol
                # print(freq)

            # if 'LSEQ' in subcase:
                # lseq_id = subcase.get_parameter('LSEQ')[0]
                # lseq = fem2.loads[lseq_id]
                # assert sol in [], sol
                # print(lseq)
            if 'SPC' in subcase:
                spc_id = subcase.get_parameter('SPC')[0]
                fem2.get_spcs(spc_id)
            if 'MPC' in subcase:
                mpc_id = subcase.get_parameter('MPC')[0]
                fem2.get_mpcs(mpc_id)

            if 'DLOAD' in subcase:
                assert sol in [26, 68, 76, 78, 88, 99, 103, 108, 109, 111, 112, 118, 129, 146,
                               153, 159, 400, 601], 'sol=%s DLOAD' % sol
                if 'LOADSET' in subcase:
                    raise NotImplementedError('LOADSET & DLOAD -> LSEQ')
                if 'IC' in subcase:
                    raise NotImplementedError('IC & DLOAD -> TIC')

                # DLOAD (case)   -> dynamic loads -> DLOAD, RLOAD1, RLOAD2, TLOAD1, TLOAD2, ACSRCE
                # LOADSET (case) -> static load sequence - > LSEQ
                # LSEQ (bulk)    -> sequence of static load sets
                # IC (case)      -> points to TIC (initial conditions)
                #
                # TYPE 0 (LOAD)
                #  - no LOADSET -> DAREA, static, thermal load entry
                #  -    LOADSET -> static, thermal loads as specified by LSEQ
                # TYPE 1/2/3 (DISP, VELO, ACCE)
                #  - no LOADSET -> SPCD
                #  -    LOADSET -> SPCDs as specified by LSEQ
                dload_id = subcase.get_parameter('DLOAD')[0]
                if dload_id in fem2.dloads:
                    dload = fem2.dloads[dload_id]
                else:
                    dload = fem2.dload_entries[dload_id]
                # dload = DLOAD()
                # print(dload)
                # for
                # loads, sf = dload.get_loads()
                scale_factors2 = []
                loads2 = []
                for load in dload:
                    # print('DLOAD\n', load)
                    if isinstance(load, DLOAD):
                        scale = load.scale
                        scale_factors = []
                        loads = []
                        # scale_factors, loads = load.get_reduced_loads()
                        for load, scale_factor in zip(load.load_ids, load.scale_factors):
                            if isinstance(load, list):
                                for loadi in load:
                                    assert not isinstance(loadi, list), loadi
                                    scale_factors.append(scale * scale_factor)
                                    loads.append(loadi)
                            else:
                                scale_factors.append(scale * scale_factor)
                                assert not isinstance(load, list), load
                                loads.append(load)
                        scale_factors2 += scale_factors
                        loads2 += loads
                    else:
                        scale_factors2.append(1.)
                        loads2.append(load)

                if sol in [108, 111]:  # direct frequency, modal frequency
                    for load2, scale_factor in zip(loads2, scale_factors2):
                        # for
                        #print(load2)
                        freq_id = subcase.get_parameter('FREQ')[0]
                        freq = fem2.frequencies[freq_id]
                        #print('freqs =', freq.freqs)
                        fmax = freq.freqs[-1]
                        force = load2.get_load_at_freq(fmax) * scale_factor
                elif sol in [109, 129]:  # direct transient (time linear), time nonlinear
                    for load2, scale_factor in zip(loads2, scale_factors2):
                        # for
                        #print(load2)
                        force = load2.get_load_at_time(0.) * scale_factor
                ### 111
                else:
                    fem2.log.debug('solution=%s; DLOAD is not supported' % sol)

                # print(loads)

    fem2.write_bdf(out_model_2, interspersed=False, size=size, is_double=is_double)
    #fem2.writeAsCTRIA3(out_model_2)
    os.remove(out_model_2)
    return fem2
Пример #9
0
def run_bdf(folder, bdfFilename, debug=False, xref=True, check=True, punch=False,
            cid=None, meshForm='combined', isFolder=False, print_stats=False,
            sum_load=False, size=8, precision='single',
            reject=False, nastran='', dynamic_vars={}):
    bdfModel = str(bdfFilename)
    print("bdfModel = %s" % bdfModel)
    if isFolder:
        bdfModel = os.path.join(test_path, folder, bdfFilename)

    assert os.path.exists(bdfModel), '%r doesnt exist' % bdfModel

    if reject:
        fem1 = BDFReplacer(bdfModel + '.rej', debug=debug, log=None)
    else:
        fem1 = BDF(debug=debug, log=None)
    if dynamic_vars:
        fem1.set_dynamic_syntax(dynamic_vars)

    fem1.log.info('starting fem1')
    sys.stdout.flush()
    fem2 = None
    diffCards = []
    try:
        (outModel) = run_fem1(fem1, bdfModel, meshForm, xref, punch, sum_load, size, precision, cid)
        (fem2)     = run_fem2(      bdfModel, outModel, xref, punch, sum_load, size, precision, reject, debug=debug, log=None)
        (diffCards) = compare(fem1, fem2, xref=xref, check=check, print_stats=print_stats)
        nastran = 'nastran scr=yes bat=no old=no '
        if nastran and 0:
            dirname = os.path.dirname(bdfModel)
            basename = os.path.basename(bdfModel).split('.')[0]

            op2_model = os.path.join(dirname, 'out_%s.op2' % basename)

            cwd = os.getcwd()
            bdf_model2 = os.path.join(cwd, 'out_%s.bdf' % basename)
            op2_model2 = os.path.join(cwd, 'out_%s.op2' % basename)
            f06_model2 = os.path.join(cwd, 'out_%s.f06' % basename)
            print(bdf_model2)
            if os.path.exists(bdf_model2):
                os.remove(bdf_model2)

            # make sure we're writing an OP2
            bdf = BDF()
            bdf.read_bdf(outModel)
            if 'POST' in bdf.params:
                post = bdf.params['POST']
                #print('post = %s' % post)
                post.update_values(value1=-1)
                #print('post = %s' % post)
            else:
                card = ['PARAM', 'POST', -1]
                bdf.add_card(card, 'PARAM', is_list=True)
            bdf.write_bdf(bdf_model2)

            #os.rename(outModel, outModel2)
            os.system(nastran + bdf_model2)
            op2 = OP2()
            if not os.path.exists(op2_model2):
                raise RuntimeError('%s failed' % f06_model2)
            op2.read_op2(op2_model2)
            print(op2.get_op2_stats())

    except KeyboardInterrupt:
        sys.exit('KeyboardInterrupt...sys.exit()')
    except IOError:
        pass
    #except AttributeError:  # only temporarily uncomment this when running lots of tests
        #pass
    #except SyntaxError:  # only temporarily uncomment this when running lots of tests
        #pass
    #except AssertionError:  # only temporarily uncomment this when running lots of tests
        #pass
    except SystemExit:
        sys.exit('sys.exit...')
    except:
        #exc_type, exc_value, exc_traceback = sys.exc_info()
        #print "\n"
        traceback.print_exc(file=sys.stdout)
        #print msg
        print("-" * 80)
        raise

    print("-" * 80)
    return (fem1, fem2, diffCards)
Пример #10
0
def run_fem2(bdfModel, out_model, xref, punch,
             sum_load, size, is_double,
             reject, debug=False, log=None):
    """
    Reads/writes the BDF to verify nothing has been lost

    Parameters
    ----------
    bdfModel
    out_model
    xref : bool
       xrefs
    punch : bool
       punches
    sum_load : bool
       sums static load
    size : int
    is_double : bool
    reject : bool
        True : rejects the cards
    debug : bool
        debugs
    log : logger / None
        ignored
    """
    assert os.path.exists(bdfModel), bdfModel
    assert os.path.exists(out_model), out_model

    if reject:
        fem2 = BDFReplacer(bdfModel + '.rej', debug=debug, log=None)
    else:
        fem2 = BDF(debug=debug, log=None)
    fem2.log.info('starting fem2')
    sys.stdout.flush()
    try:
        fem2.read_bdf(out_model, xref=xref, punch=punch)
    except:
        print("failed reading %r" % out_model)
        raise

    outModel2 = bdfModel + '_out2'

    if sum_load:
        p0 = array([0., 0., 0.])

        subcase_keys = fem2.case_control_deck.get_subcase_list()
        subcases = fem2.subcases

        sol_200_map = fem2.case_control_deck.sol_200_map
        sol_base = fem2.sol
        for isubcase in subcase_keys[1:]:  # drop isubcase = 0
            subcase = subcases[isubcase]
            if sol_base == 200:
                analysis = subcase.get_parameter('ANALYSIS')[0]
                sol = sol_200_map[analysis]
            else:
                sol = sol_base

            if subcase.has_parameter('METHOD'):
                method_id = subcase.get_parameter('METHOD')[0]
                method = fem2.methods[method_id]
                assert sol in [5, 76, 101, 103, 105, 106, 107, 108, 110, 111, 112, 144, 145, 187], 'sol=%s METHOD' % sol
            if subcase.has_parameter('CMETHOD'):
                method_id = subcase.get_parameter('CMETHOD')[0]
                method = fem2.cMethods[method_id]
                assert sol in [107, 110, 145], 'sol=%s CMETHOD' % sol

            if subcase.has_parameter('LOAD'):
                loadcase_id = fem2.case_control_deck.get_subcase_parameter(isubcase, 'LOAD')[0]
                F, M = fem2.sum_forces_moments(p0, loadcase_id, include_grav=False)
                print('  isubcase=%i F=%s M=%s' % (isubcase, F, M))
                assert sol in [1, 5, 24, 61, 64, 66, 101, 103, 105, 106, 107, 108, 110, 112,
                               144, 145, 153, 400, 601], 'sol=%s LOAD' % sol
            else:
                # print('is_load =', subcase.has_parameter('LOAD'))
                pass

            if subcase.has_parameter('FREQUENCY'):
                freq_id = subcase.get_parameter('FREQUENCY')[0]
                freq = fem2.frequencies[freq_id]
                assert sol in [26, 68, 76, 78, 88, 108, 101, 111, 112, 118], 'sol=%s FREQUENCY' % sol
                # print(freq)

            # if subcase.has_parameter('LSEQ'):
                # lseq_id = subcase.get_parameter('LSEQ')[0]
                # lseq = fem2.loads[lseq_id]
                # assert sol in [], sol
                # print(lseq)
            if subcase.has_parameter('DLOAD'):
                assert sol in [26, 68, 76, 78, 88, 99, 103, 108, 109, 111, 112, 118, 129,
                               153, 159, 400, 601], 'sol=%s DLOAD' % sol
                if subcase.has_parameter('LOADSET'):
                    raise NotImplementedError('LOADSET & DLOAD -> LSEQ')
                if subcase.has_parameter('IC'):
                    raise NotImplementedError('IC & DLOAD -> TIC')

                # DLOAD (case)   -> dynamic loads -> DLOAD, RLOAD1, RLOAD2, TLOAD1, TLOAD2, ACSRCE
                # LOADSET (case) -> static load sequence - > LSEQ
                # LSEQ (bulk)    -> sequence of static load sets
                # IC (case)      -> points to TIC (initial conditions)
                #
                # TYPE 0 (LOAD)
                #  - no LOADSET -> DAREA, static, thermal load entry
                #  -    LOADSET -> static, thermal loads as specified by LSEQ
                # TYPE 1/2/3 (DISP, VELO, ACCE)
                #  - no LOADSET -> SPCD
                #  -    LOADSET -> SPCDs as specified by LSEQ
                dload_id = subcase.get_parameter('DLOAD')[0]
                if dload_id in fem2.dloads:
                    dload = fem2.dloads[dload_id]
                else:
                    dload = fem2.dload_entries[dload_id]
                # dload = DLOAD()
                # print(dload)
                # for
                # loads, sf = dload.get_loads()
                scale_factors2 = []
                loads2 = []
                for load in dload:
                    # print('DLOAD\n', load)
                    if isinstance(load, DLOAD):
                        scale = load.scale
                        scale_factors = []
                        loads = []
                        # scale_factors, loads = load.get_reduced_loads()
                        for load, sf in zip(load.loadIDs, load.scaleFactors):
                            if isinstance(load, list):
                                for loadi in load:
                                    assert not isinstance(loadi, list), loadi
                                    scale_factors.append(scale * sf)
                                    loads.append(loadi)
                            else:
                                scale_factors.append(scale * sf)
                                assert not isinstance(load, list), load
                                loads.append(load)
                        scale_factors2 += scale_factors
                        loads2 += loads
                    else:
                        scale_factors2.append(1.)
                        loads2.append(load)

                if sol in [108, 111]:  # direct frequency, modal frequency
                    for load2, scale_factor in zip(loads2, scale_factors2):
                        # for
                        #print(load2)
                        F = load2.get_load_at_freq(100.) * scale_factor
                elif sol in [109, 129]:  # direct transient (time linear), time nonlinear
                    for load2, scale_factor in zip(loads2, scale_factors2):
                        # for
                        #print(load2)
                        F = load2.get_load_at_time(0.) * scale_factor
                ### 111
                else:
                    fem2.log.debug('solution=%s; DLOAD is not supported' % sol)

                # print(loads)

    fem2.write_bdf(outModel2, interspersed=False, size=size, is_double=is_double)
    #fem2.writeAsCTRIA3(outModel2)
    os.remove(outModel2)
    return fem2