def remake_model(bdf_model, fem1, pickle_obj): """reloads the model if we're testing pickling""" remake = pickle_obj if remake: #log = fem1.log model_name = os.path.splitext(bdf_model)[0] obj_model = '%s.test_bdfv.obj' % (model_name) #out_model_8 = '%s.test_bdfv.bdf' % (model_name) #out_model_16 = '%s.test_bdfv.bdf' % (model_name) fem1.save(obj_model) fem1.save(obj_model, unxref=False) #fem1.write_bdf(out_model_8) fem1.get_bdf_stats() fem1 = BDF(debug=fem1.debug, log=fem1.log) fem1.load(obj_model) #fem1.write_bdf(out_model_8) #fem1.log = log os.remove(obj_model) fem1.get_bdf_stats() return fem1
def run_fem2(bdf_model, out_model, xref, punch, sum_load, size, is_double, mesh_form, encoding=None, debug=False, quiet=False, stop_on_failure=True): """ 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 ??? mesh_form : str {combined, separate} 'combined' : interspersed=True 'separate' : interspersed=False debug : bool debugs quiet : bool supress prints """ assert os.path.exists(bdf_model), bdf_model assert os.path.exists(out_model), out_model fem2 = BDF(debug=debug, log=None) if not quiet: fem2.log.info('starting fem2') sys.stdout.flush() try: fem2.read_bdf(out_model, xref=False, punch=punch, encoding=encoding) except: print("failed reading %r" % out_model) raise out_model_2 = bdf_model + '_out2' if xref and sum_load: if 'POST' in fem2.params: value = fem2.params['POST'].values[0] if value >= 0: msg = 'PARAM,POST,%i is not supported by the OP2 reader' % value fem2.log.error(msg) else: msg = 'PARAM,POST,0 is not supported by the OP2 reader' fem2.log.error(msg) p0 = np.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.system_command_lines: if line.strip().upper().startswith('RESTART'): is_restart = True #if not is_restart: #validate_case_control(fem2, p0, sol_base, subcase_keys, subcases, sol_200_map, #stop_on_failure=stop_on_failure) if mesh_form is not None: fem2.write_bdf(out_model_2, interspersed=False, size=size, is_double=is_double) os.remove(out_model_2) #fem2.write_as_ctria3(out_model_2) return fem2
def run_and_compare_fems( bdf_model, out_model, debug=False, xref=True, check=True, punch=False, cid=None, mesh_form='combined', print_stats=False, encoding=None, sum_load=True, size=8, is_double=False, stop=False, nastran='', post=-1, dynamic_vars=None, quiet=False, dumplines=False, dictsort=False, nerrors=0, dev=False, crash_cards=None, safe_xref=True, run_extract_bodies=False, pickle_obj=False, stop_on_failure=True, ): """runs two fem models and compares them""" assert os.path.exists(bdf_model), '%r doesnt exist' % bdf_model 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) if dynamic_vars: fem1.set_dynamic_syntax(dynamic_vars) if not quiet: fem1.log.info('starting fem1') sys.stdout.flush() fem2 = None diff_cards = [] try: #nastran_cmd = 'nastran scr=yes bat=no old=no news=no ' nastran_cmd = '' #try: fem1 = run_fem1(fem1, bdf_model, out_model, mesh_form, xref, punch, sum_load, size, is_double, cid, run_extract_bodies=run_extract_bodies, encoding=encoding, crash_cards=crash_cards, safe_xref=safe_xref, pickle_obj=pickle_obj, stop=stop) if stop: if not quiet: 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, mesh_form, encoding=encoding, debug=debug, quiet=quiet, stop_on_failure=stop_on_failure) diff_cards = compare(fem1, fem2, xref=xref, check=check, print_stats=print_stats, quiet=quiet) test_get_cards_by_card_types(fem2) #fem2.update_model_by_desvars(xref) #except: #return 1, 2, 3 run_nastran(bdf_model, nastran_cmd, 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 MissingDeckSections: if not dev: raise print('failed test because MissingDeckSections...ignoring') except DuplicateIDsError as e: # only temporarily uncomment this when running lots of tests if 'GRIDG' in fem1.card_count or 'CGEN' in fem1.card_count or 'SPCG' in fem1.card_count: print( 'failed test because mesh adaption (GRIDG,CGEN,SPCG)...ignoring' ) print(e) elif not dev: raise else: print('failed test because DuplicateIDsError...ignoring') except DisabledCardError as e: if not dev: raise except RuntimeError as e: # only temporarily uncomment this when running lots of tests if not dev: raise if 'GRIDG' in fem1.card_count or 'CGEN' in fem1.card_count or 'SPCG' in fem1.card_count: print( 'failed test because mesh adaption (GRIDG,CGEN,SPCG)...ignoring' ) print(e) else: raise #except AttributeError: # only temporarily uncomment this when running lots of tests #pass except SyntaxError as e: # only temporarily uncomment this when running lots of tests if not dev: raise if 'GRIDG' in fem1.card_count or 'CGEN' in fem1.card_count or 'SPCG' in fem1.card_count: print( 'failed test because mesh adaption (GRIDG,CGEN,SPCG)...ignoring' ) print(e) else: raise except KeyError as e: # only temporarily uncomment this when running lots of tests if not dev: raise if 'GRIDG' in fem1.card_count or 'CGEN' in fem1.card_count or 'SPCG' in fem1.card_count: print( 'failed test because mesh adaption (GRIDG,CGEN,SPCG)...ignoring' ) print(e) else: raise #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 if not quiet: print("-" * 80) return (fem1, fem2, diff_cards)