예제 #1
0
def test_voigt():
    a = rand(3, 3)
    # symmetric tensor
    s = np.dot(a, a.T)
    v = crys.tensor2voigt(s)
    assert (crys.voigt2tensor(v) == s).all()
    assert v[0] == s[0, 0]
    assert v[1] == s[1, 1]
    assert v[2] == s[2, 2]
    assert v[3] == s[1, 2] == s[2, 1]
    assert v[4] == s[0, 2] == s[2, 0]
    assert v[5] == s[0, 1] == s[1, 0]

    nstep = 10
    a = rand(nstep, 3, 3)
    s = np.array([np.dot(a[i, ...], a[i, ...].T) for i in range(nstep)])
    v = crys.tensor2voigt3d(s)
    assert (v[:, 0] == s[:, 0, 0]).all()
    assert (v[:, 1] == s[:, 1, 1]).all()
    assert (v[:, 2] == s[:, 2, 2]).all()
    assert (v[:, 3] == s[:, 1, 2]).all()
    assert (v[:, 4] == s[:, 0, 2]).all()
    assert (v[:, 5] == s[:, 0, 1]).all()
    assert (v[:, 3] == s[:, 2, 1]).all()
    assert (v[:, 4] == s[:, 2, 0]).all()
    assert (v[:, 5] == s[:, 1, 0]).all()

    assert (crys.voigt2tensor3d(v) == s).all()
    assert (crys.tensor2voigt3d(s) == \
            np.array([crys.tensor2voigt(s[i,...]) for i in \
            range(nstep)])).all()
    assert (crys.voigt2tensor3d(v) == \
            np.array([crys.voigt2tensor(v[i,...]) for i in \
            range(nstep)])).all()
예제 #2
0
def test_voigt():
    a = rand(3,3) 
    # symmetric tensor
    s = np.dot(a,a.T)
    v = crys.tensor2voigt(s)
    assert (crys.voigt2tensor(v) == s).all()
    assert v[0] == s[0,0]
    assert v[1] == s[1,1]
    assert v[2] == s[2,2]
    assert v[3] == s[1,2] == s[2,1]
    assert v[4] == s[0,2] == s[2,0]
    assert v[5] == s[0,1] == s[1,0]
    
    nstep = 10
    a = rand(nstep,3,3) 
    s = np.array([np.dot(a[i,...],a[i,...].T) for i in range(nstep)])
    v = crys.tensor2voigt3d(s)
    assert (v[:,0] == s[:,0,0]).all()
    assert (v[:,1] == s[:,1,1]).all()
    assert (v[:,2] == s[:,2,2]).all()
    assert (v[:,3] == s[:,1,2]).all()
    assert (v[:,4] == s[:,0,2]).all()
    assert (v[:,5] == s[:,0,1]).all()
    assert (v[:,3] == s[:,2,1]).all()
    assert (v[:,4] == s[:,2,0]).all()
    assert (v[:,5] == s[:,1,0]).all()

    assert (crys.voigt2tensor3d(v) == s).all()
    assert (crys.tensor2voigt3d(s) == \
            np.array([crys.tensor2voigt(s[i,...]) for i in \
            range(nstep)])).all()
    assert (crys.voigt2tensor3d(v) == \
            np.array([crys.voigt2tensor(v[i,...]) for i in \
            range(nstep)])).all()
예제 #3
0
def stress_pwtools2ase(pwstress):
    """
    Convert (3,3) stress tensor (GPa) to Voigt 6-vector for ASE (eV/Ang^3).
    Note that ASE uses another sign convention (too small unit cell = negative
    pressure instead of positive).

    Parameters
    ----------
    pwstress : (3,3)
        symmetric stress tensor (GPa)
    
    Returns
    -------
    [Pxx, Pyy, Pzz, Pyz, Pxz, Pxy] in eV/Ang^3
    """    
    return -crys.tensor2voigt(pwstress) / constants.eV_by_Ang3_to_GPa
예제 #4
0
def stress_pwtools2ase(pwstress):
    """
    Convert (3,3) stress tensor (GPa) to Voigt 6-vector for ASE (eV/Ang^3).
    Note that ASE uses another sign convention (too small unit cell = negative
    pressure instead of positive).

    Parameters
    ----------
    pwstress : (3,3)
        symmetric stress tensor (GPa)
    
    Returns
    -------
    [Pxx, Pyy, Pzz, Pyz, Pxz, Pxy] in eV/Ang^3
    """
    return -crys.tensor2voigt(pwstress) / constants.eV_by_Ang3_to_GPa