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, *, def to_pole(self, *,
uvw: FloatSequence = None, uvw: FloatSequence = None,
hkl: 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). 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) uvw|hkl : numpy.ndarray, shape (...,3)
Miller indices of crystallographic direction or plane normal. Miller indices of crystallographic direction or plane normal.
Shape of vector blends with shape of own rotation array. 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 with_symmetry : bool, optional
Calculate all N symmetrically equivalent vectors. Calculate all N symmetrically equivalent vectors.
Defaults to False.
normalize : bool, optional
Normalize output vector.
Defaults to True.
Returns Returns
------- -------
vector : numpy.ndarray, shape (...,3) or (...,N,3) 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) v = self.to_frame(uvw=uvw,hkl=hkl)
blend = util.shapeblender(self.shape,v.shape[:-1]) 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: if with_symmetry:
sym_ops = self.symmetry_operations sym_ops = self.symmetry_operations
shape = v.shape[:-1]+sym_ops.shape shape = v.shape[:-1]+sym_ops.shape

View File

@ -1023,26 +1023,26 @@ class Result:
@staticmethod @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 c = q['meta']['c/a'] if 'c/a' in q['meta'] else 1
brackets = ['[]','()','⟨⟩','{}'][(uvw is None)*1+with_symmetry*2] brackets = ['[]','()','⟨⟩','{}'][(uvw is None)*1+with_symmetry*2]
label = 'p^' + '{}{} {} {}{}'.format(brackets[0], label = 'p^' + '{}{} {} {}{}'.format(brackets[0],
*(uvw if uvw else hkl), *(uvw if uvw else hkl),
brackets[-1],) 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 { return {
'data': pole, 'data': ori.to_pole(uvw=uvw,hkl=hkl,with_symmetry=with_symmetry,normalize=normalize),
'label': label, 'label': label,
'meta' : { 'meta' : {
'unit': '1', 'unit': '1',
'description': 'lab frame vector along lattice ' \ 'description': f'{"normalized " if normalize else ""}lab frame vector along lattice ' \
+ ('direction' if uvw else 'plane') \ + ('direction' if uvw is not None else 'plane') \
+ ('s' if with_symmetry else ''), + ('s' if with_symmetry else ''),
'creator': 'add_pole' '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). 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. Miller indices of crystallographic direction or plane normal.
with_symmetry : bool, optional with_symmetry : bool, optional
Calculate all N symmetrically equivalent vectors. 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 @staticmethod

View File

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

View File

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

View File

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

View File

@ -471,7 +471,7 @@ program DAMASK_grid
call materialpoint_restartWrite call materialpoint_restartWrite
endif endif
if (signal) call signals_setSIGUSR2(.false.) 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 (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error'
if (signal) exit loadCaseLooping if (signal) exit loadCaseLooping
endif skipping endif skipping

View File

@ -10,13 +10,13 @@ module signals
private private
logical, volatile, public, protected :: & logical, volatile, public, protected :: &
signals_SIGTERM, & !< termination signal signals_SIGINT = .false., & !< interrupt signal
signals_SIGUSR1, & !< 1. user-defined signal signals_SIGUSR1 = .false., & !< 1. user-defined signal
signals_SIGUSR2 !< 2. user-defined signal signals_SIGUSR2 = .false. !< 2. user-defined signal
public :: & public :: &
signals_init, & signals_init, &
signals_setSIGTERM, & signals_setSIGINT, &
signals_setSIGUSR1, & signals_setSIGUSR1, &
signals_setSIGUSR2 signals_setSIGUSR2
@ -28,29 +28,26 @@ contains
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
subroutine signals_init() subroutine signals_init()
call signalterm_c(c_funloc(catchSIGTERM)) call signalint_c(c_funloc(catchSIGINT))
call signalusr1_c(c_funloc(catchSIGUSR1)) call signalusr1_c(c_funloc(catchSIGUSR1))
call signalusr2_c(c_funloc(catchSIGUSR2)) call signalusr2_c(c_funloc(catchSIGUSR2))
call signals_setSIGTERM(.false.)
call signals_setSIGUSR1(.false.)
call signals_setSIGUSR2(.false.)
end subroutine signals_init 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. !> @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 integer(C_INT), value :: signal
print'(a,i0)', ' received signal ',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 logical, intent(in) :: state
signals_SIGTERM = state signals_SIGINT = state
print*, 'set SIGTERM to',state print*, 'set SIGINT to',state
end subroutine signals_setSIGTERM end subroutine signals_setSIGINT
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------

View File

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