def test1(): import upf;reload(upf) import matplotlib.pyplot as plt import os ex_text_filename = os.path.join( path_to_vpsc,'examples', 'ex15_FLD','magnesium','az31','az31dirk.cmb') mypf =upf.polefigure( filename=ex_text_filename, csym='hexag',cdim=[1,1,1.6235]) fig = mypf.pf_new( poles=[[0,0,0,2],[1,0,-1,1],[1,1,-2,1]],nlev=5, mode='line',cmap='jet',ires=True,mn=0.5, dth=15,dph=15) fig = mypf.pf_new( poles=[[0,0,0,2],[1,0,-1,1],[1,1,-2,1]],nlev=5, mode='fill',cmap='jet',ires=True,mn=0.5, dth=15,dph=15) fig = mypf.pf_new( poles=[[0,0,0,2],[1,0,-1,1],[1,1,-2,1]],nlev=5, mode='fill',cmap='rainbow',ires=True,mn=0.5, dth=15,dph=15)
def main(component='cube', ngrain=100, w0=10, ifig=1): """ arguments ========= component = 'cube', 'copper', 'rbrass', 'goss' ngrain = 100 w0 = 10 ifig = 1 """ import upf angs = comp2euler(component) xtal = [] for i in range(len(angs)): myx = textur(p1=angs[i][0], p=angs[i][1], p2=angs[i][2], w0=w0, ngrain = ngrain/len(angs), filename='dum', iplot=False) myx.gr for j in range(len(myx.gr)): xtal.append(myx.gr[j]) mypf = upf.polefigure(grains = xtal, csym='cubic') mypf.pf(pole=[[1,0,0],[1,1,0],[1,1,1]], ifig=ifig, mode='contourf') f = open('%s%s.cmb'%(str(len(xtal)),component), 'w') f.write('dum\ndum\ndum\nB %i\n'%len(xtal)) for i in range(len(xtal)): f.write('%9.2f %9.2f %9.2f %s\n'%( xtal[i][0], xtal[i][1], xtal[i][2], str(1./len(xtal)))) return xtal
def main(component='cube', ngrain=100, w0=10, ifig=1): """ arguments ========= component = 'cube', 'copper', 'rbrass', 'goss' ngrain = 100 w0 = 10 ifig = 1 """ import upf angs = comp2euler(component) xtal = [] for i in range(len(angs)): myx = textur(p1=angs[i][0], p=angs[i][1], p2=angs[i][2], w0=w0, ngrain=ngrain / len(angs), filename='dum', iplot=False) myx.gr for j in range(len(myx.gr)): xtal.append(myx.gr[j]) mypf = upf.polefigure(grains=xtal, csym='cubic') mypf.pf(pole=[[1, 0, 0], [1, 1, 0], [1, 1, 1]], ifig=ifig, mode='contourf') f = open('%s%s.cmb' % (str(len(xtal)), component), 'w') f.write('dum\ndum\ndum\nB %i\n' % len(xtal)) for i in range(len(xtal)): f.write('%9.2f %9.2f %9.2f %s\n' % (xtal[i][0], xtal[i][1], xtal[i][2], str(1. / len(xtal)))) return xtal
def main(odf, ngrain, outputfile, iplot=True, irandom=True): """ Arguments odf: od filename ngrain : number of grains in the RVE output : combined file iplot =True : flag for plotting """ import upf import matplotlib.pyplot as plt temp = RVE(ngrain=ngrain, odf=odf, cmbfile=outputfile) if iplot==True: mypf = upf.polefigure(grains = temp.rve, csym='cubic') mypf.pf(pole=[[1,0,0],[1,1,0],[1,1,1]], mode='contourf', ifig=2) plt.show() pass if irandom==True: filename='iso.cmb' FILE = open(filename, 'w') FILE.writelines('dummy\ndummy\ndummy\n %s %i\n'%('B', int(ngrain))) for i in range(len(temp.gr)): FILE.writelines('%11.7f %11.7f %11.7f %10.4e \n'% (temp.gr[i][0], temp.gr[i][1], temp.gr[i][2], temp.gr[i][3])) pass FILE.close() #np.savetxt(filename, temp.gr) print 'The random isotropic aggregate is written to %s'%filename pass pass
def __init__(self, p1, p2, p, w0, ngrain, filename='temp.txt', dist='g', iplot=True, mode='contour', pole=[[1, 0, 0], [1, 1, 0], [1, 1, 1]], ifig=1): f = open(filename, 'w') f.writelines('Designed texture '\ 'using probability distributions \n') f.writelines('Given Euler angles are as below \n') f.writelines('ph1, phi2, PHI = ' + str(p1) + str(p2) + str(p)) f.write('\nB ' + str(ngrain)) self.gr = [] for i in range(ngrain): txt = text(p1=p1, p2=p2, p=p, w0=w0, dist=dist) angle = txt.angle f.write('\n %9.2f %9.2f %9.2f %9.3f' % (angle[0], angle[1], angle[2], 0.1)) self.gr.append([angle[0], angle[1], angle[2], 0.1]) f.close() if iplot == True: mypf = upf.polefigure(filename=filename, csym='cubic') mypf.pf(pole=pole, mode=mode, ifig=ifig)
def main(ngrains=100, sigma=15., c2a=1.6235, mu=0., prc='cst', isc=False, tilt_1=0., tilts_about_ax1=0., tilts_about_ax2=0.): """ Arguments ========= ngrains = 100 sigma = 15. c2a = 1.6235 prc = 'cst' or 'ext' tilts_about_ax1 = 0. -- Systematic tilting abount axis 1 tilts_about_ax2 = 0. -- Systematic tilting abount axis 2 tilt_1 = 0. -- Tilt in the basis pole. (systematic tilting away from ND) """ if isc: h = mmm() else: h = np.array([np.identity(3)]) gr = [] for i in xrange(ngrains): dth = random.uniform(-180., 180.) if prc == 'cst': g = gen_gr_fiber(th=dth, sigma=sigma, mu=mu, tilt=tilt_1, iopt=0) # Basal//ND elif prc == 'ext': g = gen_gr_fiber(th=dth, sigma=sigma, mu=mu, tilt=tilt_1, iopt=1) # Basal//ED else: raise IOError, 'Unexpected option' for j in xrange(len(h)): temp = np.dot(g, h[j].T) ## tilts_about_ax1 if abs(tilts_about_ax1) > 0: g_tilt = rd_rot(tilts_about_ax1) temp = np.dot(temp, g_tilt.T) ## tilts_about_ax2? elif abs(tilts_about_ax2) > 0: g_tilt = td_rot(tilts_about_ax2) temp = np.dot(temp, g_tilt.T) elif abs(tilts_about_ax2) > 0 and abs(tilts_about_ax2) > 0: raise IOError, 'One tilt at a time is allowed.' phi1, phi, phi2 = euler(a=temp, echo=False) gr.append([phi1, phi, phi2, 1. / ngrains]) mypf = upf.polefigure(grains=gr, csym='hexag', cdim=[1, 1, c2a]) mypf.pf_new(poles=[[0, 0, 0, 2], [1, 0, -1, 0]], cmap='jet', ix='TD', iy='RD') return np.array(gr)
def progressive_texture(steps=[0,1]): import upf import matplotlib.pyplot as plt plt.ioff() for i in range(len(steps)): step = steps[i] gr=readerstep(fn='TEX_PH1.OUT', step=step, mode='texture') mypf=upf.polefigure(csym='cubic',grains=gr) mypf.pf(pole=[[0,0,1]],ifig=i+1) plt.figure(i+1).savefig('pf_%i.pdf'%(steps[i]+1)) plt.close(i+1) print 'i th pf saved'
def progressive_texture(steps=[0, 1]): import upf import matplotlib.pyplot as plt plt.ioff() for i in range(len(steps)): step = steps[i] gr = readerstep(fn='TEX_PH1.OUT', step=step, mode='texture') mypf = upf.polefigure(csym='cubic', grains=gr) mypf.pf(pole=[[0, 0, 1]], ifig=i + 1) plt.figure(i + 1).savefig('pf_%i.pdf' % (steps[i] + 1)) plt.close(i + 1) print 'i th pf saved'
def plot(self,csym='cubic',**kwargs): """ Plot pole figure Arguments --------- csym : crystal symmetry **kwargs: kw arguments to be passed to pf_new """ import upf,time mypf = upf.polefigure(grains = self.rve, csym=csym) fig=mypf.pf_new(**kwargs) plt.show() return fig
def main(hkl,uvw,w0,ngr=1,ifig=10): import upf import matplotlib.pyplot as plt phi1,phi,phi2 = miller2euler(hkl,uvw) mat0 = eul(phi1,phi,phi2,echo=False) # ca<-sa # print 'mat0:', mat0 mmm = sample_mmm() mats = [mat0] # print mats for i in range(len(mmm)): mats.append(np.dot(mat0,mmm[i])) gauss = random.gauss r = random.random # print 'ind_mat:', ind_mat # print 'ngr:', ngr grs = [] for i in range(ngr): ind_mat = int(r() * len(mats)) if w0==0: w=0 else: w = gauss(mu=0., sigma=w0) # print 'w:',w # print 'mats:', mats[ind_mat] C = rot_vectang(th=w, r=mats[ind_mat]) # print C phi1, phi, phi2 = eul(a=C, echo=False) grs.append([phi1,phi,phi2,1]) #print phi1,phi,phi2 #print grs mypf = upf.polefigure(grains=grs,csym='cubic') mypf.pf(mode='contourf',cmode='gray_r',ifig=ifig) #mypf.pf(mode='dot',cmode='gray_r',ifig=ifig) plt.tight_layout() hkl = '%i%i%i'%(hkl[0],hkl[1],hkl[2]) uvw = '%i%i%i'%(uvw[0],uvw[1],uvw[2]) fn = 'hkl_%s_uvw_%s_th_%i_ngr_%i.txt'%(hkl,uvw,w0,ngr) f = open(fn,'w') f.writelines(' dum\n dum\n dum\n B %i \n'%ngr) for i in range(ngr): f.writelines('%8.3f %8.3f %8.3f %12.7f\n'%( grs[i][0],grs[i][1],grs[i][2],1./ngr)) f.close() print '%s has created'%fn
def main(hkl, uvw, w0, ngr=1, ifig=10): import upf import matplotlib.pyplot as plt phi1, phi, phi2 = miller2euler(hkl, uvw) mat0 = eul(phi1, phi, phi2, echo=False) # ca<-sa # print 'mat0:', mat0 mmm = sample_mmm() mats = [mat0] # print mats for i in range(len(mmm)): mats.append(np.dot(mat0, mmm[i])) gauss = random.gauss r = random.random # print 'ind_mat:', ind_mat # print 'ngr:', ngr grs = [] for i in range(ngr): ind_mat = int(r() * len(mats)) if w0 == 0: w = 0 else: w = gauss(mu=0., sigma=w0) # print 'w:',w # print 'mats:', mats[ind_mat] C = rot_vectang(th=w, r=mats[ind_mat]) # print C phi1, phi, phi2 = eul(a=C, echo=False) grs.append([phi1, phi, phi2, 1]) #print phi1,phi,phi2 #print grs mypf = upf.polefigure(grains=grs, csym='cubic') mypf.pf(mode='contourf', cmode='gray_r', ifig=ifig) #mypf.pf(mode='dot',cmode='gray_r',ifig=ifig) plt.tight_layout() hkl = '%i%i%i' % (hkl[0], hkl[1], hkl[2]) uvw = '%i%i%i' % (uvw[0], uvw[1], uvw[2]) fn = 'hkl_%s_uvw_%s_th_%i_ngr_%i.txt' % (hkl, uvw, w0, ngr) f = open(fn, 'w') f.writelines(' dum\n dum\n dum\n B %i \n' % ngr) for i in range(ngr): f.writelines('%8.3f %8.3f %8.3f %12.7f\n' % (grs[i][0], grs[i][1], grs[i][2], 1. / ngr)) f.close() print '%s has created' % fn
def main(fn='TEX_PH1.OUT', step=100, igr=1,ifig=3): """ Given the texture file, plots a continuous trace of texture evolution in the pole figure representation. Arguments ========= fn = 'TEX_PH1.OUT' step = 100 igr = 1 ifig = 3 """ import upf grains, eps = reader(fn, step, igr) # particular grain mypf = upf.polefigure(csym='cubic', grains=grains) mypf.pf(pole=[[0,0,1]], mode='trace',ifig=ifig)
def main(fn='TEX_PH1.OUT', step=100, igr=1, ifig=3): """ Given the texture file, plots a continuous trace of texture evolution in the pole figure representation. Arguments ========= fn = 'TEX_PH1.OUT' step = 100 igr = 1 ifig = 3 """ import upf grains, eps = reader(fn, step, igr) # particular grain mypf = upf.polefigure(csym='cubic', grains=grains) mypf.pf(pole=[[0, 0, 1]], mode='trace', ifig=ifig)
def sampling(odf=None, p1=360., p2=90., *args): """ Sampling several representative grain sets. --------- Arguments odf = None : discrete OD file name *args: number of grains. (500,~) ------- Example In order to obtain 500, 1000, 2000, 4000, RVEs, follow the below: >>> import randomEuler >>> randomEuler.sampling('304_surface.TXT', 500,1000,2000,4000,...) . . . """ import upf files = [] print 'p1=', p1, 'p2=', p2 for i in range(len(args)): re = randomEuler(ngrain=args[i], p1=p1, p2=p2) re.odf_reading(odf) filename = "%s_%s%s" % (odf.split('.TXT')[0], str( args[i]).zfill(5), '.cmb') re.combine( filename ) #"%s_%s%s"%(odf.split('.TXT')[0],str(args[i]).zfill(5),'.cmb')) files.append(filename) pass ## pole figure plotting flag = raw_input('Polefigure? (bcc or fcc)') if flag == 'bcc' or 'fcc': for i in range(len(files)): pf = upf.polefigure(filename=files[i], csym='cubic', cdim=[1., 1., 1.], cang=[90., 90., 90.]) pf.pf(pole=[[1, 1, 1]], mode='contourf', ifig=1 + i, cmode=None) pass pass else: pass pass
def main(ngrains=100,sigma=15.,c2a=1.6235,mu=0., prc='cst',isc=False,tilt_1=0., tilts_about_ax1=0.,tilts_about_ax2=0.): """ Arguments ========= ngrains = 100 sigma = 15. c2a = 1.6235 prc = 'cst' or 'ext' tilts_about_ax1 = 0. -- Systematic tilting abount axis 1 tilts_about_ax2 = 0. -- Systematic tilting abount axis 2 tilt_1 = 0. -- Tilt in the basis pole. (systematic tilting away from ND) """ if isc: h = mmm() else: h=np.array([np.identity(3)]) gr = [] for i in xrange(ngrains): dth = random.uniform(-180., 180.) if prc=='cst': g = gen_gr_fiber(th=dth,sigma=sigma,mu=mu,tilt=tilt_1,iopt=0) # Basal//ND elif prc=='ext': g = gen_gr_fiber(th=dth,sigma=sigma,mu=mu,tilt=tilt_1,iopt=1) # Basal//ED else: raise IOError, 'Unexpected option' for j in xrange(len(h)): temp = np.dot(g,h[j].T) ## tilts_about_ax1 if abs(tilts_about_ax1)>0: g_tilt = rd_rot(tilts_about_ax1) temp = np.dot(temp,g_tilt.T) ## tilts_about_ax2? elif abs(tilts_about_ax2)>0: g_tilt = td_rot(tilts_about_ax2) temp = np.dot(temp,g_tilt.T) elif abs(tilts_about_ax2)>0 and abs(tilts_about_ax2)>0: raise IOError, 'One tilt at a time is allowed.' phi1,phi,phi2 = euler(a=temp, echo=False) gr.append([phi1,phi,phi2,1./ngrains]) mypf=upf.polefigure(grains=gr,csym='hexag',cdim=[1,1,c2a]) mypf.pf_new(poles=[[0,0,0,2],[1,0,-1,0]],cmap='jet',ix='TD',iy='RD') return np.array(gr)
def main(odf, ngrain, outputfile, iplot=True, irandom=False): """ Arguments ========= odf: od filename ngrain : number of grains in the RVE outputfile : combined file iplot =True : flag for plotting irandom=True """ import upf, time import matplotlib.pyplot as plt temp = RVE(ngrain=ngrain, odf=odf, cmbfile=outputfile) if iplot == True: mypf = upf.polefigure(grains=temp.rve, csym='cubic') mypf.pf(pole=[[1, 0, 0], [1, 1, 0], [1, 1, 1]], mode='contourf', ifig=2) plt.show() pass if irandom == True: filename = 'iso.cmb' FILE = open(filename, 'w') FILE.writelines( '%s\n%s\n%s\n %s %i\n' % (time.asctime(), 'Current texture file was made by cmb.py', 'contact: [email protected]', 'B', int(ngrain))) for i in range(len(temp.gr)): FILE.writelines( '%11.7f %11.7f %11.7f %10.4e \n' % (temp.gr[i][0], temp.gr[i][1], temp.gr[i][2], temp.gr[i][3])) pass FILE.close() #np.savetxt(filename, temp.gr) print 'The random isotropic aggregate is written to %s' % filename pass pass
def sampling(odf=None, p1=360., p2=90., *args): """ Sampling several representative grain sets. --------- Arguments odf = None : discrete OD file name *args: number of grains. (500,~) ------- Example In order to obtain 500, 1000, 2000, 4000, RVEs, follow the below: >>> import randomEuler >>> randomEuler.sampling('304_surface.TXT', 500,1000,2000,4000,...) . . . """ import upf files = [] print 'p1=', p1, 'p2=', p2 for i in range(len(args)): re = randomEuler(ngrain=args[i], p1=p1, p2=p2) re.odf_reading(odf) filename = "%s_%s%s"%(odf.split('.TXT')[0],str(args[i]).zfill(5),'.cmb') re.combine(filename) #"%s_%s%s"%(odf.split('.TXT')[0],str(args[i]).zfill(5),'.cmb')) files.append(filename) pass ## pole figure plotting flag = raw_input('Polefigure? (bcc or fcc)') if flag=='bcc' or 'fcc': for i in range(len(files)): pf = upf.polefigure(filename=files[i], csym='cubic', cdim=[1.,1.,1.], cang=[90.,90.,90.]) pf.pf(pole=[[1,1,1]], mode='contourf', ifig=1+i, cmode=None) pass pass else: pass pass
def test1(): import upf reload(upf) import matplotlib.pyplot as plt import os ex_text_filename = os.path.join(path_to_vpsc, 'examples', 'ex15_FLD', 'magnesium', 'az31', 'az31dirk.cmb') mypf = upf.polefigure(filename=ex_text_filename, csym='hexag', cdim=[1, 1, 1.6235]) fig = mypf.pf_new(poles=[[0, 0, 0, 2], [1, 0, -1, 1], [1, 1, -2, 1]], nlev=5, mode='line', cmap='jet', ires=True, mn=0.5, dth=15, dph=15) fig = mypf.pf_new(poles=[[0, 0, 0, 2], [1, 0, -1, 1], [1, 1, -2, 1]], nlev=5, mode='fill', cmap='jet', ires=True, mn=0.5, dth=15, dph=15) fig = mypf.pf_new(poles=[[0, 0, 0, 2], [1, 0, -1, 1], [1, 1, -2, 1]], nlev=5, mode='fill', cmap='rainbow', ires=True, mn=0.5, dth=15, dph=15)
def __init__(self, p1, p2, p, w0, ngrain, filename='temp.txt', dist='g', iplot=True, mode='contour', pole=[[1,0,0],[1,1,0],[1,1,1]], ifig=1): f = open(filename, 'w') f.writelines('Designed texture '\ 'using probability distributions \n') f.writelines('Given Euler angles are as below \n') f.writelines('ph1, phi2, PHI = ' + str(p1) + str(p2)+ str(p) ) f.write('\nB '+ str(ngrain)) self.gr = [] for i in range(ngrain): txt = text(p1=p1, p2=p2, p=p, w0=w0, dist=dist) angle = txt.angle f.write('\n %9.2f %9.2f %9.2f %9.3f'%( angle[0],angle[1],angle[2], 0.1)) self.gr.append([angle[0],angle[1],angle[2], 0.1]) f.close() if iplot==True: mypf = upf.polefigure(filename=filename, csym='cubic') mypf.pf(pole=pole, mode=mode, ifig=ifig)
def sampling_simplex(odf=None, iang = 10., ngrain=100,maxiter=40,xtol=10, header = None, p1=360., p2=90., iplot=False,ifig=30): """ RVE sampling over an OD file using an optimization scheme argument odf = grided crystallograhpic orientation distribution file iang = initial anglular increment ngrain = 100, # the targetted number of grains maxiter = 40, maximum number of iteration for which the optimization loop iterates xtol = 10, the tolerance header = None p1 = 360, (maximum phi1 angle) p2 = 90 , (maximum phi2 angle) """ import matplotlib.pyplot as plt #import upf from scipy.optimize import fmin #optimization scheme rst = fmin(__refunc__, #function to be optimized [iang,0], # the parameters args=(ngrain,p1,p2), # *args callback = __callback__, # callback function xtol = xtol, ##changeable... maxiter=maxiter ) # raw_input('press enter to close >>>') # plt.close() print 'angle =', rst grains = [] while True: tmp = randomEuler(d_ang=rst[0], p1=p1, p2=p2, echo=False) grains.append(tmp.ngr) if tmp.ngr==ngrain: break pass print "-----------------------" print "Interation: %i"%len(grains) print "mean number: %6.2f"%np.array(grains).mean() print "-----------------------" tmp.odf_reading(odf) if header==None: filename= '%s.cmb'%str(ngrain).zfill(5) else: filename= '%s_%s.cmb'%(header, str(ngrain).zfill(5)) tmp.combine(filename) print "written to '%s'"%filename if iplot==True: import upf pf = upf.polefigure(filename=filename, csym='cubic', cdim=[1.,1.,1.], cang=[90.,90.,90.]) pf.pf(pole=[[1,0,0],[1,1,0],[1,1,1]], mode='contourf', ifig=ifig) pass return rst
def c2e(component='cube', ngrain=100, w0=10, ifig=1, mode='contour'): """ Provided (hkl)// ND and [uvw]//RD, arguments ========= component = 'cube' ngrain = 100 w0 = 10 ifig = 1 mode = 'contour' """ import numpy as np from euler import euler import upf comp = component.lower() print comp if comp == 'cube': hkl = [1, 0, 0] uvw = [0, 1, 0] elif comp == 'copper': hkl = [1, 1, 2] uvw = [-1, -1, 1] elif comp == 'goss': hkl = [1, 1, 0] uvw = [0, 0, 1] elif comp == 'rbrass': hkl = [-1, 1, 0] uvw = [1, 1, 1] print 'hkl', hkl print 'uvw', uvw, '\n' # mat0: trasformation matrix that converts # sample axes to crystal ones [ca<-sa] mat0 = miller2mat(hkl=map(round, hkl), uvw=map(round, uvw)) print 'mat0' for i in range(len(mat0)): for j in range(len(mat0[i])): print '%5.1f ' % mat0[i][j], print '' # Mirror reflection by RD and TD in the sample coordinate system. # mat0[ca<-sa] RD, TD = orthogonal() mat1 = np.dot(mat0, RD) mat2 = np.dot(mat0, TD) mat3 = np.dot(np.dot(mat0, RD), TD) print 'mat1' for i in range(len(mat1)): for j in range(len(mat1[i])): print '%5.1f ' % mat1[i][j], print '' print 'mat2' for i in range(len(mat2)): for j in range(len(mat2[i])): print '%5.1f ' % mat2[i][j], print '' print 'mat3' for i in range(len(mat3)): for j in range(len(mat3[i])): print '%5.1f ' % mat3[i][j], print '' ang0 = euler(a=mat0, echo=False) ang1 = euler(a=mat1, echo=False) ang2 = euler(a=mat2, echo=False) ang3 = euler(a=mat3, echo=False) angs = [ang0, ang1, ang2, ang3] for i in range(len(angs)): for j in iter(angs[i]): print '%5.1f ' % j, print '' xtal = [] for i in range(4): phi1, p, phi2 = angs[i] myx = textur(p1=phi1, p=p, p2=phi2, w0=w0, ngrain=ngrain / 4, filename='dum', iplot=False) for j in range(len(myx.gr)): xtal.append(myx.gr[j]) mypf = upf.polefigure(grains=xtal, csym='cubic') mypf.pf(pole=[[1, 0, 0], [1, 1, 0], [1, 1, 1]], mode=mode, ifig=ifig) ## Write gr2f(gr=xtal, header='module: %s, w0: %i' % ('ce2', w0), filename='%i%s%i_%s.cmb' % (len(xtal), component, w0, 'ce2')) return xtal
def main(ngrains=100,sigma=5.,iopt=1,ifig=1,fiber='gamma', iexit=False,ipfplot=False): """ Arguments ========= ngrains = 100 sigma = 5. iopt = 1 (1: gauss (recommended); 2: expov; 3: logno; 4: norma) ifig = 1 fiber = 'gamma', 'alpha', 'eta', 'epsilon', 'sigma', 'random' ipfplot = False Returns ------- It returns the poly-crystal aggregate in the form of numpy's ndarray. """ import upf import matplotlib.pyplot as plt import cmb # h = mmm() ## m-m-m sample symmetry is applied. h = [np.identity(3)] gr = [] for i in xrange(ngrains): dth = random.uniform(-180., 180.) if fiber in ['gamma','alpha', 'eta', 'epsilon', 'sigma']: g = gen_gr_fiber(dth,sigma,iopt,fiber) elif fiber=='random': g = cmb.randomGrain(360,360,360) for j in xrange(len(h)): temp = np.dot(g,h[j].T) phi1,phi,phi2 = euler(a=temp, echo=False) gr.append([phi1,phi,phi2,1./ngrains]) if iexit: return np.array(gr) fn = '%s_fib_ngr%s_sigma%s.cmb'%(fiber,str(len(gr)).zfill(5),str(sigma).zfill(3)) f = open(fn,'w') f.writelines('Artificial %s fibered polycrystal aggregate\n'%fiber) f.writelines('bcc_rolling_fiber.py python script\n') f.writelines('distribution: ') if iopt==1: f.writelines(' gauss') if iopt==2: f.writelines(' expov') if iopt==3: f.writelines(' logno') if iopt==4: f.writelines(' norma') f.writelines('\n') f.writelines('B %i\n'%ngrains) for i in xrange(len(gr)): f.writelines('%+7.3f %+7.3f %+7.3f %+13.4e\n'%( gr[i][0], gr[i][1], gr[i][2], 1./len(gr))) if ipfplot: mypf1 = upf.polefigure(grains=gr,csym='cubic') mypf1.pf_new(poles=[[1,0,0],[1,1,0],[1,1,1]],ix='RD',iy='TD') fig=plt.gcf() fig.tight_layout() print 'aggregate saved to %s'%fn fig.savefig( '%s_contf.pdf'%(fn.split('.cmb')[0]), bbox_inches='tight') fig.savefig( '%s_contf.png'%(fn.split('.cmb')[0]), bbox_inches='tight') fig.clf() plt.close(fig) return np.array(gr),fn
def c2e(component='cube', ngrain=100, w0=10, ifig=1, mode='contour'): """ Provided (hkl)// ND and [uvw]//RD, arguments ========= component = 'cube' ngrain = 100 w0 = 10 ifig = 1 mode = 'contour' """ import numpy as np from euler import euler import upf comp = component.lower() print comp if comp=='cube': hkl=[1,0,0] uvw=[0,1,0] elif comp=='copper': hkl=[1,1,2] uvw=[-1,-1,1] elif comp=='goss': hkl=[1,1,0] uvw=[0,0,1] elif comp=='rbrass': hkl=[-1,1,0] uvw=[1,1,1] print 'hkl',hkl print 'uvw',uvw,'\n' # mat0: trasformation matrix that converts # sample axes to crystal ones [ca<-sa] mat0 = miller2mat(hkl=map(round, hkl), uvw=map(round, uvw)) print 'mat0' for i in range(len(mat0)): for j in range(len(mat0[i])): print '%5.1f '%mat0[i][j], print '' # Mirror reflection by RD and TD in the sample coordinate system. # mat0[ca<-sa] RD, TD = orthogonal() mat1 = np.dot(mat0, RD) mat2 = np.dot(mat0, TD) mat3 = np.dot(np.dot(mat0, RD), TD) print 'mat1' for i in range(len(mat1)): for j in range(len(mat1[i])): print '%5.1f '%mat1[i][j], print '' print 'mat2' for i in range(len(mat2)): for j in range(len(mat2[i])): print '%5.1f '%mat2[i][j], print '' print 'mat3' for i in range(len(mat3)): for j in range(len(mat3[i])): print '%5.1f '%mat3[i][j], print '' ang0 = euler(a=mat0, echo=False) ang1 = euler(a=mat1, echo=False) ang2 = euler(a=mat2, echo=False) ang3 = euler(a=mat3, echo=False) angs = [ang0, ang1, ang2, ang3] for i in range(len(angs)): for j in iter(angs[i]): print '%5.1f '%j, print '' xtal = [] for i in range(4): phi1, p, phi2 = angs[i] myx = textur(p1=phi1,p=p, p2=phi2, w0=w0, ngrain = ngrain/4, filename='dum', iplot=False) for j in range(len(myx.gr)): xtal.append(myx.gr[j]) mypf = upf.polefigure(grains=xtal,csym='cubic') mypf.pf(pole=[[1,0,0],[1,1,0],[1,1,1]], mode=mode, ifig=ifig) ## Write gr2f(gr=xtal, header='module: %s, w0: %i'%('ce2', w0), filename='%i%s%i_%s.cmb'%(len(xtal), component, w0, 'ce2')) return xtal
def ex(fact=100, res=1.0, filename=None, ngrain=None): kde = stats.gaussian_kde mypf = upf.polefigure(ngrain=ngrain, filename=filename, csym='cubic') mypf.pf(pole=[[1, 0, 0]], mode='contourf') # PF[# of pole, mgrid(rot=azmthl), ngrid(tilt= declination)] PF = mypf.pfnodes[0] mn, nn = PF.shape dbeta = 360. / (mn - 1) # Rotating dalpha = 90. / (nn - 1) # tilting beta = np.linspace(0., 360., mn) # 0.~360. alpha = np.linspace(0., 90., nn) # 0.~90. #dum1 = np.arange(0.,360. + res/10., res) #dum2 = np.arange(0.,90. + res/10., res) x = [] y = [] #len(dum2))) # |---------------| # | | | | | # |---------------| # | | | | | # |---------------| # | | | | | # |---------------| # | | | | | # |---------------| maxint = max(PF.flatten()) for i in range(len(PF)): for j in range(len(PF[i])): nsample = int(PF[i][j] / maxint * fact) for k in range(nsample): x.append(beta[i]) y.append(alpha[j]) # For a new resolution beta = np.arange(0., 360. + res / 2., res) alpha = np.arange(0., 90. + res / 2., res) A, B = np.meshgrid(alpha, beta) positions = np.vstack([B.ravel(), A.ravel()]) values = np.vstack([x, y]) # beta, alpha kernel = stats.gaussian_kde(values) Z = np.reshape(kernel.evaluate(positions).T, A.shape) plt.figure(3) ax = plt.gca() ax.set_frame_on(False) ax.set_aspect('equal') ax.set_axis_off() rx, ry = upf.circle() ax.plot(rx, ry, 'k') pi = np.pi nm = (360.0 - 0.) / res nn = (180. - 90.) / res theta = np.linspace(pi, pi / 2., nn + 1) phi = np.linspace(0., 2. * pi, nm + 1) r = np.sin(theta) / (1 - np.cos(theta)) R, PHI = np.meshgrid(r, phi) PHI = PHI + pi / 2. x = R * np.cos(PHI) y = R * np.sin(PHI) ax.contourf(x, y, Z)
def ex(fact=100, res=1.0,filename=None,ngrain=None): kde = stats.gaussian_kde mypf = upf.polefigure(ngrain=ngrain, filename=filename, csym='cubic') mypf.pf(pole=[[1,0,0]],mode='contourf') # PF[# of pole, mgrid(rot=azmthl), ngrid(tilt= declination)] PF = mypf.pfnodes[0] mn, nn = PF.shape dbeta = 360./(mn -1) # Rotating dalpha = 90./(nn-1) # tilting beta = np.linspace(0.,360., mn) # 0.~360. alpha = np.linspace(0., 90., nn) # 0.~90. #dum1 = np.arange(0.,360. + res/10., res) #dum2 = np.arange(0.,90. + res/10., res) x = [] y = [] #len(dum2))) # |---------------| # | | | | | # |---------------| # | | | | | # |---------------| # | | | | | # |---------------| # | | | | | # |---------------| maxint = max(PF.flatten()) for i in range(len(PF)): for j in range(len(PF[i])): nsample = int(PF[i][j]/maxint*fact) for k in range(nsample): x.append(beta[i]) y.append(alpha[j]) # For a new resolution beta = np.arange(0.,360.+res/2.,res) alpha = np.arange(0.,90.+res/2.,res) A, B = np.meshgrid(alpha, beta) positions = np.vstack([B.ravel(), A.ravel()]) values = np.vstack([x,y]) # beta, alpha kernel = stats.gaussian_kde(values) Z = np.reshape(kernel.evaluate(positions).T, A.shape) plt.figure(3) ax = plt.gca() ax.set_frame_on(False) ax.set_aspect('equal') ax.set_axis_off() rx, ry = upf.circle() ax.plot(rx,ry,'k') pi = np.pi nm = (360.0-0.)/res; nn = (180.-90.)/res theta = np.linspace(pi, pi/2., nn+1) phi = np.linspace(0.,2.*pi, nm+1) r = np.sin(theta)/(1-np.cos(theta)) R, PHI = np.meshgrid(r,phi) PHI = PHI + pi/2. x = R*np.cos(PHI); y= R*np.sin(PHI) ax.contourf(x, y, Z)
def sampling_simplex(odf=None, iang=10., ngrain=100, maxiter=40, xtol=10, header=None, p1=360., p2=90., iplot=False, ifig=30): """ RVE sampling over an OD file using an optimization scheme argument odf = grided crystallograhpic orientation distribution file iang = initial anglular increment ngrain = 100, # the targetted number of grains maxiter = 40, maximum number of iteration for which the optimization loop iterates xtol = 10, the tolerance header = None p1 = 360, (maximum phi1 angle) p2 = 90 , (maximum phi2 angle) """ import matplotlib.pyplot as plt #import upf from scipy.optimize import fmin #optimization scheme rst = fmin( __refunc__, #function to be optimized [iang, 0], # the parameters args=(ngrain, p1, p2), # *args callback=__callback__, # callback function xtol=xtol, ##changeable... maxiter=maxiter) # raw_input('press enter to close >>>') # plt.close() print 'angle =', rst grains = [] while True: tmp = randomEuler(d_ang=rst[0], p1=p1, p2=p2, echo=False) grains.append(tmp.ngr) if tmp.ngr == ngrain: break pass print "-----------------------" print "Interation: %i" % len(grains) print "mean number: %6.2f" % np.array(grains).mean() print "-----------------------" tmp.odf_reading(odf) if header == None: filename = '%s.cmb' % str(ngrain).zfill(5) else: filename = '%s_%s.cmb' % (header, str(ngrain).zfill(5)) tmp.combine(filename) print "written to '%s'" % filename if iplot == True: import upf pf = upf.polefigure(filename=filename, csym='cubic', cdim=[1., 1., 1.], cang=[90., 90., 90.]) pf.pf(pole=[[1, 0, 0], [1, 1, 0], [1, 1, 1]], mode='contourf', ifig=ifig) pass return rst
def app(ngr=100,c2a=1.6235): """ Application for FLD-Mg paper Create a set of polycrystals ## ZE10 1) Small doughnut 2) Big dougnut ## AZ31 1) double let (tilt of 30 degree) 1) double let (tilt of 50 degree) Arguments --------- ngr=100 c2a=1.6235 c2a ratio for HCP structure """ import matplotlib.pyplot as plt ## small donuts # plt.gcf().clf() grs = main(mu=0,ngrains=ngr,tilt_1=30.,sigma=15) plt.gcf().savefig('small_doughnut.pdf',bbox_inches='tight') plt.gcf().clf() f = gen_file(lab='sm_doughnut',ngr=ngr) write_gr(f,grs) ## Big donuts grs = main(mu=0,ngrains=ngr,tilt_1=50.,sigma=15) plt.gcf().savefig('big_doughnut.pdf',bbox_inches='tight') plt.gcf().clf() f = gen_file(lab='big_doughnut',ngr=ngr) write_gr(f,grs) ## twin tilts (30). gr1=main(mu=0,ngrains=ngr/2,tilts_about_ax1=30.,sigma=45) plt.gcf().clf() gr2=main(mu=0,ngrains=ngr/2,tilts_about_ax1=-30.,sigma=45) plt.gcf().clf() grs =[] for i in xrange(len(gr1)): grs.append(gr1[i]) grs.append(gr2[i]) grs=np.array(grs) mypf=upf.polefigure(grains=grs,csym='hexag',cdim=[1,1,c2a]) mypf.pf_new(poles=[[0,0,0,1],[1,0,-1,0]],cmap='jet',ix='TD',iy='RD') plt.gcf().savefig('t30.pdf',bbox_inches='tight') f = gen_file(lab='dbl_lets_30',ngr=ngr) write_gr(f,grs) ## twin tilts (50). gr1=main(mu=0,ngrains=ngr/2,tilts_about_ax1=50.,sigma=45) plt.gcf().clf() gr2=main(mu=0,ngrains=ngr/2,tilts_about_ax1=-50.,sigma=45) plt.gcf().clf() gr =[] for i in xrange(len(gr1)): gr.append(gr1[i]) gr.append(gr2[i]) gr=np.array(gr) mypf=upf.polefigure(grains=gr,csym='hexag',cdim=[1,1,c2a]) mypf.pf_new(poles=[[0,0,0,1],[1,0,-1,0]],cmap='jet',ix='TD',iy='RD') plt.gcf().savefig('t50.pdf',bbox_inches='tight') plt.gcf().clf() f = gen_file(lab='dbl_lets_50',ngr=ngr) write_gr(f,gr)
def app(ngr=100,c2a=1.6235): """ Application for FLD-Mg paper Create a set of polycrystals ## ZE10 1) Small doughnut 2) Big dougnut ## AZ31 1) double let (tilt of 30 degree) 1) double let (tilt of 50 degree) Arguments --------- ngr=100 c2a=1.6235 c2a ratio for HCP structure """ import matplotlib.pyplot as plt ## small donuts # plt.gcf().clf() grs = main(mu=0,ngrains=ngr,tilt_1=30.,sigma=15) plt.gcf().savefig('small_doughnut.pdf',bbox_inches='tight') plt.gcf().clf() f = gen_file(lab='sm_doughnut',ngr=ngr) write_gr(f,grs) ## Big donuts grs = main(mu=0,ngrains=ngr,tilt_1=50.,sigma=15) plt.gcf().savefig('big_doughnut.pdf',bbox_inches='tight') plt.gcf().clf() f = gen_file(lab='big_doughnut',ngr=ngr) write_gr(f,grs) ## twin tilts (30). gr1=main(mu=0,ngrains=ngr/2,tilts_about_ax1=30.,sigma=45) plt.gcf().clf() gr2=main(mu=0,ngrains=ngr/2,tilts_about_ax1=-30.,sigma=45) plt.gcf().clf() grs =[] for i in range(len(gr1)): grs.append(gr1[i]) grs.append(gr2[i]) grs=np.array(grs) mypf=upf.polefigure(grains=grs,csym='hexag',cdim=[1,1,c2a]) mypf.pf_new(poles=[[0,0,0,1],[1,0,-1,0]],cmap='jet',ix='TD',iy='RD') plt.gcf().savefig('t30.pdf',bbox_inches='tight') f = gen_file(lab='dbl_lets_30',ngr=ngr) write_gr(f,grs) ## twin tilts (50). gr1=main(mu=0,ngrains=ngr/2,tilts_about_ax1=50.,sigma=45) plt.gcf().clf() gr2=main(mu=0,ngrains=ngr/2,tilts_about_ax1=-50.,sigma=45) plt.gcf().clf() gr =[] for i in range(len(gr1)): gr.append(gr1[i]) gr.append(gr2[i]) gr=np.array(gr) mypf=upf.polefigure(grains=gr,csym='hexag',cdim=[1,1,c2a]) mypf.pf_new(poles=[[0,0,0,1],[1,0,-1,0]],cmap='jet',ix='TD',iy='RD') plt.gcf().savefig('t50.pdf',bbox_inches='tight') plt.gcf().clf() f = gen_file(lab='dbl_lets_50',ngr=ngr) write_gr(f,gr)
def harm_pf(grains=None, filename=None, l=2, dm=7.5, dn=7.5, pole=[[1,0,0]], csym='cubic'): """ Something is wrong and I couldn't figure out. Further development is defferred. Arguments ========= grains = None filename = None l = 10 dm = 7.5 dn = 7.5 pole = [[1, 0, 0]] csym = 'cubic' """ import numpy as np import cmb from upf import polefigure, circle pi = np.pi if grains==None and filename==None: gr = cmb.random(filename='dum.tex',ngrain=1000, phi1=360., phi=90., phi2=180.) mypf = polefigure(grains=grains, csym=csym) else: mypf = polefigure(grains=grains, filename=filename, csym=csym) mypf.pf(pole=pole, dm=dm, dn=dn) hpf = [] import matplotlib.pyplot as plt fact = 2. #size factor figsize = (len(pole)*2.*fact, 1.*2.*fact) fig = plt.figure(33, figsize=figsize) ax = plt.gca() for ip in range(len(pole)): extended_PF = extPF(mypf.pfnodes[ip]) print 'extended_PF.shape', extended_PF.shape #dum = harm_PF(PF=mypf.pfnodes[ip], l=l) dum = harm_PF(PF=extended_PF, l=l) reduced_PF = redPF(dum) hpf.append(reduced_PF) # print 'max:', np.real(max(hpf[ip].flatten())) # print 'min:', np.real(min(hpf[ip].flatten())) theta = np.linspace(pi, pi/2., (90.)/dn + 1) phi = np.linspace(0.,2.*pi, (360.)/dm+1) r = np.sin(theta)/(1-np.cos(theta)) R, PHI = np.meshgrid(r,phi) PHI = PHI + pi/2. x = R*np.cos(PHI); y = R*np.sin(PHI) # return x, y, mypf.pfnodes[0] cnt = ax.contourf(x,y, hpf[0]) ax.set_frame_on(False) ax.set_axis_off() ax.set_aspect('equal') rx, ry = circle() ax.plot(rx, ry, 'k') ax.set_xlim(-1.2,1.5) ax.set_ylim(-1.2,1.5) tcolors = cnt.tcolors clev = cnt._levels for i in range(len(tcolors)): cc = tcolors[i][0][0:3] #if levels==None: if ip==len(pole)-1: ## level line ax.plot([1.28, 1.35], [1. - i * 0.2, 1. - i * 0.2], color=cc) ## level text ax.text(x=1.40, y= 1. - i*0.2 - 0.05, s='%3.2f'%(clev[i]), fontsize=4*fact) return hpf, mypf.pfnodes
def harm_pf(grains=None, filename=None, l=2, dm=7.5, dn=7.5, pole=[[1, 0, 0]], csym='cubic'): """ Something is wrong and I couldn't figure out. Further development is defferred. Arguments ========= grains = None filename = None l = 10 dm = 7.5 dn = 7.5 pole = [[1, 0, 0]] csym = 'cubic' """ import numpy as np import cmb from upf import polefigure, circle pi = np.pi if grains == None and filename == None: gr = cmb.random(filename='dum.tex', ngrain=1000, phi1=360., phi=90., phi2=180.) mypf = polefigure(grains=grains, csym=csym) else: mypf = polefigure(grains=grains, filename=filename, csym=csym) mypf.pf(pole=pole, dm=dm, dn=dn) hpf = [] import matplotlib.pyplot as plt fact = 2. #size factor figsize = (len(pole) * 2. * fact, 1. * 2. * fact) fig = plt.figure(33, figsize=figsize) ax = plt.gca() for ip in range(len(pole)): extended_PF = extPF(mypf.pfnodes[ip]) print 'extended_PF.shape', extended_PF.shape #dum = harm_PF(PF=mypf.pfnodes[ip], l=l) dum = harm_PF(PF=extended_PF, l=l) reduced_PF = redPF(dum) hpf.append(reduced_PF) # print 'max:', np.real(max(hpf[ip].flatten())) # print 'min:', np.real(min(hpf[ip].flatten())) theta = np.linspace(pi, pi / 2., (90.) / dn + 1) phi = np.linspace(0., 2. * pi, (360.) / dm + 1) r = np.sin(theta) / (1 - np.cos(theta)) R, PHI = np.meshgrid(r, phi) PHI = PHI + pi / 2. x = R * np.cos(PHI) y = R * np.sin(PHI) # return x, y, mypf.pfnodes[0] cnt = ax.contourf(x, y, hpf[0]) ax.set_frame_on(False) ax.set_axis_off() ax.set_aspect('equal') rx, ry = circle() ax.plot(rx, ry, 'k') ax.set_xlim(-1.2, 1.5) ax.set_ylim(-1.2, 1.5) tcolors = cnt.tcolors clev = cnt._levels for i in range(len(tcolors)): cc = tcolors[i][0][0:3] #if levels==None: if ip == len(pole) - 1: ## level line ax.plot([1.28, 1.35], [1. - i * 0.2, 1. - i * 0.2], color=cc) ## level text ax.text(x=1.40, y=1. - i * 0.2 - 0.05, s='%3.2f' % (clev[i]), fontsize=4 * fact) return hpf, mypf.pfnodes