pyNastran/op2/vector_utils¶
This is the pyNastran.op2.vector_utils.rst file.
vector_utils
Module¶
- defines some methods for working with arrays:
- filter1d(a, b=None, zero_tol=0.001)
- where_searchsorted(a, v, side=’left’, x=None, y=None)
- sortedsum1d(ids, values, axis=None)
- iformat(format_old, precision=2)
- abs_max_min_global(values)
- abs_max_min_vector(values)
- abs_max_min(values, global_abs_max=True)
- principal_3d(o11, o22, o33, o12, o23, o13)
- transform_force(force_in_local,
- coord_out, coords, nid_cd, i_transform)
- transform_force_moment(force_in_local, moment_in_local,
- coord_out, coords, nid_cd, i_transform, xyz_cid0, summation_point_cid0=None, consider_rxf=True, debug=False, logger=None)
- transform_force_moment_sum(force_in_local, moment_in_local,
- coord_out, coords, nid_cd, i_transform, xyz_cid0, summation_point_cid0=None, consider_rxf=True, debug=False, logger=None)
-
pyNastran.op2.vector_utils.
abs_max_min
(values, global_abs_max=True)[source]¶ Gets the maximum value of x and -x. This is used for getting the max/min principal stress.
-
pyNastran.op2.vector_utils.
abs_max_min_global
(values)[source]¶ This is useful for figuring out absolute max or min principal stresses across single/multiple elements and finding a global max/min value.
Parameters: - values: ndarray/listtuple
an ND-array of values; common NDARRAY/list/tuple shapes:
- [nprincipal_stresses]
- [nelements, nprincipal_stresses]
Returns: - abs_max_mins: int/float
an array of the max or min principal stress don’t input mixed types
- nvalues >= 1
>>> element1 = [0.0, -1.0, 2.0] # 2.0 >>> element2 = [0.0, -3.0, 2.0] # -3.0 >>> values = abs_max_min_global([element1, element2]) >>> values -3.0
>>> element1 = [0.0, -1.0, 2.0] # 2.0 >>> values = abs_max_min_global([element1]) >>> values 2.0
Note
[3.0, 2.0, -3.0] will return 3.0, and [-3.0, 2.0, 3.0] will return 3.0
-
pyNastran.op2.vector_utils.
abs_max_min_vector
(values)[source]¶ This is useful for figuring out principal stresses across multiple elements.
Parameters: - values: ndarray/listtuple
an array of values, where the rows are interated over and the columns are going to be compressed
- common NDARRAY/list/tuple shapes:
- [nprincipal_stresses]
- [nelements, nprincipal_stresses]
Returns: - abs_max_mins: NDARRAY shape=[nelements] with dtype=values.dtype
an array of the max or min principal stress don’t input mixed types
- ::
>>> element1 = [0.0, 1.0, 2.0] # 2.0 >>> element2 = [0.0, -1.0, 2.0] # 2.0 >>> element3 = [0.0, -3.0, 2.0] # -3.0 >>> values = [element1 element2, element3] >>> values0 = abs_max_min_vectorized(values) >>> values0 [2.0, 2.0, -3.0]
Note
[3.0, 2.0, -3.0] will return 3.0, and [-3.0, 2.0, 3.0] will return 3.0
-
pyNastran.op2.vector_utils.
filter1d
(a, b=None, zero_tol=0.001)[source]¶ Filters a 1d numpy array of values near 0.
Parameters: - a : (n, ) float ndarray
a vector to compare
- b : (n, ) float ndarray; default=None
another vector to compare If b is defined, both a and b must be near 0 for a value to be removed.
- zero_tol : float; default=0.001
the zero tolerance value
Returns: - k : (m, ) int ndarray
the indices of the removed values
- a = [1., 2., 0.1]
>>> i = filter(a, zero_tol=0.5) ..
- a[i]
>>> [0, 1] ..
- a = [1., 2., 0.1]
- b = [1., -0.1, 0.1]
>>> i = filter(a, b, zero_tol=0.5) ..
- [0, 1]
-
pyNastran.op2.vector_utils.
iformat
(format_old, precision=2)[source]¶ Converts binary data types to size vector arrays.
Parameters: - format_old : str
the int/float data types in single precision format
- precision : int; default=2
the precision to convert to 1 : single precision (no conversion) 2 : double precision
Returns: - format_new : str
the int/float data types in single/double precision format
Examples
>>> iformat('8i6f10s', precision=1) '8i6f10s' >>> iformat('8i6f10s', precision=2) '8l6d10q'
-
pyNastran.op2.vector_utils.
sortedsum1d
(ids, values, axis=None)[source]¶ Sums the values in a sorted 1d/2d array.
Parameters: - ids : (n, ) int ndarray
the integer values in a sorted order that indicate what is to be summed
- values : (n, m) float ndarray
the values to be summed Presumably m is 2 because this function is intended to be used for summing forces and moments
- axis : None or int or tuple of ints, optional
Axis or axes along which a sum is performed. The default (axis=None) is perform a sum over all the dimensions of the input array. axis may be negative, in which case it counts from the last to the first axis. If this is a tuple of ints, a sum is performed on multiple axes, instead of a single axis or all the axes as before.
Not actually supported…
Returns: - out : (nunique, m) float ndarray
the summed values
Examples
1D Example For an set of arrays, there are 5 values in sorted order.
..code-block :: python
ids = [1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 5] values = 1.0 * idsWe want to sum the values such that: ..code-block :: python
out = [2.0, 4.0, 9.0, 4.0, 15.0]2D Example ..code-block :: python
ids = [1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 5] values = [
[1.0, 1.0, 2.0, 2.0, 3.0, 3.0], [1.0, 1.0, 2.0, 2.0, 3.0, 3.0],]
values = 1.0 * ids For 2D
Todo
This could probably be more efficient
Todo
Doesn’t support axis
-
pyNastran.op2.vector_utils.
transform_force
(force_in_local, coord_out, coords, nid_cd, unused_icd_transform)[source]¶ Transforms force/moment from global to local and returns all the forces.
Supports cylindrical/spherical coordinate systems.
Parameters: - force : (N, 3) ndarray
forces in the local frame
- coord_out : CORD()
the desired local frame
- coords : dict[int] = CORDx
all the coordinate systems key : int value : CORDx
- nid_cd : (M, 2) int ndarray
the (BDF.point_ids, cd) array
- icd_transform : dict[cd] = (Mi, ) int ndarray
the mapping for nid_cd
- #xyz_cid0 : (n, 3) ndarray
#the nodes in the global frame
- #summation_point_cid0 : (3, ) ndarray
#the summation point in the global frame
- .. warning:: the function signature will change…
- .. todo:: sum of moments about a point must have an rxF term to get the
same value as Patran.
- Fglobal = Flocal @ T
- Flocal = T.T @ Fglobal
- Flocal2 = T2.T @ (Flocal1 @ T1)
-
pyNastran.op2.vector_utils.
transform_force_moment
(force_in_local, moment_in_local, coord_out, coords, nid_cd, icd_transform, xyz_cid0, summation_point_cid0=None, consider_rxf=True, debug=False, logger=None)[source]¶ Transforms force/moment from global to local and returns all the forces.
Parameters: - force_in_local : (N, 3) ndarray
forces in the local frame
- moment_in_local : (N, 3) ndarray
moments in the local frame
- coord_out : CORDx()
the desired local frame
- coords : dict[int] = CORDx
all the coordinate systems key : int value : CORDx
- nid_cd : (M, 2) int ndarray
the (BDF.point_ids, cd) array
- icd_transform : dict[cd] = (Mi, ) int ndarray
the mapping for nid_cd
- xyz_cid0 : (n, 3) ndarray
the nodes in the global frame
- summation_point_cid0 : (3, ) ndarray
the summation point in the global frame???
- consider_rxf : bool; default=True
considers the r x F term
- debug : bool; default=False
debugging flag
- logger : logger; default=None
a logger object that gets used when debug=True
Returns: - force_out : (n, 3) float ndarray
the ith float components in the coord_out coordinate frame
- moment_out : (n, 3) float ndarray
the ith moment components about the summation point in the coord_out coordinate frame
Todo
doesn’t seem to handle cylindrical/spherical systems ..
- https://flexiblelearning.auckland.ac.nz/sportsci303/13_3/forceplate_manual.pdf
- xyz0 = T_1_to_0 @ xyz1
- xyz1 = T_1_to_0.T @ xyz0
- xyz2 = T_2_to_0.T @ xyz0
- xyz2 = T_2_to_0.T @ T_1_to_0 @ xyz1
- xyz_g = T_a2g @ xyz_a
- xyz_g = T_b2g @ xyz_b
- T_b2g @ xyz_b = T_a2g @ xyz_a
- xyz_b = T_b2g.T @ T_a2g @ xyz_a = T_g2b @ T_a2g @ xyz_a
-
pyNastran.op2.vector_utils.
transform_force_moment_sum
(force_in_local, moment_in_local, coord_out, coords, nid_cd, icd_transform, xyz_cid0, summation_point_cid0=None, consider_rxf=True, debug=False, logger=None)[source]¶ Transforms force/moment from global to local and returns a sum of forces/moments.
Parameters: - force_in_local : (N, 3) ndarray
forces in the local frame
- moment_in_local : (N, 3) ndarray
moments in the local frame
- coord_out : CORDx()
the desired local frame
- coords : dict[int] = CORDx
all the coordinate systems key : int value : CORDx
- nid_cd : (M, 2) int ndarray
the (BDF.point_ids, cd) array
- icd_transform : dict[cd] = (Mi, ) int ndarray
the mapping for nid_cd
- xyz_cid0 : (nnodes + nspoints + nepoints, 3) ndarray
the grid locations in coordinate system 0
- summation_point_cid0 : (3, ) ndarray
the summation point in the global frame
- consider_rxf : bool; default=True
considers the r x F term
- debug : bool; default=False
debugging flag
- logger : logger; default=None
a logger object that gets used when debug=True
Returns: - force_out : (n, 3) float ndarray
the ith float components in the coord_out coordinate frame
- moment_out : (n, 3) float ndarray
the ith moment components about the summation point in the coord_out coordinate frame
- force_out_sum : (3, ) float ndarray
the sum of forces in the coord_out coordinate frame
- moment_out_sum : (3, ) float ndarray
the sum of moments about the summation point in the coord_out coordinate frame
Todo
doesn’t seem to handle cylindrical/spherical systems ..
-
pyNastran.op2.vector_utils.
where_searchsorted
(a, v, side='left', x=None, y=None)[source]¶ Implements a np.where that assumes a sorted array set.