Skip to content

Commit

Permalink
Merge pull request #56 from Haruki-Yama/fix-my-new-feature
Browse files Browse the repository at this point in the history
npm->nps
  • Loading branch information
taiga4112 authored Oct 3, 2024
2 parents 0cffe65 + 8d5e5f1 commit fb9ef17
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 127 deletions.
72 changes: 36 additions & 36 deletions shipmmg/mmg_3dof.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def simulate_mmg_3dof(
maneuvering_params: Mmg3DofManeuveringParams,
time_list: List[float],
δ_list: List[float],
npm_list: List[float],
nps_list: List[float],
u0: float = 0.0,
v0: float = 0.0,
r0: float = 0.0,
Expand Down Expand Up @@ -209,8 +209,8 @@ def simulate_mmg_3dof(
time list of simulation.
δ_list (list[float]):
rudder angle list of simulation.
npm_list (List[float]):
npm list of simulation.
nps_list (List[float]):
nps list of simulation.
u0 (float, optional):
axial velocity [m/s] in initial condition (`time_list[0]`).
Defaults to 0.0.
Expand Down Expand Up @@ -329,7 +329,7 @@ def simulate_mmg_3dof(
>>> sampling = 2000
>>> time_list = np.linspace(0.00, duration, sampling)
>>> δ_list = np.full(len(time_list), 35.0 * np.pi / 180.0)
>>> npm_list = np.full(len(time_list), 20.338)
>>> nps_list = np.full(len(time_list), 20.338)
>>> basic_params = Mmg3DofBasicParams(
>>> L_pp=7.00,
>>> B=1.27,
Expand Down Expand Up @@ -384,7 +384,7 @@ def simulate_mmg_3dof(
>>> maneuvering_params,
>>> time_list,
>>> δ_rad_list,
>>> npm_list,
>>> nps_list,
>>> u0=2.29 * 0.512,
>>> )
>>> result = sol.sol(time_list)
Expand Down Expand Up @@ -445,7 +445,7 @@ def simulate_mmg_3dof(
N_rrr_dash=maneuvering_params.N_rrr_dash,
time_list=time_list,
δ_list=δ_list,
npm_list=npm_list,
nps_list=nps_list,
u0=u0,
v0=v0,
r0=r0,
Expand Down Expand Up @@ -509,7 +509,7 @@ def simulate(
N_rrr_dash: float,
time_list: List[float],
δ_list: List[float],
npm_list: List[float],
nps_list: List[float],
u0: float = 0.0,
v0: float = 0.0,
r0: float = 0.0,
Expand Down Expand Up @@ -630,8 +630,8 @@ def simulate(
time list of simulation.
δ_list (list[float]):
rudder angle list of simulation.
npm_list (List[float]):
npm list of simulation.
nps_list (List[float]):
nps list of simulation.
u0 (float, optional):
axial velocity [m/s] in initial condition (`time_list[0]`).
Defaults to 0.0.
Expand Down Expand Up @@ -750,7 +750,7 @@ def simulate(
>>> sampling = 2000
>>> time_list = np.linspace(0.00, duration, sampling)
>>> δ_list = np.full(len(time_list), 35.0 * np.pi / 180.0)
>>> npm_list = np.full(len(time_list), 17.95)
>>> nps_list = np.full(len(time_list), 17.95)
>>> L_pp=7.00
>>> B=1.27
>>> d=0.46
Expand Down Expand Up @@ -842,7 +842,7 @@ def simulate(
>>> N_rrr_dash=N_rrr_dash,
>>> time_list,
>>> δ_rad_list,
>>> npm_list,
>>> nps_list,
>>> u0=2.29 * 0.512,
>>> )
>>> result = sol.sol(time_list)
Expand All @@ -855,11 +855,11 @@ def simulate(
"""
spl_δ = interp1d(time_list, δ_list, "cubic", fill_value="extrapolate")
spl_npm = interp1d(time_list, npm_list, "cubic", fill_value="extrapolate")
spl_nps = interp1d(time_list, nps_list, "cubic", fill_value="extrapolate")

def mmg_3dof_eom_solve_ivp(t, X):

u, v, r, x, y, ψ, δ, npm = X
u, v, r, x, y, ψ, δ, nps = X

U = np.sqrt(u**2 + (v - r * x_G) ** 2)

Expand All @@ -870,13 +870,13 @@ def mmg_3dof_eom_solve_ivp(t, X):
# w_P = w_P0
w_P = w_P0 * np.exp(-4.0 * (β - x_P * r_dash) ** 2)

J = 0.0 if npm == 0.0 else (1 - w_P) * u / (npm * D_p)
J = 0.0 if nps == 0.0 else (1 - w_P) * u / (nps * D_p)
K_T = k_0 + k_1 * J + k_2 * J**2
β_R = β - l_R * r_dash
γ_R = γ_R_minus if β_R < 0.0 else γ_R_plus
v_R = U * γ_R * β_R
u_R = (
np.sqrt(η * (κ * ϵ * 8.0 * k_0 * npm**2 * D_p**4 / np.pi) ** 2)
np.sqrt(η * (κ * ϵ * 8.0 * k_0 * nps**2 * D_p**4 / np.pi) ** 2)
if J == 0.0
else u
* (1 - w_P)
Expand Down Expand Up @@ -905,7 +905,7 @@ def mmg_3dof_eom_solve_ivp(t, X):
)
)
X_R = -(1 - t_R) * F_N * np.sin(δ)
X_P = (1 - t_P) * ρ * K_T * npm**2 * D_p**4
X_P = (1 - t_P) * ρ * K_T * nps**2 * D_p**4
Y_H = (
0.5
* ρ
Expand Down Expand Up @@ -949,13 +949,13 @@ def mmg_3dof_eom_solve_ivp(t, X):
d_y = u * np.sin(ψ) + v * np.cos(ψ)
d_ψ = r
d_δ = derivative(spl_δ, t)
d_npm = derivative(spl_npm, t)
return [d_u, d_v, d_r, d_x, d_y, d_ψ, d_δ, d_npm]
d_nps = derivative(spl_nps, t)
return [d_u, d_v, d_r, d_x, d_y, d_ψ, d_δ, d_nps]

sol = solve_ivp(
mmg_3dof_eom_solve_ivp,
[time_list[0], time_list[-1]],
[u0, v0, r0, x0, y0, ψ0, δ_list[0], npm_list[0]],
[u0, v0, r0, x0, y0, ψ0, δ_list[0], nps_list[0]],
dense_output=True,
method=method,
t_eval=t_eval,
Expand All @@ -971,7 +971,7 @@ def get_sub_values_from_simulation_result(
v_list: List[float],
r_list: List[float],
δ_list: List[float],
npm_list: List[float],
nps_list: List[float],
basic_params: Mmg3DofBasicParams,
maneuvering_params: Mmg3DofManeuveringParams,
ρ: float = 1025.0,
Expand All @@ -988,8 +988,8 @@ def get_sub_values_from_simulation_result(
r list of MMG simulation result.
δ_list (List[float]):
δ list of MMG simulation result.
npm_list (List[float]):
npm list of MMG simulation result.
nps_list (List[float]):
nps list of MMG simulation result.
basic_params (Mmg3DofBasicParams):
u of MMG simulation result.
maneuvering_params (Mmg3DofManeuveringParams):
Expand Down Expand Up @@ -1056,12 +1056,12 @@ def get_sub_values_from_simulation_result(
)
J_list = list(
map(
lambda w_P, u, npm: 0.0
if npm == 0.0
else (1 - w_P) * u / (npm * basic_params.D_p),
lambda w_P, u, nps: 0.0
if nps == 0.0
else (1 - w_P) * u / (nps * basic_params.D_p),
w_P_list,
u_list,
npm_list,
nps_list,
)
)
K_T_list = list(
Expand Down Expand Up @@ -1095,14 +1095,14 @@ def get_sub_values_from_simulation_result(
)
u_R_list = list(
map(
lambda u, J, npm, K_T, w_P: np.sqrt(
lambda u, J, nps, K_T, w_P: np.sqrt(
basic_params.η
* (
basic_params.κ
* basic_params.ϵ
* 8.0
* maneuvering_params.k_0
* npm**2
* nps**2
* basic_params.D_p**4
/ np.pi
)
Expand All @@ -1123,7 +1123,7 @@ def get_sub_values_from_simulation_result(
),
u_list,
J_list,
npm_list,
nps_list,
K_T_list,
w_P_list,
)
Expand Down Expand Up @@ -1170,13 +1170,13 @@ def get_sub_values_from_simulation_result(
)
X_P_list = list(
map(
lambda K_T, npm: (1 - basic_params.t_P)
lambda K_T, nps: (1 - basic_params.t_P)
* ρ
* K_T
* npm**2
* nps**2
* basic_params.D_p**4,
K_T_list,
npm_list,
nps_list,
)
)
Y_H_list = list(
Expand Down Expand Up @@ -1274,7 +1274,7 @@ def zigzag_test_mmg_3dof(
target_δ_rad: float,
target_ψ_rad_deviation: float,
time_list: List[float],
npm_list: List[float],
nps_list: List[float],
δ0: float = 0.0,
δ_rad_rate: float = 1.0 * np.pi / 180,
u0: float = 0.0,
Expand Down Expand Up @@ -1303,8 +1303,8 @@ def zigzag_test_mmg_3dof(
target absolute value of psi deviation from ψ0[rad].
time_list (list[float]):
time list of simulation.
npm_list (List[float]):
npm list of simulation.
nps_list (List[float]):
nps list of simulation.
δ0 (float):
Initial rudder angle [rad].
Defaults to 0.0.
Expand Down Expand Up @@ -1453,7 +1453,7 @@ def zigzag_test_mmg_3dof(
maneuvering_params,
time_list[start_index:],
δ_list,
npm_list[start_index:],
nps_list[start_index:],
u0=u0,
v0=v0,
r0=r0,
Expand Down
42 changes: 21 additions & 21 deletions shipmmg/ship_obj_3dof.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class ShipObj3dof:
List of azimuth [rad] in simulation result.
δ (list[float]):
rudder angle list of simulation.
npm (List[float]):
npm list of simulation.
nps (List[float]):
nps list of simulation.
"""

# Ship overview
Expand All @@ -66,7 +66,7 @@ class ShipObj3dof:
y: List[float] = dataclasses.field(default_factory=list)
psi: List[float] = dataclasses.field(default_factory=list)
δ: List[float] = dataclasses.field(default_factory=list)
npm: List[float] = dataclasses.field(default_factory=list)
nps: List[float] = dataclasses.field(default_factory=list)

def register_simulation_result(
self,
Expand Down Expand Up @@ -422,8 +422,8 @@ def draw_chart(
target_x = self.δ
elif x_index == "δ":
target_x = self.δ
elif x_index == "npm":
target_x = self.npm
elif x_index == "nps":
target_x = self.nps
if target_x is None:
raise Exception(
"`x_index` is not good. Please set `x_index` from ["
Expand All @@ -445,7 +445,7 @@ def draw_chart(
", "
" δ"
", "
" npm"
" nps"
"]"
)

Expand All @@ -468,8 +468,8 @@ def draw_chart(
target_y = self.δ
elif y_index == "δ":
target_y = self.δ
elif y_index == "npm":
target_y = self.npm
elif y_index == "nps":
target_y = self.nps
if target_y is None:
raise Exception(
"`y_index` is not good. Please set `y_index` from ["
Expand All @@ -491,7 +491,7 @@ def draw_chart(
", "
" δ"
", "
" npm"
" nps"
"]"
"]"
)
Expand Down Expand Up @@ -636,8 +636,8 @@ def draw_multi_x_chart(
target_y = self.δ
elif y_index == "δ":
target_y = self.δ
elif y_index == "npm":
target_y = self.npm
elif y_index == "nps":
target_y = self.nps
if target_y is None:
raise Exception(
"`x_index` is not good. Please set `x_index` from ["
Expand All @@ -659,7 +659,7 @@ def draw_multi_x_chart(
", "
" δ"
", "
" npm"
" nps"
"]"
)

Expand All @@ -683,8 +683,8 @@ def draw_multi_x_chart(
target_x_list.append(self.δ)
elif x_index == "δ":
target_x_list.append(self.δ)
elif x_index == "npm":
target_x_list.append(self.npm)
elif x_index == "nps":
target_x_list.append(self.nps)
if len(target_x_list) == 0:
raise Exception(
"`y_index` is not good. Please set `y_index` from ["
Expand All @@ -706,7 +706,7 @@ def draw_multi_x_chart(
", "
" δ"
", "
" npm"
" nps"
"]"
"]"
)
Expand Down Expand Up @@ -853,8 +853,8 @@ def draw_multi_y_chart(
target_x = self.δ
elif x_index == "δ":
target_x = self.δ
elif x_index == "npm":
target_x = self.npm
elif x_index == "nps":
target_x = self.nps
if target_x is None:
raise Exception(
"`x_index` is not good. Please set `x_index` from ["
Expand All @@ -876,7 +876,7 @@ def draw_multi_y_chart(
", "
" δ"
", "
" npm"
" nps"
"]"
)

Expand All @@ -900,8 +900,8 @@ def draw_multi_y_chart(
target_y_list.append(self.δ)
elif y_index == "δ":
target_y_list.append(self.δ)
elif y_index == "npm":
target_y_list.append(self.npm)
elif y_index == "nps":
target_y_list.append(self.nps)
if len(target_y_list) == 0:
raise Exception(
"`y_index` is not good. Please set `y_index` from ["
Expand All @@ -923,7 +923,7 @@ def draw_multi_y_chart(
", "
" δ"
", "
" npm"
" nps"
"]"
"]"
)
Expand Down
Loading

0 comments on commit fb9ef17

Please sign in to comment.