better readable

This commit is contained in:
Martin Diehl 2019-09-20 08:45:23 -07:00
parent d69d57221d
commit 7ff106a1fc
1 changed files with 13 additions and 15 deletions

View File

@ -71,7 +71,8 @@ module rotations
procedure, private :: rotRot__ procedure, private :: rotRot__
generic, public :: operator(*) => rotRot__ generic, public :: operator(*) => rotRot__
procedure, public :: rotVector procedure, public :: rotVector
procedure, public :: rotTensor procedure, public :: rotTensor2
!procedure, public :: rotTensor4
procedure, public :: misorientation procedure, public :: misorientation
end type rotation end type rotation
@ -221,7 +222,6 @@ end function rotRot__
!--------------------------------------------------------------------------------------------------- !---------------------------------------------------------------------------------------------------
!> @author Marc De Graef, Carnegie Mellon University !> @author Marc De Graef, Carnegie Mellon University
!> @brief rotate a vector passively (default) or actively !> @brief rotate a vector passively (default) or actively
!> @details: rotation is based on unit quaternion or rotation matrix (fallback)
!--------------------------------------------------------------------------------------------------- !---------------------------------------------------------------------------------------------------
function rotVector(self,v,active) result(vRot) function rotVector(self,v,active) result(vRot)
@ -230,8 +230,9 @@ function rotVector(self,v,active) result(vRot)
real(pReal), intent(in), dimension(3) :: v real(pReal), intent(in), dimension(3) :: v
logical, intent(in), optional :: active logical, intent(in), optional :: active
type(quaternion) :: q real(pReal), dimension(3) :: v_normed
logical :: passive type(quaternion) :: q
logical :: passive
if (present(active)) then if (present(active)) then
passive = .not. active passive = .not. active
@ -239,19 +240,16 @@ function rotVector(self,v,active) result(vRot)
passive = .true. passive = .true.
endif endif
if (dEq(norm2(v),1.0_pReal,tol=1.0e-15_pReal)) then if (dEq0(norm2(v))) then
if (passive) then vRot = v
q = self%q * (quaternion([0.0_pReal, v(1), v(2), v(3)]) * conjg(self%q) )
else
q = conjg(self%q) * (quaternion([0.0_pReal, v(1), v(2), v(3)]) * self%q )
endif
vRot = q%real()
else else
v_normed = v_normed/norm2(v)
if (passive) then if (passive) then
vRot = matmul(self%asRotationMatrix(),v) q = self%q * (quaternion([0.0_pReal, v_normed(1), v_normed(2), v_normed(3)]) * conjg(self%q) )
else else
vRot = matmul(transpose(self%asRotationMatrix()),v) q = conjg(self%q) * (quaternion([0.0_pReal, v_normed(1), v_normed(2), v_normed(3)]) * self%q )
endif endif
vRot = q%real()*norm2(v)
endif endif
end function rotVector end function rotVector
@ -262,7 +260,7 @@ end function rotVector
!> @brief rotate a second rank tensor passively (default) or actively !> @brief rotate a second rank tensor passively (default) or actively
!> @details: rotation is based on rotation matrix !> @details: rotation is based on rotation matrix
!--------------------------------------------------------------------------------------------------- !---------------------------------------------------------------------------------------------------
function rotTensor(self,m,active) result(mRot) function rotTensor2(self,m,active) result(mRot)
real(pReal), dimension(3,3) :: mRot real(pReal), dimension(3,3) :: mRot
class(rotation), intent(in) :: self class(rotation), intent(in) :: self
@ -283,7 +281,7 @@ function rotTensor(self,m,active) result(mRot)
mRot = matmul(matmul(transpose(self%asRotationMatrix()),m),self%asRotationMatrix()) mRot = matmul(matmul(transpose(self%asRotationMatrix()),m),self%asRotationMatrix())
endif endif
end function rotTensor end function rotTensor2
!--------------------------------------------------------------------------------------------------- !---------------------------------------------------------------------------------------------------