otaf.assembly_modeling package

Submodules

otaf.assembly_modeling.assemblyDataProcessor module

class otaf.assembly_modeling.assemblyDataProcessor.AssemblyDataProcessor(system_data=None)[source]

Bases: object

Class to manage and validate mechanical system data for assembly representation.

This class transforms a minimal representation of mechanical system data into a structured format usable by the rest of the code. It ensures data integrity and validates compatibility with defined requirements, including surfaces, points, interactions, and constraints.

Parameters:

system_data (dict, optional) – A nested dictionary representing mechanical system data. If not provided, an empty structure is initialized.

system_data

The validated and potentially augmented system data.

Type:

dict

compatibility_loops_expanded

Placeholder for compatibility loop expansions, initialized as None.

Type:

None or dict

__getitem__(key)[source]

Retrieve data associated with a key from the system data.

Parameters:

key (str) – The key for accessing system data.

Returns:

The value associated with the specified key.

Return type:

Any

__repr__()[source]

Generate a string representation of the system data.

Returns:

A string representation of the system data dictionary.

Return type:

str

__setitem__(key, val)[source]

Set a value in the system data for a given key.

Parameters:
  • key (str) – The key for the data to be set.

  • val (Any) – The value to assign to the key in the system data.

add_surface_points(part_id, surf_id, point_dict, ignore_duplicates=False)[source]

Add surface points to a specified part and surface, ensuring uniqueness and validating the input.

Parameters:
  • part_id (str) – The ID of the part to which the surface belongs.

  • surf_id (str) – The ID of the surface to which the points will be added.

  • point_dict (Dict[str, Union[Tuple, numpy.ndarray, List]]) – A dictionary where keys are point labels and values are their corresponding coordinates.

  • ignore_duplicates (bool, optional) – If True, ignore duplicate points that match exactly with existing points (default is False).

Raises:

Notes

  • Surface points are stored under the “POINTS” key of the surface’s dictionary.

  • If the label of a point matches the origin pattern (SURF_ORIGIN_PATTERN), the point is set as the surface’s origin.

generate_expanded_loops()[source]

Generate the full representation of compatibility loops and store them as an attribute.

This method processes the compact descriptions of compatibility loops in the system data and expands them into their detailed forms.

compatibility_loops_expanded

A dictionary where keys are loop names and values are the fully expanded loop strings.

Type:

dict

Return type:

None

generate_functional_planes()[source]

Generate planes representing each planar feature in the assembly

Returns:

A list of trimesh objects for each part and surface.

Return type:

list

Notes

  • The method uses a color palette to assign unique colors to the spheres for each part and surface.

  • The generated spheres are translated globally based on the global_translation parameter.

generate_points_for_surface(part_id, surf_id)[source]

Generate points for a surface based on its type and characteristics.

This method determines the surface type and dispatches the task to the appropriate surface-specific point generation method.

Parameters:
  • part_id (str) – The ID of the part containing the surface.

  • surf_id (str) – The ID of the surface for which points will be generated.

Raises:
Return type:

None

generate_sphere_clouds(radius=0.5, global_translation=array([0, 0, 0]))[source]

Generate sphere representations for each set of points in the system data.

This method creates a list of 3D spheres representing the points in the system data, grouped by parts and surfaces. Each group of points is assigned a unique color.

Parameters:
  • radius (Union[float, int], optional) – The radius of the spheres (default is 0.5).

  • global_translation (Union[list, numpy.ndarray], optional) – A 3D vector representing a global translation applied to all points (default is [0, 0, 0]).

Returns:

A list of trimesh sphere objects for each part and surface.

Return type:

list

Notes

  • The method uses a color palette to assign unique colors to the spheres for each part and surface.

  • The generated spheres are translated globally based on the global_translation parameter.

get_notebook_scene_sphere_clouds(radius=0.5, background_hex_color='e6e6e6')[source]

Create a 3D notebook scene with sphere clouds representing the system’s points.

This method generates a 3D scene containing spheres for the system’s points and renders it as a scene compatible with Jupyter Notebook.

Parameters:
  • radius (float, optional) – The radius of the spheres in the scene (default is 0.5).

  • background_hex_color (str, optional) – The hexadecimal color code for the scene’s background (default is “e6e6e6”).

Returns:

A scene object rendered in a format suitable for Jupyter Notebook.

Return type:

scene

get_surface_points(part_id, surf_id)[source]

Retrieve a copy of the points associated with a specific surface.

Parameters:
  • part_id (str) – The ID of the part containing the surface.

  • surf_id (str) – The ID of the surface.

Returns:

A copy of the points associated with the surface.

Return type:

dict

Raises:

KeyError – If the specified part or surface ID is not found.

validate_point_dict(point_dict)[source]

Validate a dictionary of points for compliance with labeling, formatting, and uniqueness rules.

Parameters:

point_dict (Dict[str, Union[Tuple, numpy.ndarray]]) – A dictionary where keys are point labels and values are their corresponding coordinates.

Raises:

Notes

  • Labels must conform to the SURF_POINT_PATTERN defined in the otaf.constants module.

  • Labels must have consistent prefixes (e.g., “A”, “B”, etc.) and unique numeric suffixes.

  • The coordinates for all points must be unique.

validate_system_data_structure()[source]

Validate the structure and integrity of the system data.

Ensures that the required keys and nested structures exist and conform to expected standards, including part IDs, surface labels, types, points, interactions, and constraints.

Raises:

otaf.assembly_modeling.assemblyModelingBaseObjects module

class otaf.assembly_modeling.assemblyModelingBaseObjects.DeviationMatrix(index=-1, translations='xyz', rotations='xyz', inverse=False, name='')[source]

Bases: object

Represents a deviation matrix used in structural analysis.

A deviation matrix defines deviations in translation and rotation for parts and assemblies. It can be compared to a small deviation torsor.

Parameters:
  • index (int, optional) – An index used to differentiate variable names. The same index can be used multiple times.

  • translations (str, optional) – Degrees of freedom for translation (‘x’, ‘y’, ‘z’). Example: “xyz” for all three degrees.

  • rotations (str, optional) – Degrees of freedom for rotation (‘x’, ‘y’, ‘z’).

  • inverse (bool, optional) – Indicates whether the matrix represents deviations from nominal to real (True) or vice versa (False). This affects the signs of the matrices and is necessary if a matrix is used in two directions.

  • name (str, optional) – Name of the matrix for identification (default is an empty string).

__repr__()[source]

Generate a string representation of the DeviationMatrix.

Returns:

String representation of the DeviationMatrix instance.

Return type:

str

get_inverse()[source]

Generate the inverse of the current DeviationMatrix.

The inverse matrix has the same degrees of freedom (translations and rotations) but with reversed directionality.

Returns:

A new instance of DeviationMatrix representing the inverse of the current matrix.

Return type:

DeviationMatrix

get_matrix()[source]

Generate the SE(3) matrix for the deviation matrix.

The SE(3) matrix is constructed using the indices of the degrees of freedom specified during initialization.

Returns:

A list of symbolic matrices corresponding to the SE(3) basis elements.

Return type:

List[sympy.MatrixBase]

get_matrix_inverse()[source]

Generate the inverse SE(3) matrix for the deviation matrix.

The inverse SE(3) matrix is constructed by reversing the directionality of the degrees of freedom (i.e., multiplying by -1).

Returns:

A list of symbolic matrices corresponding to the inverse SE(3) basis elements.

Return type:

List[sympy.MatrixBase]

get_variables()[source]

Retrieve the symbolic variables associated with the deviation matrix.

These variables correspond to the degrees of freedom in translations and rotations, defined during initialization.

Returns:

A list of symbolic variables representing the degrees of freedom.

Return type:

List[sympy.Symbol]

class otaf.assembly_modeling.assemblyModelingBaseObjects.GapMatrix(index=-1, translations_blocked='', rotations_blocked='', inverse=False, name='')[source]

Bases: object

Represents a gap matrix used in structural analysis.

A gap matrix defines gaps or clearances in translation and rotation for parts and assemblies.

Parameters:
  • index (int, optional) – An index used to differentiate variable names. The same index can be used multiple times (default is -1).

  • translations_blocked (str, optional) – Degrees of freedom for translation that are blocked (‘x’, ‘y’, ‘z’) (default is an empty string).

  • rotations_blocked (str, optional) – Degrees of freedom for rotation that are blocked (‘x’, ‘y’, ‘z’) (default is an empty string).

  • inverse (bool, optional) – Indicates whether the matrix represents gaps or clearances (True) or blocked degrees of freedom (False).

  • name (str, optional) – Name of the matrix for identification (default is an empty string).

__repr__()[source]

Generate a string representation of the GapMatrix.

Returns:

String representation of the GapMatrix instance.

Return type:

str

get_inverse()[source]

Generate the inverse of the current GapMatrix.

The inverse matrix has the same blocked degrees of freedom for translations and rotations but reverses the directionality (gaps versus clearances).

Returns:

A new instance of GapMatrix representing the inverse of the current matrix.

Return type:

GapMatrix

get_matrix()[source]

Generate the SE(3) matrix for the gap matrix.

The SE(3) matrix is constructed using the indices of the degrees of freedom that are not blocked, specified during initialization.

Returns:

A list of symbolic matrices corresponding to the SE(3) basis elements.

Return type:

List[sympy.MatrixBase]

get_matrix_inverse()[source]

Generate the inverse SE(3) matrix for the gap matrix.

The inverse SE(3) matrix is constructed by reversing the directionality of the degrees of freedom (i.e., multiplying by -1).

Returns:

A list of symbolic matrices corresponding to the inverse SE(3) basis elements.

Return type:

List[sympy.MatrixBase]

get_variables()[source]

Retrieve the symbolic variables associated with the gap matrix.

These variables correspond to the degrees of freedom in translations and rotations that are not blocked, as defined during initialization.

Returns:

A list of symbolic variables representing the degrees of freedom.

Return type:

List[sympy.Symbol]

class otaf.assembly_modeling.assemblyModelingBaseObjects.I4[source]

Bases: object

Class representing a 4x4 identity matrix.

The identity matrix is commonly used in transformations as a neutral element, where no translation or rotation is applied.

get_matrix()[source]

Generate a 4x4 identity matrix.

Returns:

A symbolic representation of a 4x4 identity matrix.

Return type:

sympy.MatrixBase

get_matrix_inverse()[source]

Generate the inverse of the 4x4 identity matrix.

Since the inverse of an identity matrix is itself, this method returns the same matrix.

Returns:

A symbolic representation of the 4x4 identity matrix.

Return type:

sympy.MatrixBase

class otaf.assembly_modeling.assemblyModelingBaseObjects.J4[source]

Bases: object

Class representing a 4x4 rotation matrix for a 180° rotation around the z-axis.

This matrix is often used to represent a transformation involving a half-turn rotation in a Cartesian coordinate system.

get_matrix()[source]

Generate a 4x4 rotation matrix representing a 180° rotation around the z-axis.

The matrix is constructed as follows:
  • The x-axis and y-axis are negated.

  • The z-axis and translation remain unchanged.

Returns:

A symbolic representation of a 4x4 rotation matrix for a 180° z-axis rotation.

Return type:

sympy.MatrixBase

get_matrix_inverse()[source]

Generate the inverse of the 4x4 rotation matrix.

Since the inverse of a 180° rotation around the z-axis is the same rotation, this method returns the same matrix.

Returns:

A symbolic representation of the 4x4 rotation matrix for a 180° z-axis rotation.

Return type:

sympy.MatrixBase

class otaf.assembly_modeling.assemblyModelingBaseObjects.TransformationMatrix(index=-1, initial=array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]), final=array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]), name='', matrix=None)[source]

Bases: object

Class representing transformation matrices within the nominal geometry of a part.

Transformation matrices define the transformation between two coordinate systems.

Parameters:
  • index (int, optional) – An index used to differentiate transformation matrices. The same index can be used multiple times (default is -1).

  • initial (np.ndarray, optional) – The initial 4x4 matrix representing the initial coordinate system (default is the identity matrix).

  • final (np.ndarray, optional) – The final 4x4 matrix representing the final coordinate system (default is the identity matrix).

  • name (str, optional) – Name of the transformation matrix for identification (default is an empty string).

  • matrix (Optional[Union[np.ndarray, sympy.MatrixBase]], optional) – The explicit transformation matrix. If provided, it overrides initial and final matrices (default is None).

Raises:

AssertionError – If the provided matrix is not a valid affine transformation matrix.

__repr__()[source]

Generate a string representation of the TransformationMatrix.

Returns:

String representation of the TransformationMatrix instance, including its index and matrix values.

Return type:

str

get_change_of_basis_matrix(initial, final, as_array=False)[source]

Calculate the change of basis matrix between two coordinate systems.

The change of basis matrix is computed as the relative transformation from the initial coordinate system to the final coordinate system.

Parameters:
  • initial (np.ndarray) – The initial 4x4 matrix representing the initial coordinate system.

  • final (np.ndarray) – The final 4x4 matrix representing the final coordinate system.

  • as_array (bool, optional) – If True, returns the matrix as a NumPy array; otherwise, returns a sympy.Matrix (default is False).

Returns:

The change of basis matrix between the initial and final coordinate systems.

Return type:

Union[sympy.MatrixBase, np.ndarray]

get_inverse()[source]

Generate the inverse of the current TransformationMatrix.

The inverse transformation matrix swaps the initial and final coordinate systems, or directly computes the inverse of the provided matrix.

Returns:

A new instance of TransformationMatrix representing the inverse transformation.

Return type:

TransformationMatrix

get_matrix()[source]

Retrieve the transformation matrix.

If the transformation matrix was explicitly provided during initialization, it is returned. Otherwise, it is computed as the change of basis matrix between the initial and final coordinate systems.

Returns:

The transformation matrix as a symbolic sympy.Matrix.

Return type:

sympy.MatrixBase

get_matrix_inverse()[source]

Retrieve the inverse of the transformation matrix.

If the transformation matrix was explicitly provided during initialization, its inverse is computed. Otherwise, the inverse is calculated as the change of basis matrix between the final and initial coordinate systems.

Returns:

The inverse transformation matrix as a symbolic sympy.Matrix.

Return type:

sympy.MatrixBase

otaf.assembly_modeling.compatibilityLoopHandling module

class otaf.assembly_modeling.compatibilityLoopHandling.CompatibilityLoopHandling(assemblyDataProcessor)[source]

Bases: object

Class for processing system data and constructing compatibility constraint matrices.

This class processes system data to generate and manage compatibility loops, constructing the matrices required to define compatibility constraints in geometrical product specifications. It facilitates tolerance analysis by providing compatibility equations and handling matrix expansions for compatibility loops.

Parameters:

assemblyDataProcessor (AssemblyDataProcessor)

ADP

Object containing processed system data, including expanded compatibility loops.

Type:

otaf.AssemblyDataProcessor

_deviation_matrix_map

Cache mapping deviation matrix identifiers to their corresponding matrices.

Type:

dict

_gap_matrix_map

Cache mapping gap matrix identifiers to their corresponding matrices.

Type:

dict

_transformation_matrix_map

Cache mapping transformation matrix identifiers to their corresponding matrices.

Type:

dict

compatibility_loops_matrices

Dictionary mapping compatibility loop IDs to lists of corresponding matrices.

Type:

dict

compatibility_loops_FO_matrices

Dictionary mapping compatibility loop IDs to first-order expanded matrices.

Type:

dict

compatibility_expressions

List of symbolic expressions representing compatibility constraints.

Type:

list of sympy.Expr

__init__(assemblyDataProcessor)[source]

Initialize the class with processed system data.

get_gap_matrix_by_id(ID)[source]

Retrieve a gap matrix by its identifier.

Parameters:

ID (str | int)

Return type:

list[GapMatrix | TransformationMatrix]

get_deviation_matrix_by_id(ID)[source]

Retrieve a deviation matrix by its identifier.

Parameters:

ID (str | int)

Return type:

list[DeviationMatrix]

get_compatibility_expression_from_FO_matrices()[source]

Generate symbolic expressions for compatibility constraints.

Return type:

list[Expr]

generate_loop_id_to_matrix_list_dict()[source]

Create a dictionary mapping loop IDs to matrix lists for compatibility loops.

Return type:

dict[str, list[TransformationMatrix | DeviationMatrix | GapMatrix]]

generate_FO_loop_matrices()[source]

Generate first-order matrix expansions for compatibility loops.

Return type:

dict[str, MatrixBase]

apply_FO_matrix_expansion_to_matrix_loop_list(compatibility_loop_matrix_list)[source]

Apply first-order matrix expansion to a list of compatibility loop matrices.

Parameters:

compatibility_loop_matrix_list (list[TransformationMatrix | DeviationMatrix | GapMatrix])

Return type:

MatrixBase

generate_matrices_from_expanded_loop(expanded_loop_str)[source]

Generate matrices for a compatibility loop from its expanded string representation.

Parameters:

expanded_loop_str (str)

Return type:

list[TransformationMatrix | DeviationMatrix | GapMatrix]

generate_transformation_matrix(el_info)[source]

Generate a transformation matrix from loop element information.

Parameters:

el_info (dict)

Return type:

list[TransformationMatrix]

generate_deviation_matrix(el_info)[source]

Generate a deviation matrix based on loop element information.

Parameters:

el_info (dict)

Return type:

list[DeviationMatrix]

generate_gap_matrix(el_info)[source]

Generate a gap matrix based on loop element information.

Parameters:

el_info (dict)

Return type:

list[GapMatrix | TransformationMatrix]

calculate_nominal_gap_transform(el_info, ID, nullify_x=True, nullify_y=True, nullify_z=True)[source]

Calculate the nominal transformation matrix between two surfaces in a gap, with options to nullify specific translation components.

Parameters:
  • el_info (dict)

  • ID (int)

  • nullify_x (bool)

  • nullify_y (bool)

  • nullify_z (bool)

Return type:

TransformationMatrix

apply_FO_matrix_expansion_to_matrix_loop_list(compatibility_loop_matrix_list)[source]

Apply first-order matrix expansion to a list of compatibility loop matrices.

Parameters:

compatibility_loop_matrix_list (list of otaf.TransformationMatrix, otaf.DeviationMatrix, otaf.GapMatrix) – List of matrices representing a compatibility loop.

Returns:

The first-order expansion of the compatibility loop matrices.

Return type:

sympy.MatrixBase

calculate_nominal_gap_transform(el_info, ID, nullify_x=True, nullify_y=True, nullify_z=True)[source]

Calculate the nominal transformation matrix between two surfaces in a gap.

This method computes the nominal transformation matrix between two surfaces in the compatibility loop, with options to nullify specific components of the translation vector.

Parameters:
  • el_info (dict) – Dictionary containing loop element information, including part and surface identifiers.

  • ID (int) – Unique identifier for the transformation matrix.

  • nullify_x (bool, optional) – Whether to nullify the x-component of the translation vector. Defaults to True.

  • nullify_y (bool, optional) – Whether to nullify the y-component of the translation vector. Defaults to True.

  • nullify_z (bool, optional) – Whether to nullify the z-component of the translation vector. Defaults to True.

Returns:

The calculated nominal transformation matrix with specified components nullified.

Return type:

otaf.TransformationMatrix

Notes

  • The method extracts point and frame information for the specified surfaces and uses it to compute the nominal transformation matrix.

  • Nullification of translation components is applied directly to the matrix.

Raises:

KeyError – If required surface or frame information is missing in the input data.

Parameters:
  • el_info (dict)

  • ID (int)

  • nullify_x (bool)

  • nullify_y (bool)

  • nullify_z (bool)

Return type:

TransformationMatrix

generate_FO_loop_matrices()[source]

Generate first-order expanded matrices for compatibility loops.

Returns:

A dictionary mapping compatibility loop IDs to their first-order expanded matrices.

Return type:

dict

generate_deviation_matrix(el_info)[source]

Generate a deviation matrix based on loop element information.

This method creates a deviation matrix for a specified element in the compatibility loop, taking into account surface types, constraints, and global constraints.

Parameters:

el_info (dict) – Dictionary containing loop element information, including the matrix string (mstring), surface type, and relevant constraints.

Returns:

A list containing the generated deviation matrix or its inverse, depending on the specified configuration.

Return type:

list of otaf.DeviationMatrix

Notes

  • If the deviation matrix for the given element already exists, it retrieves it from the cache.

  • Surface constraints and global constraints influence the degrees of freedom (translations and rotations) of the generated deviation matrix.

Raises:

KeyError – If required surface or global constraints are missing in the input data.

Parameters:

el_info (dict)

Return type:

list[DeviationMatrix]

generate_gap_matrix(el_info)[source]

Generate a gap matrix based on loop element information.

This method creates a gap matrix for the specified pair of surfaces in the compatibility loop, taking into account surface types, contact constraints, manual constraints, and global constraints.

Parameters:

el_info (dict) – Dictionary containing loop element information, including the matrix string (mstring), part and surface identifiers, and relevant constraints.

Returns:

A list containing the generated gap matrix, its nominal transform, or their inverses, depending on the configuration.

Return type:

list of Union[otaf.GapMatrix, otaf.TransformationMatrix]

Notes

  • If the gap matrix for the given element already exists, it retrieves it from the cache.

  • Contact constraints and manual constraints (translations and rotations) influence the blocked degrees of freedom in the generated gap matrix.

  • A nominal gap transform is calculated and returned alongside the gap matrix.

Raises:

KeyError – If required surface or contact constraints are missing in the input data.

Parameters:

el_info (dict)

Return type:

list[GapMatrix | TransformationMatrix]

generate_loop_id_to_matrix_list_dict()[source]

Create a dictionary mapping compatibility loop IDs to lists of matrices.

Returns:

A dictionary where keys are compatibility loop IDs, and values are lists of matrices representing the corresponding compatibility loops.

Return type:

dict

generate_matrices_from_expanded_loop(expanded_loop_str)[source]

Generate matrices for a compatibility loop from its expanded string representation.

Parameters:

expanded_loop_str (str) – The string representation of an expanded compatibility loop.

Returns:

List of matrices corresponding to the expanded loop.

Return type:

list of otaf.TransformationMatrix, otaf.DeviationMatrix, otaf.GapMatrix

Raises:

ValueError – If the matrix type in the string is unknown.

generate_transformation_matrix(el_info)[source]

Generate a transformation matrix from loop element information.

Parameters:

el_info (dict) – Dictionary containing loop element information, including part IDs, surfaces, points, and transformation details.

Returns:

A list containing the generated transformation matrix.

Return type:

list of otaf.TransformationMatrix

Notes

  • If the matrix already exists in the transformation matrix map, it is retrieved from the cache.

  • The inverse of the generated transformation matrix is also cached.

get_compatibility_expression_from_FO_matrices()[source]

Generate symbolic expressions representing compatibility constraints.

Returns:

A list of symbolic expressions for the compatibility constraints derived from the first-order expanded matrices.

Return type:

list of sympy.Expr

get_deviation_matrix_by_id(ID)[source]

Retrieve a deviation matrix by its identifier.

Parameters:

ID (str or int) – The identifier of the deviation matrix.

Returns:

The corresponding deviation matrix.

Return type:

list of otaf.DeviationMatrix

Raises:

KeyError – If the specified ID does not exist in the deviation matrix map.

get_gap_matrix_by_id(ID)[source]

Retrieve a gap matrix by its identifier.

Parameters:

ID (str or int) – The identifier of the gap matrix.

Returns:

The corresponding gap matrix or transformation matrix.

Return type:

list of otaf.GapMatrix or otaf.TransformationMatrix

Raises:

KeyError – If the specified ID does not exist in the gap matrix map.

otaf.assembly_modeling.firstOrderMatrixExpansion module

class otaf.assembly_modeling.firstOrderMatrixExpansion.FirstOrderMatrixExpansion(matrix_list)[source]

Bases: object

Initialize the FirstOrderMatrixExpansion class.

Parameters:

matrix_list (List[Union[otaf.DeviationMatrix, otaf.GapMatrix, otaf.TransformationMatrix, otaf.I4, otaf.J4]]) – List of matrices to be used in the first-order Taylor expansion.

compute_first_order_expansion(tolerance=1e-08)[source]

Construct the first-order Taylor expansion of a matrix product.

This method computes the expansion by iterating through the provided list of matrices, identifying constant terms and first-order variable-dependent terms.

Parameters:

tolerance (float, optional) – Tolerance value for symbolic simplification (default is 1e-8).

Returns:

A symbolic matrix representing the simplified first-order Taylor expansion.

Return type:

sp.MatrixBase

otaf.assembly_modeling.systemOfConstraintsAssemblyModel module

class otaf.assembly_modeling.systemOfConstraintsAssemblyModel.SystemOfConstraintsAssemblyModel(compatibility_eqs, interface_eqs, verbose=0)[source]

Bases: object

Prepare matrices for tolerance analysis involving deviations and gaps.

This class processes compatibility and interface equations to generate a matrix representation suitable for linear programming solvers like scipy.optimize.linprog.

deviation_symbols

List of deviation variables.

Type:

list

gap_symbols

List of gap variables.

Type:

list

A_eq_Def

Coefficient matrix for deviation variables in compatibility equations.

Type:

numpy.ndarray

A_eq_Gap

Coefficient matrix for gap variables in compatibility equations.

Type:

numpy.ndarray

K_eq

Constants in compatibility equations.

Type:

numpy.ndarray

A_ub_Def

Coefficient matrix for deviation variables in interface equations.

Type:

numpy.ndarray

A_ub_Gap

Coefficient matrix for gap variables in interface equations.

Type:

numpy.ndarray

K_ub

Constants in interface equations.

Type:

numpy.ndarray

nD

Number of deviation variables.

Type:

int

nG

Number of gap variables.

Type:

int

nC

Number of compatibility equations.

Type:

int

nI

Number of interface equations.

Type:

int

__init__(compatibility_eqs, interface_eqs, verbose=0)[source]

Initialize the matrix preparer with compatibility and interface equations.

__call__(deviation_array, bounds=None, C=None)[source]

Generate input matrices and bounds for linear programming optimization.

Parameters:
  • deviation_array (ndarray | Iterable)

  • bounds (list[list[float]] | ndarray | None)

  • C (ndarray | list[int | float] | None)

Return type:

tuple[ndarray, ndarray, ndarray, ndarray, ndarray, ndarray]

Parameters:
  • compatibility_eqs (list of sympy.Expr) – List of compatibility equations (equality constraints).

  • interface_eqs (list of sympy.Expr) – List of interface equations (inequality constraints).

  • verbose (int, optional) – Verbosity level for logging (default is 0).

__call__(deviation_array, bounds=None, C=None)[source]

Generate input matrices and bounds for linear programming optimization.

This method prepares inputs for scipy.optimize.linprog using the deviation variables and optionally provided bounds and objective coefficients.

Parameters:
  • deviation_array (numpy.ndarray or Iterable) – Array of shape (nDOE, nD) representing deviation variables.

  • bounds (list of list of float or numpy.ndarray, optional) – Bounds for gap variables (default is automatically determined).

  • C (numpy.ndarray or list of float, optional) – Coefficients of the linear objective function to be minimized (default is inferred).

Returns:

Contains the following elements: - C : numpy.ndarray

Coefficients of the linear objective function.

  • A_ubnumpy.ndarray

    Matrix representing inequality constraints.

  • B_ubnumpy.ndarray

    Right-hand side of inequality constraints.

  • A_eqnumpy.ndarray

    Matrix representing equality constraints.

  • B_eqnumpy.ndarray

    Right-hand side of equality constraints.

  • boundsnumpy.ndarray

    Variable bounds.

Return type:

tuple

Raises:

ValueError – If the number of deviation variables in deviation_array does not match self.deviation_symbols.

Notes

  • Deviation variables must be in the same order as self.deviation_symbols.

  • Gap variables must be in the same order as self.gap_symbols.

  • Default bounds are generated if bounds is not provided or improperly formatted.

embedOptimizationVariable()[source]

Embed an auxiliary optimization variable for feasibility.

This method adds an auxiliary variable, s, to the gap variables. The variable s ensures that a feasible solution can be found, even in cases where the optimization problem would otherwise have no solution. The sign of s indicates whether the parts can be assembled, and the variable can be used in meta-model construction.

Notes

  • The variable s is appended to the list of gap variables (self.gap_symbols).

  • The A_ub_Gap and A_eq_Gap matrices are updated to include the new variable: - A_ub_Gap is augmented with a column of -1. - A_eq_Gap is augmented with a column of zeros.

extractFreeGapAndDeviationVariables()[source]

Extract sets of deviation and gap variables present in compatibility equations.

This method identifies the free variables used in the compatibility equations and verifies that all variables appearing in the interface equations are included.

Returns:

A tuple containing: - deviation_symbols : list of sympy.Symbol

List of deviation variables present in the compatibility equations.

  • gap_symbolslist of sympy.Symbol

    List of gap variables present in the compatibility equations.

Return type:

tuple

Raises:

AssertionError – If any variable in the interface equations is not included in the compatibility equations.

Notes

  • Deviation and gap variables are extracted separately from both compatibility and interface equations.

  • This ensures consistency between the two sets of equations.

generateConstraintMatrices(rnd=9)[source]

Decompose equations into matrix representations for compatibility and interface constraints.

This method converts the equations into matrix forms suitable for linear programming: - Compatibility equations (equality constraints) are represented as:

A_eq_Def * X + A_eq_Gap * Y + K_eq = 0.

  • Interface equations (inequality constraints) are represented as: A_ub_Def * X + A_ub_Gap * Y + K_ub >= 0.

Parameters:

rnd (int, optional) – Number of decimal places to round the matrix elements (default is 9).

Returns:

A tuple containing the following matrices: - A_eq_Def : numpy.ndarray

Coefficient matrix for deviation variables in compatibility equations.

  • A_eq_Gapnumpy.ndarray

    Coefficient matrix for gap variables in compatibility equations.

  • K_eqnumpy.ndarray

    Constants in compatibility equations.

  • A_ub_Defnumpy.ndarray

    Coefficient matrix for deviation variables in interface equations.

  • A_ub_Gapnumpy.ndarray

    Coefficient matrix for gap variables in interface equations.

  • K_ubnumpy.ndarray

    Constants in interface equations.

Return type:

tuple

Notes

  • The method iterates through each compatibility and interface equation to extract coefficients for deviation and gap variables.

  • Variables not explicitly included in the equations are assigned zero coefficients in the matrices.

get_feature_indices_and_dimensions()[source]

Extract unique feature indices (classes) and their corresponding sizes from deviation symbols.

This method processes the self.deviation_symbols list to identify unique class indices based on the pattern _d_X (where X is the numeric class identifier). It counts the number of variables associated with each class index and returns two lists: - A sorted list of unique class indices. - A list of corresponding sizes, representing the number of variables per class.

Returns:

  • list of int

    Sorted list of unique class indices.

  • list of int

    List of sizes, where each size corresponds to the number of variables for a class index.

Return type:

tuple

Notes

  • Each deviation symbol is assumed to contain the class identifier in the format _d_X.

  • The method uses a regular expression to extract the class identifier and counts occurrences for each class.

validateOptimizationResults(gap_array, deviation_array, rnd=9)[source]

Validate optimization results using original equations.

This method evaluates the original compatibility and interface equations with given values for the gap and deviation variables, returning the computed results for validation.

Parameters:
  • gap_array (numpy.ndarray) – Array of gap variables.

  • deviation_array (numpy.ndarray) – Array of deviation variables.

  • rnd (int, optional) – Number of decimal places to round the results (default is 9).

Returns:

  • List[float]: Results of evaluating the compatibility equations.

  • List[float]: Results of evaluating the interface equations.

Return type:

tuple

Notes

  • The method substitutes the provided gap and deviation values into the original equations.

  • Compatibility results close to zero indicate a valid solution, while larger values suggest potential issues.

  • Interface results show the satisfaction level of inequality constraints.

Module contents

class otaf.assembly_modeling.AssemblyDataProcessor(system_data=None)[source]

Bases: object

Class to manage and validate mechanical system data for assembly representation.

This class transforms a minimal representation of mechanical system data into a structured format usable by the rest of the code. It ensures data integrity and validates compatibility with defined requirements, including surfaces, points, interactions, and constraints.

Parameters:

system_data (dict, optional) – A nested dictionary representing mechanical system data. If not provided, an empty structure is initialized.

system_data

The validated and potentially augmented system data.

Type:

dict

compatibility_loops_expanded

Placeholder for compatibility loop expansions, initialized as None.

Type:

None or dict

__getitem__(key)[source]

Retrieve data associated with a key from the system data.

Parameters:

key (str) – The key for accessing system data.

Returns:

The value associated with the specified key.

Return type:

Any

__repr__()[source]

Generate a string representation of the system data.

Returns:

A string representation of the system data dictionary.

Return type:

str

__setitem__(key, val)[source]

Set a value in the system data for a given key.

Parameters:
  • key (str) – The key for the data to be set.

  • val (Any) – The value to assign to the key in the system data.

add_surface_points(part_id, surf_id, point_dict, ignore_duplicates=False)[source]

Add surface points to a specified part and surface, ensuring uniqueness and validating the input.

Parameters:
  • part_id (str) – The ID of the part to which the surface belongs.

  • surf_id (str) – The ID of the surface to which the points will be added.

  • point_dict (Dict[str, Union[Tuple, numpy.ndarray, List]]) – A dictionary where keys are point labels and values are their corresponding coordinates.

  • ignore_duplicates (bool, optional) – If True, ignore duplicate points that match exactly with existing points (default is False).

Raises:

Notes

  • Surface points are stored under the “POINTS” key of the surface’s dictionary.

  • If the label of a point matches the origin pattern (SURF_ORIGIN_PATTERN), the point is set as the surface’s origin.

generate_expanded_loops()[source]

Generate the full representation of compatibility loops and store them as an attribute.

This method processes the compact descriptions of compatibility loops in the system data and expands them into their detailed forms.

compatibility_loops_expanded

A dictionary where keys are loop names and values are the fully expanded loop strings.

Type:

dict

Return type:

None

generate_functional_planes()[source]

Generate planes representing each planar feature in the assembly

Returns:

A list of trimesh objects for each part and surface.

Return type:

list

Notes

  • The method uses a color palette to assign unique colors to the spheres for each part and surface.

  • The generated spheres are translated globally based on the global_translation parameter.

generate_points_for_surface(part_id, surf_id)[source]

Generate points for a surface based on its type and characteristics.

This method determines the surface type and dispatches the task to the appropriate surface-specific point generation method.

Parameters:
  • part_id (str) – The ID of the part containing the surface.

  • surf_id (str) – The ID of the surface for which points will be generated.

Raises:
Return type:

None

generate_sphere_clouds(radius=0.5, global_translation=array([0, 0, 0]))[source]

Generate sphere representations for each set of points in the system data.

This method creates a list of 3D spheres representing the points in the system data, grouped by parts and surfaces. Each group of points is assigned a unique color.

Parameters:
  • radius (Union[float, int], optional) – The radius of the spheres (default is 0.5).

  • global_translation (Union[list, numpy.ndarray], optional) – A 3D vector representing a global translation applied to all points (default is [0, 0, 0]).

Returns:

A list of trimesh sphere objects for each part and surface.

Return type:

list

Notes

  • The method uses a color palette to assign unique colors to the spheres for each part and surface.

  • The generated spheres are translated globally based on the global_translation parameter.

get_notebook_scene_sphere_clouds(radius=0.5, background_hex_color='e6e6e6')[source]

Create a 3D notebook scene with sphere clouds representing the system’s points.

This method generates a 3D scene containing spheres for the system’s points and renders it as a scene compatible with Jupyter Notebook.

Parameters:
  • radius (float, optional) – The radius of the spheres in the scene (default is 0.5).

  • background_hex_color (str, optional) – The hexadecimal color code for the scene’s background (default is “e6e6e6”).

Returns:

A scene object rendered in a format suitable for Jupyter Notebook.

Return type:

scene

get_surface_points(part_id, surf_id)[source]

Retrieve a copy of the points associated with a specific surface.

Parameters:
  • part_id (str) – The ID of the part containing the surface.

  • surf_id (str) – The ID of the surface.

Returns:

A copy of the points associated with the surface.

Return type:

dict

Raises:

KeyError – If the specified part or surface ID is not found.

validate_point_dict(point_dict)[source]

Validate a dictionary of points for compliance with labeling, formatting, and uniqueness rules.

Parameters:

point_dict (Dict[str, Union[Tuple, numpy.ndarray]]) – A dictionary where keys are point labels and values are their corresponding coordinates.

Raises:

Notes

  • Labels must conform to the SURF_POINT_PATTERN defined in the otaf.constants module.

  • Labels must have consistent prefixes (e.g., “A”, “B”, etc.) and unique numeric suffixes.

  • The coordinates for all points must be unique.

validate_system_data_structure()[source]

Validate the structure and integrity of the system data.

Ensures that the required keys and nested structures exist and conform to expected standards, including part IDs, surface labels, types, points, interactions, and constraints.

Raises:
class otaf.assembly_modeling.CompatibilityLoopHandling(assemblyDataProcessor)[source]

Bases: object

Class for processing system data and constructing compatibility constraint matrices.

This class processes system data to generate and manage compatibility loops, constructing the matrices required to define compatibility constraints in geometrical product specifications. It facilitates tolerance analysis by providing compatibility equations and handling matrix expansions for compatibility loops.

Parameters:

assemblyDataProcessor (AssemblyDataProcessor)

ADP

Object containing processed system data, including expanded compatibility loops.

Type:

otaf.AssemblyDataProcessor

_deviation_matrix_map

Cache mapping deviation matrix identifiers to their corresponding matrices.

Type:

dict

_gap_matrix_map

Cache mapping gap matrix identifiers to their corresponding matrices.

Type:

dict

_transformation_matrix_map

Cache mapping transformation matrix identifiers to their corresponding matrices.

Type:

dict

compatibility_loops_matrices

Dictionary mapping compatibility loop IDs to lists of corresponding matrices.

Type:

dict

compatibility_loops_FO_matrices

Dictionary mapping compatibility loop IDs to first-order expanded matrices.

Type:

dict

compatibility_expressions

List of symbolic expressions representing compatibility constraints.

Type:

list of sympy.Expr

__init__(assemblyDataProcessor)[source]

Initialize the class with processed system data.

get_gap_matrix_by_id(ID)[source]

Retrieve a gap matrix by its identifier.

Parameters:

ID (str | int)

Return type:

list[GapMatrix | TransformationMatrix]

get_deviation_matrix_by_id(ID)[source]

Retrieve a deviation matrix by its identifier.

Parameters:

ID (str | int)

Return type:

list[DeviationMatrix]

get_compatibility_expression_from_FO_matrices()[source]

Generate symbolic expressions for compatibility constraints.

Return type:

list[Expr]

generate_loop_id_to_matrix_list_dict()[source]

Create a dictionary mapping loop IDs to matrix lists for compatibility loops.

Return type:

dict[str, list[TransformationMatrix | DeviationMatrix | GapMatrix]]

generate_FO_loop_matrices()[source]

Generate first-order matrix expansions for compatibility loops.

Return type:

dict[str, MatrixBase]

apply_FO_matrix_expansion_to_matrix_loop_list(compatibility_loop_matrix_list)[source]

Apply first-order matrix expansion to a list of compatibility loop matrices.

Parameters:

compatibility_loop_matrix_list (list[TransformationMatrix | DeviationMatrix | GapMatrix])

Return type:

MatrixBase

generate_matrices_from_expanded_loop(expanded_loop_str)[source]

Generate matrices for a compatibility loop from its expanded string representation.

Parameters:

expanded_loop_str (str)

Return type:

list[TransformationMatrix | DeviationMatrix | GapMatrix]

generate_transformation_matrix(el_info)[source]

Generate a transformation matrix from loop element information.

Parameters:

el_info (dict)

Return type:

list[TransformationMatrix]

generate_deviation_matrix(el_info)[source]

Generate a deviation matrix based on loop element information.

Parameters:

el_info (dict)

Return type:

list[DeviationMatrix]

generate_gap_matrix(el_info)[source]

Generate a gap matrix based on loop element information.

Parameters:

el_info (dict)

Return type:

list[GapMatrix | TransformationMatrix]

calculate_nominal_gap_transform(el_info, ID, nullify_x=True, nullify_y=True, nullify_z=True)[source]

Calculate the nominal transformation matrix between two surfaces in a gap, with options to nullify specific translation components.

Parameters:
  • el_info (dict)

  • ID (int)

  • nullify_x (bool)

  • nullify_y (bool)

  • nullify_z (bool)

Return type:

TransformationMatrix

apply_FO_matrix_expansion_to_matrix_loop_list(compatibility_loop_matrix_list)[source]

Apply first-order matrix expansion to a list of compatibility loop matrices.

Parameters:

compatibility_loop_matrix_list (list of otaf.TransformationMatrix, otaf.DeviationMatrix, otaf.GapMatrix) – List of matrices representing a compatibility loop.

Returns:

The first-order expansion of the compatibility loop matrices.

Return type:

sympy.MatrixBase

calculate_nominal_gap_transform(el_info, ID, nullify_x=True, nullify_y=True, nullify_z=True)[source]

Calculate the nominal transformation matrix between two surfaces in a gap.

This method computes the nominal transformation matrix between two surfaces in the compatibility loop, with options to nullify specific components of the translation vector.

Parameters:
  • el_info (dict) – Dictionary containing loop element information, including part and surface identifiers.

  • ID (int) – Unique identifier for the transformation matrix.

  • nullify_x (bool, optional) – Whether to nullify the x-component of the translation vector. Defaults to True.

  • nullify_y (bool, optional) – Whether to nullify the y-component of the translation vector. Defaults to True.

  • nullify_z (bool, optional) – Whether to nullify the z-component of the translation vector. Defaults to True.

Returns:

The calculated nominal transformation matrix with specified components nullified.

Return type:

otaf.TransformationMatrix

Notes

  • The method extracts point and frame information for the specified surfaces and uses it to compute the nominal transformation matrix.

  • Nullification of translation components is applied directly to the matrix.

Raises:

KeyError – If required surface or frame information is missing in the input data.

Parameters:
  • el_info (dict)

  • ID (int)

  • nullify_x (bool)

  • nullify_y (bool)

  • nullify_z (bool)

Return type:

TransformationMatrix

generate_FO_loop_matrices()[source]

Generate first-order expanded matrices for compatibility loops.

Returns:

A dictionary mapping compatibility loop IDs to their first-order expanded matrices.

Return type:

dict

generate_deviation_matrix(el_info)[source]

Generate a deviation matrix based on loop element information.

This method creates a deviation matrix for a specified element in the compatibility loop, taking into account surface types, constraints, and global constraints.

Parameters:

el_info (dict) – Dictionary containing loop element information, including the matrix string (mstring), surface type, and relevant constraints.

Returns:

A list containing the generated deviation matrix or its inverse, depending on the specified configuration.

Return type:

list of otaf.DeviationMatrix

Notes

  • If the deviation matrix for the given element already exists, it retrieves it from the cache.

  • Surface constraints and global constraints influence the degrees of freedom (translations and rotations) of the generated deviation matrix.

Raises:

KeyError – If required surface or global constraints are missing in the input data.

Parameters:

el_info (dict)

Return type:

list[DeviationMatrix]

generate_gap_matrix(el_info)[source]

Generate a gap matrix based on loop element information.

This method creates a gap matrix for the specified pair of surfaces in the compatibility loop, taking into account surface types, contact constraints, manual constraints, and global constraints.

Parameters:

el_info (dict) – Dictionary containing loop element information, including the matrix string (mstring), part and surface identifiers, and relevant constraints.

Returns:

A list containing the generated gap matrix, its nominal transform, or their inverses, depending on the configuration.

Return type:

list of Union[otaf.GapMatrix, otaf.TransformationMatrix]

Notes

  • If the gap matrix for the given element already exists, it retrieves it from the cache.

  • Contact constraints and manual constraints (translations and rotations) influence the blocked degrees of freedom in the generated gap matrix.

  • A nominal gap transform is calculated and returned alongside the gap matrix.

Raises:

KeyError – If required surface or contact constraints are missing in the input data.

Parameters:

el_info (dict)

Return type:

list[GapMatrix | TransformationMatrix]

generate_loop_id_to_matrix_list_dict()[source]

Create a dictionary mapping compatibility loop IDs to lists of matrices.

Returns:

A dictionary where keys are compatibility loop IDs, and values are lists of matrices representing the corresponding compatibility loops.

Return type:

dict

generate_matrices_from_expanded_loop(expanded_loop_str)[source]

Generate matrices for a compatibility loop from its expanded string representation.

Parameters:

expanded_loop_str (str) – The string representation of an expanded compatibility loop.

Returns:

List of matrices corresponding to the expanded loop.

Return type:

list of otaf.TransformationMatrix, otaf.DeviationMatrix, otaf.GapMatrix

Raises:

ValueError – If the matrix type in the string is unknown.

generate_transformation_matrix(el_info)[source]

Generate a transformation matrix from loop element information.

Parameters:

el_info (dict) – Dictionary containing loop element information, including part IDs, surfaces, points, and transformation details.

Returns:

A list containing the generated transformation matrix.

Return type:

list of otaf.TransformationMatrix

Notes

  • If the matrix already exists in the transformation matrix map, it is retrieved from the cache.

  • The inverse of the generated transformation matrix is also cached.

get_compatibility_expression_from_FO_matrices()[source]

Generate symbolic expressions representing compatibility constraints.

Returns:

A list of symbolic expressions for the compatibility constraints derived from the first-order expanded matrices.

Return type:

list of sympy.Expr

get_deviation_matrix_by_id(ID)[source]

Retrieve a deviation matrix by its identifier.

Parameters:

ID (str or int) – The identifier of the deviation matrix.

Returns:

The corresponding deviation matrix.

Return type:

list of otaf.DeviationMatrix

Raises:

KeyError – If the specified ID does not exist in the deviation matrix map.

get_gap_matrix_by_id(ID)[source]

Retrieve a gap matrix by its identifier.

Parameters:

ID (str or int) – The identifier of the gap matrix.

Returns:

The corresponding gap matrix or transformation matrix.

Return type:

list of otaf.GapMatrix or otaf.TransformationMatrix

Raises:

KeyError – If the specified ID does not exist in the gap matrix map.

class otaf.assembly_modeling.DeviationMatrix(index=-1, translations='xyz', rotations='xyz', inverse=False, name='')[source]

Bases: object

Represents a deviation matrix used in structural analysis.

A deviation matrix defines deviations in translation and rotation for parts and assemblies. It can be compared to a small deviation torsor.

Parameters:
  • index (int, optional) – An index used to differentiate variable names. The same index can be used multiple times.

  • translations (str, optional) – Degrees of freedom for translation (‘x’, ‘y’, ‘z’). Example: “xyz” for all three degrees.

  • rotations (str, optional) – Degrees of freedom for rotation (‘x’, ‘y’, ‘z’).

  • inverse (bool, optional) – Indicates whether the matrix represents deviations from nominal to real (True) or vice versa (False). This affects the signs of the matrices and is necessary if a matrix is used in two directions.

  • name (str, optional) – Name of the matrix for identification (default is an empty string).

__repr__()[source]

Generate a string representation of the DeviationMatrix.

Returns:

String representation of the DeviationMatrix instance.

Return type:

str

get_inverse()[source]

Generate the inverse of the current DeviationMatrix.

The inverse matrix has the same degrees of freedom (translations and rotations) but with reversed directionality.

Returns:

A new instance of DeviationMatrix representing the inverse of the current matrix.

Return type:

DeviationMatrix

get_matrix()[source]

Generate the SE(3) matrix for the deviation matrix.

The SE(3) matrix is constructed using the indices of the degrees of freedom specified during initialization.

Returns:

A list of symbolic matrices corresponding to the SE(3) basis elements.

Return type:

List[sympy.MatrixBase]

get_matrix_inverse()[source]

Generate the inverse SE(3) matrix for the deviation matrix.

The inverse SE(3) matrix is constructed by reversing the directionality of the degrees of freedom (i.e., multiplying by -1).

Returns:

A list of symbolic matrices corresponding to the inverse SE(3) basis elements.

Return type:

List[sympy.MatrixBase]

get_variables()[source]

Retrieve the symbolic variables associated with the deviation matrix.

These variables correspond to the degrees of freedom in translations and rotations, defined during initialization.

Returns:

A list of symbolic variables representing the degrees of freedom.

Return type:

List[sympy.Symbol]

class otaf.assembly_modeling.FirstOrderMatrixExpansion(matrix_list)[source]

Bases: object

Initialize the FirstOrderMatrixExpansion class.

Parameters:

matrix_list (List[Union[otaf.DeviationMatrix, otaf.GapMatrix, otaf.TransformationMatrix, otaf.I4, otaf.J4]]) – List of matrices to be used in the first-order Taylor expansion.

compute_first_order_expansion(tolerance=1e-08)[source]

Construct the first-order Taylor expansion of a matrix product.

This method computes the expansion by iterating through the provided list of matrices, identifying constant terms and first-order variable-dependent terms.

Parameters:

tolerance (float, optional) – Tolerance value for symbolic simplification (default is 1e-8).

Returns:

A symbolic matrix representing the simplified first-order Taylor expansion.

Return type:

sp.MatrixBase

class otaf.assembly_modeling.GapMatrix(index=-1, translations_blocked='', rotations_blocked='', inverse=False, name='')[source]

Bases: object

Represents a gap matrix used in structural analysis.

A gap matrix defines gaps or clearances in translation and rotation for parts and assemblies.

Parameters:
  • index (int, optional) – An index used to differentiate variable names. The same index can be used multiple times (default is -1).

  • translations_blocked (str, optional) – Degrees of freedom for translation that are blocked (‘x’, ‘y’, ‘z’) (default is an empty string).

  • rotations_blocked (str, optional) – Degrees of freedom for rotation that are blocked (‘x’, ‘y’, ‘z’) (default is an empty string).

  • inverse (bool, optional) – Indicates whether the matrix represents gaps or clearances (True) or blocked degrees of freedom (False).

  • name (str, optional) – Name of the matrix for identification (default is an empty string).

__repr__()[source]

Generate a string representation of the GapMatrix.

Returns:

String representation of the GapMatrix instance.

Return type:

str

get_inverse()[source]

Generate the inverse of the current GapMatrix.

The inverse matrix has the same blocked degrees of freedom for translations and rotations but reverses the directionality (gaps versus clearances).

Returns:

A new instance of GapMatrix representing the inverse of the current matrix.

Return type:

GapMatrix

get_matrix()[source]

Generate the SE(3) matrix for the gap matrix.

The SE(3) matrix is constructed using the indices of the degrees of freedom that are not blocked, specified during initialization.

Returns:

A list of symbolic matrices corresponding to the SE(3) basis elements.

Return type:

List[sympy.MatrixBase]

get_matrix_inverse()[source]

Generate the inverse SE(3) matrix for the gap matrix.

The inverse SE(3) matrix is constructed by reversing the directionality of the degrees of freedom (i.e., multiplying by -1).

Returns:

A list of symbolic matrices corresponding to the inverse SE(3) basis elements.

Return type:

List[sympy.MatrixBase]

get_variables()[source]

Retrieve the symbolic variables associated with the gap matrix.

These variables correspond to the degrees of freedom in translations and rotations that are not blocked, as defined during initialization.

Returns:

A list of symbolic variables representing the degrees of freedom.

Return type:

List[sympy.Symbol]

class otaf.assembly_modeling.I4[source]

Bases: object

Class representing a 4x4 identity matrix.

The identity matrix is commonly used in transformations as a neutral element, where no translation or rotation is applied.

get_matrix()[source]

Generate a 4x4 identity matrix.

Returns:

A symbolic representation of a 4x4 identity matrix.

Return type:

sympy.MatrixBase

get_matrix_inverse()[source]

Generate the inverse of the 4x4 identity matrix.

Since the inverse of an identity matrix is itself, this method returns the same matrix.

Returns:

A symbolic representation of the 4x4 identity matrix.

Return type:

sympy.MatrixBase

class otaf.assembly_modeling.InterfaceLoopHandling(system_data_augmented, compatibility_loop_handling, circle_resolution=8)[source]

Bases: object

extract_unique_gap_matrices_from_expanded_loops()[source]

Extract unique gap matrices from expanded compatibility loops and return them as a set.

Return type:

set[str]

property facing_point_dictionary
filter_gap_matrices(existing_gap_matrices, all_gap_matrices)[source]

Filter and organize gap matrices into used and unused categories.

This method categorizes gap matrices into ‘used’ and ‘unused’ based on their presence in the existing gap matrices set. It iterates through all provided gap matrices, comparing them with existing ones, and then organizes them into a nested dictionary indicating their usage status. This only categorizes the matrices when there is at least a common elemnt

Parameters:
  • existing_gap_matrices (Set[str]) – A set of existing gap matrix names.

  • all_gap_matrices (Dict[str, Dict[str, Set[str]]]) – A dictionary of all gap matrices, structured by parts and surfaces.

Returns:

A nested dictionary categorizing gap matrices into ‘used’ and ‘unused’ for each part and surface.

Return type:

Dict[str, Dict[str, Dict[str, Set[str]]]]

generate_all_gap_matrix_names()[source]

Generate and return a dictionary of gap matrix names based on facing points.

This method iterates through the facing points in the system, creating and organizing gap matrix names. Each gap matrix name represents a potential spatial relationship between different parts and surfaces in the system. The names are stored in a nested dictionary structure keyed by part and surface IDs.

Additionally, it ensures that for every gap matrix, its inverse exists in the set for the corresponding surface on the other part. If an inverse gap matrix is missing, it is added to maintain consistency in the representation of spatial relationships.

Return type:

dict[str, dict[str, set[str]]]

get_interface_loop_expressions()[source]
class otaf.assembly_modeling.J4[source]

Bases: object

Class representing a 4x4 rotation matrix for a 180° rotation around the z-axis.

This matrix is often used to represent a transformation involving a half-turn rotation in a Cartesian coordinate system.

get_matrix()[source]

Generate a 4x4 rotation matrix representing a 180° rotation around the z-axis.

The matrix is constructed as follows:
  • The x-axis and y-axis are negated.

  • The z-axis and translation remain unchanged.

Returns:

A symbolic representation of a 4x4 rotation matrix for a 180° z-axis rotation.

Return type:

sympy.MatrixBase

get_matrix_inverse()[source]

Generate the inverse of the 4x4 rotation matrix.

Since the inverse of a 180° rotation around the z-axis is the same rotation, this method returns the same matrix.

Returns:

A symbolic representation of the 4x4 rotation matrix for a 180° z-axis rotation.

Return type:

sympy.MatrixBase

class otaf.assembly_modeling.SystemOfConstraintsAssemblyModel(compatibility_eqs, interface_eqs, verbose=0)[source]

Bases: object

Prepare matrices for tolerance analysis involving deviations and gaps.

This class processes compatibility and interface equations to generate a matrix representation suitable for linear programming solvers like scipy.optimize.linprog.

deviation_symbols

List of deviation variables.

Type:

list

gap_symbols

List of gap variables.

Type:

list

A_eq_Def

Coefficient matrix for deviation variables in compatibility equations.

Type:

numpy.ndarray

A_eq_Gap

Coefficient matrix for gap variables in compatibility equations.

Type:

numpy.ndarray

K_eq

Constants in compatibility equations.

Type:

numpy.ndarray

A_ub_Def

Coefficient matrix for deviation variables in interface equations.

Type:

numpy.ndarray

A_ub_Gap

Coefficient matrix for gap variables in interface equations.

Type:

numpy.ndarray

K_ub

Constants in interface equations.

Type:

numpy.ndarray

nD

Number of deviation variables.

Type:

int

nG

Number of gap variables.

Type:

int

nC

Number of compatibility equations.

Type:

int

nI

Number of interface equations.

Type:

int

__init__(compatibility_eqs, interface_eqs, verbose=0)[source]

Initialize the matrix preparer with compatibility and interface equations.

__call__(deviation_array, bounds=None, C=None)[source]

Generate input matrices and bounds for linear programming optimization.

Parameters:
  • deviation_array (ndarray | Iterable)

  • bounds (list[list[float]] | ndarray | None)

  • C (ndarray | list[int | float] | None)

Return type:

tuple[ndarray, ndarray, ndarray, ndarray, ndarray, ndarray]

Parameters:
  • compatibility_eqs (list of sympy.Expr) – List of compatibility equations (equality constraints).

  • interface_eqs (list of sympy.Expr) – List of interface equations (inequality constraints).

  • verbose (int, optional) – Verbosity level for logging (default is 0).

__call__(deviation_array, bounds=None, C=None)[source]

Generate input matrices and bounds for linear programming optimization.

This method prepares inputs for scipy.optimize.linprog using the deviation variables and optionally provided bounds and objective coefficients.

Parameters:
  • deviation_array (numpy.ndarray or Iterable) – Array of shape (nDOE, nD) representing deviation variables.

  • bounds (list of list of float or numpy.ndarray, optional) – Bounds for gap variables (default is automatically determined).

  • C (numpy.ndarray or list of float, optional) – Coefficients of the linear objective function to be minimized (default is inferred).

Returns:

Contains the following elements: - C : numpy.ndarray

Coefficients of the linear objective function.

  • A_ubnumpy.ndarray

    Matrix representing inequality constraints.

  • B_ubnumpy.ndarray

    Right-hand side of inequality constraints.

  • A_eqnumpy.ndarray

    Matrix representing equality constraints.

  • B_eqnumpy.ndarray

    Right-hand side of equality constraints.

  • boundsnumpy.ndarray

    Variable bounds.

Return type:

tuple

Raises:

ValueError – If the number of deviation variables in deviation_array does not match self.deviation_symbols.

Notes

  • Deviation variables must be in the same order as self.deviation_symbols.

  • Gap variables must be in the same order as self.gap_symbols.

  • Default bounds are generated if bounds is not provided or improperly formatted.

embedOptimizationVariable()[source]

Embed an auxiliary optimization variable for feasibility.

This method adds an auxiliary variable, s, to the gap variables. The variable s ensures that a feasible solution can be found, even in cases where the optimization problem would otherwise have no solution. The sign of s indicates whether the parts can be assembled, and the variable can be used in meta-model construction.

Notes

  • The variable s is appended to the list of gap variables (self.gap_symbols).

  • The A_ub_Gap and A_eq_Gap matrices are updated to include the new variable: - A_ub_Gap is augmented with a column of -1. - A_eq_Gap is augmented with a column of zeros.

extractFreeGapAndDeviationVariables()[source]

Extract sets of deviation and gap variables present in compatibility equations.

This method identifies the free variables used in the compatibility equations and verifies that all variables appearing in the interface equations are included.

Returns:

A tuple containing: - deviation_symbols : list of sympy.Symbol

List of deviation variables present in the compatibility equations.

  • gap_symbolslist of sympy.Symbol

    List of gap variables present in the compatibility equations.

Return type:

tuple

Raises:

AssertionError – If any variable in the interface equations is not included in the compatibility equations.

Notes

  • Deviation and gap variables are extracted separately from both compatibility and interface equations.

  • This ensures consistency between the two sets of equations.

generateConstraintMatrices(rnd=9)[source]

Decompose equations into matrix representations for compatibility and interface constraints.

This method converts the equations into matrix forms suitable for linear programming: - Compatibility equations (equality constraints) are represented as:

A_eq_Def * X + A_eq_Gap * Y + K_eq = 0.

  • Interface equations (inequality constraints) are represented as: A_ub_Def * X + A_ub_Gap * Y + K_ub >= 0.

Parameters:

rnd (int, optional) – Number of decimal places to round the matrix elements (default is 9).

Returns:

A tuple containing the following matrices: - A_eq_Def : numpy.ndarray

Coefficient matrix for deviation variables in compatibility equations.

  • A_eq_Gapnumpy.ndarray

    Coefficient matrix for gap variables in compatibility equations.

  • K_eqnumpy.ndarray

    Constants in compatibility equations.

  • A_ub_Defnumpy.ndarray

    Coefficient matrix for deviation variables in interface equations.

  • A_ub_Gapnumpy.ndarray

    Coefficient matrix for gap variables in interface equations.

  • K_ubnumpy.ndarray

    Constants in interface equations.

Return type:

tuple

Notes

  • The method iterates through each compatibility and interface equation to extract coefficients for deviation and gap variables.

  • Variables not explicitly included in the equations are assigned zero coefficients in the matrices.

get_feature_indices_and_dimensions()[source]

Extract unique feature indices (classes) and their corresponding sizes from deviation symbols.

This method processes the self.deviation_symbols list to identify unique class indices based on the pattern _d_X (where X is the numeric class identifier). It counts the number of variables associated with each class index and returns two lists: - A sorted list of unique class indices. - A list of corresponding sizes, representing the number of variables per class.

Returns:

  • list of int

    Sorted list of unique class indices.

  • list of int

    List of sizes, where each size corresponds to the number of variables for a class index.

Return type:

tuple

Notes

  • Each deviation symbol is assumed to contain the class identifier in the format _d_X.

  • The method uses a regular expression to extract the class identifier and counts occurrences for each class.

validateOptimizationResults(gap_array, deviation_array, rnd=9)[source]

Validate optimization results using original equations.

This method evaluates the original compatibility and interface equations with given values for the gap and deviation variables, returning the computed results for validation.

Parameters:
  • gap_array (numpy.ndarray) – Array of gap variables.

  • deviation_array (numpy.ndarray) – Array of deviation variables.

  • rnd (int, optional) – Number of decimal places to round the results (default is 9).

Returns:

  • List[float]: Results of evaluating the compatibility equations.

  • List[float]: Results of evaluating the interface equations.

Return type:

tuple

Notes

  • The method substitutes the provided gap and deviation values into the original equations.

  • Compatibility results close to zero indicate a valid solution, while larger values suggest potential issues.

  • Interface results show the satisfaction level of inequality constraints.

class otaf.assembly_modeling.TransformationMatrix(index=-1, initial=array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]), final=array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]), name='', matrix=None)[source]

Bases: object

Class representing transformation matrices within the nominal geometry of a part.

Transformation matrices define the transformation between two coordinate systems.

Parameters:
  • index (int, optional) – An index used to differentiate transformation matrices. The same index can be used multiple times (default is -1).

  • initial (np.ndarray, optional) – The initial 4x4 matrix representing the initial coordinate system (default is the identity matrix).

  • final (np.ndarray, optional) – The final 4x4 matrix representing the final coordinate system (default is the identity matrix).

  • name (str, optional) – Name of the transformation matrix for identification (default is an empty string).

  • matrix (Optional[Union[np.ndarray, sympy.MatrixBase]], optional) – The explicit transformation matrix. If provided, it overrides initial and final matrices (default is None).

Raises:

AssertionError – If the provided matrix is not a valid affine transformation matrix.

__repr__()[source]

Generate a string representation of the TransformationMatrix.

Returns:

String representation of the TransformationMatrix instance, including its index and matrix values.

Return type:

str

get_change_of_basis_matrix(initial, final, as_array=False)[source]

Calculate the change of basis matrix between two coordinate systems.

The change of basis matrix is computed as the relative transformation from the initial coordinate system to the final coordinate system.

Parameters:
  • initial (np.ndarray) – The initial 4x4 matrix representing the initial coordinate system.

  • final (np.ndarray) – The final 4x4 matrix representing the final coordinate system.

  • as_array (bool, optional) – If True, returns the matrix as a NumPy array; otherwise, returns a sympy.Matrix (default is False).

Returns:

The change of basis matrix between the initial and final coordinate systems.

Return type:

Union[sympy.MatrixBase, np.ndarray]

get_inverse()[source]

Generate the inverse of the current TransformationMatrix.

The inverse transformation matrix swaps the initial and final coordinate systems, or directly computes the inverse of the provided matrix.

Returns:

A new instance of TransformationMatrix representing the inverse transformation.

Return type:

TransformationMatrix

get_matrix()[source]

Retrieve the transformation matrix.

If the transformation matrix was explicitly provided during initialization, it is returned. Otherwise, it is computed as the change of basis matrix between the initial and final coordinate systems.

Returns:

The transformation matrix as a symbolic sympy.Matrix.

Return type:

sympy.MatrixBase

get_matrix_inverse()[source]

Retrieve the inverse of the transformation matrix.

If the transformation matrix was explicitly provided during initialization, its inverse is computed. Otherwise, the inverse is calculated as the change of basis matrix between the final and initial coordinate systems.

Returns:

The inverse transformation matrix as a symbolic sympy.Matrix.

Return type:

sympy.MatrixBase