コード例 #1
0
ファイル: var_gam_fiber.py プロジェクト: usnistgov/texture
def main(ngrains=100, sigma=5.0, iopt=1, ifig=1):
    """
    arguments
    =========
    ngrains = 100
    sigma   = 5.
    iopt    = 1 (1: gauss (recommended); 2: expov; 3: logno; 4: norma)
    ifig    = 1
    """
    import upf
    import matplotlib.pyplot as plt

    h = mmm()
    gr = []
    for i in range(ngrains):
        dth = random.uniform(-180.0, 180.0)
        g = gen_gamma_gr(dth, sigma, iopt=iopt)
        for j in range(len(h)):
            temp = np.dot(g, h[j].T)
            phi1, phi, phi2 = euler(a=temp, echo=False)
            gr.append([phi1, phi, phi2, 1.0 / ngrains])

    fn = "gam_fib_ngr%s_sigma%s.cmb" % (str(len(gr)).zfill(5), str(sigma).zfill(3))
    f = open(fn, "w")
    f.writelines("Artificial gamma fibered polycrystal aggregate\n")
    f.writelines("var_gam_fiber.py python script\n")
    f.writelines("distribution: %s")
    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 range(len(gr)):
        f.writelines("%7.3f %7.3f %7.3f %13.4e\n" % (gr[i][0], gr[i][1], gr[i][2], 1.0 / len(gr)))

    upf.cubgr(gr=gr, ifig=ifig)
    plt.figure(ifig).savefig("%s.pdf" % (fn.split(".cmb")[0]))

    return np.array(gr)
コード例 #2
0
def rolling(fibers=['gamma','alpha','eta','epsilon','sigma'],
            wgts=[0.7,0.1,0.1,0.1],ifig=3,sigma=15,
            ngr=100):
    """
    """
    fn='rolling_texture_%s.cmb'%str(ngr).zfill(5)
    f = open(fn,'w')
    f.writelines('Artifical rolling texture for bcc\n')
    f.writelines('Combinations of:')
    for i in xrange(len(fibers)):
        f.writelines('%3i)  %s; '%(i+1,fibers[i]))
    f.writelines('\n')
    f.writelines('weigts of comp :')
    for i in xrange(len(fibers)):
        f.writelines('%3.1f;  '%wgts[i])
    f.writelines('\n')

    import upf
    import matplotlib.pyplot as plt
    wgts = np.array(wgts)
    wgts = wgts/wgts.sum()

    total_pop = []

    for i in xrange(len(fibers)):
        gr = main(ngrains=ngr/len(fibers),sigma=sigma,
                  iopt=1,iexit=True,fiber=fibers[i])
        grt = gr.T
        grt[-1] = grt[-1] * wgts[i]
        gr = grt.T
        for j in xrange(len(gr)):
            total_pop.append(gr[j])
    total_pop = np.array(total_pop)

    f.writelines('B %i\n'%len(total_pop))
    for i in xrange(len(total_pop)):
        f.writelines('%+7.3f %+7.3f %+7.3f %+13.4e\n'%(
            total_pop[i][0], total_pop[i][1], total_pop[i][2], 1./len(total_pop)))

    upf.cubgr(gr=total_pop,ifig=ifig)
    return total_pop
コード例 #3
0
def main(ngrains=100,sigma=5.,iopt=1,ifig=1):
    """
    arguments
    =========
    ngrains = 100
    sigma   = 5.
    iopt    = 1 (1: gauss (recommended); 2: expov; 3: logno; 4: norma)
    ifig    = 1
    """
    import upf
    import matplotlib.pyplot as plt
    h = mmm()
    gr = []
    for i in range(ngrains):
        dth = random.uniform(-180., 180.)
        g = gen_gamma_gr(dth, sigma, iopt=iopt)
        for j in range(len(h)):
            temp = np.dot(g,h[j].T)
            phi1,phi,phi2 = euler(a=temp, echo=False)
            gr.append([phi1,phi,phi2,1./ngrains])

    fn = 'gam_fib_ngr%s_sigma%s.cmb'%(str(len(gr)).zfill(5),str(sigma).zfill(3))
    f = open(fn,'w')
    f.writelines('Artificial gamma fibered polycrystal aggregate\n')
    f.writelines('var_gam_fiber.py python script\n')
    f.writelines('distribution: %s')
    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 range(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)))

    upf.cubgr(gr=gr,ifig=ifig)
    plt.figure(ifig).savefig('%s.pdf'%(fn.split('.cmb')[0]))

    return np.array(gr)
コード例 #4
0
def odf2dg(odfn=None, mmm=False, rot=0, fnout=None, ng=None):
    """
    write into weighted discrete grain files

    Arguments
    =========
    odfn = None
    mmm  = False
    rot  = 0
    """
    import os
    import matplotlib.pyplot as plt
    import numpy as np
    os.sys.path.append('/Users/yj/Dropbox/devel/EVPSC_f2py/pyscripts')
    os.sys.path.append('/Users/yj/Dropbox/devel/EVPSC_f2py/pyscripts/pf')

    import cmb, upf
    if type(ng) != type(None):
        ng = [20000]

    if mmm: ng = np.array(ng) / 4
    for igr in range(len(ng)):
        cmb.main(odf=odfn, ngrain=ng[igr], outputfile='dum.tex', iplot=False)
        # sample symmetry recovery when mmm has been applied (reduced 90x90x90)
        if mmm: grains = sample_mmm(fn='dum.tex')
        else: grains = np.loadtxt('dum.tex', skiprows=4)

        os.remove('dum.tex')
        grains = inplanerot(rot=rot, grains=grains)

        fout = open('%s_%i.cmb' % (fnout, len(grains)), 'w')
        fout.writelines('dummy\ndummy\ndummy\n B  %i\n ' % len(grains))

        for i in range(len(grains)):
            fout.writelines(
                '%.5f %.5f %.5f  %.7e\n' %
                (grains[i][0], grains[i][1], grains[i][2], grains[i][3]))
        upf.cubgr(gr=grains, ifig=igr, poles=[[1, 1, 0], [2, 0, 0], [2, 1, 1]])
        plt.gcf().savefig('pf_%i.pdf' % ng[igr])