Skip to content

Commit

Permalink
Merge branch 'main' into dev-ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaeltimbo authored Oct 17, 2024
2 parents 0a93f37 + d939735 commit 098868c
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 94 deletions.
54 changes: 48 additions & 6 deletions ross/bearing_seal_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
and 2 element options with 8 or 12 degrees of freedom.
"""

import os
import warnings
from inspect import signature

import numpy as np
import toml
import warnings
from inspect import signature
from numpy.polynomial import Polynomial
from plotly import graph_objects as go
from scipy import interpolate as interpolate
Expand Down Expand Up @@ -984,6 +982,19 @@ def __init__(
scale_factor=1.0,
color="#355d7a",
):
self.nz = nz
self.ntheta = ntheta
self.length = length
self.omega = omega
self.p_in = p_in
self.p_out = p_out
self.radius_rotor = radius_rotor
self.radius_stator = radius_stator
self.visc = visc
self.rho = rho
self.eccentricity = eccentricity
self.load = load

K = np.zeros((4, len(omega)))
C = np.zeros((4, len(omega)))

Expand Down Expand Up @@ -1130,6 +1141,7 @@ def __init__(
color="#77ACA2",
**kwargs,
):
self.seal_leakage = seal_leakage

super().__init__(
n=n,
Expand All @@ -1150,7 +1162,7 @@ def __init__(
n_link=n_link,
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

Expand Down Expand Up @@ -1233,6 +1245,11 @@ def __init__(
scale_factor=1,
color="#355d7a",
):
self.n_balls = n_balls
self.d_balls = d_balls
self.fs = fs
self.alpha = alpha

Kb = 13.0e6
kyy = (
Kb
Expand Down Expand Up @@ -1353,6 +1370,11 @@ def __init__(
scale_factor=1,
color="#355d7a",
):
self.n_rollers = n_rollers
self.l_rollers = l_rollers
self.fs = fs
self.alpha = alpha

Kb = 1.0e9
kyy = Kb * n_rollers**0.9 * l_rollers**0.8 * fs**0.1 * (np.cos(alpha)) ** 1.9

Expand Down Expand Up @@ -1602,6 +1624,15 @@ class CylindricalBearing(BearingElement):
Bore assembly radial clearance (m).
oil_viscosity : float, pint.Quantity
Oil viscosity (Pa.s).
tag : str, optional
A tag to name the element
Default is None.
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
-------
Expand Down Expand Up @@ -1640,6 +1671,9 @@ def __init__(
journal_diameter=None,
radial_clearance=None,
oil_viscosity=None,
tag=None,
scale_factor=1,
color="#355d7a",
**kwargs,
):
self.n = n
Expand Down Expand Up @@ -1729,7 +1763,15 @@ def __init__(
weight / (radial_clearance * spd) * term
)

super().__init__(self.n, frequency=self.speed, **coefficients_dict, **kwargs)
super().__init__(
n,
frequency=self.speed,
tag=tag,
scale_factor=scale_factor,
color=color,
**coefficients_dict,
**kwargs,
)


class BearingElement6DoF(BearingElement):
Expand Down
10 changes: 6 additions & 4 deletions ross/element.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import inspect
from inspect import signature
from abc import ABC, abstractmethod
from collections import namedtuple
from pathlib import Path
Expand Down Expand Up @@ -42,8 +42,7 @@ def save(self, file):
>>> disk.save(file)
"""
# get __init__ arguments
signature = inspect.signature(self.__init__)
args_list = list(signature.parameters)
args_list = list(signature(self.__init__).parameters)
args = {arg: getattr(self, arg) for arg in args_list}
try:
data = toml.load(file)
Expand Down Expand Up @@ -85,7 +84,10 @@ def read_toml_data(cls, data):
>>> bearing1 == bearing1_loaded
True
"""
return cls(**data)
args_list = set(signature(cls.__init__).parameters).intersection(data.keys())
required_data = {arg: data[arg] for arg in args_list}

return cls(**required_data)

@classmethod
def load(cls, file):
Expand Down
53 changes: 8 additions & 45 deletions ross/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def __init__(self, *, node, node_pos, ru_e, rv_e):
# kappa encodes the relation between the axis and the precession.
minor = np.sqrt(lam.min())
major = np.sqrt(lam.max())
kappa = minor / major

diff = nv - nu

# we need to evaluate if 0 < nv - nu < pi.
Expand All @@ -289,10 +289,11 @@ def __init__(self, *, node, node_pos, ru_e, rv_e):
# if nv = nu or nv = nu + pi then the response is a straight line.
if diff == 0 or diff == np.pi:
kappa = 0

# if 0 < nv - nu < pi, then a backward rotating mode exists.
elif 0 < diff < np.pi:
kappa *= -1
kappa = -minor / major
else:
kappa = minor / major

self.minor_axis = np.real(minor)
self.major_axis = np.real(major)
Expand Down Expand Up @@ -892,7 +893,6 @@ def __init__(
self.number_dof = number_dof
self.modes = self.evectors[: self.ndof]
self.shapes = []
kappa_modes = []
for mode in range(len(self.wn)):
self.shapes.append(
Shape(
Expand All @@ -904,42 +904,6 @@ def __init__(
number_dof=self.number_dof,
)
)
kappa_color = []
kappa_mode = self.kappa_mode(mode)
for kappa in kappa_mode:
kappa_color.append("blue" if kappa > 0 else "red")
kappa_modes.append(kappa_color)
self.kappa_modes = kappa_modes

@staticmethod
def whirl(kappa_mode):
"""Evaluate the whirl of a mode.
Parameters
----------
kappa_mode : list
A list with the value of kappa for each node related
to the mode/natural frequency of interest.
Returns
-------
whirldir : str
A string indicating the direction of precession related to the
kappa_mode.
Example
-------
>>> kappa_mode = [-5.06e-13, -3.09e-13, -2.91e-13, 0.011, -4.03e-13, -2.72e-13, -2.72e-13]
>>> ModalResults.whirl(kappa_mode)
'Forward'
"""
if all(kappa >= -1e-3 for kappa in kappa_mode):
whirldir = "Forward"
elif all(kappa <= 1e-3 for kappa in kappa_mode):
whirldir = "Backward"
else:
whirldir = "Mixed"
return whirldir

@staticmethod
@np.vectorize
Expand Down Expand Up @@ -1048,11 +1012,10 @@ def whirl_direction(self):
-------
whirl_w : array
An array of strings indicating the direction of precession related
to the kappa_mode. Backward, Mixed or Forward depending on values
of kappa_mode.
to the mode shape. Backward, Mixed or Forward.
"""
# whirl direction/values are methods because they are expensive.
whirl_w = [self.whirl(self.kappa_mode(wd)) for wd in range(len(self.wd))]
whirl_w = [self.shapes[wd].whirl for wd in range(len(self.wd))]

return np.array(whirl_w)

Expand Down Expand Up @@ -1211,7 +1174,7 @@ def plot_mode_3d(
f"{title}<br>"
f"Mode {mode} | "
f"{frequency['speed']} {frequency_units} | "
f"whirl: {self.whirl_direction()[mode]} | "
f"whirl: {shape.whirl} | "
f"{frequency[frequency_type]} {frequency_units} | "
f"{damping_name} = {damping_value:.2f}"
),
Expand Down Expand Up @@ -1306,7 +1269,7 @@ def plot_mode_2d(
f"{title}<br>"
f"Mode {mode} | "
f"{frequency['speed']} {frequency_units} | "
f"whirl: {self.whirl_direction()[mode]} | "
f"whirl: {shape.whirl} | "
f"{frequency[frequency_type]} {frequency_units} | "
f"{damping_name} = {damping_value:.2f}"
),
Expand Down
Loading

0 comments on commit 098868c

Please sign in to comment.