Math#

This module contains math functions.

Core

math.linsteps(points[, num, endpoint, axis, ...])

Return a sequence from batches of evenly spaced samples between pairs of milestone points.

math.rotation_matrix(alpha_deg[, dim, axis])

Rotation matrix with given rotation axis and dimension (2d or 3d).

Field

math.defgrad(field)

math.strain(field)

math.extract(field[, grad, sym, add_identity])

Extract gradient or interpolated field values at quadrature points.

math.values(field)

Return values of a field or a tuple of fields.

math.norm(array[, axis])

Calculate the norm of an array or the norms of a list of arrays.

math.interpolate(field)

Interpolate method of field A.

math.grad(field[, sym])

Gradient method of field A.

Tensor

math.identity([A, dim, shape])

Identity according to matrix A with optional specified dim.

math.sym(A)

Symmetric part of matrix A.

math.dya(A, B[, mode, parallel])

Dyadic (outer or kronecker) product of two tensors.

math.inv(A[, determinant, full_output, sym])

"Inverse of A with optionally pre-calculated determinant, optional additional output of the calculated determinant or a simplified calculation of the inverse for sym.

math.det(A)

Determinant of matrix A.

math.dev(A)

Deviator of matrix A.

math.cof(A)

Cofactor matrix of A (as a wrapper for the inverse of A).

math.eig(A[, eig])

Eigenvalues and -vectors of matrix A.

math.eigh(A)

Eigenvalues and -vectors of a symmetric matrix A.

math.eigvals(A[, shear, eig])

Eigenvalues (and optional principal shear values) of a matrix A.

math.eigvalsh(A[, shear])

Eigenvalues (and optional principal shear values) of a symmetric matrix A.

math.transpose(A[, mode])

Transpose (mode=1) or major-transpose (mode=2) of matrix A.

math.majortranspose(A)

math.trace(A)

The sum of the diagonal elements of A.

math.cdya_ik(A, B[, parallel])

ik - crossed dyadic-product of A and B.

math.cdya_il(A, B[, parallel])

il - crossed dyadic-product of A and B.

math.cdya(A, B[, parallel])

symmetric - crossed dyadic-product of A and B.

math.cross(a, b)

Cross product of two vectors a and b.

math.dot(A, B[, mode, parallel])

Dot-product of A and B with inputs of n trailing axes..

math.ddot(A, B[, mode, parallel])

Double-Dot-product of A and B with inputs of n trailing axes.

math.tovoigt(A[, strain])

Convert (3, 3) tensor to (6, ) voigt notation.

math.reshape(A, shape[, trailing_axes])

math.ravel(A[, trailing_axes])

Detailed API Reference

felupe.math.cdya(A, B, parallel=False, **kwargs)[source]#

symmetric - crossed dyadic-product of A and B.

felupe.math.cdya_ik(A, B, parallel=False, **kwargs)[source]#

ik - crossed dyadic-product of A and B.

felupe.math.cdya_il(A, B, parallel=False, **kwargs)[source]#

il - crossed dyadic-product of A and B.

felupe.math.cof(A)[source]#

Cofactor matrix of A (as a wrapper for the inverse of A).

felupe.math.cross(a, b)[source]#

Cross product of two vectors a and b.

felupe.math.ddot(A, B, mode=(2, 2), parallel=False)[source]#

Double-Dot-product of A and B with inputs of n trailing axes.

felupe.math.det(A)[source]#

Determinant of matrix A.

felupe.math.dev(A)[source]#

Deviator of matrix A.

felupe.math.dot(A, B, mode=(2, 2), parallel=False)[source]#

Dot-product of A and B with inputs of n trailing axes..

felupe.math.dya(A, B, mode=2, parallel=False, **kwargs)[source]#

Dyadic (outer or kronecker) product of two tensors.

felupe.math.eig(A, eig=<function eig>)[source]#

Eigenvalues and -vectors of matrix A.

felupe.math.eigh(A)[source]#

Eigenvalues and -vectors of a symmetric matrix A.

felupe.math.eigvals(A, shear=False, eig=<function eig>)[source]#

Eigenvalues (and optional principal shear values) of a matrix A.

felupe.math.eigvalsh(A, shear=False)[source]#

Eigenvalues (and optional principal shear values) of a symmetric matrix A.

felupe.math.extract(field, grad=True, sym=False, add_identity=True)[source]#

Extract gradient or interpolated field values at quadrature points.

felupe.math.grad(field, sym=False)[source]#

Gradient method of field A.

felupe.math.identity(A=None, dim=None, shape=None)[source]#

Identity according to matrix A with optional specified dim.

felupe.math.interpolate(field)[source]#

Interpolate method of field A.

felupe.math.inv(A, determinant=None, full_output=False, sym=False)[source]#

“Inverse of A with optionally pre-calculated determinant, optional additional output of the calculated determinant or a simplified calculation of the inverse for sym. matrices.

felupe.math.linsteps(points, num=10, endpoint=True, axis=None, axes=None)[source]#

Return a sequence from batches of evenly spaced samples between pairs of milestone points.

Parameters:
  • points (array_like) – The milestone values of the sequence.

  • num (int, optional) – Number of samples (without the end point) to generate. Must be non-negative (default is 10).

  • endpoint (bool, optional) – If True, points[-1] is the last sample. Otherwise, it is not included (default is True).

  • axis (int or None, optional) – The axis in the result to store the samples. By default (None), the samples will be concatenated along the existing first axis. If axis > 0, the samples will be inserted at column axis. Only positive integers are supported.

  • axes (int or None, optional) – Number of output columns if axis is not None. Requires axes > axis and will be set to axes = axis + 1 by default (None).

Returns:

samples – Concatenated batches of num equally spaced samples.

Return type:

ndarray

Examples

>>> import felupe as fem
>>> fem.math.linsteps([0, 0.5, 1.5, 3.5], num=2)
array([0.  , 0.25, 0.5 , 1.  , 1.5 , 2.5 , 3.5 ])

Not including the end value of the sequence does not change the step size.

>>> fem.math.linsteps([0, 0.5, 1.5, 3.5], num=2, endpoint=False)
array([0.  , 0.25, 0.5 , 1.  , 1.5 , 2.5 ])
>>> fem.math.linsteps([0, 0.5, 1.5, 3.5], num=2, axis=1)
array([[0.  , 0.  ],
       [0.  , 0.25],
       [0.  , 0.5 ],
       [0.  , 1.  ],
       [0.  , 1.5 ],
       [0.  , 2.5 ],
       [0.  , 3.5 ]])

Output with four columns:

>>> fem.math.linsteps([0, 0.5, 1.5, 3.5], num=2, axis=1, axes=4)
array([[0.  , 0.  , 0.  , 0.  ],
       [0.  , 0.25, 0.  , 0.  ],
       [0.  , 0.5 , 0.  , 0.  ],
       [0.  , 1.  , 0.  , 0.  ],
       [0.  , 1.5 , 0.  , 0.  ],
       [0.  , 2.5 , 0.  , 0.  ],
       [0.  , 3.5 , 0.  , 0.  ]])

The ouput degenerates to the end value

>>> fem.math.linsteps([0, 0.5, 1.5, 3.5], num=0)
array([3.5])

or an empty array.

>>> fem.math.linsteps([0, 0.5, 1.5, 3.5], num=0, endpoint=False)
array([], dtype=float64)

See also

numpy.linspace

Return evenly spaced numbers over a specified interval.

felupe.math.norm(array, axis=None)[source]#

Calculate the norm of an array or the norms of a list of arrays.

felupe.math.rotation_matrix(alpha_deg, dim=3, axis=0)[source]#

Rotation matrix with given rotation axis and dimension (2d or 3d).

Parameters:
  • alpha_deg (int) – Rotation angle in degree.

  • dim (int, optional (default is 3)) – Dimension of the rotation matrix.

  • axis (int, optional (default is 0)) – Rotation axis.

Returns:

rotation_matrix – Rotation matrix of dim 2 or 3 with given rotation axis.

Return type:

ndarray

felupe.math.sym(A)[source]#

Symmetric part of matrix A.

felupe.math.tovoigt(A, strain=False)[source]#

Convert (3, 3) tensor to (6, ) voigt notation.

felupe.math.trace(A)[source]#

The sum of the diagonal elements of A.

felupe.math.transpose(A, mode=1)[source]#

Transpose (mode=1) or major-transpose (mode=2) of matrix A.

felupe.math.values(field)[source]#

Return values of a field or a tuple of fields.