Skip to content

Commit

Permalink
Merge pull request #1054 from jguarato/fix-nlinks-6dof
Browse files Browse the repository at this point in the history
Fix n_links for the 6 dof model
  • Loading branch information
raphaeltimbo authored May 16, 2024
2 parents 21e4d6e + a553b87 commit b05c643
Show file tree
Hide file tree
Showing 5 changed files with 369 additions and 27 deletions.
18 changes: 18 additions & 0 deletions ross/bearing_seal_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,12 @@ def M(self, frequency):

M = np.array([[mxx, mxy, 0], [myx, myy, 0], [0, 0, mzz]])

if self.n_link is not None:
# fmt: off
M = np.vstack((np.hstack([M, -M]),
np.hstack([-M, M])))
# fmt: on

return M

def K(self, frequency):
Expand Down Expand Up @@ -2161,6 +2167,12 @@ def K(self, frequency):

K = np.array([[kxx, kxy, 0], [kyx, kyy, 0], [0, 0, kzz]])

if self.n_link is not None:
# fmt: off
K = np.vstack((np.hstack([K, -K]),
np.hstack([-K, K])))
# fmt: on

return K

def C(self, frequency):
Expand Down Expand Up @@ -2194,6 +2206,12 @@ def C(self, frequency):

C = np.array([[cxx, cxy, 0], [cyx, cyy, 0], [0, 0, czz]])

if self.n_link is not None:
# fmt: off
C = np.vstack((np.hstack([C, -C]),
np.hstack([-C, C])))
# fmt: on

return C


Expand Down
8 changes: 4 additions & 4 deletions ross/disk_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,17 +667,17 @@ def Kdt(self):
[0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0.33, 0. , 0. ]])
[0. , 0. , 0. , 0.33, 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. ]])
"""
Ip = self.Ip
# fmt: off
Kdt = np.array([[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, Ip, 0, 0]])
[0, 0, 0, Ip, 0, 0],
[0, 0, 0, 0, 0, 0]])
# fmt: on
return Kdt

Expand Down
268 changes: 264 additions & 4 deletions ross/point_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ross.element import Element
from ross.units import check_units

__all__ = ["PointMass"]
__all__ = ["PointMass", "PointMass6DoF"]


class PointMass(Element):
Expand Down Expand Up @@ -66,6 +66,7 @@ def __init__(self, n=None, m=None, mx=None, my=None, tag=None, color="DarkSalmon
self.tag = tag
self.dof_global_index = None
self.color = color
self.size = 2

def __hash__(self):
return hash(self.tag)
Expand Down Expand Up @@ -180,7 +181,7 @@ def C(self):
array([[0., 0.],
[0., 0.]])
"""
C = np.zeros((2, 2))
C = np.zeros((self.size, self.size))
return C

def K(self):
Expand All @@ -201,7 +202,7 @@ def K(self):
array([[0., 0.],
[0., 0.]])
"""
K = np.zeros((2, 2))
K = np.zeros((self.size, self.size))
return K

def G(self):
Expand All @@ -222,7 +223,7 @@ def G(self):
array([[0., 0.],
[0., 0.]])
"""
G = np.zeros((2, 2))
G = np.zeros((self.size, self.size))
return G

def dof_mapping(self):
Expand Down Expand Up @@ -324,6 +325,240 @@ def _patch(self, position, fig):
return fig


class PointMass6DoF(PointMass):
"""A point mass element.
This class will create a point mass element.
This element can be used to link other elements in the analysis.
The mass provided to the element can be different on the x, y and z directions
(e.g. different support inertia for x, y and z directions).
Parameters
----------
n: int
Node which the bearing will be located in.
m: float, pint.Quantity, optional
Mass for the element.
mx: float, pint.Quantity, optional
Mass for the element on the x direction.
my: float, pint.Quantity, optional
Mass for the element on the y direction.
mz: float, pint.Quantity, optional
Mass for the element on the z direction.
tag: str
A tag to name the element
color : str, optional
A color to be used when the element is represented.
Default is "DarkSalmon".
Examples
--------
>>> p0 = PointMass6DoF(n=0, m=2)
>>> p0.M()
array([[2., 0., 0.],
[0., 2., 0.],
[0., 0., 2.]])
>>> p1 = PointMass6DoF(n=0, mx=2, my=3, mz=4)
>>> p1.M()
array([[2., 0., 0.],
[0., 3., 0.],
[0., 0., 4.]])
"""

@check_units
def __init__(
self, n=None, m=None, mx=None, my=None, mz=None, tag=None, color="DarkSalmon"
):
self.n = n

if mx is None and my is None:
mx = float(m)
my = float(m)
mz = float(m)

self.mx = float(mx)
self.my = float(my)
self.mz = float(mz)
self.tag = tag
self.dof_global_index = None
self.color = color
self.size = 3

def __repr__(self):
"""Return a string representation of a point mass element.
Returns
-------
A string representation of a point mass element object.
Examples
--------
>>> point_mass = point_mass_example_6dof()
>>> point_mass
PointMass6DoF(n=0, mx=1.0, my=2.0, mz=3.0, tag='pointmass')
"""
return (
f"{self.__class__.__name__}"
f"(n={self.n}, mx={self.mx:{0}.{5}},"
f" my={self.my:{0}.{5}},"
f" mz={self.mz:{0}.{5}},"
f" tag={self.tag!r})"
)

def __str__(self):
"""Convert object into string.
Returns
-------
The object's parameters translated to strings
Example
-------
>>> print(PointMass6DoF(n=0, mx=2.5, my=3.25, mz=4.15, tag="PointMass"))
Tag: PointMass
Node: 0
Mass X dir. (kg): 2.5
Mass Y dir. (kg): 3.25
Mass Z dir. (kg): 4.15
"""
return (
f"Tag: {self.tag}"
f"\nNode: {self.n}"
f"\nMass X dir. (kg): {self.mx:{2}.{5}}"
f"\nMass Y dir. (kg): {self.my:{2}.{5}}"
f"\nMass Z dir. (kg): {self.mz:{2}.{5}}"
)

def M(self):
"""Mass matrix for an instance of a point mass element.
This method will return the mass matrix for an instance of a point mass element.
Returns
-------
M : np.ndarray
A matrix of floats containing the values of the mass matrix.
Examples
--------
>>> p1 = PointMass6DoF(n=0, mx=2, my=3, mz=4)
>>> p1.M()
array([[2., 0., 0.],
[0., 3., 0.],
[0., 0., 4.]])
"""
mx = self.mx
my = self.my
mz = self.mz
# fmt: off
M = np.array([[mx, 0, 0],
[ 0, my, 0],
[ 0, 0, mz]])
# fmt: on

return M

def dof_mapping(self):
"""Degrees of freedom mapping.
Returns a dictionary with a mapping between degree of freedom and its index.
Returns
-------
dof_mapping : dict
A dictionary containing the degrees of freedom and their indexes.
Examples
--------
The numbering of the degrees of freedom for each node.
Being the following their ordering for a node:
x_0 - horizontal translation
y_0 - vertical translation
z_0 - axial translation
>>> p1 = PointMass6DoF(n=0, mx=2, my=3, mz=4)
>>> p1.dof_mapping()
{'x_0': 0, 'y_0': 1, 'z_0': 2}
"""
return dict(x_0=0, y_0=1, z_0=2)

def _patch(self, position, fig):
"""Point mass element patch.
Patch that will be used to draw the point mass element using Plotly library.
Parameters
----------
position : float
Position in which the patch will be drawn.
fig : plotly.graph_objects.Figure
The figure object which traces are added on.
Returns
-------
fig : plotly.graph_objects.Figure
The figure object which traces are added on.
"""
zpos, ypos = position
radius = ypos / 12

customdata = [self.n, self.mx, self.my, self.mz]
hovertemplate = (
f"PointMass Node: {customdata[0]}<br>"
+ f"Mass (X): {customdata[1]:.3f}<br>"
+ f"Mass (Y): {customdata[2]:.3f}<br>"
+ f"Mass (Z): {customdata[2]:.3f}<br>"
)

fig.add_trace(
go.Scatter(
x=[zpos, zpos],
y=[ypos, -ypos],
customdata=[customdata] * 2,
text=hovertemplate,
mode="markers",
marker=dict(size=5.0, color=self.color),
showlegend=False,
name=self.tag,
legendgroup="pointmass",
hoverinfo="text",
hovertemplate=hovertemplate,
hoverlabel=dict(bgcolor=self.color),
)
)

fig.add_shape(
dict(
type="circle",
xref="x",
yref="y",
x0=zpos - radius,
y0=ypos - radius,
x1=zpos + radius,
y1=ypos + radius,
fillcolor=self.color,
line_color="black",
)
)
fig.add_shape(
dict(
type="circle",
xref="x",
yref="y",
x0=zpos - radius,
y0=-ypos - radius,
x1=zpos + radius,
y1=-ypos + radius,
fillcolor=self.color,
line_color="black",
)
)

return fig


def point_mass_example():
"""Create an example of point mass element.
Expand All @@ -346,3 +581,28 @@ def point_mass_example():
my = 2.0
point_mass = PointMass(n=n, mx=mx, my=my, tag="pointmass")
return point_mass


def point_mass_example_6dof():
"""Create an example of point mass element for the 6 dof model.
This function returns an instance of a simple point mass. The purpose is to make
available a simple model so that doctest can be written using it.
Returns
-------
point_mass : ross.PointMass
An instance of a point mass object.
Examples
--------
>>> pointmass = point_mass_example_6dof()
>>> pointmass.mz
3.0
"""
n = 0
mx = 1.0
my = 2.0
mz = 3.0
point_mass = PointMass6DoF(n=n, mx=mx, my=my, mz=mz, tag="pointmass")
return point_mass
Loading

0 comments on commit b05c643

Please sign in to comment.