no direct connection to Orientation object
This commit is contained in:
parent
f7e1aad147
commit
bfc3fe410f
|
@ -177,8 +177,8 @@ class Orientation(Rotation):
|
|||
for m in master:
|
||||
self.kinematics[m] = {'direction':master[m][:,0:3],'plane':master[m][:,3:6]} \
|
||||
if master[m].shape[-1] == 6 else \
|
||||
{'direction':self.Bravais_to_Miller(uvtw=master[m][:,0:4]),
|
||||
'plane': self.Bravais_to_Miller(hkil=master[m][:,4:8])}
|
||||
{'direction':lattice_.Bravais_to_Miller(uvtw=master[m][:,0:4]),
|
||||
'plane': lattice_.Bravais_to_Miller(hkil=master[m][:,4:8])}
|
||||
elif lattice in set(lattice_symmetries.values()):
|
||||
self.family = lattice
|
||||
self.lattice = None
|
||||
|
@ -676,10 +676,10 @@ class Orientation(Rotation):
|
|||
o = r[ol]
|
||||
|
||||
p_,_p = np.zeros(m.shape[:-1]+(3,)),np.zeros(o.shape[:-1]+(3,))
|
||||
p_[...,0,:] = m[...,0,:] if m.shape[-1] == 3 else self.Bravais_to_Miller(uvtw=m[...,0,0:4])
|
||||
p_[...,1,:] = m[...,1,:] if m.shape[-1] == 3 else self.Bravais_to_Miller(hkil=m[...,1,0:4])
|
||||
_p[...,0,:] = o[...,0,:] if o.shape[-1] == 3 else self.Bravais_to_Miller(uvtw=o[...,0,0:4])
|
||||
_p[...,1,:] = o[...,1,:] if o.shape[-1] == 3 else self.Bravais_to_Miller(hkil=o[...,1,0:4])
|
||||
p_[...,0,:] = m[...,0,:] if m.shape[-1] == 3 else lattice_.Bravais_to_Miller(uvtw=m[...,0,0:4])
|
||||
p_[...,1,:] = m[...,1,:] if m.shape[-1] == 3 else lattice_.Bravais_to_Miller(hkil=m[...,1,0:4])
|
||||
_p[...,0,:] = o[...,0,:] if o.shape[-1] == 3 else lattice_.Bravais_to_Miller(uvtw=o[...,0,0:4])
|
||||
_p[...,1,:] = o[...,1,:] if o.shape[-1] == 3 else lattice_.Bravais_to_Miller(hkil=o[...,1,0:4])
|
||||
|
||||
return (Rotation.from_parallel(p_,_p),ol) \
|
||||
if return_lattice else \
|
||||
|
@ -1158,64 +1158,6 @@ class Orientation(Rotation):
|
|||
)
|
||||
|
||||
|
||||
@classmethod
|
||||
def Bravais_to_Miller(cls,*,uvtw=None,hkil=None):
|
||||
"""
|
||||
Transform 4 Miller–Bravais indices to 3 Miller indices of crystal direction [uvw] or plane normal (hkl).
|
||||
|
||||
Parameters
|
||||
----------
|
||||
uvtw|hkil : numpy.ndarray of shape (...,4)
|
||||
Miller–Bravais indices of crystallographic direction [uvtw] or plane normal (hkil).
|
||||
|
||||
Returns
|
||||
-------
|
||||
uvw|hkl : numpy.ndarray of shape (...,3)
|
||||
Miller indices of [uvw] direction or (hkl) plane normal.
|
||||
|
||||
"""
|
||||
if (uvtw is not None) ^ (hkil is None):
|
||||
raise KeyError('Specify either "uvtw" or "hkil"')
|
||||
axis,basis = (np.array(uvtw),np.array([[1,0,-1,0],
|
||||
[0,1,-1,0],
|
||||
[0,0, 0,1]])) \
|
||||
if hkil is None else \
|
||||
(np.array(hkil),np.array([[1,0,0,0],
|
||||
[0,1,0,0],
|
||||
[0,0,0,1]]))
|
||||
return np.einsum('il,...l',basis,axis)
|
||||
|
||||
|
||||
@classmethod
|
||||
def Miller_to_Bravais(cls,*,uvw=None,hkl=None):
|
||||
"""
|
||||
Transform 3 Miller indices to 4 Miller–Bravais indices of crystal direction [uvtw] or plane normal (hkil).
|
||||
|
||||
Parameters
|
||||
----------
|
||||
uvw|hkl : numpy.ndarray of shape (...,3)
|
||||
Miller indices of crystallographic direction [uvw] or plane normal (hkl).
|
||||
|
||||
Returns
|
||||
-------
|
||||
uvtw|hkil : numpy.ndarray of shape (...,4)
|
||||
Miller–Bravais indices of [uvtw] direction or (hkil) plane normal.
|
||||
|
||||
"""
|
||||
if (uvw is not None) ^ (hkl is None):
|
||||
raise KeyError('Specify either "uvw" or "hkl"')
|
||||
axis,basis = (np.array(uvw),np.array([[ 2,-1, 0],
|
||||
[-1, 2, 0],
|
||||
[-1,-1, 0],
|
||||
[ 0, 0, 3]])/3) \
|
||||
if hkl is None else \
|
||||
(np.array(hkl),np.array([[ 1, 0, 0],
|
||||
[ 0, 1, 0],
|
||||
[-1,-1, 0],
|
||||
[ 0, 0, 1]]))
|
||||
return np.einsum('il,...l',basis,axis)
|
||||
|
||||
|
||||
def to_lattice(self,*,direction=None,plane=None):
|
||||
"""
|
||||
Calculate lattice vector corresponding to crystal frame direction or plane normal.
|
||||
|
|
|
@ -1,5 +1,62 @@
|
|||
import numpy as _np
|
||||
|
||||
|
||||
def Bravais_to_Miller(*,uvtw=None,hkil=None):
|
||||
"""
|
||||
Transform 4 Miller–Bravais indices to 3 Miller indices of crystal direction [uvw] or plane normal (hkl).
|
||||
|
||||
Parameters
|
||||
----------
|
||||
uvtw|hkil : numpy.ndarray of shape (...,4)
|
||||
Miller–Bravais indices of crystallographic direction [uvtw] or plane normal (hkil).
|
||||
|
||||
Returns
|
||||
-------
|
||||
uvw|hkl : numpy.ndarray of shape (...,3)
|
||||
Miller indices of [uvw] direction or (hkl) plane normal.
|
||||
|
||||
"""
|
||||
if (uvtw is not None) ^ (hkil is None):
|
||||
raise KeyError('Specify either "uvtw" or "hkil"')
|
||||
axis,basis = (_np.array(uvtw),_np.array([[1,0,-1,0],
|
||||
[0,1,-1,0],
|
||||
[0,0, 0,1]])) \
|
||||
if hkil is None else \
|
||||
(_np.array(hkil),_np.array([[1,0,0,0],
|
||||
[0,1,0,0],
|
||||
[0,0,0,1]]))
|
||||
return _np.einsum('il,...l',basis,axis)
|
||||
|
||||
|
||||
def Miller_to_Bravais(*,uvw=None,hkl=None):
|
||||
"""
|
||||
Transform 3 Miller indices to 4 Miller–Bravais indices of crystal direction [uvtw] or plane normal (hkil).
|
||||
|
||||
Parameters
|
||||
----------
|
||||
uvw|hkl : numpy.ndarray of shape (...,3)
|
||||
Miller indices of crystallographic direction [uvw] or plane normal (hkl).
|
||||
|
||||
Returns
|
||||
-------
|
||||
uvtw|hkil : numpy.ndarray of shape (...,4)
|
||||
Miller–Bravais indices of [uvtw] direction or (hkil) plane normal.
|
||||
|
||||
"""
|
||||
if (uvw is not None) ^ (hkl is None):
|
||||
raise KeyError('Specify either "uvw" or "hkl"')
|
||||
axis,basis = (_np.array(uvw),_np.array([[ 2,-1, 0],
|
||||
[-1, 2, 0],
|
||||
[-1,-1, 0],
|
||||
[ 0, 0, 3]])/3) \
|
||||
if hkl is None else \
|
||||
(_np.array(hkl),_np.array([[ 1, 0, 0],
|
||||
[ 0, 1, 0],
|
||||
[-1,-1, 0],
|
||||
[ 0, 0, 1]]))
|
||||
return _np.einsum('il,...l',basis,axis)
|
||||
|
||||
|
||||
kinematics = {
|
||||
'cF': {
|
||||
'slip' : _np.array([
|
||||
|
|
|
@ -8,7 +8,9 @@ from damask import Table
|
|||
from damask import util
|
||||
from damask import grid_filters
|
||||
from damask import lattice
|
||||
from damask._orientation import crystal_families
|
||||
from damask import _orientation
|
||||
|
||||
crystal_families = set(_orientation.lattice_symmetries.values())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -358,14 +360,6 @@ class TestOrientation:
|
|||
with pytest.raises(KeyError):
|
||||
Orientation(lattice=None).basis_reciprocal # noqa
|
||||
|
||||
def test_double_Bravais_to_Miller(self):
|
||||
with pytest.raises(KeyError):
|
||||
Orientation.Bravais_to_Miller(uvtw=np.ones(4),hkil=np.ones(4)) # noqa
|
||||
|
||||
def test_double_Miller_to_Bravais(self):
|
||||
with pytest.raises(KeyError):
|
||||
Orientation.Miller_to_Bravais(uvw=np.ones(4),hkl=np.ones(4)) # noqa
|
||||
|
||||
def test_double_to_lattice(self):
|
||||
with pytest.raises(KeyError):
|
||||
Orientation().to_lattice(direction=np.ones(3),plane=np.ones(3)) # noqa
|
||||
|
@ -490,26 +484,6 @@ class TestOrientation:
|
|||
assert np.allclose(vector,
|
||||
L.to_frame(**{keyFrame:L.to_lattice(**{keyLattice:vector})}))
|
||||
|
||||
@pytest.mark.parametrize('vector',np.array([
|
||||
[1,0,0],
|
||||
[1,1,0],
|
||||
[1,1,1],
|
||||
[1,0,-2],
|
||||
]))
|
||||
@pytest.mark.parametrize('kw_Miller,kw_Bravais',[('uvw','uvtw'),('hkl','hkil')])
|
||||
def test_Miller_Bravais_Miller(self,vector,kw_Miller,kw_Bravais):
|
||||
assert np.all(vector == Orientation.Bravais_to_Miller(**{kw_Bravais:Orientation.Miller_to_Bravais(**{kw_Miller:vector})}))
|
||||
|
||||
@pytest.mark.parametrize('vector',np.array([
|
||||
[1,0,-1,2],
|
||||
[1,-1,0,3],
|
||||
[1,1,-2,-3],
|
||||
[0,0,0,1],
|
||||
]))
|
||||
@pytest.mark.parametrize('kw_Miller,kw_Bravais',[('uvw','uvtw'),('hkl','hkil')])
|
||||
def test_Bravais_Miller_Bravais(self,vector,kw_Miller,kw_Bravais):
|
||||
assert np.all(vector == Orientation.Miller_to_Bravais(**{kw_Miller:Orientation.Bravais_to_Miller(**{kw_Bravais:vector})}))
|
||||
|
||||
@pytest.mark.parametrize('lattice,a,b,c,alpha,beta,gamma',
|
||||
[
|
||||
('aP',0.5,2.0,3.0,0.8,0.5,1.2),
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
import pytest
|
||||
import numpy as np
|
||||
|
||||
from damask import lattice
|
||||
|
||||
class TestLattice:
|
||||
|
||||
def test_double_Bravais_to_Miller(self):
|
||||
with pytest.raises(KeyError):
|
||||
lattice.Bravais_to_Miller(uvtw=np.ones(4),hkil=np.ones(4)) # noqa
|
||||
|
||||
def test_double_Miller_to_Bravais(self):
|
||||
with pytest.raises(KeyError):
|
||||
lattice.Miller_to_Bravais(uvw=np.ones(4),hkl=np.ones(4)) # noqa
|
||||
|
||||
@pytest.mark.parametrize('vector',np.array([
|
||||
[1,0,0],
|
||||
[1,1,0],
|
||||
[1,1,1],
|
||||
[1,0,-2],
|
||||
]))
|
||||
@pytest.mark.parametrize('kw_Miller,kw_Bravais',[('uvw','uvtw'),('hkl','hkil')])
|
||||
def test_Miller_Bravais_Miller(self,vector,kw_Miller,kw_Bravais):
|
||||
assert np.all(vector == lattice.Bravais_to_Miller(**{kw_Bravais:lattice.Miller_to_Bravais(**{kw_Miller:vector})}))
|
||||
|
||||
@pytest.mark.parametrize('vector',np.array([
|
||||
[1,0,-1,2],
|
||||
[1,-1,0,3],
|
||||
[1,1,-2,-3],
|
||||
[0,0,0,1],
|
||||
]))
|
||||
@pytest.mark.parametrize('kw_Miller,kw_Bravais',[('uvw','uvtw'),('hkl','hkil')])
|
||||
def test_Bravais_Miller_Bravais(self,vector,kw_Miller,kw_Bravais):
|
||||
assert np.all(vector == lattice.Miller_to_Bravais(**{kw_Miller:lattice.Bravais_to_Miller(**{kw_Bravais:vector})}))
|
Loading…
Reference in New Issue