add_pole is working again

This commit is contained in:
Martin Diehl 2021-07-18 18:03:36 +02:00
parent 19ca99e033
commit de428efca5
3 changed files with 38 additions and 54 deletions

View File

@ -843,10 +843,9 @@ class Orientation(Rotation,Crystal):
Lab frame vector (or vectors if with_symmetry) along [uvw] direction or (hkl) plane normal. Lab frame vector (or vectors if with_symmetry) along [uvw] direction or (hkl) plane normal.
""" """
sym_ops = self.symmetry_operations
# ToDo: simplify 'with_symmetry'
v = self.to_frame(uvw=uvw,hkl=hkl) v = self.to_frame(uvw=uvw,hkl=hkl)
if with_symmetry: if with_symmetry:
sym_ops = self.symmetry_operations
v = sym_ops.broadcast_to(sym_ops.shape+v.shape[:-1],mode='right') \ v = sym_ops.broadcast_to(sym_ops.shape+v.shape[:-1],mode='right') \
@ np.broadcast_to(v,sym_ops.shape+v.shape) @ np.broadcast_to(v,sym_ops.shape+v.shape)
return ~(self if self.shape+v.shape[:-1] == () else self.broadcast_to(self.shape+v.shape[:-1],mode='right')) \ return ~(self if self.shape+v.shape[:-1] == () else self.broadcast_to(self.shape+v.shape[:-1],mode='right')) \

View File

@ -979,47 +979,35 @@ class Result:
self._add_generic_pointwise(self._add_stress_second_Piola_Kirchhoff,{'P':P,'F':F}) self._add_generic_pointwise(self._add_stress_second_Piola_Kirchhoff,{'P':P,'F':F})
# The add_pole functionality needs discussion.
# The new Crystal object can perform such a calculation but the outcome depends on the lattice parameters
# as well as on whether a direction or plane is concerned (see the DAMASK_examples/pole_figure notebook).
# Below code appears to be too simplistic.
# @staticmethod @staticmethod
# def _add_pole(q,p,polar): def _add_pole(q,uvw,hkl):
# pole = np.array(p) c = q['meta']['c/a'] if 'c/a' in q['meta'] else 1
# unit_pole = pole/np.linalg.norm(pole) pole = Orientation(q['data'], lattice=q['meta']['lattice'], a=1, c=c).to_pole(uvw=uvw,hkl=hkl)
# m = util.scale_to_coprime(pole)
# rot = Rotation(q['data'].view(np.double).reshape(-1,4)) return {
# 'data': pole,
# rotatedPole = rot @ np.broadcast_to(unit_pole,rot.shape+(3,)) # rotate pole according to crystal orientation 'label': 'p^[{} {} {}]'.format(*uvw) if uvw else 'p^({} {} {})'.format(*hkl),
# xy = rotatedPole[:,0:2]/(1.+abs(unit_pole[2])) # stereographic projection 'meta' : {
# coords = xy if not polar else \ 'unit': '1',
# np.block([np.sqrt(xy[:,0:1]*xy[:,0:1]+xy[:,1:2]*xy[:,1:2]),np.arctan2(xy[:,1:2],xy[:,0:1])]) 'description': f"lab frame vector along lattice {'direction' if uvw else 'plane'}",
# return { 'creator': 'add_pole'
# 'data': coords, }
# 'label': 'p^{}_[{} {} {})'.format(u'rφ' if polar else 'xy',*m), }
# 'meta' : { def add_pole(self,q='O',*,uvw=None,hkl=None):
# 'unit': '1', """
# 'description': '{} coordinates of stereographic projection of pole (direction/plane) in crystal frame'\ Add lab frame vector along lattice direction [uvw] or plane normal (hkl).
# .format('Polar' if polar else 'Cartesian'),
# 'creator': 'add_pole' Parameters
# } ----------
# } q : str
# def add_pole(self,q,p,polar=False): Name of the dataset containing the crystallographic orientation as quaternions.
# """ Defaults to 'O'.
# Add coordinates of stereographic projection of given pole in crystal frame. uvw|hkl : numpy.ndarray of shape (...,3)
# Miller indices of crystallographic direction or plane normal.
# Parameters
# ---------- """
# q : str self._add_generic_pointwise(self._add_pole,{'q':q},{'uvw':uvw,'hkl':hkl})
# Name of the dataset containing the crystallographic orientation as quaternions.
# p : numpy.array of shape (3)
# Crystallographic direction or plane.
# polar : bool, optional
# Give pole in polar coordinates. Defaults to False.
#
# """
# self._add_generic_pointwise(self._add_pole,{'q':q},{'p':p,'polar':polar})
@staticmethod @staticmethod

View File

@ -12,7 +12,6 @@ import vtk
import numpy as np import numpy as np
from damask import Result from damask import Result
from damask import Rotation
from damask import Orientation from damask import Orientation
from damask import tensor from damask import tensor
from damask import mechanics from damask import mechanics
@ -220,17 +219,15 @@ class TestResult:
in_file = default.place('S') in_file = default.place('S')
assert np.allclose(in_memory,in_file) assert np.allclose(in_memory,in_file)
@pytest.mark.skip(reason='requires rework of lattice.f90') @pytest.mark.parametrize('options',[{'uvw':[1,0,0]},{'hkl':[0,1,1]}])
@pytest.mark.parametrize('polar',[True,False]) def test_add_pole(self,default,options):
def test_add_pole(self,default,polar): default.add_pole(**options)
pole = np.array([1.,0.,0.]) rot = default.place('O')
default.add_pole('O',pole,polar) in_memory = Orientation(rot,lattice=rot.dtype.metadata['lattice']).to_pole(**options)
rot = Rotation(default.place('O')) brackets = ['[[]','[]]'] if 'uvw' in options.keys() else ['(',')'] # escape fnmatch
rotated_pole = rot * np.broadcast_to(pole,rot.shape+(3,)) label = '{}{} {} {}{}'.format(brackets[0],*(list(options.values())[0]),brackets[1])
xy = rotated_pole[:,0:2]/(1.+abs(pole[2])) in_file = default.place(f'p^{label}')
in_memory = xy if not polar else \ print(in_file - in_memory)
np.block([np.sqrt(xy[:,0:1]*xy[:,0:1]+xy[:,1:2]*xy[:,1:2]),np.arctan2(xy[:,1:2],xy[:,0:1])])
in_file = default.place('p^{}_[1 0 0)'.format(u'' if polar else 'xy'))
assert np.allclose(in_memory,in_file) assert np.allclose(in_memory,in_file)
def test_add_rotation(self,default): def test_add_rotation(self,default):