2021-06-02 12:58:27 +05:30
|
|
|
import pytest
|
|
|
|
import numpy as np
|
|
|
|
|
2021-08-18 14:47:13 +05:30
|
|
|
import damask
|
2021-06-08 01:19:04 +05:30
|
|
|
from damask import Crystal
|
2021-06-02 12:58:27 +05:30
|
|
|
|
2021-06-08 01:19:04 +05:30
|
|
|
class TestCrystal:
|
2021-06-02 12:58:27 +05:30
|
|
|
|
2021-08-18 14:47:13 +05:30
|
|
|
@pytest.mark.parametrize('lattice,family',[('aP','cubic'),('xI','cubic')])
|
|
|
|
def test_invalid_init(self,lattice,family):
|
|
|
|
with pytest.raises(KeyError):
|
|
|
|
Crystal(family=family,lattice=lattice)
|
|
|
|
|
|
|
|
def test_eq(self):
|
|
|
|
family = np.random.choice(list(damask._crystal.lattice_symmetries.values()))
|
|
|
|
assert Crystal(family=family) == Crystal(family=family)
|
|
|
|
|
2021-06-02 12:58:27 +05:30
|
|
|
def test_double_to_lattice(self):
|
2021-06-08 01:19:04 +05:30
|
|
|
c = Crystal(lattice='cF')
|
2021-06-02 12:58:27 +05:30
|
|
|
with pytest.raises(KeyError):
|
2021-06-08 01:19:04 +05:30
|
|
|
c.to_lattice(direction=np.ones(3),plane=np.ones(3))
|
2021-06-02 12:58:27 +05:30
|
|
|
|
|
|
|
def test_double_to_frame(self):
|
2021-06-08 01:19:04 +05:30
|
|
|
c = Crystal(lattice='cF')
|
2021-06-02 12:58:27 +05:30
|
|
|
with pytest.raises(KeyError):
|
2021-06-08 01:19:04 +05:30
|
|
|
c.to_frame(uvw=np.ones(3),hkl=np.ones(3))
|
2021-06-02 12:58:27 +05:30
|
|
|
|
|
|
|
@pytest.mark.parametrize('lattice,a,b,c,alpha,beta,gamma',
|
|
|
|
[
|
|
|
|
('aP',0.5,2.0,3.0,0.8,0.5,1.2),
|
|
|
|
('mP',1.0,2.0,3.0,np.pi/2,0.5,np.pi/2),
|
|
|
|
('oI',0.5,1.5,3.0,np.pi/2,np.pi/2,np.pi/2),
|
|
|
|
('tP',0.5,0.5,3.0,np.pi/2,np.pi/2,np.pi/2),
|
|
|
|
('hP',1.0,None,1.6,np.pi/2,np.pi/2,2*np.pi/3),
|
|
|
|
('cF',1.0,1.0,None,np.pi/2,np.pi/2,np.pi/2),
|
|
|
|
])
|
|
|
|
def test_bases_contraction(self,lattice,a,b,c,alpha,beta,gamma):
|
2021-06-08 01:19:04 +05:30
|
|
|
c = Crystal(lattice=lattice,
|
2021-06-02 12:58:27 +05:30
|
|
|
a=a,b=b,c=c,
|
|
|
|
alpha=alpha,beta=beta,gamma=gamma)
|
2021-06-08 01:19:04 +05:30
|
|
|
assert np.allclose(np.eye(3),np.einsum('ik,jk',c.basis_real,c.basis_reciprocal))
|
2021-06-02 12:58:27 +05:30
|
|
|
|
2022-01-15 17:52:15 +05:30
|
|
|
def test_basis_invalid(self):
|
|
|
|
with pytest.raises(KeyError):
|
|
|
|
Crystal(family='cubic').basis_real
|
2021-06-02 12:58:27 +05:30
|
|
|
|
|
|
|
@pytest.mark.parametrize('keyFrame,keyLattice',[('uvw','direction'),('hkl','plane'),])
|
|
|
|
@pytest.mark.parametrize('vector',np.array([
|
|
|
|
[1.,1.,1.],
|
|
|
|
[-2.,3.,0.5],
|
|
|
|
[0.,0.,1.],
|
|
|
|
[1.,1.,1.],
|
|
|
|
[2.,2.,2.],
|
|
|
|
[0.,1.,1.],
|
|
|
|
]))
|
|
|
|
@pytest.mark.parametrize('lattice,a,b,c,alpha,beta,gamma',
|
|
|
|
[
|
|
|
|
('aP',0.5,2.0,3.0,0.8,0.5,1.2),
|
|
|
|
('mP',1.0,2.0,3.0,np.pi/2,0.5,np.pi/2),
|
|
|
|
('oI',0.5,1.5,3.0,np.pi/2,np.pi/2,np.pi/2),
|
|
|
|
('tP',0.5,0.5,3.0,np.pi/2,np.pi/2,np.pi/2),
|
|
|
|
('hP',1.0,1.0,1.6,np.pi/2,np.pi/2,2*np.pi/3),
|
|
|
|
('cF',1.0,1.0,1.0,np.pi/2,np.pi/2,np.pi/2),
|
|
|
|
])
|
|
|
|
def test_to_frame_to_lattice(self,lattice,a,b,c,alpha,beta,gamma,vector,keyFrame,keyLattice):
|
2021-06-08 01:19:04 +05:30
|
|
|
c = Crystal(lattice=lattice,
|
2021-06-02 12:58:27 +05:30
|
|
|
a=a,b=b,c=c,
|
|
|
|
alpha=alpha,beta=beta,gamma=gamma)
|
|
|
|
assert np.allclose(vector,
|
2021-06-08 01:19:04 +05:30
|
|
|
c.to_frame(**{keyFrame:c.to_lattice(**{keyLattice:vector})}))
|
2021-09-30 20:31:42 +05:30
|
|
|
|
|
|
|
@pytest.mark.parametrize('lattice,a,b,c,alpha,beta,gamma,points',
|
|
|
|
[
|
|
|
|
('aP',0.5,2.0,3.0,0.8,0.5,1.2,[[0,0,0]]),
|
|
|
|
('mS',1.0,2.0,3.0,np.pi/2,0.5,np.pi/2,[[0,0,0],[0.5,0.5,0.0]]),
|
|
|
|
('oI',0.5,1.5,3.0,np.pi/2,np.pi/2,np.pi/2,[[0,0,0],[0.5,0.5,0.5]]),
|
|
|
|
('hP',1.0,1.0,1.6,np.pi/2,np.pi/2,2*np.pi/3,[[0,0,0],[2./3.,1./3.,0.5]]),
|
|
|
|
('cF',1.0,1.0,1.0,np.pi/2,np.pi/2,np.pi/2,[[0,0,0],[0.0,0.5,0.5],[0.5,0.0,0.5],[0.5,0.5,0.0]]),
|
|
|
|
])
|
|
|
|
def test_lattice_points(self,lattice,a,b,c,alpha,beta,gamma,points):
|
|
|
|
c = Crystal(lattice=lattice,
|
|
|
|
a=a,b=b,c=c,
|
|
|
|
alpha=alpha,beta=beta,gamma=gamma)
|
|
|
|
assert np.allclose(points,c.lattice_points)
|
2022-01-05 12:38:10 +05:30
|
|
|
|
|
|
|
@pytest.mark.parametrize('crystal,length',
|
|
|
|
[(Crystal(lattice='cF'),[12,6]),
|
|
|
|
(Crystal(lattice='cI'),[12,12,24]),
|
|
|
|
(Crystal(lattice='hP'),[3,3,6,12,6]),
|
|
|
|
(Crystal(lattice='tI',c=1.2),[2,2,2,4,2,4,2,2,4,8,4,8,8])
|
|
|
|
])
|
|
|
|
def test_N_slip(self,crystal,length):
|
|
|
|
assert [len(s) for s in crystal.kinematics('slip')['direction']] == length
|
|
|
|
assert [len(s) for s in crystal.kinematics('slip')['plane']] == length
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('crystal,length',
|
|
|
|
[(Crystal(lattice='cF'),[12]),
|
|
|
|
(Crystal(lattice='cI'),[12]),
|
|
|
|
(Crystal(lattice='hP'),[6,6,6,6]),
|
|
|
|
])
|
|
|
|
def test_N_twin(self,crystal,length):
|
|
|
|
assert [len(s) for s in crystal.kinematics('twin')['direction']] == length
|
|
|
|
assert [len(s) for s in crystal.kinematics('twin')['plane']] == length
|
|
|
|
|
2022-02-26 22:10:12 +05:30
|
|
|
@pytest.mark.parametrize('crystal', [Crystal(lattice='cF'),
|
|
|
|
Crystal(lattice='cI'),
|
|
|
|
Crystal(lattice='hP'),
|
|
|
|
Crystal(lattice='tI',c=1.2)])
|
|
|
|
def test_related(self,crystal):
|
|
|
|
for r in crystal.orientation_relationships:
|
|
|
|
crystal.relation_operations(r)
|
|
|
|
|
2023-11-07 04:12:11 +05:30
|
|
|
@pytest.mark.parametrize('crystal', [Crystal(lattice='cF'),
|
|
|
|
Crystal(lattice='cI'),
|
|
|
|
Crystal(lattice='hP')])
|
|
|
|
def test_related_invalid_target(self,crystal):
|
|
|
|
relationship = np.random.choice(crystal.orientation_relationships)
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
crystal.relation_operations(relationship,crystal)
|
|
|
|
|