Skip to main content

Contraction

This generic function performs contraction of tensors.

The contraction method contracts the multi-dimension arrays.

The general syntax is given below:

ans = CONTRACTION(a1, a2)

where,

  • a1 and a2 can be a Fortran array of rank 1, 2, 3, and 4.

Let's employ the following notation:

  • r0 rank-0 scalar
  • r1 rank-1 vector
  • r2 rank-2 matrix
  • r3 rank-3
  • r4 rank-4

Then, the following table explains this operator.

a1a2ans
r1r1r0
r1r2r1
r1r3r2
r1r4r3
r2r1r1
r2r2r0
r2r3r1
r2r4r2
r3r1r2
r3r2r1
r3r3r0
r3r4r1
r4r1r3
r4r2r2
r4r3r1
r4r4r0

Interface 1

INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:, :, :, :)
REAL(DFP), INTENT(IN) :: a2(:)
REAL(DFP) :: ans(size(a1, 1), size(a1, 2), size(a1, 3))
END FUNCTION
END INTERFACE

Interface 2

INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:, :, :, :)
REAL(DFP), INTENT(IN) :: a2(:,:)
REAL(DFP) :: ans(size(a1, 1), size(a1, 2))
END FUNCTION
END INTERFACE

Interface 3

 INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:, :, :, :)
REAL(DFP), INTENT(IN) :: a2(:, :, :)
REAL(DFP) :: ans(size(a1, 1))
END FUNCTION
END INTERFACE

Interface 4

INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:, :, :, :)
REAL(DFP), INTENT(IN) :: a2(:, :, :, :)
REAL(DFP) :: ans
END FUNCTION
END INTERFACE

Interface 5

 INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:, :, :)
REAL(DFP), INTENT(IN) :: a2(:)
REAL(DFP) :: ans(size(a1, 1), size(a1, 2))
END FUNCTION
END INTERFACE

Interface 6

 INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:, :, :)
REAL(DFP), INTENT(IN) :: a2(:, :)
REAL(DFP) :: ans(size(a1, 1))
END FUNCTION
END INTERFACE

Interface 7

 INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:,:,:)
REAL(DFP), INTENT(IN) :: a2(:, :, :)
REAL(DFP) :: ans
END FUNCTION
END INTERFACE

Interface 8

 INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:,:,:)
REAL(DFP), INTENT(IN) :: a2(:, :, :, :)
REAL(DFP) :: ans(size(a2,4))
END FUNCTION
END INTERFACE

Interface 9

 INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:, :)
REAL(DFP), INTENT(IN) :: a2(:)
REAL(DFP) :: ans(size(a1, 1))
END FUNCTION
END INTERFACE

Interface 10

 INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:, :)
REAL(DFP), INTENT(IN) :: a2(:, :)
REAL(DFP) :: ans
END FUNCTION
END INTERFACE

Interface 11

 INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:,:)
REAL(DFP), INTENT(IN) :: a2(:, :, :)
REAL(DFP) :: ans(size(a2,3))
END FUNCTION
END INTERFACE

Interface 12

 INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:,:)
REAL(DFP), INTENT(IN) :: a2(:, :, :, :)
REAL(DFP) :: ans(size(a2,3), size(a2,4))
END FUNCTION
END INTERFACE

Interface 13

 INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:)
REAL(DFP), INTENT(IN) :: a2(:)
REAL(DFP) :: ans
END FUNCTION
END INTERFACE

Interface 14

 INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:)
REAL(DFP), INTENT(IN) :: a2(:, :)
REAL(DFP) :: ans(size(a2,2))
END FUNCTION
END INTERFACE

Interface 15

 INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:)
REAL(DFP), INTENT(IN) :: a2(:, :, :)
REAL(DFP) :: ans(size(a2,2), size(a2,3))
END FUNCTION
END INTERFACE

Interface 16

 INTERFACE
MODULE PURE FUNCTION Contraction(a1, a2) RESULT(ans)
REAL(DFP), INTENT(IN) :: a1(:)
REAL(DFP), INTENT(IN) :: a2(:, :, :, :)
REAL(DFP) :: ans(size(a2,2), size(a2,3), size(a2,4))
END FUNCTION
END INTERFACE