aerosandbox.weights#

Submodules#

Package Contents#

Classes#

AeroSandboxObject

Helper class that provides a standard way to create an ABC using

MassProperties

Mass properties of a rigid 3D object.

Functions#

trim_string(string[, length])

Trims a string to be less than a given length. If the string would exceed the length, makes it end in ellipses ("…").

mass_properties_from_radius_of_gyration(mass[, x_cg, ...])

Returns the mass properties of an object, given its radius of gyration.

Attributes#

mp1

class aerosandbox.weights.AeroSandboxObject[source]#

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

_asb_metadata: Dict[str, str]#
__eq__(other)[source]#

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__.

Parameters:

other – Another object.

Returns:

True if the objects are equal, False otherwise.

Return type:

bool

save(filename=None, verbose=True, automatically_add_extension=True)[source]#

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.

Parameters:
  • filename (Union[str, pathlib.Path]) – The filename to save this object to. Should be a .asb file.

  • verbose (bool) – If True, prints messages to console on successful save.

  • automatically_add_extension (bool) – If True, automatically adds the .asb extension to the filename if it doesn’t already have it. If False, does not add the extension.

Return type:

None

Returns: None (writes to file)

copy()[source]#

Returns a shallow copy of the object.

deepcopy()[source]#

Returns a deep copy of the object.

substitute_solution(sol, inplace=None)[source]#

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:

Parameters:
  • sol (casadi.OptiSol) –

  • inplace (bool) –

aerosandbox.weights.trim_string(string, length=80)[source]#

Trims a string to be less than a given length. If the string would exceed the length, makes it end in ellipses (”…”).

Parameters:
  • string (str) – The string to be trimmed.

  • length (int) – The length to trim the string to, including any ellipses that may be added.

Return type:

str

Returns: The trimmed string, including ellipses if needed.

class aerosandbox.weights.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)[source]#

Bases: 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

Parameters:
  • mass (Union[float, aerosandbox.numpy.ndarray]) –

  • x_cg (Union[float, aerosandbox.numpy.ndarray]) –

  • y_cg (Union[float, aerosandbox.numpy.ndarray]) –

  • z_cg (Union[float, aerosandbox.numpy.ndarray]) –

  • Ixx (Union[float, aerosandbox.numpy.ndarray]) –

  • Iyy (Union[float, aerosandbox.numpy.ndarray]) –

  • Izz (Union[float, aerosandbox.numpy.ndarray]) –

  • Ixy (Union[float, aerosandbox.numpy.ndarray]) –

  • Iyz (Union[float, aerosandbox.numpy.ndarray]) –

  • Ixz (Union[float, aerosandbox.numpy.ndarray]) –

property xyz_cg#
property inertia_tensor#
__repr__()[source]#

Return repr(self).

Return type:

str

__getitem__(index)[source]#

Indexes one item from each attribute of an MassProperties instance. Returns a new MassProperties instance.

Parameters:

index – The index that is being called; e.g.,: >>> first_mass_props = mass_props[0]

Return type:

MassProperties

Returns: A new MassProperties instance, where each attribute is subscripted at the given value, if possible.

__len__()[source]#
__array__(dtype='O')[source]#

Allows NumPy array creation without infinite recursion in __len__ and __getitem__.

__neg__()[source]#
Return type:

MassProperties

__add__(other)[source]#

Combines one MassProperties object with another.

Parameters:

other (MassProperties) –

Return type:

MassProperties

__radd__(other)[source]#

Allows sum() to work with MassProperties objects.

Basically, makes addition commutative.

Parameters:

other (MassProperties) –

Return type:

MassProperties

__sub__(other)[source]#

Subtracts one MassProperties object from another. (opposite of __add__() )

Parameters:

other (MassProperties) –

Return type:

MassProperties

__mul__(other)[source]#

Returns a new MassProperties object that is equivalent to if you had summed together N (with other interpreted as N) identical MassProperties objects.

Parameters:

other (float) –

Return type:

MassProperties

__rmul__(other)[source]#

Allows multiplication of a scalar by a MassProperties object. Makes multiplication commutative.

Parameters:

other (float) –

Return type:

MassProperties

__truediv__(other)[source]#

Returns a new MassProperties object that is equivalent to if you had divided the mass of the current MassProperties object by a factor.

Parameters:

other (float) –

Return type:

MassProperties

allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False)[source]#
Parameters:

other (MassProperties) –

Return type:

bool

inv_inertia_tensor()[source]#

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.

get_inertia_tensor_about_point(x=0.0, y=0.0, z=0.0, return_tensor=True)[source]#

Returns the inertia tensor about an arbitrary point. Using https://en.wikipedia.org/wiki/Parallel_axis_theorem#Tensor_generalization

Parameters:
  • x (float) – x-position of the new point, in the same axes as this MassProperties instance is specified in.

  • y (float) – y-position of the new point, in the same axes as this MassProperties instance is specified in.

  • z (float) – z-position of the new point, in the same axes as this MassProperties instance is specified in.

  • return_tensor (bool) – 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)

Return type:

If return_tensor is True

is_physically_possible()[source]#

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.

Return type:

bool

is_point_mass()[source]#

Returns True if this MassProperties object corresponds to a point mass, False otherwise.

Return type:

bool

generate_possible_set_of_point_masses(method='optimization', check_if_already_a_point_mass=True)[source]#

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.

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
Parameters:
  • method – The method to use to generate the set of point masses. Currently, only “optimization” is supported.

  • check_if_already_a_point_mass (bool) –

Returns:

A list of MassProperties objects, each of which is a point mass (i.e., zero inertia tensor).

Return type:

List[MassProperties]

export_AVL_mass_file(filename)[source]#

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

Parameters:

filename – The filename to export to.

Return type:

None

Returns: None

aerosandbox.weights.mp1[source]#
aerosandbox.weights.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)[source]#

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.

Parameters:
  • mass (float) – Mass [kg]

  • x_cg (float) – x-position of the center of gravity

  • y_cg (float) – y-position of the center of gravity

  • z_cg (float) – z-position of the center of gravity

  • radius_of_gyration_x (float) – Radius of gyration along the x-axis, about the center of gravity [m]

  • radius_of_gyration_y (float) – Radius of gyration along the y-axis, about the center of gravity [m]

  • radius_of_gyration_z (float) – Radius of gyration along the z-axis, about the center of gravity [m]

Return type:

aerosandbox.weights.mass_properties.MassProperties

Returns: MassProperties object.