GooseTensor
Python module to perform simple tensor multiplications. This module is extremely compact and simple, as it just provides a front-end for the C++ library <cppmat/tensor.h>
.
The module is based on three types of tensors, which are each NumPy arrays (below exemplified using zero-tensors):
Type |
cppmat type |
Definition in Python |
---|---|---|
Vectors | cppmat::cartesian::vector |
np.zeros((nd)) |
2nd order tensors | cppmat::cartesian::tensor2 |
np.zeros((nd,nd)) |
4th order tensors | cppmat::cartesian::tensor4 |
np.zeros((nd,nd,nd,nd)) |
The
cppmat
tensors with a special structure (i.e.cppmat::tensor2s
andcppmat::tensor2d
) are not available from Python.
The following functions are available, whereby the trailing (two) number(s) of both the functions and the variables are indicative for the rank of the input tensor(s).
-
C4 = ddot44 ( A4, B4 )
Double tensor contraction Cijmn = Aijkl Blkmn
-
C2 = ddot42 ( A4 , B2 )
Double tensor contraction Cij = Aijkl Blk
-
C2 = ddot24 ( A2 , B4 )
Double tensor contraction Ckl = Aij Bjikl
-
C = ddot22 ( A2 , B2 )
Double tensor contraction C = Aij Bji
-
C2 = dot22 ( A2 , B2 )
Tensor contraction Cik = Aij Bjk
-
C1 = dot21 ( A2 , B1 )
Tensor contraction Ci = Aij Bj
-
C1 = dot12 ( A1 , B2 )
Tensor contraction Cj = Ai Bij
-
C = dot11 ( A1 , B1 )
Tensor contraction C = Ai Bi
-
C4 = dyadic22 ( A2 , B2 )
Dyadic product Cijkl = Aij Bkl
-
C2 = dyadic11 ( A1 , B1 )
Dyadic product Cij = Ai Bj
-
C1 = cross ( A1 , B1 )
Cross product Ci
-
C4 = transpose4 ( A4 )
Transposition Clkji = Aijkl
-
C4 = transpose4L ( A4 )
Left-transposition Cjikl = Aijkl
-
C4 = transpose4R ( A4 )
Right-transposition Cijlk = Aijkl
-
C2 = transpose2 ( A2 )
Transposition Cji = Aij
-
C = trace2 ( A2 )
The trace of the tensor (i.e. the sum of the diagonal components) C = Aii
-
C = det2 ( A2 )
The determinant C
-
C2 = inv2 ( A2 )
The inverse Cij
Installation
Pre-compiled version using PyPi
Use
pip3 install GooseTensor
(replace pip3
with the Python version you'd want to use, e.g. by pip
).
Local build
To compile and install this module use
python3 setup.py build
python3 setup.py install
(replace python3
with the executable of the Python version you'd want to use, e.g. by python
).
Develop
Create a new release
-
Update the version number by modifying
__version__
insetup.py
. -
Upload the changes to GitHub and create a new release there (with the correct version number).
-
Upload the package to PyPi:
$ python3 setup.py bdist_wheel --universal $ twine upload dist/*