Skip to content

Commit

Permalink
removed "symmetry_index" option; add_pole now hardwired exception
Browse files Browse the repository at this point in the history
  • Loading branch information
eisenlohr committed May 22, 2024
1 parent ec70acb commit 444e03b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
10 changes: 2 additions & 8 deletions python/damask/_orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,6 @@ def to_frame(self, *,
hkl: Optional[FloatSequence] = None,
with_symmetry: bool = False,
normalize: bool = True,
symmetry_index: str = 'head',
) -> np.ndarray:
"""
Calculate lab frame vector along lattice direction [uvw] or plane normal (hkl).
Expand All @@ -844,19 +843,14 @@ def to_frame(self, *,
normalize : bool, optional
Normalize output vector.
Defaults to True.
symmetry_index : [head, tail], optional
Symmetrically equivalent results are indexed in leading or trailing dimension of resulting vector.
Defaults to 'head'.
Returns
-------
vector : numpy.ndarray, shape (...,3) or (N,...,3) or (...,N,3)
vector : numpy.ndarray, shape (...,3) or (N,...,3)
Lab frame vector (or N vectors if with_symmetry) along
[uvw] direction or (hkl) plane normal.
"""
if symmetry_index not in ['head','tail']:
raise ValueError('symmetry_position is neither "head" nor "tail"')
v = super().to_frame(uvw=uvw,hkl=hkl)
s_v = v.shape[:-1]
blend = util.shapeblender(self.shape,s_v)
Expand All @@ -869,7 +863,7 @@ def to_frame(self, *,
v = sym_ops.broadcast_to(s_v) @ v[...,np.newaxis,:]

return np.moveaxis(~(self.broadcast_to(blend)) @ np.broadcast_to(v,blend+(3,)),
-2 if with_symmetry and symmetry_index=='head' else 0,
-2 if with_symmetry else 0,
0)


Expand Down
9 changes: 4 additions & 5 deletions python/damask/_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,15 +1150,14 @@ def pole(q: DADF5Dataset,
ori = Orientation(q['data'],lattice=q['meta']['lattice'],a=1,c=c)

return {
'data': ori.to_frame(uvw=uvw,hkl=hkl,
with_symmetry=with_symmetry,
normalize=normalize,
symmetry_index='tail'),
'data': np.moveaxis(ori.to_frame(uvw=uvw,hkl=hkl,
with_symmetry=with_symmetry,
normalize=normalize),0,-2 if with_symmetry else 0),
'label': label,
'meta' : {
'unit': '1',
'description': f'{"normalized " if normalize else ""}lab frame vector along lattice ' \
+ ('direction' if uvw is not None else 'plane') \
+ ('plane' if uvw is None else 'direction') \
+ ('s' if with_symmetry else ''),
'creator': 'add_pole'
}
Expand Down
8 changes: 3 additions & 5 deletions python/tests/test_Orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,22 +328,20 @@ def test_relationship_reference(self,update,res_path,model,lattice):
])
@pytest.mark.parametrize('kw',['uvw','hkl'])
@pytest.mark.parametrize('with_symmetry',[False,True])
@pytest.mark.parametrize('symmetry_index',['head','tail'])
@pytest.mark.parametrize('shape',[None,1,(12,24)])
@pytest.mark.parametrize('vector',[
np.random.random( 3 ),
np.random.random( (4,3)),
np.random.random((4,8,3)),
])
def test_to_frame(self,shape,lattice,a,b,c,alpha,beta,gamma,vector,kw,with_symmetry,symmetry_index):
def test_to_frame(self,shape,lattice,a,b,c,alpha,beta,gamma,vector,kw,with_symmetry):
o = Orientation.from_random(shape=shape,
lattice=lattice,
a=a,b=b,c=c,
alpha=alpha,beta=beta,gamma=gamma)
assert o.to_frame(**{kw:vector,'with_symmetry':with_symmetry,'symmetry_index':symmetry_index}).shape \
== (o.symmetry_operations.shape if with_symmetry and symmetry_index=='head' else ()) \
assert o.to_frame(**{kw:vector,'with_symmetry':with_symmetry}).shape \
== (o.symmetry_operations.shape if with_symmetry else ()) \
+ util.shapeblender(o.shape,vector.shape[:-1]) \
+ (o.symmetry_operations.shape if with_symmetry and symmetry_index=='tail' else ()) \
+ vector.shape[-1:]

@pytest.mark.parametrize('lattice',['hP','cI','cF']) #tI not included yet
Expand Down
3 changes: 2 additions & 1 deletion python/tests/test_Result.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ def test_add_stress_second_Piola_Kirchhoff(self,default):
def test_add_pole(self,default,options):
default.add_pole(**options)
rot = default.place('O')
in_memory = Orientation(rot,lattice=rot.dtype.metadata['lattice']).to_frame(**options,symmetry_index='tail')
in_memory = np.moveaxis(Orientation(rot,lattice=rot.dtype.metadata['lattice']).to_frame(**options),
0,-2 if options['with_symmetry'] else 0)
brackets = [['[[]','[]]'],'()','⟨⟩','{}'][('hkl' in options)*1+(options['with_symmetry'])*2] # escape fnmatch
label = 'p^{}{} {} {}{}'.format(brackets[0],
*(list(options.values())[0]),
Expand Down

0 comments on commit 444e03b

Please sign in to comment.