Notation: Converter Numeric

[1]:
import mechkit
import numpy as np
import sympy as sp
import itertools
[2]:
np.set_printoptions(
    linewidth=140,
    precision=3,
    # suppress=False,
)
converter = mechkit.notation.Converter()
[3]:
# ### Mandel6: symmetric, Mandel9: Mandel6 + asymmetric parts
basics = mechkit.tensors.Basic()
[4]:
# Symmetric identity
print(converter.to_mandel6(basics.I4s))
print(converter.to_mandel9(basics.I4s))
[[1. 0. 0. 0. 0. 0.]
 [0. 1. 0. 0. 0. 0.]
 [0. 0. 1. 0. 0. 0.]
 [0. 0. 0. 1. 0. 0.]
 [0. 0. 0. 0. 1. 0.]
 [0. 0. 0. 0. 0. 1.]]
[[ 1.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00]
 [ 0.000e+00  1.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00]
 [ 0.000e+00  0.000e+00  1.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00]
 [ 0.000e+00  0.000e+00  0.000e+00  1.000e+00  0.000e+00  0.000e+00 -4.266e-17  0.000e+00  0.000e+00]
 [ 0.000e+00  0.000e+00  0.000e+00  0.000e+00  1.000e+00  0.000e+00  0.000e+00  4.266e-17  0.000e+00]
 [ 0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  1.000e+00  0.000e+00  0.000e+00 -4.266e-17]
 [ 0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00]
 [ 0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00]
 [ 0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00]]
[5]:
# Asymmetric identity
print(converter.to_mandel6(basics.I4a))
print(converter.to_mandel9(basics.I4a))
[[0. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0.]]
[[ 0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00]
 [ 0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00]
 [ 0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00]
 [ 0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00]
 [ 0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00]
 [ 0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00]
 [ 0.000e+00  0.000e+00  0.000e+00 -4.266e-17  0.000e+00  0.000e+00  1.000e+00  0.000e+00  0.000e+00]
 [ 0.000e+00  0.000e+00  0.000e+00  0.000e+00  4.266e-17  0.000e+00  0.000e+00  1.000e+00  0.000e+00]
 [ 0.000e+00  0.000e+00  0.000e+00  0.000e+00  0.000e+00 -4.266e-17  0.000e+00  0.000e+00  1.000e+00]]

Convenient autodetection of the notation: Specify only target

[6]:
tensor = np.ones((3, 3, 3, 3))
mandel6 = converter.to_mandel6(tensor)
# Pass through
print(converter.to_tensor(mandel6))
print(converter.to_mandel6(mandel6))
print(converter.to_mandel9(mandel6))
[[[[1. 1. 1.]
   [1. 1. 1.]
   [1. 1. 1.]]

  [[1. 1. 1.]
   [1. 1. 1.]
   [1. 1. 1.]]

  [[1. 1. 1.]
   [1. 1. 1.]
   [1. 1. 1.]]]


 [[[1. 1. 1.]
   [1. 1. 1.]
   [1. 1. 1.]]

  [[1. 1. 1.]
   [1. 1. 1.]
   [1. 1. 1.]]

  [[1. 1. 1.]
   [1. 1. 1.]
   [1. 1. 1.]]]


 [[[1. 1. 1.]
   [1. 1. 1.]
   [1. 1. 1.]]

  [[1. 1. 1.]
   [1. 1. 1.]
   [1. 1. 1.]]

  [[1. 1. 1.]
   [1. 1. 1.]
   [1. 1. 1.]]]]
[[1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]]
[[1.    1.    1.    1.414 1.414 1.414 0.    0.    0.   ]
 [1.    1.    1.    1.414 1.414 1.414 0.    0.    0.   ]
 [1.    1.    1.    1.414 1.414 1.414 0.    0.    0.   ]
 [1.414 1.414 1.414 2.    2.    2.    0.    0.    0.   ]
 [1.414 1.414 1.414 2.    2.    2.    0.    0.    0.   ]
 [1.414 1.414 1.414 2.    2.    2.    0.    0.    0.   ]
 [0.    0.    0.    0.    0.    0.    0.    0.    0.   ]
 [0.    0.    0.    0.    0.    0.    0.    0.    0.   ]
 [0.    0.    0.    0.    0.    0.    0.    0.    0.   ]]

Vectorized explicit converter

[7]:
expl_converter = mechkit.notation.ExplicitConverter()
[8]:
tensors = np.ones((2, 5, 3, 3, 3, 3))  # We have 5 times 2 tensors of fourth order
[9]:
mandel6s = expl_converter.convert(
    inp=tensors, source="tensor", target="mandel6", quantity="stiffness"
)
[10]:
for i in range(2):
    for j in range(5):
        print(f"Tensor at position {i}, {j} in Mandel6 notation")
        print(mandel6s[i, j, ...])
        print()
Tensor at position 0, 0 in Mandel6 notation
[[1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]]

Tensor at position 0, 1 in Mandel6 notation
[[1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]]

Tensor at position 0, 2 in Mandel6 notation
[[1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]]

Tensor at position 0, 3 in Mandel6 notation
[[1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]]

Tensor at position 0, 4 in Mandel6 notation
[[1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]]

Tensor at position 1, 0 in Mandel6 notation
[[1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]]

Tensor at position 1, 1 in Mandel6 notation
[[1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]]

Tensor at position 1, 2 in Mandel6 notation
[[1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]]

Tensor at position 1, 3 in Mandel6 notation
[[1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]]

Tensor at position 1, 4 in Mandel6 notation
[[1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.    1.    1.    1.414 1.414 1.414]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]
 [1.414 1.414 1.414 2.    2.    2.   ]]