Skip to content

Commit

Permalink
refactor system for freeplay
Browse files Browse the repository at this point in the history
  • Loading branch information
samayala22 committed Jan 25, 2025
1 parent 4ba8df2 commit b07ddab
Show file tree
Hide file tree
Showing 3 changed files with 945 additions and 25 deletions.
3 changes: 2 additions & 1 deletion data/2dof.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,10 @@ def alpha_linear(alpha):

def create_monolithic_system(y0: np.ndarray, ndv: NDVars, M: callable):
def monolithic_system(t, y: np.ndarray):
# Yung p212
"""
system unknowns:
[h, a, hd, ad, x1, x2]
q = [h, a, hd, ad, x1, x2]
"""
M1 = np.zeros((6,6))
M2 = np.zeros((6,6))
Expand Down
226 changes: 202 additions & 24 deletions data/3dof_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ class Vars:
a: float # Dimensionless distance between mid-chord and EA (-0.5)
b: float # Semi-chord (0.127 m)
c: float # Dimensionless distance between flap hinge and mid-chord (0.5); Plunge structural damping coefficient per unit span (1.7628 kg/ms)
C_h: float # Plunge structural damping coefficient per unit span (1.7628 kg/ms)
C_alpha: float # Pitch structural damping coefficient per unit span (0.0231 kgm/s)
C_beta: float # Flap structural damping coefficient per unit span (0.0008 kgm/s)
I_alpha: float # Mass moment of inertia of the wing-flap about wing EA per unit span (0.01347 kgm)
I_beta: float # Mass moment of inertia of the flap about the flap hinge line per unit span (0.0003264 kgm)
k_h: float # linear strctural stiffness coefficient of plunging per unit span
Expand All @@ -35,9 +32,158 @@ class Vars:
zeta_beta: float # flap damping ratio
U: float # velocity

def alpha_freeplay(alpha, M0 = 0.0, Mf = 0.0, delta = np.radians(4.24), a_f = np.radians(-2.12)):
if (alpha < a_f):
return M0 + alpha - a_f
elif (alpha >= a_f and alpha <= (a_f + delta)):
return M0 + Mf * (alpha - a_f)
else: # alpha > a_F + delta
return M0 + alpha - a_f + delta * (Mf - 1)

def alpha_linear(alpha):
return alpha

def create_monolithic_system(y0: np.ndarray, v: Vars):
# def monolithic_system(t, y: np.ndarray):
# A = np.zeros((8,8))

# M_s = np.zeros((3,3)) # dimensionless structural intertia matrix
# D_s = np.zeros((3,3)) # dimensionless structural damping matrix
# K_s = np.zeros((3,3)) # dimensionless structural stiffness matrix

# sigma = v.omega_h / v.omega_alpha
# V = v.U / (v.b * v.omega_alpha)
# mu = v.m / (np.pi * v.rho * v.b**2)

# M_s[0, 0] = v.m_t / v.m
# M_s[0, 1] = v.x_alpha
# M_s[0, 2] = v.x_beta
# M_s[1, 0] = v.x_alpha
# M_s[1, 1] = v.r_alpha**2
# M_s[1, 2] = (v.c - v.a) * v.x_beta + v.r_beta**2
# M_s[2, 0] = v.x_beta
# M_s[2, 1] = (v.c - v.a) * v.x_beta + v.r_beta**2
# M_s[2, 2] = v.r_beta**2
# M_s = mu * M_s

# D_s[0, 0] = sigma * v.zeta_h
# D_s[1, 1] = v.r_alpha**2 * v.zeta_alpha
# D_s[2, 2] = (v.omega_beta / v.omega_alpha) * v.r_beta**2 * v.zeta_beta
# D_s = 2 * mu * D_s

# gamma = 10 # Cubic factor (0 for linear spring)
# K_s[0, 0] = sigma**2 * (1 + gamma * y[3]**2)
# K_s[1, 1] = v.r_alpha**2
# K_s[2, 2] = (v.omega_beta / v.omega_alpha)**2 * v.r_beta**2
# K_s = mu * K_s

# sqrt_1_minus_c2 = np.sqrt(1 - v.c**2)
# acos_c = np.arccos(v.c)

# T1 = (-1/3) * sqrt_1_minus_c2 * (2 + v.c**2) + v.c * acos_c
# T2 = v.c * (1 - v.c**2) - sqrt_1_minus_c2 * (1 + v.c**2) * acos_c + v.c * (acos_c)**2
# T3 = -((1/8) + v.c**2) * (acos_c)**2 + (1/4) * v.c * sqrt_1_minus_c2 * acos_c * (7 + 2*v.c**2) - (1/8) * (1 - v.c**2) * (5 * v.c**2 + 4)
# T4 = -acos_c + v.c * sqrt_1_minus_c2
# T5 = -(1 - v.c**2) - (acos_c)**2 + 2 * v.c * sqrt_1_minus_c2 * acos_c
# T6 = T2
# T7 = -((1/8) + v.c**2) * acos_c + (1/8) * v.c * sqrt_1_minus_c2 * (7 + 2 * v.c**2)
# T8 = (-1/3) * sqrt_1_minus_c2 * (2 * v.c**2 + 1) + v.c * acos_c
# T9 = (1/2) * ((1/3) * (sqrt_1_minus_c2)**3 + v.a * T4)
# T10 = sqrt_1_minus_c2 + acos_c
# T11 = acos_c * (1 - 2 * v.c) + sqrt_1_minus_c2 * (2 - v.c)
# T12 = sqrt_1_minus_c2 * (2 + v.c) - acos_c * (2 * v.c + 1)
# T13 = (1/2) * (-T7 - (v.c - v.a) * T1)
# T14 = (1/16) + (1/2) * v.a * v.c

# M_a = np.zeros((3,3)) # dimensionless aerodynamic inertia matrix
# D_a = np.zeros((3,3)) # dimensionless aerodynamic damping matrix
# K_a = np.zeros((3,3)) # dimensionless aerodynamic stiffness matrix
# L_delta = np.zeros((3, 2)) # dimensionless aero lagging matrix
# Q_a = np.zeros((2, 3)) # matrix of terms multiplied by the modal accelerations
# Q_v = np.zeros((2, 3)) # matrix of terms multiplied by the modal velocities
# L_lambda = np.zeros((2, 2))

# M_a[0, 0] = -1
# M_a[0, 1] = v.a
# M_a[0, 2] = T1 / np.pi
# M_a[1, 0] = v.a
# M_a[1, 1] = -(1/8 + v.a**2)
# M_a[1, 2] = -2 * T13 / np.pi
# M_a[2, 0] = T1 / np.pi
# M_a[2, 1] = -2 * T13 / np.pi
# M_a[2, 2] = T3 / (np.pi**2)

# D_a[0, 0] = (-2)
# D_a[0, 1] = (-2 * (1 - v.a))
# D_a[0, 2] = (T4 - T11) / np.pi
# D_a[1, 0] = (1 + 2 * v.a)
# D_a[1, 1] = (v.a * (1 - 2 * v.a))
# D_a[1, 2] = (T8 - T1 + (v.c - v.a) * T4 + v.a * T11) / np.pi
# D_a[2, 0] = (-T12 / np.pi)
# D_a[2, 1] = (2 * T9 + T1 + (T12 - T4) * (v.a - 0.5)) / np.pi
# D_a[2, 2] = (T11 * (T4 - T12)) / (2 * np.pi**2)
# D_a = V * D_a

# K_a[0, 0] = 0
# K_a[0, 1] = (-2)
# K_a[0, 2] = (-2 * T10) / np.pi
# K_a[1, 0] = 0
# K_a[1, 1] = (1 + 2 * v.a)
# K_a[1, 2] = (2 * v.a * T10 - T4) / np.pi
# K_a[2, 0] = 0
# K_a[2, 1] = (-T12) / np.pi
# K_a[2, 2] = (-1 / np.pi**2) * (T5 - T10 * (T4 - T12))
# K_a = V**2 * K_a

# # Difference lies between coeffs of R.T Jones and W.P Jones
# # Yung p220
# d1 = 0.165
# d2 = 0.335
# # l1 = 0.041
# # l2 = 0.320
# l1 = 0.0455
# l2 = 0.300

# L_delta[0, 0] = d1
# L_delta[0, 1] = d2
# L_delta[1, 0] = - (0.5 + v.a) * d1
# L_delta[1, 1] = - (0.5 + v.a) * d2
# L_delta[2, 0] = T12 * d1 / (2 * np.pi)
# L_delta[2, 1] = T12 * d2 / (2 * np.pi)
# L_delta = 2 * V * L_delta

# Q_a[0, 0] = 1
# Q_a[0, 1] = 0.5 - v.a
# Q_a[0, 2] = T11 / (2 * np.pi)
# Q_a[1, 0] = 1
# Q_a[1, 1] = 0.5 - v.a
# Q_a[1, 2] = T11 / (2 * np.pi)

# Q_v[0, 1] = 1
# Q_v[0, 2] = T10 / np.pi
# Q_v[1, 1] = 1
# Q_v[1, 2] = T10 / np.pi
# Q_v = V * Q_v

# L_lambda[0, 0] = - l1
# L_lambda[1, 1] = - l2
# L_lambda = V * L_lambda

# inv_inert_mat = np.linalg.inv(M_s - M_a)
# A[0:3, 0:3] = - inv_inert_mat @ (D_s - D_a)
# A[0:3, 3:6] = - inv_inert_mat @ (K_s - K_a)
# A[0:3, 6:8] = inv_inert_mat @ L_delta
# A[3:6, 0:3] = np.eye(3)
# A[6:8, 0:3] = Q_a @ A[0:3, 0:3]+ Q_v
# A[6:8, 3:6] = Q_a @ A[0:3, 3:6]
# A[6:8, 6:8] = Q_a @ A[0:3, 6:8] + L_lambda

# return A @ y

def monolithic_system(t, y: np.ndarray):
A = np.zeros((8,8))
M1 = np.zeros((8, 8))
M2 = np.zeros((8, 8))
yn = np.zeros(8) # nonlinear terms

M_s = np.zeros((3,3)) # dimensionless structural intertia matrix
D_s = np.zeros((3,3)) # dimensionless structural damping matrix
Expand Down Expand Up @@ -127,6 +273,8 @@ def monolithic_system(t, y: np.ndarray):
K_a[2, 2] = (-1 / np.pi**2) * (T5 - T10 * (T4 - T12))
K_a = V**2 * K_a

# Difference lies between coeffs of R.T Jones and W.P Jones
# Yung p220
d1 = 0.165
d2 = 0.335
# l1 = 0.041
Expand Down Expand Up @@ -159,16 +307,20 @@ def monolithic_system(t, y: np.ndarray):
L_lambda[1, 1] = - l2
L_lambda = V * L_lambda

inv_inert_mat = np.linalg.inv(M_s - M_a)
A[0:3, 0:3] = - inv_inert_mat @ (D_s - D_a)
A[0:3, 3:6] = - inv_inert_mat @ (K_s - K_a)
A[0:3, 6:8] = inv_inert_mat @ L_delta
A[3:6, 0:3] = np.eye(3)
A[6:8, 0:3] = Q_a @ A[0:3, 0:3]+ Q_v
A[6:8, 3:6] = Q_a @ A[0:3, 3:6]
A[6:8, 6:8] = Q_a @ A[0:3, 6:8] + L_lambda
M2[0:3, 0:3] = M_s - M_a
M2[3:6, 3:6] = np.eye(3)
M2[6:8, 6:8] = np.eye(2)
# M2[3:8, 3:8] = np.eye(5)
M2[6:8, 0:3] = - Q_a

return A @ y
M1[0:3, 0:3] = D_a - D_s
M1[0:3, 3:6] = K_a - K_s
M1[0:3, 6:8] = L_delta
M1[3:6, 0:3] = np.eye(3)
M1[6:8, 0:3] = Q_v
M1[6:8, 6:8] = L_lambda

return np.linalg.solve(M2, M1 @ y + yn)

return monolithic_system

Expand Down Expand Up @@ -237,33 +389,59 @@ def format_subplot(fig, row, col, xlabel, ylabel):
)

if __name__ == "__main__":
# Darabseh 2022
# v = Vars(
# a = -0.5,
# b = 0.127, # m
# c = 0.5,
# I_alpha = 0.01347, # kgm
# I_beta = 0.0003264, # kgm
# k_h = 2818.8, # kg/ms^2
# k_alpha = 37.34, # kg/ms^2
# k_beta = 3.9, # kg/ms^2
# m = 1.558, # kg/m
# m_t = 3.3843, # kg/m
# r_alpha = 0.7321,
# r_beta = 0.1140,
# S_alpha = 0.08587, # kg
# S_beta = 0.00395, # kg
# x_alpha = 0.4340,
# x_beta = 0.02,
# omega_h = 42.5352, # Hz
# omega_alpha = 52.6506, # Hz
# omega_beta = 109.3093,
# rho = 1.225, # kg/m^3
# zeta_h = 0.0133,
# zeta_alpha = 0.01626,
# zeta_beta = 0.0133,
# U = 23.72 # m/s
# )

# Conner
v = Vars(
a = -0.5,
b = 0.127, # m
c = 0.5,
C_h = 1.7628, # kg/ms
C_alpha = 0.0231, # kg/ms
C_beta = 0.0008, # kg/ms
I_alpha = 0.01347, # kgm
I_beta = 0.0003264, # kgm
k_h = 2818.8, # kg/ms^2
k_alpha = 37.34, # kg/ms^2
k_beta = 3.9, # kg/ms^2
m = 1.558, # kg/m
m_t = 3.3843, # kg/m
m = 1.5666, # kg/m
m_t = 3.39298, # kg/m
r_alpha = 0.7321,
r_beta = 0.1140,
S_alpha = 0.08587, # kg
S_beta = 0.00395, # kg
x_alpha = 0.4340,
x_beta = 0.02,
omega_h = 42.5352, # Hz
omega_alpha = 52.6506, # Hz
omega_beta = 109.3093,
omega_h = 42.5352, # rad/s
omega_alpha = 52.6506, # rad/s
omega_beta = 109.3093, # rad/s
rho = 1.225, # kg/m^3
zeta_h = 0.0133,
zeta_h = 0.0113,
zeta_alpha = 0.01626,
zeta_beta = 0.0133,
zeta_beta = 0.0115,
U = 23.72 # m/s
)

Expand All @@ -277,7 +455,7 @@ def format_subplot(fig, row, col, xlabel, ylabel):
0, # dh / dt
0, # dalpha / dt
0, # dbeta / dt
0.005 / v.b, # h
0.01 / v.b, # h
0, # alpha
0, # beta
0, # x1
Expand Down
Loading

0 comments on commit b07ddab

Please sign in to comment.