Merge remote-tracking branch 'origin/development' into more-material-parameters

This commit is contained in:
Martin Diehl 2022-05-17 01:57:31 +02:00
commit af4e31ca1c
9 changed files with 58 additions and 46 deletions

View File

@ -1 +1 @@
3.0.0-alpha6-343-gc8d48d6eb
3.0.0-alpha6-355-g6c7f2344d

View File

@ -786,7 +786,8 @@ class Orientation(Rotation,Crystal):
def to_pole(self, *,
uvw: FloatSequence = None,
hkl: FloatSequence = None,
with_symmetry: bool = False) -> np.ndarray:
with_symmetry: bool = False,
normalize: bool = True) -> np.ndarray:
"""
Calculate lab frame vector along lattice direction [uvw] or plane normal (hkl).
@ -795,18 +796,26 @@ class Orientation(Rotation,Crystal):
uvw|hkl : numpy.ndarray, shape (...,3)
Miller indices of crystallographic direction or plane normal.
Shape of vector blends with shape of own rotation array.
For example, a rotation array, shape (3,2) and a vector array of shape (2,4) result in (3,2,4) outputs.
For example, a rotation array of shape (3,2) and a vector
array of shape (2,4) result in (3,2,4) outputs.
with_symmetry : bool, optional
Calculate all N symmetrically equivalent vectors.
Defaults to False.
normalize : bool, optional
Normalize output vector.
Defaults to True.
Returns
-------
vector : numpy.ndarray, shape (...,3) or (...,N,3)
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.
"""
v = self.to_frame(uvw=uvw,hkl=hkl)
blend = util.shapeblender(self.shape,v.shape[:-1])
if normalize:
v /= np.linalg.norm(v,axis=-1,keepdims=len(v.shape)>1)
if with_symmetry:
sym_ops = self.symmetry_operations
shape = v.shape[:-1]+sym_ops.shape

View File

@ -1023,26 +1023,26 @@ class Result:
@staticmethod
def _add_pole(q,uvw,hkl,with_symmetry):
def _add_pole(q,uvw,hkl,with_symmetry,normalize):
c = q['meta']['c/a'] if 'c/a' in q['meta'] else 1
brackets = ['[]','()','⟨⟩','{}'][(uvw is None)*1+with_symmetry*2]
label = 'p^' + '{}{} {} {}{}'.format(brackets[0],
*(uvw if uvw else hkl),
brackets[-1],)
pole = Orientation(q['data'],lattice=q['meta']['lattice'],a=1,c=c).to_pole(uvw=uvw,hkl=hkl,with_symmetry=with_symmetry)
ori = Orientation(q['data'],lattice=q['meta']['lattice'],a=1,c=c)
return {
'data': pole,
'data': ori.to_pole(uvw=uvw,hkl=hkl,with_symmetry=with_symmetry,normalize=normalize),
'label': label,
'meta' : {
'unit': '1',
'description': 'lab frame vector along lattice ' \
+ ('direction' if uvw else 'plane') \
'description': f'{"normalized " if normalize else ""}lab frame vector along lattice ' \
+ ('direction' if uvw is not None else 'plane') \
+ ('s' if with_symmetry else ''),
'creator': 'add_pole'
}
}
def add_pole(self,q='O',*,uvw=None,hkl=None,with_symmetry=False):
def add_pole(self,q='O',*,uvw=None,hkl=None,with_symmetry=False,normalize=True):
"""
Add lab frame vector along lattice direction [uvw] or plane normal (hkl).
@ -1055,9 +1055,15 @@ class Result:
Miller indices of crystallographic direction or plane normal.
with_symmetry : bool, optional
Calculate all N symmetrically equivalent vectors.
Defaults to True.
normalize : bool, optional
Normalize output vector.
Defaults to True.
"""
self._add_generic_pointwise(self._add_pole,{'q':q},{'uvw':uvw,'hkl':hkl,'with_symmetry':with_symmetry})
self._add_generic_pointwise(self._add_pole,
{'q':q},
{'uvw':uvw,'hkl':hkl,'with_symmetry':with_symmetry,'normalize':normalize})
@staticmethod

View File

@ -721,7 +721,7 @@ class Rotation:
Parameters
----------
q : numpy.ndarray, shape (...,4)
Unit quaternion (q_0, q_1, q_2, q_3) in positive real hemisphere, i.e. ǀqǀ = 1, q_0 0.
Unit quaternion (q_0, q_1, q_2, q_3) in positive real hemisphere, i.e. ǀqǀ = 1 and q_0 0.
accept_homomorph : bool, optional
Allow homomorphic variants, i.e. q_0 < 0 (negative real hemisphere).
Defaults to False.
@ -781,7 +781,7 @@ class Rotation:
normalize: bool = False,
P: Literal[1, -1] = -1) -> 'Rotation':
"""
Initialize from Axis angle pair.
Initialize from axisangle pair.
Parameters
----------
@ -818,12 +818,12 @@ class Rotation:
orthonormal: bool = True,
reciprocal: bool = False) -> 'Rotation':
"""
Initialize from lattice basis vectors.
Initialize from basis vector triplet.
Parameters
----------
basis : numpy.ndarray, shape (...,3,3)
Three three-dimensional lattice basis vectors.
Three three-dimensional basis vectors.
orthonormal : bool, optional
Basis is strictly orthonormal, i.e. is free of stretch components. Defaults to True.
reciprocal : bool, optional
@ -857,7 +857,7 @@ class Rotation:
Parameters
----------
R : numpy.ndarray, shape (...,3,3)
Rotation matrix with det(R) = 1, R.T R = I.
Rotation matrix with det(R) = 1 and R.T R = I.
"""
return Rotation.from_basis(R)
@ -866,14 +866,14 @@ class Rotation:
def from_parallel(a: np.ndarray,
b: np.ndarray ) -> 'Rotation':
"""
Initialize from pairs of two orthogonal lattice basis vectors.
Initialize from pairs of two orthogonal basis vectors.
Parameters
----------
a : numpy.ndarray, shape (...,2,3)
Two three-dimensional lattice vectors of first orthogonal basis.
Two three-dimensional vectors of first orthogonal basis.
b : numpy.ndarray, shape (...,2,3)
Corresponding three-dimensional lattice vectors of second basis.
Corresponding three-dimensional vectors of second basis.
"""
a_ = np.array(a)
@ -896,7 +896,7 @@ class Rotation:
normalize: bool = False,
P: Literal[1, -1] = -1) -> 'Rotation':
"""
Initialize from RodriguesFrank vector (angle separated from axis).
Initialize from RodriguesFrank vector (with angle separated from axis).
Parameters
----------

View File

@ -180,8 +180,8 @@ class TestOrientation:
o = Orientation.from_directions(uvw=a,hkl=c,**kwargs)
x = o.to_pole(uvw=a)
z = o.to_pole(hkl=c)
assert np.isclose(np.dot(x/np.linalg.norm(x),np.array([1,0,0])),1) \
and np.isclose(np.dot(z/np.linalg.norm(z),np.array([0,0,1])),1)
assert np.isclose(np.dot(x,np.array([1,0,0])),1) \
and np.isclose(np.dot(z,np.array([0,0,1])),1)
@pytest.mark.parametrize('function',[Orientation.from_random,
Orientation.from_quaternion,

View File

@ -58,8 +58,8 @@ void getusername_c(char username[], int *stat){
}
void signalterm_c(void (*handler)(int)){
signal(SIGTERM, handler);
void signalint_c(void (*handler)(int)){
signal(SIGINT, handler);
}
void signalusr1_c(void (*handler)(int)){

View File

@ -471,7 +471,7 @@ program DAMASK_grid
call materialpoint_restartWrite
endif
if (signal) call signals_setSIGUSR2(.false.)
call MPI_Allreduce(signals_SIGTERM,signal,1_MPI_INTEGER_KIND,MPI_LOGICAL,MPI_LOR,MPI_COMM_WORLD,err_MPI)
call MPI_Allreduce(signals_SIGINT,signal,1_MPI_INTEGER_KIND,MPI_LOGICAL,MPI_LOR,MPI_COMM_WORLD,err_MPI)
if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error'
if (signal) exit loadCaseLooping
endif skipping

View File

@ -10,13 +10,13 @@ module signals
private
logical, volatile, public, protected :: &
signals_SIGTERM, & !< termination signal
signals_SIGUSR1, & !< 1. user-defined signal
signals_SIGUSR2 !< 2. user-defined signal
signals_SIGINT = .false., & !< interrupt signal
signals_SIGUSR1 = .false., & !< 1. user-defined signal
signals_SIGUSR2 = .false. !< 2. user-defined signal
public :: &
signals_init, &
signals_setSIGTERM, &
signals_setSIGINT, &
signals_setSIGUSR1, &
signals_setSIGUSR2
@ -28,29 +28,26 @@ contains
!--------------------------------------------------------------------------------------------------
subroutine signals_init()
call signalterm_c(c_funloc(catchSIGTERM))
call signalint_c(c_funloc(catchSIGINT))
call signalusr1_c(c_funloc(catchSIGUSR1))
call signalusr2_c(c_funloc(catchSIGUSR2))
call signals_setSIGTERM(.false.)
call signals_setSIGUSR1(.false.)
call signals_setSIGUSR2(.false.)
end subroutine signals_init
!--------------------------------------------------------------------------------------------------
!> @brief Set global variable signals_SIGTERM to .true.
!> @brief Set global variable signals_SIGINT to .true.
!> @details This function can be registered to catch signals send to the executable.
!--------------------------------------------------------------------------------------------------
subroutine catchSIGTERM(signal) bind(C)
subroutine catchSIGINT(signal) bind(C)
integer(C_INT), value :: signal
print'(a,i0)', ' received signal ',signal
call signals_setSIGTERM(.true.)
call signals_setSIGINT(.true.)
end subroutine catchSIGTERM
end subroutine catchSIGINT
!--------------------------------------------------------------------------------------------------
@ -84,17 +81,17 @@ end subroutine catchSIGUSR2
!--------------------------------------------------------------------------------------------------
!> @brief Set global variable signals_SIGTERM.
!> @brief Set global variable signals_SIGINT.
!--------------------------------------------------------------------------------------------------
subroutine signals_setSIGTERM(state)
subroutine signals_setSIGINT(state)
logical, intent(in) :: state
signals_SIGTERM = state
print*, 'set SIGTERM to',state
signals_SIGINT = state
print*, 'set SIGINT to',state
end subroutine signals_setSIGTERM
end subroutine signals_setSIGINT
!--------------------------------------------------------------------------------------------------

View File

@ -15,7 +15,7 @@ module system_routines
getCWD, &
getHostName, &
getUserName, &
signalterm_C, &
signalint_C, &
signalusr1_C, &
signalusr2_C, &
f_c_string, &
@ -55,11 +55,11 @@ module system_routines
integer(C_INT), intent(out) :: stat
end subroutine getUserName_C
subroutine signalterm_C(handler) bind(C)
subroutine signalint_C(handler) bind(C)
use, intrinsic :: ISO_C_Binding, only: C_FUNPTR
type(C_FUNPTR), intent(in), value :: handler
end subroutine signalterm_C
end subroutine signalint_C
subroutine signalusr1_C(handler) bind(C)
use, intrinsic :: ISO_C_Binding, only: C_FUNPTR