ntrfc.math package

Submodules

ntrfc.math.methods module

ntrfc.math.methods.C_barycentric(R)

Calculates the barycentric weights for a given anisotropic matrix representing the Reynolds stress tensor.

Parameters: R (numpy.ndarray): Anisotropic matrix representing the Reynolds stress tensor.

Returns: numpy.ndarray: Barycentric weights.

The function calculates the barycentric weights for a given anisotropic matrix, which represents the Reynolds stress tensor. The Reynolds stress tensor characterizes the anisotropy present in turbulent flows by describing the correlation between fluctuating velocity components.

The anisotropic matrix R is a 3x3 symmetric matrix defined as:
R = | R11 R12 R13 |
R12 R22 R23 |
R13 R23 R33 |

The function performs the following steps: 1. Checks if all eigenvalues of the anisotropic matrix are zero. If yes, returns [0, 0, 1] as barycentric weights. 2. Calculates the eigenvalues of the anisotropic matrix, anisoEigs, which correspond to the magnitudes of the principal axes of the Reynolds stress tensor. 3. Extracts the eigenvalues gamma_1, gamma_2, and gamma_3 from anisoEigs. 4. Computes the barycentric weights C1c, C2c, and C3c using the eigenvalues. 5. Constructs and returns the barycentric weights as a numpy array, CWeights.

Note: - The anisotropic matrix R should be a 3x3 numpy array representing the Reynolds stress tensor. - The function assumes the existence of the calcAnisoEigs function to calculate the eigenvalues. - Make sure to import the necessary modules, such as numpy, for the function to work properly.

ntrfc.math.methods.autocorr(signal)

Calculate the normalized autocorrelation of a one-dimensional signal.

Parameters: signal (numpy.ndarray): Input signal.

Returns: numpy.ndarray: Normalized autocorrelation.

Compute the normalized autocorrelation of the input signal by cross-correlating it with itself. The result is normalized by dividing by the squared sum of the signal.

ntrfc.math.methods.autocorrelate(series)

Compute the autocorrelation function of a given time series.

Parameters:

series (array-like) – The 1D time series to be autocorrelated.

Returns:

The autocorrelation function of the input series.

Return type:

array-like

ntrfc.math.methods.calcAnisoEigs(anisotropy_matrix)

Calculates the eigenvalues and eigenvectors of an anisotropy matrix.

Parameters:

anisotropy_matrix (numpy.ndarray) – The anisotropy matrix represented as a 3x3 numpy array.

Returns:

A tuple containing the eigenvalues and eigenvectors.
  • eigenvalues (numpy.ndarray): A 1-dimensional numpy array containing the three eigenvalues sorted in descending order.

  • eigenvectors (numpy.ndarray or None): A 2-dimensional numpy array containing the three eigenvectors as columns. If all eigenvalues are zero, None is returned.

Return type:

tuple

Raises:

ValueError – If the input matrix is not a 3x3 numpy array.

Notes

  • The anisotropy matrix should be symmetric.

  • The eigenvalues represent the magnitudes of anisotropy along their corresponding eigenvectors.

  • If all eigenvalues are zero, it indicates an isotropic material.

Example

> anisotropy_matrix = np.array([[3, 1, 2], [1, 4, 5], [2, 5, 6]]) > eigenvalues, eigenvectors = calcAnisoEigs(anisotropy_matrix) > print(eigenvalues) array([12.866, 0.174, -2.040]) > print(eigenvectors) array([[ 0.240, -0.856, 0.458],

[-0.716, -0.513, -0.473], [ 0.657, -0.058, -0.752]])

ntrfc.math.methods.calcAnisoMatrix(reynoldsstress_tensor)
ntrfc.math.methods.find_nearest(array, value)
ntrfc.math.methods.is_equidistant(arr, tolerance=1e-08)
ntrfc.math.methods.minmax_normalize(series_array)

Normalize a given 1D array to the range [0, 1] using min-max normalization.

Parameters:

series_array (array-like) – The 1D array to be normalized.

Returns:

The normalized 1D array with values in the range [0, 1].

Return type:

array-like

Note

If all values in the input array are the same, the function will return the input array unchanged.

ntrfc.math.methods.reldiff(a, b)

Calculates the relative difference between two values or arrays of values.

Parameters: a (float or numpy array): The first value or array of values to compare. b (float or numpy array): The second value or array of values to compare.

Returns: float or numpy array: The relative difference between a and b. If a and b are both numpy arrays, the output will be a numpy array of the same shape. If one input is a float and the other is a numpy array, the output will be a numpy array of the same shape as the input array.

Notes: The relative difference is defined as the absolute difference between the two values divided by the average of their absolute values. If a and b are equal, the relative difference is 0. If either a or b is zero, the absolute difference between the two values is returned instead of the relative difference.

ntrfc.math.methods.return_intersection(hist_1, hist_2)

Calculate the intersection of two histograms.

Parameters:
  • hist_1 (numpy.ndarray) – The first histogram to be compared.

  • hist_2 (numpy.ndarray) – The second histogram to be compared.

Returns:

The intersection of the two histograms.

Return type:

float

ntrfc.math.methods.zero_crossings(data_series)

ntrfc.math.vectorcalc module

Created on Sun Oct 4 19:01:50 2020

@author: malte

ntrfc.math.vectorcalc.RotFromTwoVecs(vec1, vec2)

Find the rotation matrix that aligns vec1 to vec2 :param vec1: A 3d “source” vector :param vec2: A 3d “destination” vector :return mat: A transform matrix (3x3) which when applied to vec1, aligns it with vec2.

ntrfc.math.vectorcalc.Rx(xAngle)

using radiant :param xAngle: angle in rad :return: rotation matrix

ntrfc.math.vectorcalc.Ry(yAngle)

using radiant :param yAngle: angle in rad :return: rotation matrix

ntrfc.math.vectorcalc.Rz(zAngle)

using radiant :param zAngle: angle in rad :return: rotation matrix

ntrfc.math.vectorcalc.calc_largedistant_idx(x_coords, y_coords)

tested method to find indices of coordinates of a 2d-pointcloud with the biggest distance :param x_coords: array of x coordinates :param y_coords: array of y coordinates :return: index_1, index_2 (int)

ntrfc.math.vectorcalc.closest_node_index(node, nodes)
ntrfc.math.vectorcalc.compute_minmax_distance_in_pointcloud(pointcloud, minmax='min')
ntrfc.math.vectorcalc.distant_node_index(node, nodes)
ntrfc.math.vectorcalc.ellipsoidVol(sig)

tested method to compute the ellipsoid volume by the sigma-parameters of a parametric ellipsoid :param sig: :return:

ntrfc.math.vectorcalc.eulersFromRPG(R)
ntrfc.math.vectorcalc.findNearest(array, point)
ntrfc.math.vectorcalc.gradToRad(angle)

tested method to translate from grad to rad :param angle: :return:

ntrfc.math.vectorcalc.line_intersection(point_a1, point_a2, point_b1, point_b2)
ntrfc.math.vectorcalc.lineseg_dist(p, a, b)
Parameters:
  • p – point

  • a – line point a

  • b – line point b

Returns:

distance

ntrfc.math.vectorcalc.posVec(vec)
ntrfc.math.vectorcalc.randomOrthMat()
ntrfc.math.vectorcalc.randomUnitVec()

tested method to generate a random unit vector :return:

ntrfc.math.vectorcalc.symToMatrix(symTensor)

tested translates symmetric tensor notation to complete matrix :param symTensor: :return:

ntrfc.math.vectorcalc.unitvec(vec)
ntrfc.math.vectorcalc.unitvec_list(vecs)
ntrfc.math.vectorcalc.vecAbs(vec)

method to calculate the absolute value of a vector :param vec: :return:

ntrfc.math.vectorcalc.vecAbs_list(vecs)

method to calculate the absolute value of a vector :param np.array vec with shape (n,3): :return: array of magnitudes in shape (n)

ntrfc.math.vectorcalc.vecAngle(vec1, vec2)

Returns the angle in radians between vectors ‘v1’ and ‘v2’:

angle_between((1, 0, 0), (0, 1, 0))

1.5707963267948966

angle_between((1, 0, 0), (1, 0, 0))

0.0

angle_between((1, 0, 0), (-1, 0, 0))

3.141592653589793

ntrfc.math.vectorcalc.vecDir(vec)

tested method to compute the direction of a vector :param vec: :return: unit vec

ntrfc.math.vectorcalc.vecProjection(direction, vector)

Calculate the projection of a vector onto a direction vector.

Parameters: direction (list or numpy array): The direction vector onto which the projection will be calculated. vector (list or numpy array): The vector to be projected onto the direction vector.

Returns: projection (numpy array): A vector representing the projection of the input vector onto the direction vector.

Module contents