From f0eeb3d9b41080d56613edb47d1b4583fa19472a Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 7 Mar 2019 22:22:49 +0100 Subject: [PATCH] using naming convention of numpy --- src/math.f90 | 128 ++++++++++++++++----------------------------------- 1 file changed, 39 insertions(+), 89 deletions(-) diff --git a/src/math.f90 b/src/math.f90 index 21e92eaf4..288675703 100644 --- a/src/math.f90 +++ b/src/math.f90 @@ -68,49 +68,28 @@ module math ],[2,9]) !< arrangement in Plain notation !-------------------------------------------------------------------------------------------------- -! Provide deprecated names for compatibility - - interface math_cross - module procedure math_crossproduct - end interface math_cross - -! ToDo MD: Our naming scheme was a little bit odd: We use essentially the re-ordering according to Nye -! (convenient because Abaqus and Marc want to have 12 on position 4) -! but weight the shear components according to Mandel (convenient for matrix multiplications) - - interface math_Plain33to9 - module procedure math_33to9 - end interface math_Plain33to9 - - interface math_Plain9to33 - module procedure math_9to33 - end interface math_Plain9to33 - - interface math_Mandel33to6 - module procedure math_sym33to6 - end interface math_Mandel33to6 - - interface math_Mandel6to33 - module procedure math_6toSym33 - end interface math_Mandel6to33 - - interface math_Plain3333to99 - module procedure math_3333to99 - end interface math_Plain3333to99 - - interface math_Plain99to3333 - module procedure math_99to3333 - end interface math_Plain99to3333 - +! Provide deprecated name for compatibility + interface math_crossproduct + module procedure math_cross + end interface math_crossproduct + interface math_tensorproduct + module procedure math_outer + end interface math_tensorproduct + interface math_tensorproduct33 + module procedure math_outer + end interface math_tensorproduct33 + interface math_mul3x3 + module procedure math_inner + end interface math_mul3x3 public :: & - math_Plain33to9, & - math_Plain9to33, & - math_Mandel33to6, & - math_Mandel6to33, & - math_Plain3333to99, & - math_Plain99to3333 + math_mul3x3, & + math_mul6x6, & + math_tensorproduct33, & + math_tensorproduct, & + math_crossproduct !--------------------------------------------------------------------------------------------------- + public :: & #if defined(__PGI) norm2, & @@ -124,10 +103,8 @@ module math math_civita, & math_delta, & math_cross, & - math_crossproduct, & - math_tensorproduct33, & - math_mul3x3, & - math_mul6x6, & + math_outer, & + math_inner, & math_mul33xx33, & math_mul3333xx33, & math_mul3333xx3333, & @@ -537,73 +514,46 @@ end function math_delta !-------------------------------------------------------------------------------------------------- !> @brief cross product a x b !-------------------------------------------------------------------------------------------------- -pure function math_crossproduct(A,B) +pure function math_cross(A,B) implicit none real(pReal), dimension(3), intent(in) :: A,B - real(pReal), dimension(3) :: math_crossproduct + real(pReal), dimension(3) :: math_cross - math_crossproduct = [ A(2)*B(3) -A(3)*B(2), & - A(3)*B(1) -A(1)*B(3), & - A(1)*B(2) -A(2)*B(1) ] + math_cross = [ A(2)*B(3) -A(3)*B(2), & + A(3)*B(1) -A(1)*B(3), & + A(1)*B(2) -A(2)*B(1) ] -end function math_crossproduct +end function math_cross !-------------------------------------------------------------------------------------------------- -!> @brief tensor product A \otimes B of arbitrary sized vectors A and B +!> @brief outer product A \otimes B of arbitrary sized vectors A and B !-------------------------------------------------------------------------------------------------- -pure function math_tensorproduct(A,B) +pure function math_outer(A,B) implicit none real(pReal), dimension(:), intent(in) :: A,B - real(pReal), dimension(size(A,1),size(B,1)) :: math_tensorproduct + real(pReal), dimension(size(A,1),size(B,1)) :: math_outer integer(pInt) :: i,j - forall(i=1_pInt:size(A,1),j=1_pInt:size(B,1)) math_tensorproduct(i,j) = A(i)*B(j) + forall(i=1_pInt:size(A,1),j=1_pInt:size(B,1)) math_outer(i,j) = A(i)*B(j) -end function math_tensorproduct +end function math_outer !-------------------------------------------------------------------------------------------------- -!> @brief tensor product A \otimes B of leght-3 vectors A and B +!> @brief outer product A \otimes B of arbitrary sized vectors A and B !-------------------------------------------------------------------------------------------------- -pure function math_tensorproduct33(A,B) +real(pReal) pure function math_inner(A,B) implicit none - real(pReal), dimension(3,3) :: math_tensorproduct33 - real(pReal), dimension(3), intent(in) :: A,B - integer(pInt) :: i,j + real(pReal), dimension(:), intent(in) :: A + real(pReal), dimension(size(A,1)), intent(in) :: B - forall(i=1_pInt:3_pInt,j=1_pInt:3_pInt) math_tensorproduct33(i,j) = A(i)*B(j) + math_inner = sum(A*B) -end function math_tensorproduct33 - - -!-------------------------------------------------------------------------------------------------- -!> @brief matrix multiplication 3x3 = 1 -!-------------------------------------------------------------------------------------------------- -real(pReal) pure function math_mul3x3(A,B) - - implicit none - real(pReal), dimension(3), intent(in) :: A,B - - math_mul3x3 = sum(A*B) - -end function math_mul3x3 - - -!-------------------------------------------------------------------------------------------------- -!> @brief matrix multiplication 6x6 = 1 -!-------------------------------------------------------------------------------------------------- -real(pReal) pure function math_mul6x6(A,B) - - implicit none - real(pReal), dimension(6), intent(in) :: A,B - - math_mul6x6 = sum(A*B) - -end function math_mul6x6 +end function math_inner !-------------------------------------------------------------------------------------------------- @@ -2108,7 +2058,7 @@ function math_eigenvectorBasisSym(m) do i=1_pInt, size(m,1) math_eigenvectorBasisSym = math_eigenvectorBasisSym & - + sqrt(values(i)) * math_tensorproduct(vectors(:,i),vectors(:,i)) + + sqrt(values(i)) * math_outer(vectors(:,i),vectors(:,i)) enddo end function math_eigenvectorBasisSym