예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #4
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)