Elasticipy.SecondOrderTensor module

class Elasticipy.SecondOrderTensor.SecondOrderTensor(matrix)[source]

Bases: object

Template class for manipulation of second order tensors or arrays of second order tensors

matrix

(…,3,3) matrix storing all the components of the tensor

Type:

np.ndarray

property C

Return tensor components

For instance T.C[i,j] returns all the (i,j)-th components of each tensor in the array.

Returns:

Tensor components

Return type:

np.ndarray

property I1

First invariant of the tensor (trace)

Returns:

First invariant(s) of the tensor(s)

Return type:

np.ndarray or float

See also

I2

Second invariant of the tensors

I3

Third invariant of the tensors (det)

property I2

Second invariant of the tensor

For a matrix M, it is defined as:

I_2 = 0.5 * ( np.trace(M)**2 + np.trace(np.matmul(M, M.T)) )
Returns:

Second invariant(s) of the tensor(s)

Return type:

np.array or float

See also

I1

First invariant of the tensors (trace)

I3

Third invariant of the tensors (det)

property I3

Third invariant of the tensor (determinant)

Returns:

Third invariant(s) of the tensor(s)

Return type:

np.array or float

See also

I1

First invariant of the tensors (trace)

I2

Second invariant of the tensors

property T

Transpose the array of tensors.

It is actually an alias for transposeArray()

Returns:

Transposed array

Return type:

SecondOrderTensor

ddot(other)[source]

Double dot product (contraction of tensor product, usually denoted “:”) of two tensors.

For two tensors whose matrices are M1 and M2:

M1.ddot(M2) == np.trace(np.matmul(M1, M2))
Parameters:

other (SecondOrderTensor or np.ndarray) – Tensor or tensor array to multiply by before contraction.

Returns:

Result of double dot product

Return type:

float or np.ndarray

See also

matmul

matrix-like product between two tensor arrays.

deviatoricPart()[source]

Deviatoric part of the tensor

Return type:

SecondOrderTensor

See also

sphericalPart

spherical part of the tensor

eig()[source]

Eigenvalues of the tensor

Returns:

  • lambda (np.ndarray) – Eigenvalues of each tensor.

  • v (np.ndarray) – Eigenvectors of teach tensor.

See also

principalDirections

return only the principal directions (without eigenvalues)

classmethod eye(shape=())[source]

Create an array of tensors populated with identity matrices

Parameters:

shape (tuple or int, default ()) – If not provided, it just creates a single identity tensor. Otherwise, the tensor array will be of the specified shape.

Returns:

Array of identity tensors

Return type:

SecondOrderTensor

See also

ones

creates an array of tensors full of ones

zeros

creates an array full of zero tensors

flatten()[source]

Flatten the array of tensors.

If T is of shape [s1, s2, …, sn], the shape for T.flatten() is [s1*s2*…*sn].

Returns:

Flattened array (vector) of tensor

Return type:

SecondOrderTensor

See also

ndim

number of dimensions of the tensor array

shape

shape of the tensor array

matmul(other)[source]

Perform matrix-like product between tensor arrays. Each “product” is a matrix product between the tensor components.

If A.shape=(a1, a2, …, an) and B.shape=(b1, b2, …, bn), with C=A.matmul(B), we have:

C.shape = (a1, a2, ..., an, b1, b2, ..., bn)

and:

C[i,j,k,...,p,q,r...] = np.matmul(A[i,j,k,...], B[p,q,r,...])
Parameters:

other (SecondOrderTensor or np.ndarray or Rotation) – Tensor array or rotation to right-multiply by. If Rotation is provided, the rotations are applied on each tensor.

Returns:

Tensor array

Return type:

SecondOrderTensor

See also

__mul__

Element-wise matrix product

max(axis=None)[source]

Maximum value

Parameters:

axis (int or None, default None) – Axis to compute maximum along with. If None, returns the overall maximum (max of flattened array)

Returns:

Maximum value of tensors

Return type:

SecondOrderTensor

See also

min

Minimum value

mean

Mean value

std

Standard deviation

mean(axis=None)[source]

Arithmetic mean value

Parameters:

axis (int or None, default None) – Axis to compute the mean along with. If None, returns the overall mean (mean of flattened array)

Returns:

Mean tensor

Return type:

SecondOrderTensor

See also

std

Standard deviation

min

Minimum value

max

Maximum value

min(axis=None)[source]

Minimum value

Parameters:

axis (int or None, default None) – Axis to compute minimum along with. If None, returns the overall minimum (min of flattened array)

Returns:

Minimum value of tensors

Return type:

SecondOrderTensor

See also

max

Maximum value

mean

Mean value

std

Standard deviation

name = 'Second-order tensor'

Name to use when printing the tensor

property ndim

Return the number of dimensions of the tensor array

Returns:

number of dimensions

Return type:

float

See also

shape

shape of tensor array

classmethod ones(shape=())[source]

Create an array of tensors populated with matrices of full of ones.

Parameters:

shape (tuple or int, default ()) – If not provided, it just creates a single tensor of ones. Otherwise, the tensor array will be of the specified shape.

Returns:

Array of ones tensors

Return type:

SecondOrderTensor

See also

eye

creates an array of identity tensors

zeros

creates an array full of zero tensors

principalDirections()[source]

Principal directions of the tensors

Returns:

Principal directions of each tensor of the tensor array

Return type:

np.nparray

See also

eig

Return both eigenvalues and corresponding principal directions

property shape

Return the shape of the tensor array

Returns:

Shape of array

Return type:

tuple

See also

ndim

number of dimensions

classmethod shear(u, v, magnitude)[source]

Create an array of tensors corresponding to shear state along two orthogonal directions.

Parameters:
  • u (np.ndarray or list) – First direction. Must be a 3D vector.

  • v (np.ndarray or list) – Second direction. Must be a 3D vector.

  • magnitude (float or np.ndarray or list) – Magnitude of the shear state to consider. If a list or an array is provided, the shape of the tensor array will be of the same shape as magnitude.

Returns:

tensor or tensor array

Return type:

SecondOrderTensor

skewPart()[source]

Skew-symmetric part of the tensor

Returns:

Skew-symmetric tensor

Return type:

SecondOrderTensor

sphericalPart()[source]

Spherical (hydrostatic) part of the tensor

Returns:

Spherical part

Return type:

SecondOrderTensor

See also

I1

compute the first invariant of the tensor

deviatoricPart

deviatoric the part of the tensor

std(axis=None)[source]

Standard deviation

Parameters:

axis (int or None, default None) – Axis to compute standard deviation along with. If None, returns the overall standard deviation (std of flattened array)

Returns:

Tensor of standard deviation

Return type:

SecondOrderTensor

See also

mean

Mean value

min

Minimum value

max

Maximum value

symmetricPart()[source]

Symmetric part of the tensor

Returns:

Symmetric tensor

Return type:

SecondOrderTensor

See also

skewPart

Skew-symmetric part of the tensor

classmethod tensile(u, magnitude)[source]

Create an array of tensors corresponding to tensile state along a given direction.

Parameters:
  • u (np.ndarray or list) – Tensile direction. Must be a 3D vector.

  • magnitude (float or np.ndarray or list) – Magnitude of the tensile state to consider. If a list or an array is provided, the shape of the tensor array will be of the same shape as magnitude.

Returns:

tensor or tensor array

Return type:

SecondOrderTensor

trace()[source]

Return the traces of the tensor array

Returns:

traces of each tensor of the tensor array

Return type:

np.ndarray or float

See also

I1

First invariant of the tensors (trace)

I2

Second invariant of the tensors

I3

Third invariant of the tensors (det)

transposeArray()[source]

Transpose the array of tensors

If A is a tensor array of shape [s1, s2, …, sn], A.T is of shape [sn, …, s2, s1].

Returns:

Transposed array

Return type:

SecondOrderTensor

See also

T

transpose the tensor array (not the components)

transposeTensor()[source]

Transpose of tensors of the tensor array

Returns:

Array of transposed tensors of the tensor array

Return type:

SecondOrderTensor

See also

Transpose

transpose the array (not the components)

classmethod zeros(shape=())[source]

Create an array of tensors populated with matrices full of zeros.

Parameters:

shape (tuple or int, default ()) – If not provided, it just creates a single tensor of ones. Otherwise, the tensor array will be of the specified shape.

Returns:

Array of ones tensors

Return type:

SecondOrderTensor

See also

eye

creates an array of identity tensors

ones

creates an array of tensors full of ones

class Elasticipy.SecondOrderTensor.SymmetricSecondOrderTensor(mat)[source]

Bases: SecondOrderTensor

classmethod from_Voigt(array)[source]

Construct a SymmetricSecondOrderTensor from a Voigt vector, or slices of Voigt vectors.

If the array is of shape (6,), a single tensor is returned. If the array is of shape (m,n,o,…,6), the tensor will be of shape (m,n,o,…).

Parameters:

array (np.ndarray or list) – array to build the SymmetricSecondOrderTensor from. We must have array.ndim>0 and array.shape[-1]==6.

Return type:

SymmetricSecondOrderTensor

Examples

>>> SymmetricSecondOrderTensor.from_Voigt([11, 22, 33, 23, 13, 12])
Second-order tensor
[[11. 12. 13.]
 [12. 22. 23.]
 [13. 23. 33.]]
classmethod shear(u, v, magnitude)[source]

Create an array of tensors corresponding to shear state along two orthogonal directions.

Parameters:
  • u (np.ndarray or list) – First direction. Must be a 3D vector.

  • v (np.ndarray or list) – Second direction. Must be a 3D vector.

  • magnitude (float or np.ndarray or list) – Magnitude of the shear state to consider. If a list or an array is provided, the shape of the tensor array will be of the same shape as magnitude.

Returns:

tensor or tensor array

Return type:

SecondOrderTensor

voigt_map = [1, 1, 1, 1, 1, 1]

List of factors to use for building a tensor from Voigt vector(s)