def plot_rsq(): from MP.lib import mpl_lib import numpy as np import matplotlib.pyplot as plt from pepshkl import reader2 as reader import sfig_class from MP.mat.mech import FlowCurve as FC StressFactor=sfig_class.SF flow = FC(); flow.get_model(fn='STR_STR.OUT');flow.get_eqv() tdat,usf = reader(fn='igstrain_fbulk_ph1.out',iopt=1,isort=True) vdat,ngrd = return_vf() wf = mpl_lib.wide_fig nstp,nij,nphi,npsi = tdat.shape[1:] Psi = tdat[8,:,:,:,:] Phi = tdat[7,:,:,:,:] rsq = tdat[9,:,:,:,:] sf = tdat[3,:,:,:,:] ## swap sf axes to comply with sfig_class.SF.sf ## [nstp,nphi,npsi,nij] sf = sf.swapaxes(1,3).swapaxes(1,2) rsq=rsq.swapaxes(1,3).swapaxes(1,2) psi = Psi[0,0,0,:] phi = Phi[0,0,:,0] print psi.shape print phi.shape print sf.shape SF=StressFactor() SF.add_data(sf=sf,phi=phi,psi=psi) SF.flow = flow ## overwrite flow SF.add_vf(vdat) SF.add_rsq(rsq) SF.plot() return sf,vdat,rsq,psi
def main(fn='temp.sff', difile=None, iph=1, factor=1e6, itab=False, ieps0=4,irev=False,fn_str=None, flow=None): """ Arguments ========= fn = 'temp.sff' difile = 'None' iph = 1 factor = 1e6 itab = False (use '\t' as the delimiter) # ieps0 = 0,1,2,3 (option for ntepsphiout) # 0: int_eps_ph - at unloads (eps^hkl) # 1: int_els_ph - at loads (eps^hkl) # 2: igstrain_ph - at loads (Eps-eps^hkl) # 3: igstrain_ph - at unloads (Eps-eps^hkl) ieps0 is deprecated. The option for IG and SF is now hardwired # 4: igstrain_bulk - at loads (eps^hkl - Fij<Sij>) # 5: igstrain_bulk - at loads (eps^hkl - Fij/Fij^bulk E) IG strain is calculated from igstrain_loads_avg.out irev = False (if True, eps0 = -eps0) - This argument is for the one time. (Mistake in diffwrite subroutine...) * Note that stress factor file for Thomas's PF software takes 1/TPa unit. Either VPSC or EVPSC has itself no imposition of unit. However, single crystal file usually takes on MPa unit for both single crystal moduli and hardening parameters. So, it is most likely that the stress factor should be converted from 1/MPa to 1/TPa. 10^6 MPa = 1 TPa. There are various methods to calculate SF/IG strains in EVPSC. 1. igstrain_loads_avg.out: this file is not one of many EVPSC-generated-output files. This file is calculated based on ... 2. igstrain_bix_ph1.out (diff prior to *unloading*) 3. igstrain_fbulk_ph1.out 4. int_els_ph1.out (prior to unloading) 5. int_eps_ph1.out (post unloading) """ if not(itab): raise IOError,'use itab==True' if difile==None: print 'difile is none: find it from EVPSC.IN' dl = open('EVPSC.IN','r').readlines() nph = int(dl[1].split()[0]) n = 12*(iph-1) + 3 + 11 difile = dl[n][:-1] print difile # condition difl, nphi, phis, npsi, dum1, dum2 = condition(fn=difile) # ------------------------------------------------------- # fn_ig_avg='igstrain_loads_avg.out' ## IG strain from avg. #fn_ig_avg='igstrain_fbulk_ph1.out' from pepshkl import reader3 as reader import os.path if flow!=None and fn_str!=None: raise IOError, 'Either flow or fn_str should be given' elif flow!=None: flow.get_eqv() elif fn_str!=None: from MP.mat.mech import FlowCurve flow = FlowCurve() flow.get_model(fn=fn_str) flow.get_eqv() neps = flow.nstp strains = flow.epsilon_vm[::] if not(os.path.isfile(fn_ig_avg)): from pepshkl import ex_igb_bix_t print 'Run pepshkl.ex_igb_cf or pepshkl.ex_igb_bix_t'\ ' to obtain igstrain_loads_avg.out' dummy_rst = ex_igb_bix_t(fn='igstrain_bix_ph1.out', fnout=fn_ig_avg, flow=flow) dat,psis,fij = reader(fn_ig_avg,isort=True) # ------------------------------------------------------- # psis = psis[0] print 'difile:',difile print 'npsi', npsi npsi = len(psis) print 'npsi', npsi # (step, nphi, psi) if ieps0<4: raise IOError, 'Use if ieps0<4 is deprecated' sff = open(fn, 'w') # stress factor file sff.write('Header') for i in range(neps*10-2): sff.write('\t') sff.write('\r\n') sff.write('#strainLevels \t %i'%neps) for i in range(neps*10-3): sff.write('\t') sff.write('\r\n') sff.write('#phivalues \t%i'%nphi) for i in range(neps*10-3): sff.write('\t') sff.write('\r\n') sff.write('#psivalues \t%i'%npsi) for i in range(neps*10-3): sff.write('\t') sff.write('\r\n') sff.write(('%s'%('e^{eff} \t%5.3f'%(strains[0]))).ljust(14)) for i in range(8): sff.write('\t') if neps>1: sff.write(('\t%5.3f'%(strains[1])).rjust(115)) for i in range(9): sff.write('\t') for i in range(neps-2): sff.write(('\t%5.3f'%(strains[i+2])).rjust(118)) for j in range(9): if j==8 and i==neps-3: pass else: sff.write('\t') sff.write('\r\n') for i in range(neps): stemp = '%10s%9s ' ; ftemp = '%9s'%'%6.2f' ftemp = ftemp + '%8s '%'%6.2f' for j in range(7): stemp = stemp + '%13s ' ftemp = ftemp + '% +12.6e ' sff.write(stemp%('Phi\t','Psi\t','F11\t','F22\t', 'F33\t','F23\t','F13\t','F12\t','eps0')) if i==neps-1: pass else: sff.write('\t') if i==neps-1: pass else: sff.write('\t') print 'nphi,neps,npsi:', nphi,neps,npsi sff.write('\r\n') # line breaker for i in range(nphi): for j in range(npsi): for k in range(neps): ph = phis[i] ps = psis[j] sf = fij[k,i,j,:]*factor eps0 = dat[k,i,j] if irev: eps = - eps sff.write('%9.2f\t %9.2f\t %+12.4e\t'\ ' %+12.4e\t %+12.4e\t'\ ' %+12.4e\t %+12.4e\t'\ ' %+12.4e\t %+12.4e'%( ph,ps,sf[0],sf[1],sf[2],sf[3],sf[4],sf[5],eps0)) if k==neps-1: pass else: sff.write('\t') if k==neps-1: pass else: sff.write('\t') sff.write('\r\n') pass sff.close() pass # end of main
def intepsphiout(istep=0, phi=0, iphi=0, iph=1, isort=False, iopt=0): """ Arguments ========= istep = 0 (starts from 0) phi = -90 or iphi as index for iopt 4 and 5. iph = 1 (phase starts from 1) isort = False iopt = 0: ('int_eps_ph%i.out') - at unloads, 1: ('int_els_ph%i.out') - at loads 2: ('igstrain_load_ph%i.out') - at 3: ('igstrain_unload_ph%i.out') - at 4: ('igstrain_unloads_avg.out') at unloads 5: ('igstrain_loads_avg.out') at loads """ from ssort import shellSort as ssort from ssort import sh from ssort import ind_swap eps, sig, psi = [], [], [] if iopt==0: filename='int_eps_ph%i.out'%iph elif iopt==1: filename='int_els_ph%i.out'%iph elif iopt==2: filename='igstrain_load_ph%i.out'%iph elif iopt==3: filename='igstrain_unload_ph%i.out'%iph elif iopt==4: filename='igstrain_unloads_avg.out' elif iopt==5: filename='igstrain_loads_avg.out' fc(filename) if iopt<4: dl = open(filename, 'r').readlines() npb = int(dl[1].split()[0]) dat = dl[2:] dat = dat[(istep)*npb: (istep)*npb + npb] if len(dat)==0: raise IOError, 'empty dat is returned ..' for i in range(len(dat)): temp = map(float, dat[i].split()) step, p, beta, psi1, psi2, eps1, eps2,\ sig1, sig2, n1, n2, v1, v2 = temp[:13] ms11, ms22, ms33, ms23, ms13, ms12 = temp[13:19] me11, me22, me33, me23, me13, me12 = temp[19:25] if p==phi: eps.append(eps1); eps.append(eps2) sig.append(sig1); sig.append(sig2) psi.append(psi1) # detector 1 psi.append(psi2) # detector 2 if isort: temp1, temp2 = [], [] sortedarray, ind = ssort(psi)#, len(psi)) for k in range(len(sortedarray)): temp1.append(eps[ind[k]-1]) temp2.append(sig[ind[k]-1]) eps = temp1 sigma = temp2 psi = sortedarray return np.array(psi), np.array(eps), np.array(sig),\ ms11, ms22, ms33, ms23, ms13, ms12 if iopt==4 or iopt==5: from sff_converter import condition from pepshkl import reader3 as reader difl, nphi, phis, nbeta, neps, eps = condition() tdat, psi = reader(filename,isort) #[ist,iphi,ipsi] sin2psi = np.sin(psi*np.pi/180.)**2 npsi = len(psi) eps = tdat[istep, iphi] return psi, eps raise IOError, 'Unexpected ioption give in intepsphiout'
def main(fn='temp.sff', difile=None, iph=1, factor=1e6, itab=False, ieps0=4, irev=False, fn_str=None, flow=None): """ Arguments ========= fn = 'temp.sff' difile = 'None' iph = 1 factor = 1e6 itab = False (use '\t' as the delimiter) # ieps0 = 0,1,2,3 (option for ntepsphiout) # 0: int_eps_ph - at unloads (eps^hkl) # 1: int_els_ph - at loads (eps^hkl) # 2: igstrain_ph - at loads (Eps-eps^hkl) # 3: igstrain_ph - at unloads (Eps-eps^hkl) ieps0 is deprecated. The option for IG and SF is now hardwired # 4: igstrain_bulk - at loads (eps^hkl - Fij<Sij>) # 5: igstrain_bulk - at loads (eps^hkl - Fij/Fij^bulk E) IG strain is calculated from igstrain_loads_avg.out irev = False (if True, eps0 = -eps0) - This argument is for the one time. (Mistake in diffwrite subroutine...) * Note that stress factor file for Thomas's PF software takes 1/TPa unit. Either VPSC or EVPSC has itself no imposition of unit. However, single crystal file usually takes on MPa unit for both single crystal moduli and hardening parameters. So, it is most likely that the stress factor should be converted from 1/MPa to 1/TPa. 10^6 MPa = 1 TPa. There are various methods to calculate SF/IG strains in EVPSC. 1. igstrain_loads_avg.out: this file is not one of many EVPSC-generated-output files. This file is calculated based on ... 2. igstrain_bix_ph1.out (diff prior to *unloading*) 3. igstrain_fbulk_ph1.out 4. int_els_ph1.out (prior to unloading) 5. int_eps_ph1.out (post unloading) """ if not (itab): raise IOError, 'use itab==True' if difile == None: print 'difile is none: find it from EVPSC.IN' dl = open('EVPSC.IN', 'r').readlines() nph = int(dl[1].split()[0]) n = 12 * (iph - 1) + 3 + 11 difile = dl[n][:-1] print difile # condition difl, nphi, phis, npsi, dum1, dum2 = condition(fn=difile) # ------------------------------------------------------- # fn_ig_avg = 'igstrain_loads_avg.out' ## IG strain from avg. #fn_ig_avg='igstrain_fbulk_ph1.out' from pepshkl import reader3 as reader import os.path if flow != None and fn_str != None: raise IOError, 'Either flow or fn_str should be given' elif flow != None: flow.get_eqv() elif fn_str != None: from MP.mat.mech import FlowCurve flow = FlowCurve() flow.get_model(fn=fn_str) flow.get_eqv() neps = flow.nstp strains = flow.epsilon_vm[::] if not (os.path.isfile(fn_ig_avg)): from pepshkl import ex_igb_bix_t print 'Run pepshkl.ex_igb_cf or pepshkl.ex_igb_bix_t'\ ' to obtain igstrain_loads_avg.out' dummy_rst = ex_igb_bix_t(fn='igstrain_bix_ph1.out', fnout=fn_ig_avg, flow=flow) dat, psis, fij = reader(fn_ig_avg, isort=True) # ------------------------------------------------------- # psis = psis[0] print 'difile:', difile print 'npsi', npsi npsi = len(psis) print 'npsi', npsi # (step, nphi, psi) if ieps0 < 4: raise IOError, 'Use if ieps0<4 is deprecated' sff = open(fn, 'w') # stress factor file sff.write('Header') for i in xrange(neps * 10 - 2): sff.write('\t') sff.write('\r\n') sff.write('#strainLevels \t %i' % neps) for i in xrange(neps * 10 - 3): sff.write('\t') sff.write('\r\n') sff.write('#phivalues \t%i' % nphi) for i in xrange(neps * 10 - 3): sff.write('\t') sff.write('\r\n') sff.write('#psivalues \t%i' % npsi) for i in xrange(neps * 10 - 3): sff.write('\t') sff.write('\r\n') sff.write(('%s' % ('e^{eff} \t%5.3f' % (strains[0]))).ljust(14)) for i in xrange(8): sff.write('\t') if neps > 1: sff.write(('\t%5.3f' % (strains[1])).rjust(115)) for i in xrange(9): sff.write('\t') for i in xrange(neps - 2): sff.write(('\t%5.3f' % (strains[i + 2])).rjust(118)) for j in xrange(9): if j == 8 and i == neps - 3: pass else: sff.write('\t') sff.write('\r\n') for i in xrange(neps): stemp = '%10s%9s ' ftemp = '%9s' % '%6.2f' ftemp = ftemp + '%8s ' % '%6.2f' for j in xrange(7): stemp = stemp + '%13s ' ftemp = ftemp + '% +12.6e ' sff.write(stemp % ('Phi\t', 'Psi\t', 'F11\t', 'F22\t', 'F33\t', 'F23\t', 'F13\t', 'F12\t', 'eps0')) if i == neps - 1: pass else: sff.write('\t') if i == neps - 1: pass else: sff.write('\t') print 'nphi,neps,npsi:', nphi, neps, npsi sff.write('\r\n') # line breaker for i in xrange(nphi): for j in xrange(npsi): for k in xrange(neps): ph = phis[i] ps = psis[j] sf = fij[k, i, j, :] * factor eps0 = dat[k, i, j] if irev: eps = -eps sff.write('%9.2f\t %9.2f\t %+12.4e\t'\ ' %+12.4e\t %+12.4e\t'\ ' %+12.4e\t %+12.4e\t'\ ' %+12.4e\t %+12.4e'%( ph,ps,sf[0],sf[1],sf[2],sf[3],sf[4],sf[5],eps0)) if k == neps - 1: pass else: sff.write('\t') if k == neps - 1: pass else: sff.write('\t') sff.write('\r\n') pass sff.close() pass # end of main
def intepsphiout(istep=0, phi=0, iphi=0, iph=1, isort=False, iopt=0): """ Arguments ========= istep = 0 (starts from 0) phi = -90 or iphi as index for iopt 4 and 5. iph = 1 (phase starts from 1) isort = False iopt = 0: ('int_eps_ph%i.out') - at unloads, 1: ('int_els_ph%i.out') - at loads 2: ('igstrain_load_ph%i.out') - at 3: ('igstrain_unload_ph%i.out') - at 4: ('igstrain_unloads_avg.out') at unloads 5: ('igstrain_loads_avg.out') at loads """ from MP import ssort sh=ssort.sh ind_swap=ssort.ind_swap ssort=ssort.shellSort #from ssort import shellSort as ssort #from ssort import sh #from ssort import ind_swap eps, sig, psi = [], [], [] if iopt==0: filename='int_eps_ph%i.out'%iph elif iopt==1: filename='int_els_ph%i.out'%iph elif iopt==2: filename='igstrain_load_ph%i.out'%iph elif iopt==3: filename='igstrain_unload_ph%i.out'%iph elif iopt==4: filename='igstrain_unloads_avg.out' elif iopt==5: filename='igstrain_loads_avg.out' fc(filename) if iopt<4: dl = open(filename, 'r').readlines() npb = int(dl[1].split()[0]) dat = dl[2:] dat = dat[(istep)*npb: (istep)*npb + npb] if len(dat)==0: raise IOError, 'empty dat is returned ..' for i in xrange(len(dat)): temp = map(float, dat[i].split()) step, p, beta, psi1, psi2, eps1, eps2,\ sig1, sig2, n1, n2, v1, v2 = temp[:13] ms11, ms22, ms33, ms23, ms13, ms12 = temp[13:19] me11, me22, me33, me23, me13, me12 = temp[19:25] if p==phi: eps.append(eps1); eps.append(eps2) sig.append(sig1); sig.append(sig2) psi.append(psi1) # detector 1 psi.append(psi2) # detector 2 if isort: temp1, temp2 = [], [] sortedarray, ind = ssort(psi)#, len(psi)) for k in xrange(len(sortedarray)): temp1.append(eps[ind[k]-1]) temp2.append(sig[ind[k]-1]) eps = temp1 sigma = temp2 psi = sortedarray return np.array(psi), np.array(eps), np.array(sig),\ ms11, ms22, ms33, ms23, ms13, ms12 if iopt==4 or iopt==5: from sff_converter import condition from pepshkl import reader3 as reader difl, nphi, phis, nbeta, neps, eps = condition() tdat, psi = reader(filename,isort) #[ist,iphi,ipsi] sin2psi = np.sin(psi*np.pi/180.)**2 npsi = len(psi) eps = tdat[istep, iphi] return psi, eps raise IOError, 'Unexpected ioption give in intepsphiout'