def wrapYLD_SA(r=[1,1,1,1],y=[1,1,1,1],m=6): """ Running yld2000_sa (stand-alone) executable to deal with the unwanted stop while estimating yld2000-2d coefficieints Arguments --------- r=[1,1,1,1] y=[1,1,1,1] m=6 """ import yf_yld2000 path = os.path.split(yf_yld2000.__file__)[0] cmd = os.path.join(path,'yld2000_sa') for i in xrange(4): cmd = '%s %.5e'%(cmd, y[i]) for i in xrange(4): cmd = '%s %.5e'%(cmd, r[i]) cmd = '%s %.5e'%(cmd, m) ## append file name fnTemp = gen_tempfile(prefix='yld2000-sa',ext='tmp',affix='la') cmd = '%s %s'%(cmd,fnTemp) cmd = '%s > /tmp/dump'%cmd # print cmd flag = os.system(cmd) # print flag if flag==0: ## read la la = yld2000.readla(fnTemp) return la else: return -1 ## fail to converge raise IOError, 'unexpected case'
def makeCommands(f0,psi0,th,logFileName,mat,fnyld,fnhrd): """ Arguments --------- f0 psi0 th logFileName mat fnyld fnhrd """ from mk.library.lib import gen_tempfile stdoutFileName = gen_tempfile( prefix='stdout-mkrun') # stdoutFileName ='/tmp/dump' cmd = 'python main.py --fn %s -f %5.4f -p %+6.1f -t %+7.2f --fnyld %s --fnhrd %s '%( logFileName,f0,psi0,th,fnyld,fnhrd) if mat!=-1: cmd = cmd + ' --mat %i'%mat cmd = cmd + ' > %s'%stdoutFileName print 'cmd:',cmd return cmd
def wrapYLD_SA(r=[1, 1, 1, 1], y=[1, 1, 1, 1], m=6): """ Running yld2000_sa (stand-alone) executable to deal with the unwanted stop while estimating yld2000-2d coefficieints Arguments --------- r=[1,1,1,1] y=[1,1,1,1] m=6 """ import yf_yld2000 path = os.path.split(yf_yld2000.__file__)[0] cmd = os.path.join(path, 'yld2000_sa') for i in xrange(4): cmd = '%s %.5e' % (cmd, y[i]) for i in xrange(4): cmd = '%s %.5e' % (cmd, r[i]) cmd = '%s %.5e' % (cmd, m) ## append file name fnTemp = gen_tempfile(prefix='yld2000-sa', ext='tmp', affix='la') cmd = '%s %s' % (cmd, fnTemp) cmd = '%s > /tmp/dump' % cmd # print cmd flag = os.system(cmd) # print flag if flag == 0: ## read la la = yld2000.readla(fnTemp) return la else: return -1 ## fail to converge raise IOError, 'unexpected case'
def __init__(self,f_yld=None,f_hrd=None, hashcode=None, params_yld=None, label_yld=None, params_hrd=None, label_hrd=None): """ Arguments --------- f_yld f_hrd hashcode params_yld label_yld params_hrd label_hrd """ ## Create log-file to record ## the evolution of this material self.logfn = lib.gen_tempfile( prefix='mk-constitutive', affix='log',ext='txt') self.f_yld = f_yld self.f_hrd = f_hrd ## used when constructing <fortran> objects ## for hardening and yield function calculations ## -- see self.set_hrd and self.set_yld self.params_yld = params_yld self.params_hrd = params_hrd self.label_yld = label_yld self.label_hrd = label_hrd
nfs = 1 hfs_labels=['VpscHard_FIT'] else: nfs = len(hfs) pass # yf.plot(args.fnpickle, fnhrd_vpsc=args.fnpickle_vpsc_hard, # hashcode='aaaaa') # os._exit(0) neps_eq = len(eps_eq) nyfs = len(yfs[0]) for ihrd in xrange(nfs): ## type of hardening function if not(ivpsc_hard): hfnDill = gen_tempfile(prefix='hfs',ext='dll') with open(hfnDill, 'wb') as fo: dill.dump(hfs_labels[ihrd],fo) dill.dump(hfs_params[ihrd],fo) ## dump hardening parameters. for ieps in xrange(neps_eq): for iyld in xrange(nyfs): ## type of yield function ## Save using dill yfnDill = gen_tempfile(prefix='yfs-%s'%yfs_labels[iyld],ext='pck') hashcode = etc.gen_hash_code2(nchar=6) with open(yfnDill,'wb') as fo_: if fo_.closed: raise IOError, 'File was closed %s'%yfnDill try:
def __init__(self): self.logfn = lib.gen_tempfile( prefix='mk-constitutive', affix='log',ext='txt')
nfs = 1 hfs_labels = ['VpscHard_FIT'] else: nfs = len(hfs) pass # yf.plot(args.fnpickle, fnhrd_vpsc=args.fnpickle_vpsc_hard, # hashcode='aaaaa') # os._exit(0) neps_eq = len(eps_eq) nyfs = len(yfs[0]) for ihrd in xrange(nfs): ## type of hardening function if not (ivpsc_hard): hfnDill = gen_tempfile(prefix='hfs', ext='dll') with open(hfnDill, 'wb') as fo: dill.dump(hfs_labels[ihrd], fo) dill.dump(hfs_params[ihrd], fo) ## dump hardening parameters. for ieps in xrange(neps_eq): for iyld in xrange(nyfs): ## type of yield function ## Save using dill yfnDill = gen_tempfile(prefix='yfs-%s' % yfs_labels[iyld], ext='pck') hashcode = etc.gen_hash_code2(nchar=6) with open(yfnDill, 'wb') as fo_: if fo_.closed: raise IOError, 'File was closed %s' % yfnDill
def main( f0=0.996, psi0=0, th=0, material=None, logFileName=None): """ Run forming limit test for the given path using the given material (if none given, assume isotropic material) Arguments --------- f0 initial inhomogeneity factor psi0 [degree] th (epsAng) [degree] material = None (a material data from constitutive.Constitutive) logFileName = None """ # np.seterr(all='raise') np.seterr(all='ignore') import os from mk.library.mk_lib import findStressOnYS from mk.library.lib import gen_tempfile, calcAlphaRho from mk_paths import constructBC,findCorrectPath import mk.materials.constitutive as constitutive import dill snapshot = constitutive.Snapshot() # from yf2 import wrapHill48 print 'material:',material, type(material).__name__ if type(material).__name__=='NoneType': print 'given material', material from materials import IsoMat matA = IsoMat() matB = IsoMat() elif type(material).__name__=='str': with open(material,'rb') as fo: matA = dill.load(fo) with open(material,'rb') as fo: matB = dill.load(fo) matA.set_hrd() matA.set_yld() matB.set_hrd() matB.set_yld() else: raise IOError, 'Unexpected case' # ## Should work on here to allow # ## both A and B materials are described using the # ## same constitutive model # matA = material # matB = material rad2deg = 180./np.pi deg2rad = 1./rad2deg stressA_off, dum1, dum2 = constructBC( epsAng = th, f_yld = matA.f_yld, verbose = False) ## put the stress on the locus matA.update_yld(stressA_off) np.set_printoptions(precision=3) print('stressA:'+('%7.3f'*6)%( matA.stress[0],matA.stress[1],matA.stress[2], matA.stress[3],matA.stress[4],matA.stress[5])) print('strainA:'+('%7.3f'*6)%( matA.dphi[0],matA.dphi[1],matA.dphi[2], matA.dphi[3],matA.dphi[4],matA.dphi[5])) alpha,rho = calcAlphaRho(matA.stress,matA.dphi) print('alpha: %7.4f'%alpha) print('rho : %7.4f'%rho) if type(logFileName).__name__=='NoneType': logFileName = gen_tempfile( prefix='mk-f0%3.3i-th%4.4i-psi%2.2i'%( int(f0*1e3),int(th),int(psi0)), affix='log') logFile = open(logFileName,'w') ## integrate for each path. absciss = 1e3 absciss0 = 1e3 nind = max([len(matA.logfn),len(matB.logfn)])+3 print('Iteration over the given psi angle') head = ( '%8s'*9+ ## variables ('%'+'%is'%nind)*2+ ## aLogFN and bLogFN '%'+'%is'%(len(snapshot.logfn)+3))%( 'epsRD','epsTD','psi0','psif','sigRD', 'sigTD','sigA','T','cmpt','aLogFN','bLogFN','ssFN') head = '%s\n'%head logFile.write(head) t0 = time.time() ynew, absciss, xbb= onepath( matA=matA,matB=matB, psi0=psi0*deg2rad,f0=f0, T=absciss,snapshot=snapshot) matA.recordCurrentStat() matB.recordCurrentStat() dTime = time.time() - t0 psif1 = xbb[0] cnt = ( '%8.3f'*8+ '%8i'+ ('%'+'%is'%nind)*2+ '%'+'%is'%(len(snapshot.logfn)+3))%( ynew[1],ynew[2],psi0, psif1*rad2deg, matA.stress[0],matA.stress[1], matA.sig, ## hardening (effective stress) absciss,dTime,matA.logfn,matB.logfn,snapshot.logfn) print(cnt) logFile.write(cnt+'\n') uet(dTime,'total time spent');print('') logFile.close() print('%s has been saved'%logFileName) return logFileName,dTime, matA, matB
if type(args.fnyld).__name__=='str' \ and type(args.fnhrd).__name__=='str': with open(args.fnyld,'rb') as fo: yf_label=pickle.load(fo) p_yld = pickle.load(fo) with open(args.fnhrd,'rb') as fo: fhrd_type = dill.load(fo) p_hrd = dill.load(fo) matClass = mk.materials.constitutive.Constitutive( f_yld=None,f_hrd=None, params_yld=p_yld,label_yld=yf_label, params_hrd=p_hrd,label_hrd=fhrd_type) fn = gen_tempfile(prefix='mkmat',ext='dll') with open(fn,'wb') as fo: dill.dump(matClass,fo) mat = fn ## save file name to mat elif args.mat==-1: raise IOError, 'Unexpected case 1: %s %s'%( type(args.fnyld).__name__, type(args.fnhrd).__name__) elif args.mat!=-1: print '-'*50 print args.fnyld print args.fnhrd print '-'*50 mat = mk.materials.materials.library(args.mat) else:
if ivpsc_hard: print 'Read based on VPSC hardening fittings' ## find suitable fnhrd_vpsc that has the nearest <rhop> value ## in comparison with each individual rho value given. with open(args.fnhrd_vpsc,'rb') as fo: WorkContour_vpsc_rho = dill.load(fo) rhops = dill.load(fo) rhops = np.array(rhops) fns_vpsc_hfs=[] for ir in xrange(len(rhos)): diffs = np.abs(rhops - rhos[ir]) inds = np.argsort(diffs) i0 = inds[0] ## nearest hardening function fn = gen_tempfile(prefix='hfs-voce-VPSC',ext='dll') with open(fn,'wb') as fo: # dill.dump(WorkContour_vpsc_rho[i0].f_voce,fo) dill.dump('voce-vpsc',fo) ## type: Voce dill.dump(WorkContour_vpsc_rho[i0].p_voce,fo) fns_vpsc_hfs.append(fn) ths = rhos2ths(rhos) uet = progress_bar.update_elapsed_time logFileNames=[] k=0 p0s=[] print '---' for i in xrange(len(ths)): ## each rho _psi0s_=findCorrectPsi(ths[i]*180/np.pi) p0s.append(_psi0s_)