Exemplo n.º 1
0
def reduce_go1_mat(l_pl1_g1, l_g1_go1):
    l_go1_g1 = np.linalg.inv(l_g1_go1)
    l_pl1_go1 = np.dot(l_g1_go1, l_pl1_g1);

    tmat1  = int_man.int_finder(l_pl1_go1)
    t_ind = np.where(abs(tmat1) == abs(tmat1).max())
    t_ind_1 = t_ind[0][0]; t_ind_2 = t_ind[1][0];
    Dnum = tmat1[t_ind_1, t_ind_2] / l_pl1_go1[t_ind_1, t_ind_2]

    l_pl1_go1 = lll_reduction(tmat1)/Dnum
    l_pl1_g1 = np.dot(l_go1_g1, l_pl1_go1)
    return l_pl1_g1
Exemplo n.º 2
0
def test_int_finder():
    """
    Test cases for the int_finder function in integer_manipulations
    """
    Mat = np.zeros(3,
                   dtype=[('Matrix', '(3,3)float64'), ('row', '(1,3)float64'),
                          ('col', '(3,1)float64')])
    Mat['Matrix'][0] = np.array(([1.5, 2, 3.0e-7], [-4, 5,
                                                    6], [7, 2.0e-5, 1.0e-5]))
    Mat['Matrix'][1] = np.array(([1.5, 2, 3e-6], [-4, 0,
                                                  6], [3.5, -2e-6, 1e-6]))
    Mat['Matrix'][2] = np.array(([1.5, 2, 3e-7], [-4, 5,
                                                  6], [3.5, -2e-6, 1e-6]))
    Mat['row'][0] = np.array(([1.5e-7, 0, 3e-6]))
    Mat['row'][1] = np.array(([1.5e-7, 1, 3e-6]))
    Mat['row'][2] = np.array(([1.5, 4, 3e-7]))
    Mat['col'][0] = np.array(([1.5e-7], [0], [3e-6]))
    Mat['col'][1] = np.array(([1.5e-7], [1], [3e-6]))
    Mat['col'][2] = np.array(([1.5], [4], [3e-7]))
    order = np.zeros(2, 'a4')
    order[0] = 'rows'
    order[1] = 'col'
    # order[2] = 'cols'
    cnt = 0
    for j in Mat.dtype.names:
        for i in range(Mat.shape[0]):
            for k in range(len(order)):
                cnt += 1
                print 'case:', cnt, '\n'
                print Mat[j][i], '\n\n', 'order:', order[k], '\nanswer:\n'

                # a = int_man.int_finder(Mat[j][i], tolerance, order[k])
                a = int_man.int_finder(Mat[j][i])
                print a, '\n', '--'
                a = int_man.int_finder(Mat[j][i], 1.0e-5, 'rows', 1.0e-5)
                print a, '\n', '--'
                a = int_man.int_finder(Mat[j][i], 1e-5, 'rows')
                print a, '\n', '--'
                a = int_man.int_finder(Mat[j][i], 1e-5, 'col')
                print a, '\n', '--'
                a = int_man.int_finder(Mat[j][i], 1e-5, 'columns')
                print a, '\n', '--'
                a = int_man.int_finder(Mat[j][i], 1e-5, order[k], 1e-5)
                print a, '\n', '--'

                print '\n', '-----------------------------------------'

    print cnt, ' test cases have been tried.'
    if __name__ == '__main__':
        test_int_finder
Exemplo n.º 3
0
def bicryst_planar_den(inds, t_mat, l_g_go, inds_type='miller_index',
                       mat_ref='go1'):
    """
    The function computes the planar densities of the planes
    1 and 2 and the two-dimensional CSL

    Parameters
    ---------------
    inds: numpy array
        The boundary plane indices.

    inds_type: string
        {'miller_index', 'normal_go', 'normal_g'}

    t_mat: numpy array
        Transformation matrix from g1 to g2 in go1 (or g1) reference frame.

    mat_ref: string
        {'go1', 'g1'}

    lattice: Lattice class
        Attributes of the underlying lattice.

    Returns
    -----------
    pl_den_pl1, pl_den_pl2: numpy array
        The planar density of planes 1 and 2.

    pl_den_csl: numpy array
        The planare density of the two-dimensional CSL.
    """
    l_g1_go1 = l_g_go
    l_rg1_go1 = fcd.reciprocal_mat(l_g1_go1)
    l_go1_rg1 = np.linalg.inv(l_rg1_go1)

    if inds_type == 'normal_go':
        bp1_go1 = inds
        miller1_inds = int_man.int_finder(np.dot(l_go1_rg1, bp1_go1))
    elif inds_type == 'miller_index':
        miller1_inds = inds
    elif inds_type == 'normal_g':
        bp1_g1 = inds
        l_g1_rg1 = np.dot(l_go1_rg1, l_g1_go1)
        miller1_inds = int_man.int_finder(np.dot(l_g1_rg1, bp1_g1))
    else:
        raise Exception('Wrong index type')

    if mat_ref == 'go1':
        l_2d_csl_g1, l_pl1_g1, l_pl2_g1 = gb_2d_csl(miller1_inds,
                                                    t_mat, l_g_go,
                                                    'miller_index', 'go1')
    elif mat_ref == 'g1':
        l_2d_csl_g1, l_pl1_g1, l_pl2_g1 = gb_2d_csl(miller1_inds,
                                                    t_mat, l_g_go,
                                                    'miller_index', 'g1')
    else:
        raise Exception('Wrong reference axis type')

    check_2d_csl(l_pl1_g1, l_pl2_g1, l_2d_csl_g1)

    pl_den_pl1 = pl_density(l_pl1_g1, l_g1_go1)
    pl_den_pl2 = pl_density(l_pl2_g1, l_g1_go1)
    pl_den_csl = pl_density(l_2d_csl_g1, l_g1_go1)

    return pl_den_pl1, pl_den_pl2, pl_den_csl
Exemplo n.º 4
0
def gb_2d_csl(inds, t_mat, l_g_go,
              inds_type='miller_index', mat_ref='g1'):
    """
    For a given boundary plane normal 'bp1_g1' and the misorientation
    matrix 't_g1tog2_g1', the two-dimensional CSL lattice is computed

    Parameters
    ------------------
    inds: numpy array
        The boundary plane indices

    inds_type: string
        {'miller_index', 'normal_go', 'normal_g'}

    t_mat: numpy array
        Transformation matrix from g1 to g2 in 'mat_ref' reference frame

    mat_ref: string
        {'go1', 'g1'}

    lattice: Lattice class
    Attributes of the underlying lattice

    Returns
    -----------
    l_2d_csl_g1, l_pl1_g1, l_pl2_g1: numpy arrays
        ``l_2d_csl_g1`` is the 2d CSL in g1 ref frame.\v
        ``l_pl1_g1`` is the plane 1 basis in g1 ref frame.\v
        ``l_pl2_g1`` is the plane 2 basis in g1 ref frame.\v
    """

    l_g1_go1 = l_g_go
    l_go1_g1 = np.linalg.inv(l_g1_go1)
    l_rg1_go1 = fcd.reciprocal_mat(l_g1_go1)
    l_go1_rg1 = np.linalg.inv(l_rg1_go1)

    if inds_type == 'normal_go':
        bp1_go1 = inds
        miller1_ind = int_man.int_finder(np.dot(l_go1_rg1, bp1_go1))
    elif inds_type == 'miller_index':
        miller1_ind = inds
    elif inds_type == 'normal_g':
        bp1_g1 = inds
        l_g1_rg1 = np.dot(l_go1_rg1, l_g1_go1)
        miller1_ind = int_man.int_finder(np.dot(l_g1_rg1, bp1_g1))
    else:
        raise Exception('Wrong index type')

    if mat_ref == 'go1':
        t_g1tog2_g1 = np.dot(l_go1_g1, np.dot(t_mat, l_g1_go1))
    elif mat_ref == 'g1':
        t_g1tog2_g1 = t_mat
    else:
        raise Exception('Wrong reference axis type')

    bp1_go1 = int_man.int_finder(np.dot(l_rg1_go1, miller1_ind))
    l_g2_g1 = t_g1tog2_g1
    l_g2_go1 = np.dot(l_g1_go1, l_g2_g1)
    l_rg2_go1 = fcd.reciprocal_mat(l_g2_go1)
    l_go1_rg2 = np.linalg.inv(l_rg2_go1)
    # bp2_g2 = int_man.int_finder(np.dot(-l_go1_g2, bp1_go1))
    miller2_ind = int_man.int_finder(np.dot(-l_go1_rg2, bp1_go1))

    l_pl1_g1 = bp_basis(miller1_ind)
    l_pl1_g1 = reduce_go1_mat(l_pl1_g1, l_g1_go1)
    l_pl2_g2 = bp_basis(miller2_ind)
    l_pl2_g2 = reduce_go1_mat(l_pl2_g2, l_g1_go1)
    l_pl2_g1 = np.dot(l_g2_g1, l_pl2_g2)

    l_2d_csl_g1 = csl_finder_2d(l_pl1_g1, l_pl2_g1)
    l_2d_csl_g1 = reduce_go1_mat(l_2d_csl_g1, l_g1_go1)

    return l_2d_csl_g1, l_pl1_g1, l_pl2_g1
Exemplo n.º 5
0
def bp_basis(miller_ind):
    """
    The function computes the primitve basis of the plane if the
    boundary plane indices are specified

    Parameters
    ---------------
    miller_ind: numpy array
        Miller indices of the plane (h k l)

    Returns
    -----------
    l_pl_g1: numpy array
        The primitive basis of the plane in 'g1' reference frame
    """
    miller_ind = int_man.int_finder(miller_ind)
    h = miller_ind[0]
    k = miller_ind[1]
    l = miller_ind[2]

    if h == 0 and k == 0 and l == 0:
        raise Exception('hkl indices cannot all be zero')
    else:
        if h != 0 and k != 0 and l != 0:
            gc_f1_p = gcd(k, l)
            bv1_g1 = np.array([[0], [-l / gc_f1_p], [k / gc_f1_p]])
            bv2_g1 = compute_basis_vec([h, k, l])
        else:
                if h == 0:
                    if k == 0:
                        bv1_g1 = np.array([[1], [0], [0]])
                        bv2_g1 = np.array([[0], [1], [0]])
                    elif l == 0:
                        bv1_g1 = np.array([[0], [0], [1]])
                        bv2_g1 = np.array([[1], [0], [0]])
                    else:
                        gc_f1_p = gcd(k, l)
                        bv1_g1 = np.array([[0], [-l / gc_f1_p],
                                           [k / gc_f1_p]])
                        bv2_g1 = np.array([[1], [-l / gc_f1_p],
                                           [k / gc_f1_p]])
                else:
                    if k == 0:
                        if l == 0:
                            bv1_g1 = np.array([[0], [1], [0]])
                            bv2_g1 = np.array([[0], [0], [1]])
                        else:
                            gc_f1_p = gcd(h, l)
                            bv1_g1 = np.array([[-l / gc_f1_p], [0],
                                               [h / gc_f1_p]])
                            bv2_g1 = np.array([[-l / gc_f1_p], [1],
                                               [h / gc_f1_p]])
                    else:
                        if l == 0:
                            gc_f1_p = gcd(h, k)
                            bv1_g1 = np.array([[-k / gc_f1_p],
                                               [h / gc_f1_p], [0]])
                            bv2_g1 = np.array([[-k / gc_f1_p],
                                               [h / gc_f1_p], [1]])

    #  The reduced basis vectors for the plane
    l_pl_g1 = lll_reduction(np.column_stack([bv1_g1, bv2_g1]))
    return l_pl_g1