nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: ross-rotordynamics/ross
Pull request #155 (2019-06-07 13:48:20)

Fix equality for bearing element
Fixes the equality for bearing element, allowing the comparison with
objects from different types, e.g. bearing == 1 will return False,
before an AttributeError was raised since int doesn't have .__dict__.
This also removes pytest as a dependence for the user.


Patch:
diff --git a/ross/bearing_seal_element.py b/ross/bearing_seal_element.py
index 747c17d7..9c411d0e 100644
--- a/ross/bearing_seal_element.py
+++ b/ross/bearing_seal_element.py
@@ -199,26 +199,26 @@ class BearingElement(Element):
         )
 
     def __eq__(self, other):
-        try:
-            if pytest.approx(self.__dict__) == other.__dict__:
-                return True
-            else:
-                return False
-
-        except TypeError:
-
-            self_dict = self.__dict__
-            other_dict = other.__dict__
-
-            self_dict["w"] = 0
-            other_dict["w"] = 0
-
-            if (
-                self.__dict__["w"] == other.__dict__["w"]
-            ).__bool__() and self_dict == other_dict:
-                return True
-            else:
-                return False
+        compared_attributes = [
+            "kxx",
+            "kyy",
+            "kxy",
+            "kyx",
+            "cxx",
+            "cyy",
+            "cxy",
+            "cyx",
+            "w",
+        ]
+        if isinstance(other, self.__class__):
+            return all(
+                (
+                    np.array(getattr(self, attr)).all()
+                    == np.array(getattr(other, attr)).all()
+                    for attr in compared_attributes
+                )
+            )
+        return False
 
     def save(self, file_name):
         data = self.load_data(file_name)


Test patch:
diff --git a/ross/tests/test_bearing_seal_element.py b/ross/tests/test_bearing_seal_element.py
index 5d9767b2..4d75891c 100644
--- a/ross/tests/test_bearing_seal_element.py
+++ b/ross/tests/test_bearing_seal_element.py
@@ -132,3 +132,10 @@ def bearing_constant():
 def test_bearing_constant(bearing_constant):
     assert_allclose(bearing_constant.kxx.interpolated(314.2), 8e7, rtol=1e5)
     assert_allclose(bearing_constant.cxx.interpolated(300.9), 0, rtol=1e5)
+
+
+def test_equality(bearing0, bearing1, bearing_constant):
+    assert bearing0 == bearing0
+    assert bearing0 == bearing1
+    assert not bearing0 == bearing_constant
+    assert not bearing0 == 1
Repository: ross-rotordynamics/ross
Pull request #118 (2019-05-17 19:12:01)

Fix eccentricity ratio function
The eccentricity ratio function was being calculated wrongly, using the sommerfeld number instead of the modified one, as it was supposed to use.


Patch:
diff --git a/ross/fluid_flow/fluid_flow.py b/ross/fluid_flow/fluid_flow.py
index d2279c2a..8cc4c844 100644
--- a/ross/fluid_flow/fluid_flow.py
+++ b/ross/fluid_flow/fluid_flow.py
@@ -284,6 +284,20 @@ class PressureMatrix:
                  / (8*(self.radial_clearance**2)*((1 - self.eccentricity_ratio**2)**2))) \
             * np.sqrt((16/np.pi - 1)*self.eccentricity_ratio + 1)
 
+    def modified_sommerfeld_number(self, f):
+        """Return the modified sommerfeld number.
+        Parameters
+        ----------
+        f: float
+            Load applied to the rotor.
+        Returns
+        -------
+        float
+            The modified sommerfeld number.
+        """
+        return (self.radius_stator*2*self.omega*self.visc*(self.length**3)) / \
+               (8*f*(self.radial_clearance**2))
+
     def sommerfeld_number(self, f):
         """Return the sommerfeld number.
         Parameters
@@ -295,8 +309,7 @@ class PressureMatrix:
         float
             The sommerfeld number.
         """
-        modified_s = (self.radius_stator*2*self.omega*self.visc*(self.length**3)) / \
-                     (8*f*(self.radial_clearance**2))
+        modified_s = self.modified_sommerfeld_number(f)
         return (modified_s/np.pi)*(self.radius_stator*2/self.length)**2
 
     def calculate_eccentricity_ratio(self, f):
@@ -310,7 +323,7 @@ class PressureMatrix:
         float
             The eccentricity ratio.
         """
-        s = self.sommerfeld_number(f)
+        s = self.modified_sommerfeld_number(f)
         coefficients = [1, -4, (6 - (s**2)*(16 - np.pi**2)), -(4 + (np.pi**2)*(s**2)), 1]
         roots = np.roots(coefficients)
         for i in range(0, len(roots)):


Test patch:
diff --git a/ross/tests/test_fluid_flow.py b/ross/tests/test_fluid_flow.py
index fddbfdaf..674c57dc 100644
--- a/ross/tests/test_fluid_flow.py
+++ b/ross/tests/test_fluid_flow.py
@@ -23,6 +23,6 @@ def test_sommerfeld_number():
     bearing = flow.PressureMatrix(nz, ntheta, nradius, length, omega, p_in,
                                   p_out, radius_rotor, radius_stator,
                                   eccentricity, visc, rho)
-    s = bearing.sommerfeld_number(525)
-    assert math.isclose(s, 3.571, rel_tol=0.001)
+    e = bearing.calculate_eccentricity_ratio(525)
+    assert math.isclose(e, 0.2663, rel_tol=0.001)