Merge branch 'from_fiber-improvements' into 'development'

From fiber improvements

See merge request damask/DAMASK!573
This commit is contained in:
Franz Roters 2022-05-11 13:13:31 +00:00
commit 53c345f4f1
3 changed files with 48 additions and 13 deletions

View File

@ -1010,7 +1010,7 @@ class Rotation:
def from_ODF(weights: np.ndarray,
phi: np.ndarray,
shape: Union[int, IntSequence] = None,
degrees: bool = True,
degrees: bool = False,
fractions: bool = True,
rng_seed: NumpyRngSeed = None) -> 'Rotation':
"""
@ -1063,7 +1063,7 @@ class Rotation:
def from_spherical_component(center: 'Rotation',
sigma: float,
shape: Union[int, IntSequence] = None,
degrees: bool = True,
degrees: bool = False,
rng_seed: NumpyRngSeed = None) -> 'Rotation':
"""
Initialize with samples from a Gaussian distribution around a given center.
@ -1100,7 +1100,7 @@ class Rotation:
sample: IntSequence,
sigma: float = 0.0,
shape: Union[int, IntSequence] = None,
degrees: bool = True,
degrees: bool = False,
rng_seed: NumpyRngSeed = None):
"""
Initialize with samples from a Gaussian distribution around a given direction.
@ -1108,9 +1108,11 @@ class Rotation:
Parameters
----------
crystal : numpy.ndarray, shape (2)
Polar coordinates (phi from x, theta from z) of fiber direction in crystal frame.
Polar coordinates (polar angle θ from [0 0 1], azimuthal angle φ from [1 0 0])
of fiber direction in crystal frame.
sample : numpy.ndarray, shape (2)
Polar coordinates (phi from x, theta from z) of fiber direction in sample frame.
Polar coordinates (polar angle θ from z, azimuthal angle φ from x)
of fiber direction in sample frame.
sigma : float, optional
Standard deviation of (Gaussian) misorientation distribution.
Defaults to 0.
@ -1122,13 +1124,39 @@ class Rotation:
A seed to initialize the BitGenerator.
Defaults to None, i.e. unpredictable entropy will be pulled from the OS.
Notes
-----
The crystal direction for (θ=0,φ=0) is [0 0 1],
the sample direction for (θ=0,φ=0) is z.
Polar coordinates follow the ISO 80000-2:2019 convention
typically used in physics.
See https://en.wikipedia.org/wiki/Spherical_coordinate_system.
Ranges 0θπ and 0φ2π give a unique set of coordinates.
Examples
--------
Create an ideal α-fiber texture (<1 1 0> ǀǀ RD=x) consisting of
200 orientations:
>>> import damask
>>> import numpy as np
>>> alpha = damask.Rotation.from_fiber_component([np.pi/4.,0.],[np.pi/2.,0.],shape=200)
Create an ideal γ-fiber texture (<1 1 1> ǀǀ ND=z) consisting of
100 orientations:
>>> import damask
>>> gamma = damask.Rotation.from_fiber_component([54.7,45.0],[0.,0.],shape=100,degrees=True)
"""
rng = np.random.default_rng(rng_seed)
sigma_,alpha_,beta_ = (np.radians(coordinate) for coordinate in (sigma,crystal,sample)) if degrees else \
sigma_,alpha,beta = (np.radians(coordinate) for coordinate in (sigma,crystal,sample)) if degrees else \
map(np.array, (sigma,crystal,sample))
d_cr = np.array([np.sin(alpha_[0])*np.cos(alpha_[1]), np.sin(alpha_[0])*np.sin(alpha_[1]), np.cos(alpha_[0])])
d_lab = np.array([np.sin( beta_[0])*np.cos( beta_[1]), np.sin( beta_[0])*np.sin( beta_[1]), np.cos( beta_[0])])
d_cr = np.array([np.sin(alpha[0])*np.cos(alpha[1]), np.sin(alpha[0])*np.sin(alpha[1]), np.cos(alpha[0])])
d_lab = np.array([np.sin( beta[0])*np.cos( beta[1]), np.sin( beta[0])*np.sin( beta[1]), np.cos( beta[0])])
ax_align = np.append(np.cross(d_lab,d_cr), np.arccos(np.dot(d_lab,d_cr)))
if np.isclose(ax_align[3],0.0): ax_align[:3] = np.array([1,0,0])
R_align = Rotation.from_axis_angle(ax_align if ax_align[3] > 0.0 else -ax_align,normalize=True) # rotate fiber axis from sample to crystal frame

View File

@ -158,6 +158,13 @@ class TestOrientation:
sigma=0.0,shape=None,rng_seed=0,lattice='cI').quaternion
== r.quaternion)
@pytest.mark.parametrize('crystal,sample,direction,color',[([np.pi/4,0],[np.pi/2,0],[1,0,0],[0,1,0]),
([np.arccos(3**(-.5)),np.pi/4,0],[0,0],[0,0,1],[0,0,1])])
def test_fiber_IPF(self,crystal,sample,direction,color):
fiber = Orientation.from_fiber_component(crystal=crystal,sample=sample,family='cubic',shape=200)
print(np.allclose(fiber.IPF_color(direction),color))
@pytest.mark.parametrize('kwargs',[
dict(lattice='aP',a=1.0,b=1.1,c=1.2,alpha=np.pi/4.5,beta=np.pi/3.5,gamma=np.pi/2.5),
dict(lattice='mP',a=1.0,b=1.1,c=1.2, beta=np.pi/3.5),

View File

@ -1061,7 +1061,7 @@ class TestRotation:
p = []
for run in range(5):
c = Rotation.from_random()
o = Rotation.from_spherical_component(c,sigma,shape)
o = Rotation.from_spherical_component(c,sigma,shape,degrees=True)
_, angles = c.misorientation(o).as_axis_angle(pair=True,degrees=True)
angles[::2] *= -1 # flip angle for every second to symmetrize distribution
@ -1077,8 +1077,8 @@ class TestRotation:
def test_from_fiber_component(self,sigma,shape):
p = []
for run in range(5):
alpha = np.random.random()*2*np.pi,np.arccos(np.random.random())
beta = np.random.random()*2*np.pi,np.arccos(np.random.random())
alpha = np.arccos(np.random.random()),np.random.random()*2*np.pi
beta = np.arccos(np.random.random()),np.random.random()*2*np.pi
f_in_C = np.array([np.sin(alpha[0])*np.cos(alpha[1]), np.sin(alpha[0])*np.sin(alpha[1]), np.cos(alpha[0])])
f_in_S = np.array([np.sin( beta[0])*np.cos( beta[1]), np.sin( beta[0])*np.sin( beta[1]), np.cos( beta[0])])