def main(): nastran_path = r'C:\Program Files\Siemens\SimcenterNastran_2019.2\bin\nastran.exe' print(sys.argv) export_dir = sys.argv[1] print('export_dir = %r' % export_dir) #folders_file = os.path.abspath('.') #files2 = get_all_files(folders_file, '.bdf') #files2 += get_all_files(folders_file, '.nas') #files2 += get_all_files(folders_file, '.dat') #files2 = list(set(files2)) #files2.sort() max_size = 4.2 # MB dirname = '.' files2 = get_files_of_type(dirname, '.bdf', max_size=max_size) files2 += get_files_of_type(dirname, '.nas', max_size=max_size) files2 += get_files_of_type(dirname, '.dat', max_size=max_size) files2 += get_files_of_type(dirname, '.ecd', max_size=max_size) files2 = list(set(files2)) files2.sort() skip_files = [] files = [ fname for fname in files2 if not os.path.basename(fname).startswith('out_') and '.test_op2.' not in fname # removing test output files and '.test_bdf.' not in fname and '.test_bdfv.' not in fname and 'tecplot' not in fname and os.path.basename(fname) not in skip_files ] for fname in files: #print(fname) fname2 = update_with_post(fname, export_dir) if fname2 is None: continue if not RUN_NASTRAN: continue keywords = 'scr=yes old=no news=no' run_nastran(fname2, nastran_cmd=nastran_path, keywords=keywords, run=True, run_in_bdf_dir=True)
def main(): print(sys.argv) #export_dir = sys.argv[1] export_dir = r'C:\MSC.Software\msc_nastran_runs' print('export_dir = %r' % export_dir) #folders_file = os.path.abspath('.') #files2 = get_all_files(folders_file, '.bdf') #files2 += get_all_files(folders_file, '.nas') #files2 += get_all_files(folders_file, '.dat') #files2 = list(set(files2)) #files2.sort() max_size = 4.2 # MB dirname = r'C:\MSC.Software\msc_nastran_docs_2020\tpl' files2 = get_files_of_type(dirname, '.bdf', max_size=max_size) files2 += get_files_of_type(dirname, '.nas', max_size=max_size) files2 += get_files_of_type(dirname, '.dat', max_size=max_size) files2 += get_files_of_type(dirname, '.ecd', max_size=max_size) files2 = list(set(files2)) files2.sort() skip_files = [] files = [ fname for fname in files2 if not os.path.basename(fname).startswith('out_') and '.test_op2.' not in fname # removing test output files and '.test_bdf.' not in fname and '.test_bdfv.' not in fname and 'tecplot' not in fname and os.path.basename(fname) not in skip_files ] for fname in files: #print(fname) fname2 = update_with_post(fname, export_dir) if fname2 is None: continue if not RUN_NASTRAN: continue keywords = 'scr=yes old=no news=no notify=no' run_nastran(fname2, nastran_cmd=NASTRAN_EXE, keywords=keywords, run=True, run_in_bdf_dir=True)
def test_panel_buckling_bwb(self): """panel buckling doesn't work in Python 3""" input_dir = os.path.join(model_path, 'bwb') bdf_filename = os.path.join(input_dir, 'BWB_saero.bdf') workpath = os.path.join(os.getcwd(), 'aero_buckling') op2_filename = os.path.join(workpath, 'BWB_saero.op2') #op2_filename = 'BWB_saero.op2' if workpath is not None: if not os.path.exists(workpath): os.makedirs(workpath) os.chdir(workpath) keywords = { 'old': 'no', 'scr': 'yes', 'bat': 'no', 'news': 'no', } if not os.path.exists(op2_filename) and 0: run_nastran(bdf_filename, keywords=keywords) if not os.path.exists(op2_filename): op2_filename = None run_panel_buckling(bdf_filename=bdf_filename, op2_filename=op2_filename, isubcase=1, workpath=workpath, build_model=False, rebuild_patches=True, rebulid_buckling_bdfs=False, mode='displacement', parse_eigenvalues=False, run_nastran=False, nastran_keywords=keywords, overwrite_op2_if_exists=True, op2_filenames=None)
analysis.import_from_bdf(input_file) # import bdf model #%% spanel_p = SuperAeroPanel5(1) # init panel spanel_p.init_from_femap( femap ) # popup femap interface to insert the location and config of the panel analysis.add_superpanel(spanel_p) analysis.write_cards() # write the panels on the pyNastran bdf interface analysis.export_to_bdf(output_file) # exports to bdf file #%% run nastran run_nastran(output_file, nastran_cmd=nastran_exe, keywords=['old=no']) #%% output results panel_flutter_analysis(analysis, output_file) #%% now with the ZONA51 theory analysis = PanelFlutterAnalysisModel() analysis.load_analysis_from_yaml(os.path.join(base_path, r'analysis.yml')) analysis.import_from_bdf(input_file) # reset the bdf file # analysis.import_from_bdf(input_file, reset_bdf=True) # reset the bdf file analysis.subcases[1].method = 'PK' # you may supply a value of minimum Mach number in your analysis, by default this value is sqrt(2) (i.e. 45° -> square) spanel = SuperAeroPanel1(1, np.min(analysis.subcases[1].machs))
def fully_stressed_design(bdf_filename, keywords=None, niterations_max=2, alpha=0.9): """ Optimizes shell thickness for minimum weight (ONLY shells) Parameters ---------- bdf_filename : str; BDF() the BDF filename or model Returns ------- desvars : dict[id]=values the "optimization history of the design variables """ force = True iteration = 0 niterations_max = 10 if isinstance(bdf_filename, str): model = read_bdf(bdf_filename) elif isinstance(bdf_filename, BDF): model = bdf_filename bdf_filename = model.bdf_filename else: raise TypeError(bdf_filename) doptparm = model.doptprm if doptparm is not None: if 'FSDALP' in doptparm.params: alpha = doptparm.params['FSDALP'] else: alpha = doptparm.defaults['FSDALP'] if not isinstance(alpha, float): msg = 'FSDALP on DOPTPARM must be an integer; FSDALP=%r' % (alpha) raise TypeError(msg) if not (0. < niterations_max <= 1.): msg = 'FSDALP on DOPTPARM must be between (0. < n <= 1.0); FSDALP=%s' % ( alpha) raise ValueError(msg) if 'FSDMAX' in doptparm.params: niterations_max = doptparm.params['FSDMAX'] else: niterations_max = doptparm.defaults['FSDMAX'] if not isinstance(niterations_max, int): msg = 'FSDMAX on DOPTPARM must be an integer; FSDMAX=%r' % ( niterations_max) raise TypeError(msg) if niterations_max <= 0: msg = 'FSDMAX on DOPTPARM must be > 0; FSDMAX=%s' % ( niterations_max) raise ValueError(msg) else: niterations_max = 2 alpha = 0.9 dresps_to_consider, desvars_to_consider, dvprels_to_consider = get_inputs( model) pid_to_eid = model.get_property_id_to_element_ids_map() bdf_filename2 = 'fem_baseline.bdf' op2_filename2 = 'fem_baseline.op2' try: shutil.copyfile(bdf_filename, bdf_filename2) except TypeError: msg = 'cannot copy %r to %r' % (bdf_filename, bdf_filename2) raise TypeError(msg) while iteration < niterations_max: if not os.path.exists(op2_filename2) or force: run_nastran(bdf_filename2, keywords=keywords) results = read_op2(op2_filename2, combine=True, log=None, debug=False, debug_file=None, build_dataframe=False, skip_undefined_matrices=True, mode='msc') isubcase = 1 itime = 0 stress_per_region = {} nopt = 0 for pid, region in iteritems(regions): print('pid=%s region=%s' % (pid, region)) (tmin, tmax, ovm_min, ovm_max) = region prop = model.properties[pid] told = prop.t eids_requested = pid_to_eid[pid] print('eids_requested[pid=%s] = %s' % (pid, eids_requested)) #def compute_critical_stress(results, subcases) #def compute_critical_stress(results, subcases): stress = [] eid_node = [] for res in [results.cquad4_stress, results.ctria3_stress]: resi = res[isubcase] eid_nodei = resi.element_node #print('eid_nodei = %s' % (eid_nodei)) eid = eid_nodei[:, 0] stress_data = resi.data eid_node.append(eid_nodei) # A #i = np.where(eid == eids_requested) # B #j = np.searchsorted(eid, eids_requested) #i = np.where(eid[j] == eids_requested) #j = np.in1d(eids_requested, eid) # A in B j = np.in1d(eid, eids_requested) # A in B i = np.where(j) #print('i = %s' % i) #[0] #print('j = %s' % j) #[0] #print('eid = %s' % eid) #[0] #print('eids_requested = %s' % eids_requested) #[0] if len(i) == 0: continue #print('i=%s; ni=%s' % (i, len(i))) stress_datai = stress_data[itime, i, 7] #print('eids = %s' % eid[i]) #print('stress_datai = %s' % stress_datai) stress.append(stress_datai) #print('stressA = %s' % stress) stress = np.hstack(stress) #print('stressB = %s' % stress) # PROD area # PSHELL/PCOMP thickness # PSHEAR thickness eid_node = np.vstack(eid_node) stress_max = stress.max() stress_min = stress.min() print('stress_min=%s' % stress_min) print('stress_max=%s' % stress_max) istress_max = np.where(stress == stress_max)[0] istress_min = np.where(stress == stress_min)[0] eid_max = eid_node[istress_max, 0] eid_min = eid_node[istress_min, 0] peak_stress = max(abs(stress_max), abs(stress_min)) tnew = told * stress_max / ovm_max tnew = min(tmax, tnew) tnew = max(tmin, tnew) #tnew = (oi/omax)**alpha * ti_old tratio = tnew / told if np.allclose(tratio, 1.): continue nopt += 1 stress_per_region = [stress_min, stress_max, eid_min, eid_max] print('pid=%s' % pid) print( ' stress_per_region (ovm_min, ovm_max, eid_min, eid_max) => %s' % stress_per_region) print(' told=%s tnew=%s tratio=%s\n' % (told, tnew, tratio)) prop.t *= tratio prop.z1 *= tratio prop.z2 *= tratio regions2[pid] = [ tnew, peak_stress, stress_max, eid_max, stress_min, eid_min ] # t_new, ovm_new if nopt == 0: break #eid_node = np.hstack(eid_node) #s = np.hstack(eid_node) iteration += 1 bdf_filename2 = 'fem_%i.bdf' % iteration op2_filename2 = 'fem_%i.op2' % iteration model.write_bdf(bdf_filename2) print('regions2 = %s' % regions2) return regions2
def fully_stressed_design(bdf_filename, keywords=None, niterations_max=2, alpha=0.9): """ Optimizes shell thickness for minimum weight (ONLY shells) Parameters ---------- bdf_filename : str; BDF() the BDF filename or model Returns ------- desvars : dict[id]=values the "optimization history of the design variables """ force = True iteration = 0 niterations_max = 10 if isinstance(bdf_filename, str): model = read_bdf(bdf_filename) elif isinstance(bdf_filename, BDF): model = bdf_filename bdf_filename = model.bdf_filename else: raise TypeError(bdf_filename) doptparm = model.doptprm if doptparm is not None: if 'FSDALP' in doptparm.params: alpha = doptparm.params['FSDALP'] else: alpha = doptparm.defaults['FSDALP'] if not isinstance(alpha, float): msg = 'FSDALP on DOPTPARM must be an integer; FSDALP=%r' % (alpha) raise TypeError(msg) if not(0. < niterations_max <= 1.): msg = 'FSDALP on DOPTPARM must be between (0. < n <= 1.0); FSDALP=%s' % (alpha) raise ValueError(msg) if 'FSDMAX' in doptparm.params: niterations_max = doptparm.params['FSDMAX'] else: niterations_max = doptparm.defaults['FSDMAX'] if not isinstance(niterations_max, int): msg = 'FSDMAX on DOPTPARM must be an integer; FSDMAX=%r' % (niterations_max) raise TypeError(msg) if niterations_max <= 0: msg = 'FSDMAX on DOPTPARM must be > 0; FSDMAX=%s' % (niterations_max) raise ValueError(msg) else: niterations_max = 2 alpha = 0.9 dresps_to_consider, desvars_to_consider, dvprels_to_consider = get_inputs(model) pid_to_eid = model.get_property_id_to_element_ids_map() bdf_filename2 = 'fem_baseline.bdf' op2_filename2 = 'fem_baseline.op2' try: shutil.copyfile(bdf_filename, bdf_filename2) except TypeError: msg = 'cannot copy %r to %r' % (bdf_filename, bdf_filename2) raise TypeError(msg) while iteration < niterations_max: if not os.path.exists(op2_filename2) or force: run_nastran(bdf_filename2, keywords=keywords) results = read_op2(op2_filename2, combine=True, log=None, debug=False, debug_file=None, build_dataframe=False, skip_undefined_matrices=True, mode='msc') isubcase = 1 itime = 0 stress_per_region = {} nopt = 0 for pid, region in iteritems(regions): print('pid=%s region=%s' % (pid, region)) (tmin, tmax, ovm_min, ovm_max) = region prop = model.properties[pid] told = prop.t eids_requested = pid_to_eid[pid] print('eids_requested[pid=%s] = %s' % (pid, eids_requested)) #def compute_critical_stress(results, subcases) #def compute_critical_stress(results, subcases): stress = [] eid_node = [] for res in [results.cquad4_stress, results.ctria3_stress]: resi = res[isubcase] eid_nodei = resi.element_node #print('eid_nodei = %s' % (eid_nodei)) eid = eid_nodei[:, 0] stress_data = resi.data eid_node.append(eid_nodei) # A #i = np.where(eid == eids_requested) # B #j = np.searchsorted(eid, eids_requested) #i = np.where(eid[j] == eids_requested) #j = np.in1d(eids_requested, eid) # A in B j = np.in1d(eid, eids_requested) # A in B i = np.where(j) #print('i = %s' % i) #[0] #print('j = %s' % j) #[0] #print('eid = %s' % eid) #[0] #print('eids_requested = %s' % eids_requested) #[0] if len(i) == 0: continue #print('i=%s; ni=%s' % (i, len(i))) stress_datai = stress_data[itime, i, 7] #print('eids = %s' % eid[i]) #print('stress_datai = %s' % stress_datai) stress.append(stress_datai) #print('stressA = %s' % stress) stress = np.hstack(stress) #print('stressB = %s' % stress) # PROD area # PSHELL/PCOMP thickness # PSHEAR thickness eid_node = np.vstack(eid_node) stress_max = stress.max() stress_min = stress.min() print('stress_min=%s' % stress_min) print('stress_max=%s' % stress_max) istress_max = np.where(stress == stress_max)[0] istress_min = np.where(stress == stress_min)[0] eid_max = eid_node[istress_max, 0] eid_min = eid_node[istress_min, 0] peak_stress = max(abs(stress_max), abs(stress_min)) tnew = told * stress_max / ovm_max tnew = min(tmax, tnew) tnew = max(tmin, tnew) #tnew = (oi/omax)**alpha * ti_old tratio = tnew / told if np.allclose(tratio, 1.): continue nopt += 1 stress_per_region = [stress_min, stress_max, eid_min, eid_max] print('pid=%s' % pid) print(' stress_per_region (ovm_min, ovm_max, eid_min, eid_max) => %s' % stress_per_region) print(' told=%s tnew=%s tratio=%s\n' %(told, tnew, tratio)) prop.t *= tratio prop.z1 *= tratio prop.z2 *= tratio regions2[pid] = [tnew, peak_stress, stress_max, eid_max, stress_min, eid_min] # t_new, ovm_new if nopt == 0: break #eid_node = np.hstack(eid_node) #s = np.hstack(eid_node) iteration += 1 bdf_filename2 = 'fem_%i.bdf' % iteration op2_filename2 = 'fem_%i.op2' % iteration model.write_bdf(bdf_filename2) print('regions2 = %s' % regions2) return regions2