From 9ba4b3f9a0f104beaef05de4cc2009b951d85bc7 Mon Sep 17 00:00:00 2001 From: jguarato Date: Thu, 22 Aug 2024 08:55:34 -0300 Subject: [PATCH 1/5] Change the initial arguments array to the object's dict keys --- ross/bearing_seal_element.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ross/bearing_seal_element.py b/ross/bearing_seal_element.py index 2cdb663d..d8fbd99e 100644 --- a/ross/bearing_seal_element.py +++ b/ross/bearing_seal_element.py @@ -410,10 +410,11 @@ def __eq__(self, other): "frequency", ] if isinstance(other, self.__class__): - init_args = [] - for arg in signature(self.__init__).parameters: - if arg not in ["kwargs"]: - init_args.append(arg) + init_args = list( + set(signature(self.__init__).parameters).intersection( + self.__dict__.keys() + ) + ) init_args_comparison = [] for arg in init_args: From 2c39dae122a44007d4a51d87b1b79ffac5d06e8f Mon Sep 17 00:00:00 2001 From: jguarato Date: Thu, 22 Aug 2024 11:50:40 -0300 Subject: [PATCH 2/5] Remove duplicate comparison --- ross/bearing_seal_element.py | 101 ++--------------------------------- 1 file changed, 3 insertions(+), 98 deletions(-) diff --git a/ross/bearing_seal_element.py b/ross/bearing_seal_element.py index d8fbd99e..d3eb4dd8 100644 --- a/ross/bearing_seal_element.py +++ b/ross/bearing_seal_element.py @@ -394,39 +394,13 @@ def __eq__(self, other): >>> bearing1 == bearing2 True """ - compared_attributes = [ - "kxx", - "kyy", - "kxy", - "kyx", - "cxx", - "cyy", - "cxy", - "cyx", - "mxx", - "myy", - "mxy", - "myx", - "frequency", - ] if isinstance(other, self.__class__): - init_args = list( + compared_attributes = list( set(signature(self.__init__).parameters).intersection( self.__dict__.keys() ) ) - init_args_comparison = [] - for arg in init_args: - comparison = getattr(self, arg) == getattr(other, arg) - try: - comparison = all(comparison) - except TypeError: - pass - - init_args_comparison.append(comparison) - - init_args_comparison = all(init_args_comparison) attributes_comparison = all( ( ( @@ -436,7 +410,8 @@ def __eq__(self, other): ) ) - return init_args_comparison and attributes_comparison + return attributes_comparison + return False def __hash__(self): @@ -1911,76 +1886,6 @@ def __repr__(self): f" frequency={self.frequency}, tag={self.tag!r})" ) - def __eq__(self, other): - """Equality method for comparasions. - - Parameters - ---------- - other : object - The second object to be compared with. - - Returns - ------- - bool - True if the comparison is true; False otherwise. - - Examples - -------- - >>> bearing1 = bearing_example() - >>> bearing2 = bearing_example() - >>> bearing1 == bearing2 - True - """ - compared_attributes = [ - "kxx", - "kyy", - "kxy", - "kyx", - "kzz", - "cxx", - "cyy", - "cxy", - "cyx", - "czz", - "mxx", - "myy", - "mxy", - "myx", - "mzz", - "frequency", - ] - if isinstance(other, self.__class__): - init_args = [] - for arg in signature(self.__init__).parameters: - if arg not in ["kwargs"]: - init_args.append(arg) - - init_args_comparison = [] - for arg in init_args: - comparison = getattr(self, arg) == getattr(other, arg) - try: - comparison = all(comparison) - except TypeError: - pass - - init_args_comparison.append(comparison) - - init_args_comparison = all(init_args_comparison) - attributes_comparison = all( - ( - ( - np.array(getattr(self, attr)) == np.array(getattr(other, attr)) - ).all() - for attr in compared_attributes - ) - ) - - return init_args_comparison and attributes_comparison - return False - - def __hash__(self): - return hash(self.tag) - def dof_mapping(self): """Degrees of freedom mapping. From ce870bf1d2a68306779a4af29c43e0c23c008414 Mon Sep 17 00:00:00 2001 From: jguarato Date: Fri, 23 Aug 2024 15:02:24 -0300 Subject: [PATCH 3/5] Fix error related to attributes with different size --- ross/bearing_seal_element.py | 38 +++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/ross/bearing_seal_element.py b/ross/bearing_seal_element.py index d3eb4dd8..75f14326 100644 --- a/ross/bearing_seal_element.py +++ b/ross/bearing_seal_element.py @@ -394,25 +394,35 @@ def __eq__(self, other): >>> bearing1 == bearing2 True """ + attributes_comparison = False + if isinstance(other, self.__class__): - compared_attributes = list( - set(signature(self.__init__).parameters).intersection( - self.__dict__.keys() - ) + init_args = set(signature(self.__init__).parameters).intersection( + self.__dict__.keys() ) - attributes_comparison = all( - ( - ( - np.array(getattr(self, attr)) == np.array(getattr(other, attr)) - ).all() - for attr in compared_attributes - ) - ) + coefficients = { + attr.replace("_interpolated", "") + for attr in self.__dict__.keys() + if "_interpolated" in attr + } + + compared_attributes = list(coefficients.union(init_args)) + compared_attributes.sort() + + for attr in compared_attributes: + self_attr = np.array(getattr(self, attr)) + other_attr = np.array(getattr(other, attr)) + + if self_attr.shape == other_attr.shape: + attributes_comparison = (self_attr == other_attr).all() + else: + attributes_comparison = False - return attributes_comparison + if not attributes_comparison: + return attributes_comparison - return False + return attributes_comparison def __hash__(self): return hash(self.tag) From 64dd1cfc36357d9d8d6c3c39ee3394181a4dda60 Mon Sep 17 00:00:00 2001 From: jguarato Date: Fri, 23 Aug 2024 15:05:00 -0300 Subject: [PATCH 4/5] Fix save method for specific bearing types (e.g. BallBearing). --- ross/bearing_seal_element.py | 68 +++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/ross/bearing_seal_element.py b/ross/bearing_seal_element.py index 75f14326..f1a05eb5 100644 --- a/ross/bearing_seal_element.py +++ b/ross/bearing_seal_element.py @@ -434,25 +434,20 @@ def save(self, file): data = {} # save initialization args and coefficients - args = list(signature(self.__init__).parameters) - args += [ - "kxx", - "kyy", - "kxy", - "kyx", - "cxx", - "cyy", - "cxy", - "cyx", - "mxx", - "myy", - "mxy", - "myx", - ] - brg_data = {} - for arg in args: - if arg not in ["kwargs"]: - brg_data[arg] = self.__dict__[arg] + init_args = set(signature(self.__init__).parameters).intersection( + self.__dict__.keys() + ) + + coefficients = { + attr.replace("_interpolated", "") + for attr in self.__dict__.keys() + if "_interpolated" in attr + } + + args = list(coefficients.union(init_args)) + args.sort() + + brg_data = {arg: self.__dict__[arg] for arg in args} # change np.array to lists so that we can save in .toml as list(floats) for k, v in brg_data.items(): @@ -467,7 +462,18 @@ def save(self, file): except (TypeError, AttributeError): pass - data[f"{self.__class__.__name__}_{self.tag}"] = brg_data + diff_args = set(signature(self.__init__).parameters).difference( + self.__dict__.keys() + ) + diff_args.discard("kwargs") + + class_name = ( + self.__class__.__name__ + if not diff_args + else self.__class__.__bases__[0].__name__ + ) + + data[f"{class_name}_{self.tag}"] = brg_data with open(file, "w") as f: toml.dump(data, f) @@ -929,6 +935,9 @@ class BearingFluidFlow(BearingElement): scale_factor : float, optional The scale factor is used to scale the bearing drawing. Default is 1. + color : str, optional + A color to be used when the element is represented. + Default is '#355d7a'. Returns ------- @@ -1187,6 +1196,9 @@ class BallBearingElement(BearingElement): scale_factor : float, optional The scale factor is used to scale the bearing drawing. Default is 1. + color : str, optional + A color to be used when the element is represented. + Default is '#355d7a'. References ---------- @@ -1220,6 +1232,7 @@ def __init__( tag=None, n_link=None, scale_factor=1, + color="#355d7a", ): Kb = 13.0e6 kyy = ( @@ -1259,10 +1272,9 @@ def __init__( tag=tag, n_link=n_link, scale_factor=scale_factor, + color=color, ) - self.color = "#77ACA2" - class RollerBearingElement(BearingElement): """A bearing element for roller bearings. @@ -1304,6 +1316,9 @@ class RollerBearingElement(BearingElement): scale_factor : float, optional The scale factor is used to scale the bearing drawing. Default is 1. + color : str, optional + A color to be used when the element is represented. + Default is '#355d7a'. References ---------- @@ -1337,6 +1352,7 @@ def __init__( tag=None, n_link=None, scale_factor=1, + color="#355d7a", ): Kb = 1.0e9 kyy = Kb * n_rollers**0.9 * l_rollers**0.8 * fs**0.1 * (np.cos(alpha)) ** 1.9 @@ -1370,10 +1386,9 @@ def __init__( tag=tag, n_link=n_link, scale_factor=scale_factor, + color=color, ) - self.color = "#77ACA2" - class MagneticBearingElement(BearingElement): """Magnetic bearing. @@ -1414,6 +1429,9 @@ class MagneticBearingElement(BearingElement): scale_factor : float, optional The scale factor is used to scale the bearing drawing. Default is 1. + color : str, optional + A color to be used when the element is represented. + Default is '#355d7a'. ---------- See the following reference for the electromagnetic parameters g0, i0, ag, nw, alpha: @@ -1456,6 +1474,7 @@ def __init__( tag=None, n_link=None, scale_factor=1, + color="#355d7a", **kwargs, ): self.g0 = g0 @@ -1547,6 +1566,7 @@ def __init__( tag=tag, n_link=n_link, scale_factor=scale_factor, + color=color, ) From 9e78cb7d9abae83fc2c4eaaced305011cedd2fdd Mon Sep 17 00:00:00 2001 From: jguarato Date: Mon, 16 Sep 2024 10:46:55 -0300 Subject: [PATCH 5/5] Change scale factor for seal element --- ross/bearing_seal_element.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ross/bearing_seal_element.py b/ross/bearing_seal_element.py index f1a05eb5..458e8f7f 100644 --- a/ross/bearing_seal_element.py +++ b/ross/bearing_seal_element.py @@ -1083,7 +1083,7 @@ class SealElement(BearingElement): Default is None. scale_factor : float, optional The scale factor is used to scale the bearing drawing. - Default is 1. + Default is 0.5. color : str, optional A color to be used when the element is represented. Default is "#77ACA2". @@ -1126,12 +1126,11 @@ def __init__( seal_leakage=None, tag=None, n_link=None, - scale_factor=1.0, + scale_factor=None, color="#77ACA2", **kwargs, ): - # make seals with half the bearing size as a default - seal_scale_factor = scale_factor / 2 + super().__init__( n=n, frequency=frequency, @@ -1149,11 +1148,11 @@ def __init__( myy=myy, tag=tag, n_link=n_link, - scale_factor=seal_scale_factor, color=color, ) - self.seal_leakage = seal_leakage + # make seals with half the bearing size as a default + self.scale_factor = scale_factor if scale_factor else self.scale_factor / 2 class BallBearingElement(BearingElement):