def find_err(fa,fb): """ Compare the two FlowCurve objects and return errors at indivial plastic levels. """ from MP.mat.mech import FlowCurve as FC fd = FC() if fa.nstp!=fb.nstp: raise IOError,\ 'Number of data points are not matching' fd_sigma = fa.sigma - fb.sigma fd.get_33stress(fd_sigma) fd.get_vm_stress() ##fd.get_33strain(fa.epsilon) ## fd.epsilon_vm = fa.epsilon_vm[::] return (fd.sigma_vm) / fa.sigma_vm
def find_err(fa, fb): """ Compare the two FlowCurve objects and return errors at indivial plastic levels. """ from MP.mat.mech import FlowCurve as FC fd = FC() if fa.nstp != fb.nstp: raise IOError,\ 'Number of data points are not matching' fd_sigma = fa.sigma - fb.sigma fd.get_33stress(fd_sigma) fd.get_vm_stress() ##fd.get_33strain(fa.epsilon) ## fd.epsilon_vm = fa.epsilon_vm[::] return (fd.sigma_vm) / fa.sigma_vm
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 compare_exp_mod(ntot_psi=21): import numpy as np import matplotlib.pyplot as plt from pepshkl import reader4 from RS import sff_converter from rs_exp import read_IGSF from MP.lib import mpl_lib from MP.mat.mech import FlowCurve as FC wf = mpl_lib.wide_fig sff_converter.main(fn='temp.sff',difile=None,itab=True, ieps0=4, fn_str='STR_STR.OUT') SF, dum = read_IGSF(fn='temp.sff',fn_str='STR_STR.OUT') SF.reduce_psi(bounds=[0.,0.5],ntot_psi=ntot_psi) SF.mask_vol() SF.plot(ylim=[-2,2]) ## biaxial flow = FC() exx = open('YJ_Bsteel_BB.sff','r').read().split('\n')[4].split()[1:] exx = np.array(exx,dtype='float'); eyy = exx[::]; ezz = -(exx+eyy) flow.epsilon_vm = abs(ezz) flow.nstp = len(ezz) SF, dum = read_IGSF(fn='YJ_Bsteel_BB.sff',fc=flow) SF.plot(mxnphi=3,ylim=[-2,2])
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 main_reader( path="../dat/23JUL12", fref="Bsteel_BB_00.txt", fn_sf="YJ_Bsteel_BB.sff", icheck=False, isym=False, fc=None, fn_str=None, ): """ Arguments ========= path (path that contains the data file) fref (reference data that gives strain and date-named for X-ray) fn_sf (stress factor file name) icheck isym fc (flow curve object) fn_str (stress-strain data file) """ if type(fc) == type(None) and type(fn_str) == type(None): print "---------------------------------------------" print "Strain information where SF/IG were measured" print "requires either fc or fn_str specified" print "If not the strain column in fn_sf is used," print "subsequent analysis is performed by assuming" print "that the sample is in equibiaxial strain" print "---------------------------------------------\n" # raw_input('press enter to proceed>>') # # dat = open('%s%s%s'%(path,sep,fn_sf)).read() # fn = os.path.join(path,fn_sf) # if os.path.isfile(fn): # dat = open(fn).read() if os.path.isfile(fn_sf): dat = open(fn_sf).read() else: print "Could not find fn_sf: " + fn_sf raise IOError, "tip: use the fully pathed file name" ## Find proper line-breaker lbs = ["\r", "\n"] lns = [] for i in xrange(len(lbs)): lns.append(len(dat.split(lbs[i]))) lns = np.array(lns) lb = lbs[lns.argmax()] ## -- dat_line = dat.split(lb) e1 = np.array(map(float, dat_line[4].split()[1:])) e2 = e1[::] e3 = -e1 - e2 from MP.mat.mech import FlowCurve as FC flow = FC() flow.get_strain(e1, 0, 0) flow.get_strain(e2, 1, 1) flow.get_strain(e3, 2, 2) flow.set_zero_shear_strain() flow.get_vm_strain() fc = flow elif type(fc) != type(None): print "fc was given" pass import copy EXP, SF, IG = rs_exp.read_main(path=path, fref=fref, fn_sf=fn_sf, fc=fc, fn_str=fn_str, icheck=icheck, isym=isym) ## interpolate based on experimental phis, psis, IG # EXP.plot(istps=[0,10,20]) # SF.plot() # IG.plot() print print "#-----------------------------------------------------#" print " Interpolate SF and IG for matching with D-spacings" SF_orig = copy.deepcopy(SF) IG_orig = copy.deepcopy(IG) SF_orig.flow.get_vm_strain() IG_orig.flow.get_vm_strain() SF.interp_strain(EXP.flow.epsilon_vm) SF.interp_psi(EXP.psis) ## in case that IG strain is available IG.interp_strain(EXP.flow.epsilon_vm) IG.interp_psi(EXP.psis) ## if not? if SF.phi != EXP.phis: print " ** Phi angles of SF are different **" if IG.phi != EXP.phis: print " ** Phi angles of IG are different **" print "#-----------------------------------------------------#" # SF.plot() # IG.plot() SF.determine_phis(phi_new=EXP.phi) IG.determine_phis(phi_new=EXP.phi) SF.plot() IG.plot() # EXP.plot(istps=np.arange(EXP.flow.nstp)[::7]) return EXP, SF, IG, SF_orig, IG_orig
def main_reader(path='../dat/23JUL12', fref='Bsteel_BB_00.txt', fn_sf='YJ_Bsteel_BB.sff', icheck=False, isym=False, fc=None, fn_str=None): """ Arguments ========= path (path that contains the data file) fref (reference data that gives strain and date-named for X-ray) fn_sf (stress factor file name) icheck isym fc (flow curve object) fn_str (stress-strain data file) """ if type(fc) == type(None) and type(fn_str) == type(None): print '---------------------------------------------' print 'Strain information where SF/IG were measured' print 'requires either fc or fn_str specified' print 'If not the strain column in fn_sf is used,' print 'subsequent analysis is performed by assuming' print 'that the sample is in equibiaxial strain' print '---------------------------------------------\n' # raw_input('press enter to proceed>>') # # dat = open('%s%s%s'%(path,sep,fn_sf)).read() # fn = os.path.join(path,fn_sf) # if os.path.isfile(fn): # dat = open(fn).read() if os.path.isfile(fn_sf): dat = open(fn_sf).read() else: print 'Could not find fn_sf: ' + fn_sf raise IOError, 'tip: use the fully pathed file name' ## Find proper line-breaker lbs = ['\r', '\n'] lns = [] for i in xrange(len(lbs)): lns.append(len(dat.split(lbs[i]))) lns = np.array(lns) lb = lbs[lns.argmax()] ## -- dat_line = dat.split(lb) e1 = np.array(map(float, dat_line[4].split()[1:])) e2 = e1[::] e3 = -e1 - e2 from MP.mat.mech import FlowCurve as FC flow = FC() flow.get_strain(e1, 0, 0) flow.get_strain(e2, 1, 1) flow.get_strain(e3, 2, 2) flow.set_zero_shear_strain() flow.get_vm_strain() fc = flow elif type(fc) != type(None): print 'fc was given' pass import copy EXP, SF, IG = rs_exp.read_main(path=path, fref=fref, fn_sf=fn_sf, fc=fc, fn_str=fn_str, icheck=icheck, isym=isym) ## interpolate based on experimental phis, psis, IG # EXP.plot(istps=[0,10,20]) # SF.plot() # IG.plot() print print '#-----------------------------------------------------#' print ' Interpolate SF and IG for matching with D-spacings' SF_orig = copy.deepcopy(SF) IG_orig = copy.deepcopy(IG) SF_orig.flow.get_vm_strain() IG_orig.flow.get_vm_strain() SF.interp_strain(EXP.flow.epsilon_vm) SF.interp_psi(EXP.psis) ## in case that IG strain is available IG.interp_strain(EXP.flow.epsilon_vm) IG.interp_psi(EXP.psis) ## if not? if SF.phi != EXP.phis: print ' ** Phi angles of SF are different **' if IG.phi != EXP.phis: print ' ** Phi angles of IG are different **' print '#-----------------------------------------------------#' # SF.plot() # IG.plot() SF.determine_phis(phi_new=EXP.phi) IG.determine_phis(phi_new=EXP.phi) SF.plot() IG.plot() #EXP.plot(istps=np.arange(EXP.flow.nstp)[::7]) return EXP, SF, IG, SF_orig, IG_orig
def main_reader(path='../dat/23JUL12', fref='Bsteel_BB_00.txt', fn_sf ='YJ_Bsteel_BB.sff',icheck=False,isym=False, fc=None,fn_str=None): """ Arguments ========= path fref fn_sf icheck isym fc fn_str """ if type(fc)==type(None) and type(fn_str)==type(None): print '---------------------------------------------' print 'Strain information where SF/IG were measured' print 'requires either fc or fn_str specified' print 'If not the strain column in fn_sf is used,' print 'subsequent analysis is performed by assuming' print 'that the sample is in equibiaxial strain' print '---------------------------------------------\n' raw_input('press enter to proceed>>') # # dat = open('%s%s%s'%(path,sep,fn_sf)).read() # fn = os.path.join(path,fn_sf) # if os.path.isfile(fn): # dat = open(fn).read() if os.path.isfile(fn_sf): dat = open(fn_sf).read() else: print 'Could not find fn_sf: '+fn_sf raise IOError, 'tip: use the fully pathed file name' ## Find proper line-breaker lbs=['\r','\n']; lns = [] for i in range(len(lbs)): lns.append(len(dat.split(lbs[i]))) lns = np.array(lns) lb = lbs[lns.argmax()] ## -- dat_line = dat.split(lb) e1 = np.array(map(float,dat_line[4].split()[1:])) e2 = e1[::] e3 = -e1-e2 from MP.mat.mech import FlowCurve as FC flow = FC() flow.get_strain(e1,0,0) flow.get_strain(e2,1,1) flow.get_strain(e3,2,2) flow.set_zero_shear_strain() flow.get_vm_strain() fc = flow elif type(fc)!=type(None): print 'fc was given' pass import copy EXP, SF, IG = rs_exp.read_main( path=path,fref=fref,fn_sf=fn_sf,fc=fc,fn_str=fn_str, icheck=icheck,isym=isym) ## interpolate based on experimental phis, psis, IG # EXP.plot(istps=[0,10,20]) # SF.plot() # IG.plot() print print '#-----------------------------------------------------#' print ' Interpolate SF and IG for matching with D-spacings' SF_orig = copy.deepcopy(SF) IG_orig = copy.deepcopy(IG) SF_orig.flow.get_vm_strain() IG_orig.flow.get_vm_strain() SF.interp_strain(EXP.flow.epsilon_vm) IG.interp_strain(EXP.flow.epsilon_vm) SF.interp_psi(EXP.psis) IG.interp_psi(EXP.psis) if SF.phi!=EXP.phis: print ' ** Phi angles of SF are different **' if IG.phi!=EXP.phis: print ' ** Phi angles of IG are different **' print '#-----------------------------------------------------#' # SF.plot() # IG.plot() SF.determine_phis(phi_new=EXP.phi) IG.determine_phis(phi_new=EXP.phi) SF.plot() IG.plot() #EXP.plot(istps=np.arange(EXP.flow.nstp)[::7]) return EXP, SF, IG, SF_orig, IG_orig
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