aerosandbox.weights =================== .. py:module:: aerosandbox.weights Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/aerosandbox/weights/mass_properties/index /autoapi/aerosandbox/weights/mass_properties_of_shapes/index Attributes ---------- .. autoapisummary:: aerosandbox.weights.mp1 Classes ------- .. autoapisummary:: aerosandbox.weights.AeroSandboxObject aerosandbox.weights.MassProperties Functions --------- .. autoapisummary:: aerosandbox.weights.trim_string aerosandbox.weights.mass_properties_from_radius_of_gyration Package Contents ---------------- .. py:class:: AeroSandboxObject Bases: :py:obj:`abc.ABC` Helper class that provides a standard way to create an ABC using inheritance. .. py:attribute:: _asb_metadata :type: Dict[str, str] :value: None .. py:method:: __eq__(other) Checks if two AeroSandbox objects are value-equivalent. A more sensible default for classes that represent physical objects than checking for memory equivalence. This is done by checking if the two objects are of the same type and have the same __dict__. :param other: Another object. :returns: True if the objects are equal, False otherwise. :rtype: bool .. py:method:: save(filename = None, verbose = True, automatically_add_extension = True) Saves the object to a binary file, using the `dill` library. Creates a .asb file, which is a binary file that can be loaded with `aerosandbox.load()`. This can be loaded into memory in a different Python session or a different computer, and it will be exactly the same as when it was saved. :param filename: The filename to save this object to. Should be a .asb file. :param verbose: If True, prints messages to console on successful save. :param automatically_add_extension: If True, automatically adds the .asb extension to the filename if it doesn't already have it. If False, does not add the extension. Returns: None (writes to file) .. py:method:: copy() Returns a shallow copy of the object. .. py:method:: deepcopy() Returns a deep copy of the object. .. py:method:: substitute_solution(sol, inplace = None) Substitutes a solution from CasADi's solver recursively as an in-place operation. In-place operation. To make it not in-place, do `y = copy.deepcopy(x)` or similar first. :param sol: OptiSol object. :return: .. py:function:: trim_string(string, length = 80) Trims a string to be less than a given length. If the string would exceed the length, makes it end in ellipses ("…"). :param string: The string to be trimmed. :param length: The length to trim the string to, including any ellipses that may be added. Returns: The trimmed string, including ellipses if needed. .. py:class:: MassProperties(mass = None, x_cg = 0.0, y_cg = 0.0, z_cg = 0.0, Ixx = 0.0, Iyy = 0.0, Izz = 0.0, Ixy = 0.0, Iyz = 0.0, Ixz = 0.0) Bases: :py:obj:`aerosandbox.common.AeroSandboxObject` Mass properties of a rigid 3D object. ## Notes on Inertia Tensor Definition This class uses the standard mathematical definition of the inertia tensor, which is different from the alternative definition used by some CAD and CAE applications (such as SolidWorks, NX, etc.). These differ by a sign flip in the products of inertia. Specifically, we define the inertia tensor using the standard convention: [ I11 I12 I13 ] [ Ixx Ixy Ixz ] [sum(m*(y^2+z^2)) -sum(m*x*y) -sum(m*x*z) ] I = [ I21 I22 I23 ] = [ Ixy Iyy Iyz ] = [-sum(m*x*y) sum(m*(x^2+z^2)) -sum(m*y*z) ] [ I31 I32 I33 ] [ Ixz Iyz Izz ] [-sum(m*x*z) -sum(m*y*z) sum(m*(x^2+y^2))] Whereas SolidWorks, NX, etc. define the inertia tensor as: [ I11 I12 I13 ] [ Ixx -Ixy -Ixz ] [sum(m*(y^2+z^2)) -sum(m*x*y) -sum(m*x*z) ] I = [ I21 I22 I23 ] = [-Ixy Iyy -Iyz ] = [-sum(m*x*y) sum(m*(x^2+z^2)) -sum(m*y*z) ] [ I31 I32 I33 ] [-Ixz -Iyz Izz ] [-sum(m*x*z) -sum(m*y*z) sum(m*(x^2+y^2))] See also: https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor .. py:attribute:: mass :value: None .. py:attribute:: x_cg :value: 0.0 .. py:attribute:: y_cg :value: 0.0 .. py:attribute:: z_cg :value: 0.0 .. py:attribute:: Ixx :value: 0.0 .. py:attribute:: Iyy :value: 0.0 .. py:attribute:: Izz :value: 0.0 .. py:attribute:: Ixy :value: 0.0 .. py:attribute:: Iyz :value: 0.0 .. py:attribute:: Ixz :value: 0.0 .. py:method:: __repr__() .. py:method:: __getitem__(index) Indexes one item from each attribute of an MassProperties instance. Returns a new MassProperties instance. :param index: The index that is being called; e.g.,: >>> first_mass_props = mass_props[0] Returns: A new MassProperties instance, where each attribute is subscripted at the given value, if possible. .. py:method:: __len__() .. py:method:: __array__(dtype='O') Allows NumPy array creation without infinite recursion in __len__ and __getitem__. .. py:method:: __neg__() .. py:method:: __add__(other) Combines one MassProperties object with another. .. py:method:: __radd__(other) Allows sum() to work with MassProperties objects. Basically, makes addition commutative. .. py:method:: __sub__(other) Subtracts one MassProperties object from another. (opposite of __add__() ) .. py:method:: __mul__(other) Returns a new MassProperties object that is equivalent to if you had summed together N (with `other` interpreted as N) identical MassProperties objects. .. py:method:: __rmul__(other) Allows multiplication of a scalar by a MassProperties object. Makes multiplication commutative. .. py:method:: __truediv__(other) Returns a new MassProperties object that is equivalent to if you had divided the mass of the current MassProperties object by a factor. .. py:method:: allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) .. py:property:: xyz_cg .. py:property:: inertia_tensor .. py:method:: inv_inertia_tensor() Computes the inverse of the inertia tensor, in a slightly more efficient way than raw inversion by exploiting its known structure. If you are effectively using this inertia tensor to solve a linear system, you should use a linear algebra solve() method (ideally via Cholesky decomposition) instead, for best speed. .. py:method:: get_inertia_tensor_about_point(x = 0.0, y = 0.0, z = 0.0, return_tensor = True) Returns the inertia tensor about an arbitrary point. Using https://en.wikipedia.org/wiki/Parallel_axis_theorem#Tensor_generalization :param x: x-position of the new point, in the same axes as this MassProperties instance is specified in. :param y: y-position of the new point, in the same axes as this MassProperties instance is specified in. :param z: z-position of the new point, in the same axes as this MassProperties instance is specified in. :param return_tensor: A switch for the desired return type; see below for details. [boolean] :returns: Returns the new inertia tensor, as a 2D numpy ndarray. If `return_tensor` is False: Returns the components of the new inertia tensor, as a tuple. If J is the new inertia tensor, the tuple returned is: (Jxx, Jyy, Jzz, Jxy, Jyz, Jxz) :rtype: If `return_tensor` is True .. py:method:: is_physically_possible() Checks whether it's possible for this MassProperties object to correspond to the mass properties of a real physical object. Assumes that all physically-possible objects have a positive mass (or density). Some special edge cases: - A MassProperties object with mass of 0 (i.e., null object) will return True. Note: this will return True even if the inertia tensor is not zero (which would basically be infinitesimal point masses at infinite distance). - A MassProperties object that is a point mass (i.e., inertia tensor is all zeros) will return True. :returns: True if the MassProperties object is physically possible, False otherwise. .. py:method:: is_point_mass() Returns True if this MassProperties object corresponds to a point mass, False otherwise. .. py:method:: generate_possible_set_of_point_masses(method='optimization', check_if_already_a_point_mass = True) Generates a set of point masses (represented as MassProperties objects with zero inertia tensors), that, when combined, would yield this MassProperties object. Note that there are an infinite number of possible sets of point masses that could yield this MassProperties object. This method returns one possible set of point masses, but there are many others. .. rubric:: Example >>> mp = MassProperties(mass=1, Ixx=1, Iyy=1, Izz=1, Ixy=0.1, Iyz=-0.1, Ixz=0.1) >>> point_masses = mp.generate_possible_set_of_point_masses() >>> mp.allclose(sum(point_masses)) # Asserts these are equal, within tolerance True :param method: The method to use to generate the set of point masses. Currently, only "optimization" is supported. :returns: A list of MassProperties objects, each of which is a point mass (i.e., zero inertia tensor). .. py:method:: export_AVL_mass_file(filename) Exports this MassProperties object to an AVL mass file. Note: AVL uses the SolidWorks convention for inertia tensors, which is different from the typical mathematical convention, and the convention used by this MassProperties class. In short, these differ by a sign flip in the products of inertia. More details available in the MassProperties docstring. See also: https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor :param filename: The filename to export to. Returns: None .. py:data:: mp1 .. py:function:: mass_properties_from_radius_of_gyration(mass, x_cg = 0, y_cg = 0, z_cg = 0, radius_of_gyration_x = 0, radius_of_gyration_y = 0, radius_of_gyration_z = 0) Returns the mass properties of an object, given its radius of gyration. It's assumed that the principle axes of the inertia tensor are aligned with the coordinate axes. This is a shorthand convenience function for common usage of the MassProperties constructor. For more detailed use, use the MassProperties object directly. :param mass: Mass [kg] :param x_cg: x-position of the center of gravity :param y_cg: y-position of the center of gravity :param z_cg: z-position of the center of gravity :param radius_of_gyration_x: Radius of gyration along the x-axis, about the center of gravity [m] :param radius_of_gyration_y: Radius of gyration along the y-axis, about the center of gravity [m] :param radius_of_gyration_z: Radius of gyration along the z-axis, about the center of gravity [m] Returns: MassProperties object.