otaf package

Subpackages

Module contents

class otaf.AssemblyDataProcessor(system_data=None)

Bases: object

Manage and validate mechanical system data for assemblies.

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 (the default is None).

system_data

The validated and potentially augmented system data.

Type:

dict

compatibility_loops_expanded

Placeholder for compatibility loop expansions, initialized as None.

Type:

dict or None

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

Return type:

None

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

Add surface points to a specified part and surface.

Ensures uniqueness and validates the input point dictionary.

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) – 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 (the default is False).

Raises:
Return type:

None

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 full representation of compatibility loops.

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

Return type:

None

generate_functional_cylinders()[source]

Generate open cylinders for 3D cylindrical features.

Return type:

list

generate_functional_lines(radius=0.05)[source]

Generate cylinders representing 2D lines for planar features in a 2D system.

Parameters:

radius (float)

Return type:

list

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.

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 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_id or surf_id is not found.

get_topological_graph(R_part=15, r_feat=2, d_feat=1.5, margin=1.5, part_spacing=45, seed=42)[source]
Parameters:
  • R_part (float)

  • r_feat (float)

  • d_feat (float)

  • margin (float)

  • part_spacing (float)

  • seed (int)

validate_point_dict(point_dict)[source]

Validate a dictionary of points for compliance with rules.

Checks labeling, formatting, and uniqueness rules.

Parameters:

point_dict (dict) – A dictionary where keys are point labels and values are their corresponding coordinates.

Raises:
Return type:

None

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:
Return type:

None

class otaf.CompatibilityLoopHandling(assemblyDataProcessor)

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_expressions()[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 | I4 | J4]]

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 | I4 | J4])

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 | I4 | J4]

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 | I4 | J4]

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 | I4 | J4

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 TransformationMatrix, DeviationMatrix, 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:

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 | I4 | J4

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 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[GapMatrix, 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 | I4 | J4]

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 TransformationMatrix, DeviationMatrix, 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 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_expressions()[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 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 GapMatrix or TransformationMatrix

Raises:

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

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

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 (the default is -1).

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

  • rotations (str, optional) – Degrees of freedom for rotation (‘x’, ‘y’, ‘z’) (the default is “xyz”).

  • inverse (bool, optional) – Indicates whether the matrix represents deviations from nominal to real (True) or vice versa (False) (the default is False).

  • name (str, optional) – Name of the matrix for identification (the default is “”).

ID

An index used to differentiate variable names.

Type:

int

TYPE

The type identifier, always “D”.

Type:

str

name

Name of the matrix for identification.

Type:

str

inverse

Indicates whether the matrix represents deviations from nominal to real.

Type:

bool

SE3_basis_indices

The SE(3) basis indices matching the active degrees of freedom.

Type:

list of int

variables

The symbolic variables representing the degrees of freedom.

Type:

list of sympy.Symbol

n_variables

The total number of symbolic variables initialized.

Type:

int

__repr__()[source]

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 of 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 of sympy.MatrixBase

get_variables()[source]

Retrieve symbolic variables associated with the 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 of sympy.Symbol

class otaf.FirstOrderMatrixExpansion(matrix_list)

Bases: object

First-order Taylor expansion of a matrix product.

Parameters:

matrix_list (list of objects) – List of matrices (DeviationMatrix, GapMatrix, TransformationMatrix, I4, or J4) to be used in the first-order Taylor expansion.

matrix_list

List of matrices used in the expansion.

Type:

list of objects

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 (the default is 1e-8).

Returns:

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

Return type:

sympy.MatrixBase

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

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 (the default is -1).

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

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

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

  • name (str, optional) – Name of the matrix for identification (the default is “”).

ID

An index used to differentiate variable names.

Type:

int

TYPE

The type identifier, always “G”.

Type:

str

name

Name of the matrix for identification.

Type:

str

inverse

Indicates whether the matrix represents gaps or clearances.

Type:

bool

SE3_basis_indices

The SE(3) basis indices matching the unblocked degrees of freedom.

Type:

list of int

variables

The symbolic variables representing the unblocked degrees of freedom.

Type:

list of sympy.Symbol

n_variables

The total number of symbolic variables initialized.

Type:

int

__repr__()[source]

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 of 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 of sympy.MatrixBase

get_variables()[source]

Retrieve 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 of sympy.Symbol

class otaf.I4

Bases: object

A 4x4 identity matrix.

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

TYPE

The type identifier, always "I4".

Type:

str

ID

The matrix identifier, always -1.

Type:

int

__repr__()[source]

A string representation of the I4 identity matrix.

Returns:

String representation of the I4 instance.

Return type:

str

get_inverse()[source]

Retrieve the inverse of the I4 instance.

Returns:

The identity matrix instance itself.

Return type:

I4

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.InterfaceLoopHandling(assemblyDataProcessor, compatibility_loop_handling, circle_resolution=8)

Bases: object

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

  • Dict[str, Dict[str, Dict[str, Set[str]]]] (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_expressions()[source]
class otaf.J4

Bases: object

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.

TYPE

The type identifier, always "J4".

Type:

str

ID

The matrix identifier, always -1.

Type:

int

__repr__()[source]

A string representation of the J4 rotation matrix.

Returns:

String representation of the J4 instance.

Return type:

str

get_inverse()[source]

Retrieve the inverse of the J4 instance.

Returns:

The rotation matrix instance itself.

Return type:

J4

get_matrix()[source]

Generate a 4x4 rotation matrix for a 180° z-axis rotation.

The matrix negates the x-axis and y-axis, while the z-axis and the translation components remain unchanged.

Returns:

A symbolic representation of a 4x4 rotation matrix for a 180-degree 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-degree 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-degree z-axis rotation.

Return type:

sympy.MatrixBase

class otaf.SystemOfConstraintsAssemblyModel(compatibility_eqs=None, interface_eqs=None, matrices=None, verbose=0)

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.

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

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

  • matrices (tuple of numpy.ndarray, optional) – Pre-computed constraint matrices unpacked as a sequence of six arrays (A_eq_Def, A_eq_Gap, K_eq, A_ub_Def, A_ub_Gap, K_ub).

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

deviation_symbols

List of deviation variables.

Type:

list of sympy.Symbol

gap_symbols

List of gap variables.

Type:

list of sympy.Symbol

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

verbose

Verbosity level for logging.

Type:

int

compatibility_eqs

Stored compatibility equations.

Type:

list of sympy.Expr or None

interface_eqs

Stored interface equations.

Type:

list of sympy.Expr or None

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

Generate input matrices and bounds for 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) – Array of shape (nDOE, nD) representing deviation variables.

  • bounds (numpy.ndarray, optional) – Bounds for gap variables (the default is automatically determined).

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

Returns:

  • C (numpy.ndarray) – Coefficients of the linear objective function.

  • A_ub (numpy.ndarray) – Matrix representing inequality constraints.

  • B_ub (numpy.ndarray) – Right-hand side of inequality constraints.

  • A_eq (numpy.ndarray) – Matrix representing equality constraints.

  • B_eq (numpy.ndarray) – Right-hand side of equality constraints.

  • bounds (numpy.ndarray) – Variable bounds.

Raises:

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

Return type:

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

Notes

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

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

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

__repr__()[source]

Compact textual summary with matrices for the LP.

Return type:

str

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

Return type:

None

extractFreeGapAndDeviationVariables()[source]

Extract sets of deviation and gap variables from 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:

  • deviation_symbols (list of sympy.Symbol) – List of deviation variables present in the compatibility equations.

  • gap_symbols (list of sympy.Symbol) – List of gap variables present in the compatibility equations.

Raises:

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

Return type:

tuple[list[Symbol], list[Symbol]]

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 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 (the default is 9).

Returns:

  • A_eq_Def (numpy.ndarray) – Coefficient matrix for deviation variables in compatibility equations.

  • A_eq_Gap (numpy.ndarray) – Coefficient matrix for gap variables in compatibility equations.

  • K_eq (numpy.ndarray) – Constants in compatibility equations.

  • A_ub_Def (numpy.ndarray) – Coefficient matrix for deviation variables in interface equations.

  • A_ub_Gap (numpy.ndarray) – Coefficient matrix for gap variables in interface equations.

  • K_ub (numpy.ndarray) – Constants in interface equations.

Return type:

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

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 and sizes from deviation symbols.

This method processes the 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.

Returns:

  • unique_classes (list of int) – Sorted list of unique class indices.

  • sizes (list of int) – List of sizes, where each size corresponds to the number of variables for a class index.

Return type:

tuple[list[int], list[int]]

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.

test_zero_deviation_feasibility()[source]

Test if the assembly is feasible with zero deviations.

Uses scipy.optimize.milp to solve the system where the deviations equal 0.

Returns:

A dictionary containing the success status, the status code, and the resulting gap_values.

Return type:

dict

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 (the default is 9).

Returns:

  • compatibility_result (list of float) – Results of evaluating the compatibility equations.

  • interface_results (list of float) – Results of evaluating the interface equations.

Return type:

tuple[list[float], list[float]]

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

Bases: object

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 (the default is -1).

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

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

  • name (str, optional) – Name of the transformation matrix for identification (the default is “”).

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

ID

An index used to differentiate transformation matrices.

Type:

int

TYPE

The type identifier, always “T”.

Type:

str

name

Name of the transformation matrix for identification.

Type:

str

__repr__()[source]

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 change of basis matrix between 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 (the default is False).

Returns:

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

Return type:

sympy.MatrixBase or 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